Changeset 8886

Show
Ignore:
Timestamp:
04/29/08 16:07:10 (4 months ago)
Author:
hannes
Message:

* Improve code organization in main module.
* Add some comments to model module.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/minibase/trunk/demo/main.js

    r8884 r8886  
    1010    var books = model.Book.all(); 
    1111    if (req.data.save) { 
    12         var book = new model.Book({author: req.data.author, title: req.data.title}); 
    13         book.save(); 
    14         res.redirect('/'); 
     12        createBook(); 
    1513    } 
    1614    if (req.data.remove) { 
    17         var book = model.Book.get(req.data.remove); 
    18         book.remove(); 
    19         res.redirect('/'); 
     15        removeBook(); 
    2016    } 
    2117    renderSkin('skins/index.html', { 
     
    3026} 
    3127 
     28function createBook() { 
     29    var book = new model.Book({author: req.data.author, title: req.data.title}); 
     30    book.save(); 
     31    res.redirect('/'); 
     32} 
     33 
     34function removeBook() { 
     35    var book = model.Book.get(req.data.remove); 
     36    book.remove(); 
     37    res.redirect('/'); 
     38} 
     39 
    3240function getDeleteLink(book) { 
    3341    return '<a href="/?remove=' + book._id + '">delete</a>'; 
  • sandbox/minibase/trunk/demo/model.js

    r8884 r8886  
    33 
    44/** 
    5  * Our model class 
     5 * Our model class. The only thing to observe is to return a Storable 
     6 * instance, passing this object and an object containing the persistent 
     7 * properties to the Storable constructor. 
     8 *  
    69 * @param properties persistent properties container 
    710 */ 
     
    1215    } 
    1316 
    14     return new db.Storable(this, properties); 
     17    return new db.Storable(this, properties || {}); 
    1518} 
    1619 
     20// init store instance and register persistent classes 
    1721db.store = db.store || new db.Store("db"); 
    1822db.store.registerType(Book);