1 | define([ |
---|
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': 'blue', |
---|
21 | itemActions: { |
---|
22 | Edit: { |
---|
23 | callback: lang.hitch(this,"onEditQuestion"), |
---|
24 | icon: 'Edit', |
---|
25 | description: 'Edit question' |
---|
26 | }, |
---|
27 | Publish: { |
---|
28 | callback: lang.hitch(this,"onPublishQuestion"), |
---|
29 | icon: 'Publish', |
---|
30 | description: 'Publish question' |
---|
31 | } |
---|
32 | } |
---|
33 | },this.questionBrowser); |
---|
34 | this.questionBrowser.startup(); |
---|
35 | }, |
---|
36 | onNewQuestion: function() { |
---|
37 | Deferred.when(store.add({type:'Question'})) |
---|
38 | .then(lang.hitch(this,function(question){ |
---|
39 | this.onEditQuestion(question); |
---|
40 | })); |
---|
41 | }, |
---|
42 | onEditQuestion: function(question) { |
---|
43 | Router.go("/question/"+question._id); |
---|
44 | }, |
---|
45 | onPublishQuestion: function(question) { |
---|
46 | question.publicationDate = store.timestamp(); |
---|
47 | store.put(question) |
---|
48 | .then(function(){ |
---|
49 | Content.notify("Question puplished."); |
---|
50 | },function(err){ |
---|
51 | Content.notify(err.reason,'error'); |
---|
52 | }); |
---|
53 | } |
---|
54 | }); |
---|
55 | }); |
---|