source: Dev/branches/rest-dojo-ui/client/rft/pages/questions.js @ 414

Last change on this file since 414 was 414, checked in by hendrikvanantwerpen, 12 years ago

Small issues for db name, widgets, startup.

Don't start application when database is not configured correctly.
Refactored edit widgets to use DefaultEdit?.
Fixed bug in getItems of Lists.
Renamed database to 'qed'.

File size: 2.4 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/Deferred',
4    'dojo/_base/event',
5    'dojo/_base/lang',
6    '../store',
7    '../app/Content',
8    '../app/Router',
9    '../app/Page',
10    '../ui/TabbedQuestionBrowser',
11    'dojo/text!./questions.html'
12],function(declare,Deferred,event,lang,store,Content,Router,Page,TabbedQuestionBrowser,template) {
13    return declare([Page],{
14        templateString: template,
15        startup: function() {
16            if ( this._started ) { return; }
17            this.inherited(arguments);
18            this.questionBrowser = new TabbedQuestionBrowser({
19                region: 'center',
20                'class': 'orange',
21                itemActions: {
22                    Delete: {
23                        callback: lang.hitch(this,"onDeleteQuestion"),
24                        icon: 'Delete',
25                        description: 'Delete question'
26                    },
27                    Edit: {
28                        callback: lang.hitch(this,"onEditQuestion"),
29                        icon: 'Edit',
30                        description: 'Edit question'
31                    },
32                    Publish: {
33                        callback: lang.hitch(this,"onPublishQuestion"),
34                        icon: 'Publish',
35                        description: 'Publish question'
36                    }
37                }
38            },this.questionBrowser);
39            this.questionBrowser.startup();
40        },
41        onNewQuestion: function() {
42            Deferred.when(store.add({type:'Question'}))
43            .then(lang.hitch(this,function(question){
44                this.onEditQuestion(question);
45            }));
46        },
47        onDeleteQuestion: function(question) {
48            store.remove(store.getIdentity(question),store.getRevision(question))
49            .then(function(){
50                Content.notify("Question deleted.");
51            },function(err){
52                Content.notify(err.reason,'error');
53            });
54        },
55        onEditQuestion: function(question) {
56            Router.go("/question/"+question._id);
57        },
58        onPublishQuestion: function(question) {
59            question.publicationDate = store.timestamp();
60            store.put(question)
61            .then(function(){
62                Content.notify("Question published.");
63            },function(err){
64                Content.notify(err.reason,'error');
65            });
66        }
67    });
68});
Note: See TracBrowser for help on using the repository browser.