source: Dev/trunk/src/client/qed-client/pages/questions.js @ 490

Last change on this file since 490 was 490, checked in by hendrikvanantwerpen, 11 years ago
  • Mark content as dirty to prevent moving away from unsaved data.
  • Better change propagation from lists and our own widgets.
  • Generate notifications for errors and show correct message.
  • Moved all path/url generation to the class stores, not everywhere we use it.
  • Give user always a choice between Save and Save & Close.
  • Better refresh behaviour on form changes and saves.
  • Don't generate duplicate code error when existing object is the one you're storing.
File size: 2.3 KB
Line 
1define([
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                itemActions: {
22                    Delete: {
23                        callback: lang.hitch(this,"onDeleteQuestion"),
24                        icon: 'Delete',
25                        description: 'Delete question'
26                    },
27                    Edit: {
28                        callback: lang.hitch(this,"onEditQuestion"),
29                        icon: 'Edit',
30                        description: 'Edit question'
31                    },
32                    Publish: {
33                        callback: lang.hitch(this,"onPublishQuestion"),
34                        icon: 'Publish',
35                        description: 'Publish question'
36                    }
37                }
38            },this.questionBrowser);
39            this.questionBrowser.startup();
40        },
41        onNewQuestion: function() {
42            Router.go(questions.getObjectPath('new'));
43        },
44        onDeleteQuestion: function(question) {
45            questions.remove(question)
46            .then(lang.hitch(this,function(){
47                this.notify("Question deleted.");
48            }),lang.hitch(this,function(err){
49                this.notify(err.error,'error');
50            }));
51        },
52        onEditQuestion: function(question) {
53            Router.go(questions.getObjectPath(question));
54        },
55        onPublishQuestion: function(question) {
56            question.publicationDate = new Date();
57            questions.save(question)
58            .then(lang.hitch(this,function(){
59                this.notify("Question published.");
60            }),lang.hitch(this,function(err){
61                this.notify(err.error,'error');
62            }));
63        }
64    });
65});
Note: See TracBrowser for help on using the repository browser.