define([ "../app/Page", "../app/Router", "../model/classes/questions", "../model/widgets/TabbedQuestionBrowser", "dojo/_base/Deferred", "dojo/_base/declare", "dojo/_base/event", "dojo/_base/lang", "dojo/text!./templates/questions.html" ], function(Page, Router, questions, TabbedQuestionBrowser, Deferred, declare, event, lang, template) { return declare([Page],{ templateString: template, startup: function() { if ( this._started ) { return; } this.inherited(arguments); this.questionBrowser = new TabbedQuestionBrowser({ region: 'center', 'class': 'orange', dndType: null, getItemActions: lang.hitch(this,function(item) { var actions = { Edit: { callback: lang.hitch(this,"onEditQuestion"), icon: 'Edit', description: 'Edit question' } }; if ( !item.publicationDate ) { lang.mixin(actions,{ Delete: { callback: lang.hitch(this,"onDeleteQuestion"), icon: 'Delete', description: 'Delete question' }, Publish: { callback: lang.hitch(this,"onPublishQuestion"), icon: 'Publish', description: 'Publish question' } }); } return actions; }) },this.questionBrowser); this.questionBrowser.startup(); }, onNewQuestion: function() { Router.go(questions.getObjectPath('new')); }, onDeleteQuestion: function(question) { if ( !confirm("Are you sure you want to delete this question?") ) { return; } questions.remove(question) .then(lang.hitch(this,function(){ this.questionBrowser.removeItem(question); this.notify("Question deleted."); }),lang.hitch(this,function(err){ this.notify(err.error,'error'); })); }, onEditQuestion: function(question) { Router.go(questions.getObjectPath(question)); }, onPublishQuestion: function(question) { if ( !confirm("After publication the question cannot be modified anymore, are you sure?") ) { return; } question.publicationDate = new Date(); questions.save(question) .then(lang.hitch(this,function(){ this.notify("Question published."); }),lang.hitch(this,function(err){ this.notify(err.error,'error'); })); } }); });