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

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

[Server] Refactored model classes with some meta-programming. Specific classes only define their fields and inherit from class RdfObject?. Changes to handle the new model objects correctly.
[Client] Added rft/store module for uniform resource access. Removed dependencies on 'uid' field name. Added support for references without loading full object nor exposing uri.
[Client] Added reset() to QuestionWidget?.
[RDFAPI] Fixed PHP warning.

File size: 1.8 KB
Line 
1define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','dojo/_base/Deferred','rft/store','rft/ui/_Page'],
2    function(declare,lang,event,Deferred,store,_Page){
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                }));
34                event.stop(evt);
35                return false;
36            },
37            setFields: function(obj) {
38                this.form.reset();
39                this.header.innerHTML = "Edit survey '"+(obj.title || '(undefined)')+"'";
40                obj && this.form.set('value',obj);
41            }
42        });
43    });
44
Note: See TracBrowser for help on using the repository browser.