1 | define([ |
---|
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 | if ( !confirm("Are you sure you want to delete this question?") ) { |
---|
53 | return; |
---|
54 | } |
---|
55 | questions.remove(question) |
---|
56 | .then(lang.hitch(this,function(){ |
---|
57 | this.questionBrowser.removeItem(question); |
---|
58 | this.notify("Question deleted."); |
---|
59 | }),lang.hitch(this,function(err){ |
---|
60 | this.notify(err.error,'error'); |
---|
61 | })); |
---|
62 | }, |
---|
63 | onEditQuestion: function(question) { |
---|
64 | Router.go(questions.getObjectPath(question)); |
---|
65 | }, |
---|
66 | onPublishQuestion: function(question) { |
---|
67 | if ( !confirm("After publication the question cannot be modified anymore, are you sure?") ) { |
---|
68 | return; |
---|
69 | } |
---|
70 | question.publicationDate = new Date(); |
---|
71 | questions.save(question) |
---|
72 | .then(lang.hitch(this,function(){ |
---|
73 | this.notify("Question published."); |
---|
74 | }),lang.hitch(this,function(err){ |
---|
75 | this.notify(err.error,'error'); |
---|
76 | })); |
---|
77 | } |
---|
78 | }); |
---|
79 | }); |
---|