1 | define([ |
---|
2 | "../app/Content", |
---|
3 | "../app/Page", |
---|
4 | "../app/Router", |
---|
5 | "../model/classes/questions", |
---|
6 | "../model/widgets/TabbedQuestionBrowser", |
---|
7 | "dojo/_base/Deferred", |
---|
8 | "dojo/_base/declare", |
---|
9 | "dojo/_base/event", |
---|
10 | "dojo/_base/lang", |
---|
11 | "dojo/text!./templates/questions.html" |
---|
12 | ], function(Content, Page, Router, questions, TabbedQuestionBrowser, Deferred, declare, event, lang, 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 | dndType: null, |
---|
22 | itemActions: { |
---|
23 | Delete: { |
---|
24 | callback: lang.hitch(this,"onDeleteQuestion"), |
---|
25 | icon: 'Delete', |
---|
26 | description: 'Delete question' |
---|
27 | }, |
---|
28 | Edit: { |
---|
29 | callback: lang.hitch(this,"onEditQuestion"), |
---|
30 | icon: 'Edit', |
---|
31 | description: 'Edit question' |
---|
32 | }, |
---|
33 | Publish: { |
---|
34 | callback: lang.hitch(this,"onPublishQuestion"), |
---|
35 | icon: 'Publish', |
---|
36 | description: 'Publish question' |
---|
37 | } |
---|
38 | } |
---|
39 | },this.questionBrowser); |
---|
40 | this.questionBrowser.startup(); |
---|
41 | }, |
---|
42 | onNewQuestion: function() { |
---|
43 | Router.go("/question/new"); |
---|
44 | }, |
---|
45 | onDeleteQuestion: function(question) { |
---|
46 | questions.remove(question) |
---|
47 | .then(function(){ |
---|
48 | Content.notify("Question deleted."); |
---|
49 | },function(err){ |
---|
50 | Content.notify(err,'error'); |
---|
51 | }); |
---|
52 | }, |
---|
53 | onEditQuestion: function(question) { |
---|
54 | Router.go("/question/"+question._id); |
---|
55 | }, |
---|
56 | onPublishQuestion: function(question) { |
---|
57 | question.publicationDate = new Date(); |
---|
58 | questions.save(question) |
---|
59 | .then(function(){ |
---|
60 | Content.notify("Question published."); |
---|
61 | },function(err){ |
---|
62 | Content.notify(err,'error'); |
---|
63 | }); |
---|
64 | } |
---|
65 | }); |
---|
66 | }); |
---|