JavaScript
  Home arrow JavaScript arrow Page 3 - Developing the Behavioral Layer for a Cont...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Developing the Behavioral Layer for a Content Management System with Prototype
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-04-23

    Table of Contents:
  • Developing the Behavioral Layer for a Content Management System with Prototype
  • The full source code of the previously developed front-end
  • Working with Prototype's AJAX.Updater object
  • The full client-side code of the application

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing the Behavioral Layer for a Content Management System with Prototype - Working with Prototype's AJAX.Updater object


    (Page 3 of 4 )

    In consonance with the concepts that I expressed in the section you just read, the insertion of new articles into the system, including relevant data such as titles, authors and texts, as well as the pertinent update and deletion of them will be executed via the "AJAX.Updater" object that belongs to the Prototype package.

    Based on this simple yet efficient schema, below I included a bunch of JavaScript functions which are tasked with performing the aforementioned processes, in addition to executing some useful initialization tasks.

    Having said that, please take a look at the signatures of these brand new functions, which look like this:

    <script language="javascript">
     
    // add new article to database table
     
    function uploadArticle(e){
        
    var params='command='+$F('command')+'&id='+$F('id')
    +'&title='+$F('title')+'&author='+$F('author')+'&content='+escape
    ($F('content'));
        
    var xmlobj=new Ajax.Updater
    ('contents','handle_articles.php',{method: 'get',parameters:
    params, evalScripts: true});
        
    // prevent form from submitting
        
    Event.stop(e);
        
    // reset header message
        
    Element.update('header','PROTOTYPE-BASED CMS');
        
    $('command').value='upload';
     
    }

      // update article into database table
     
    function editArticle(id,title,author,content){
        
    Element.update('header','EDITING ARTICLE...');
        
    $('title').value=title;
        
    $('author').value=author;
        
    $('content').value=content;
        
    $('id').value=id;
        
    $('command').value='update';
     
    }

      // delete article from database table
     
    function deleteArticle(id){
        
    var params='command=delete&id='+id;
        
    var xmlobj=new Ajax.Updater('contents','handle_articles.php',{method: 'get',parameters:
    params, evalScripts: true});
     
    }

      // attach handler to window object
     
    Event.observe(window,'load',initializeCMS,false);

      // initialize CMS application
     
    function initializeCMS(){

      // attach handler to article form
     
    Event.observe('articleform','submit',uploadArticle);

      // display list of articles when web page is loaded
     
    var xmlobj=new Ajax.Updater('contents','handle_articles.php',{method: 'get'});
    }
    </script>

    As you can see, the set of JavaScript functions listed above is indeed very easy to grasp. These functions perform some well-differentiated processes, like inserting new articles into the pertinent MySQL database table, as well as updating existing entries. I decided to use the same web form included in the corresponding user interface, either to add or edit the contents of a certain article, but this condition can be easily modified to utilize separate forms.

    Finally, the rest of the previous JavaScript functions are pretty straightforward, since they initialize the content management system in question and also assign the corresponding "submit" handler to the mentioned insertion/update web form. Quite simple, isn't it?

    So far, so good. At this stage I have shown you the signatures of the JavaScript functions that are responsible for adding new articles to the system, in addition to updating/deleting existing entries. Thus, the question that comes up now is: what's the next step?

    Well, since I'm pretty certain that you want to see how the previous functions and the client-side layers that were developed in the first article of the series are linked together, in the section to come I'm going to show you the complete source code of this Prototype-based CMS. Naturally this time I will include the aforementioned JavaScript functions.

    To see how the complete client-side code of the content management system will look, please go ahead and read the next few lines. I'll be there, waiting for you.

    More JavaScript Articles
    More By Alejandro Gervasio


       · This second part of the series is focused entirely on demonstrating in a...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT