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

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

[Client] Added surveys list and survey details skeleton pages.
[Client] Changed method of passing parameters to pages. This still feels clumsy, because we're working against Dojo a bit with this.
[Server] Integrated REST resources for collections and objects, since they shared more than they differed.

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