source: Dev/branches/rest-dojo-ui/client/rft/pages/survey.js @ 311

Last change on this file since 311 was 311, checked in by hendrikvanantwerpen, 13 years ago

[Client] Use toaster to show errors from server
[Client] Create widget for mainmenu, cleaner loading of index.html now.
[Server] Renamed answerset datetime to more meaningful creationdate

File size: 2.0 KB
Line 
1define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','dojo/_base/Deferred','rft/store','rft/ui/_Page','rft/api'],
2    function(declare,lang,event,Deferred,store,_Page,api){
3        return declare('rft.pages.survey',[_Page],{
4            object: null,
5            postCreate: function() {
6                this.inherited(arguments);
7                this._store = store.getStore('Survey');
8            },
9            onVisit: function() {
10                if ( this.pageArgs.uid ) {
11                    Deferred.when(this._store.get(this.pageArgs.uid))
12                    .then(lang.hitch(this,function(obj){
13                        this.object = obj;
14                        this.setFields(obj);
15                        return Deferred.when( obj.creator && store.dereference(obj.creator) );
16                    }))
17                    .then(lang.hitch(this,function(obj){
18                        this.creator.innerHTML = (obj && obj.email) || 'unknown';
19                    }));
20                } else {
21                    this.header.innerHTML = "Error: no uid for survey!"
22                }
23            },
24            onReset: function() {
25                this.setFields(this.object);
26            },
27            onSave: function(evt) {
28                lang.mixin(this.object,this.form.get('value'));
29                Deferred.when( this._store.put(this.object) )
30                .then(lang.hitch(this,function(obj){
31                    this.object = obj;
32                    this.setFields(obj);
33                    api.notify("Object saved");
34                }),lang.hitch(this,function(){
35                    api.notify("Object save failed",'error');
36                }));
37                event.stop(evt);
38                return false;
39            },
40            setFields: function(obj) {
41                this.form.reset();
42                this.header.innerHTML = "Edit survey '"+(obj.title || '(undefined)')+"'";
43                obj && this.form.set('value',obj);
44            }
45        });
46    });
47
Note: See TracBrowser for help on using the repository browser.