source: Dev/trunk/src/client/qed-client/pages/questions.js @ 495

Last change on this file since 495 was 495, checked in by hendrikvanantwerpen, 11 years ago
File size: 2.8 KB
Line 
1define([
2    "../app/Page",
3    "../app/Router",
4    "../model/classes/questions",
5    "../model/widgets/TabbedQuestionBrowser",
6    "dojo/_base/Deferred",
7    "dojo/_base/declare",
8    "dojo/_base/event",
9    "dojo/_base/lang",
10    "dojo/text!./templates/questions.html"
11], function(Page, Router, questions, TabbedQuestionBrowser, Deferred, declare, event, lang, template) {
12    return declare([Page],{
13        templateString: template,
14        startup: function() {
15            if ( this._started ) { return; }
16            this.inherited(arguments);
17            this.questionBrowser = new TabbedQuestionBrowser({
18                region: 'center',
19                'class': 'orange',
20                dndType: null,
21                getItemActions: lang.hitch(this,function(item) {
22                    var actions = {
23                        Edit: {
24                            callback: lang.hitch(this,"onEditQuestion"),
25                            icon: 'Edit',
26                            description: 'Edit question'
27                        }
28                    };
29                    if ( !item.publicationDate ) {
30                        lang.mixin(actions,{
31                            Delete: {
32                                callback: lang.hitch(this,"onDeleteQuestion"),
33                                icon: 'Delete',
34                                description: 'Delete question'
35                            },
36                            Publish: {
37                                callback: lang.hitch(this,"onPublishQuestion"),
38                                icon: 'Publish',
39                                description: 'Publish question'
40                            }
41                        });
42                    }
43                    return actions;
44                })
45            },this.questionBrowser);
46            this.questionBrowser.startup();
47        },
48        onNewQuestion: function() {
49            Router.go(questions.getObjectPath('new'));
50        },
51        onDeleteQuestion: function(question) {
52            questions.remove(question)
53            .then(lang.hitch(this,function(){
54                this.questionBrowser.removeItem(question);
55                this.notify("Question deleted.");
56            }),lang.hitch(this,function(err){
57                this.notify(err.error,'error');
58            }));
59        },
60        onEditQuestion: function(question) {
61            Router.go(questions.getObjectPath(question));
62        },
63        onPublishQuestion: function(question) {
64            question.publicationDate = new Date();
65            questions.save(question)
66            .then(lang.hitch(this,function(){
67                this.notify("Question published.");
68            }),lang.hitch(this,function(err){
69                this.notify(err.error,'error');
70            }));
71        }
72    });
73});
Note: See TracBrowser for help on using the repository browser.