Thursday, 25 November 2010

Enhancing the editor

I realise I've not updated the blog for a while, so apologies for that. A mixture of work and other engagements has meant that I've not had the time to get some thoughts down for a while!

One area of N2 I've had to look at in recent months are the editor pages. At first glimpse it might seem that there's not a great deal you can do with them to specialise them seeing as they are to cater for the creating and editing of every single page type in your website. I've not needed to go into the guts of how the editor works as yet, but I've found a few things that might be of interest and certainly may help you get round a few tricky areas.

You will have to bear with me on this whilst I explain the background to the problem. On one recent project, I had a simple hierarchy similar to this:

Suppliers 

  • WH Smith (all our books cost £10 and our magazines £5)
  • News International (all our books cost £12 and our magazines £3)

Products

  • Books
    • Call of the wild
    • The Hobbit
    • Lord of the Rings
  • Magazines
    • FMH
    • Shoot
    • Radio Times
So each supplier has a set price list and when you create a book or a magazine you have to select a supplier and then display the "summary" of that supplier including the prices. In effect the problem we have then is to take something that is generic (the creator/editor) yet add code to handle specifics. I appreciate there is ways to do this, but I didn't really want (for time reasons primarily) to get my hands dirty in the source code of N2. 

The way I did this though was to use jQuery to make Ajax calls to a web handler (ASHX files).  I'd written which returned XML with details of the supplier. My jQuery code detected the type of page we're creating and then hooked in the calls to update the supplier summary if the supplier changed. When I get more time, I will try to package a simple example of this to demonstrate the principle. In effect it is just  a jQuery/Ajax solution but it certainly allows the N2 editor to potentially become even more responsive and powerful. Taken further, maybe we can add some jQuery features to the editor to check for the uniqueness of page titles, maybe even preview the page you're working as you type!

I am not saying this method is perfect at all, but in future it's certainly a technique  I'd definitely consider again.

No comments:

Post a Comment