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

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

Put all model dependent code in one place. More separation of general and domain code.

File size: 2.3 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    '../model/widgets/TabbedQuestionBrowser',
11    'dojo/text!./templates/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            Router.go("/question/new");
43        },
44        onDeleteQuestion: function(question) {
45            store.remove(store.getIdentity(question),store.getRevision(question))
46            .then(function(){
47                Content.notify("Question deleted.");
48            },function(err){
49                Content.notify(err,'error');
50            });
51        },
52        onEditQuestion: function(question) {
53            Router.go("/question/"+question._id);
54        },
55        onPublishQuestion: function(question) {
56            question.publicationDate = store.timestamp();
57            store.put(question)
58            .then(function(){
59                Content.notify("Question published.");
60            },function(err){
61                Content.notify(err,'error');
62            });
63        }
64    });
65});
Note: See TracBrowser for help on using the repository browser.