[443] | 1 | define([ |
---|
[487] | 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" |
---|
[490] | 11 | ], function(Page, Router, questions, TabbedQuestionBrowser, Deferred, declare, event, lang, template) { |
---|
[443] | 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, |
---|
[495] | 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 | }); |
---|
[443] | 42 | } |
---|
[495] | 43 | return actions; |
---|
| 44 | }) |
---|
[443] | 45 | },this.questionBrowser); |
---|
| 46 | this.questionBrowser.startup(); |
---|
| 47 | }, |
---|
| 48 | onNewQuestion: function() { |
---|
[490] | 49 | Router.go(questions.getObjectPath('new')); |
---|
[443] | 50 | }, |
---|
| 51 | onDeleteQuestion: function(question) { |
---|
[529] | 52 | if ( !confirm("Are you sure you want to delete this question?") ) { |
---|
| 53 | return; |
---|
| 54 | } |
---|
[487] | 55 | questions.remove(question) |
---|
[490] | 56 | .then(lang.hitch(this,function(){ |
---|
[495] | 57 | this.questionBrowser.removeItem(question); |
---|
[490] | 58 | this.notify("Question deleted."); |
---|
| 59 | }),lang.hitch(this,function(err){ |
---|
| 60 | this.notify(err.error,'error'); |
---|
| 61 | })); |
---|
[443] | 62 | }, |
---|
| 63 | onEditQuestion: function(question) { |
---|
[490] | 64 | Router.go(questions.getObjectPath(question)); |
---|
[443] | 65 | }, |
---|
| 66 | onPublishQuestion: function(question) { |
---|
[529] | 67 | if ( !confirm("After publication the question cannot be modified anymore, are you sure?") ) { |
---|
| 68 | return; |
---|
| 69 | } |
---|
[487] | 70 | question.publicationDate = new Date(); |
---|
| 71 | questions.save(question) |
---|
[490] | 72 | .then(lang.hitch(this,function(){ |
---|
| 73 | this.notify("Question published."); |
---|
| 74 | }),lang.hitch(this,function(err){ |
---|
| 75 | this.notify(err.error,'error'); |
---|
| 76 | })); |
---|
[443] | 77 | } |
---|
| 78 | }); |
---|
| 79 | }); |
---|