Home arrow JavaScript arrow Page 3 - Developing the Behavioral Layer for a Content Management System with Prototype
JAVASCRIPT

Developing the Behavioral Layer for a Content Management System with Prototype


The Prototype JavaScript framework has become extremely popular with many web developers. This makes possible the development of many web applications that use the remarkable AJAX capabilities that come packaged with this library. In this article in particular, the functionality of Prototype is utilized to build a highly expandable content management system, so if you're interested in learning how this application will be created, start reading now!

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
April 23, 2007
TABLE OF CONTENTS:
  1. · Developing the Behavioral Layer for a Content Management System with Prototype
  2. · The full source code of the previously developed front-end
  3. · Working with Prototype's AJAX.Updater object
  4. · The full client-side code of the application

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials