root/sandbox/minibase/trunk/demo/main.js

Revision 8895, 1.0 kB (checked in by hannes, 2 years ago)

* Only fetch books when needed.

  • Property svn:eol-style set to native
Line 
1 importFromModule('helma.simpleweb', 'handleRequest');
2 importFromModule('helma.skin', 'renderSkin');
3 // db model
4 importModule('model');
5
6
7 // the main action is invoked for http://localhost:8080/
8 // this also shows simple skin rendering
9 function main_action() {
10     if (req.data.save) {
11         createBook();
12     }
13     if (req.data.remove) {
14         removeBook();
15     }
16     var books = model.Book.all();
17     renderSkin('skins/index.html', {
18         title: 'Minibase Demo',
19         books: function(/*tag, skin, context*/) {
20             for (var i in books) {
21                 var book = books[i]
22                 res.writeln(book.getFullTitle(), getDeleteLink(book), "<br>");
23             }
24         }
25     });
26 }
27
28 function createBook() {
29     var book = new model.Book({author: req.data.author, title: req.data.title});
30     book.save();
31     res.redirect('/');
32 }
33
34 function removeBook() {
35     var book = model.Book.get(req.data.remove);
36     book.remove();
37     res.redirect('/');
38 }
39
40 function getDeleteLink(book) {
41     return '<a href="/?remove=' + book._id + '">delete</a>';
42 }
Note: See TracBrowser for help on using the browser.