source: Dev/branches/rest-dojo-ui/client/rft/ui/TestPageController.js @ 273

Last change on this file since 273 was 263, checked in by hendrikvanantwerpen, 13 years ago
  • [Client] Finished page framework. See rft/ui/content.js or test files for details.
  • [Client] Allow login by pressing Enter.
  • [API] On exception include details in json response.
  • [Server Use Exceptions when save() fails, iso return values.
File size: 2.9 KB
Line 
1define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','rft/content',
2    'dojo/store/JsonRest','dojo/data/ObjectStore','rft/ui/_PageController','dijit/registry'],
3    function(declare,lang,event,content,JsonRest,ObjectStore,_PageController,registry) {
4        return declare([_PageController],{
5            onVisit: function() {
6                this._store = new JsonRest({
7                    target:"../server/api.php/data/Session/",
8                    idProperty: 'uid'
9                });
10
11                function setEnabledRecursive(node,value) {
12                    registry.findWidgets(node).forEach(function(w){
13                        w.set('disabled',!value);
14                        setEnabledRecursive(w.domNode,value);
15                    });
16                };
17
18                setEnabledRecursive(this.form.domNode,false);
19
20                var refreshGrid = lang.hitch(this,function(){
21                    this.grid.setStore(ObjectStore({
22                        objectStore: this._store
23                    }),'');
24                });
25                refreshGrid();
26               
27                var getSelectedItem = lang.hitch(this,function(evt){
28                    var items = this.grid.selection.getSelected();
29                    if (items.length)
30                        return items[0];
31                    return null;
32                });
33               
34                this.grid.on('rowclick',lang.hitch(this,function(evt){
35                    var obj = getSelectedItem();
36                    if ( obj) {
37                        this.form.set('value', obj);
38                        setEnabledRecursive(this.form.domNode, true);
39                    } else {
40                        setEnabledRecursive(this.form.domNode, false);
41                        this.form.reset();
42                    }
43                }));
44
45                this.grid.on('rowdblclick',lang.hitch(this,function(evt){
46                    var obj = getSelectedItem();
47                    content.goTo('/session',{
48                        uid:obj.uid
49                    });
50                }));
51
52                var submitHandler = lang.hitch(this,function(evt){
53                    this.errors.innerHTML = '';
54                    var newObj = this.form.get('value');
55                    var obj = getSelectedItem();
56                    obj = lang.mixin(obj,newObj);
57                    //this._store.put(newObj,{id:obj.uid})
58                    this._store.put(obj,{
59                        overwrite:true
60                    })
61                    .then(lang.hitch(this,function(){
62                        refreshGrid();
63                    }),lang.hitch(this,function(e){
64                        this.errors.innerHTML = e.toString();
65                    }));
66                    event.stop(evt);
67                    return false;
68                });
69               
70                this.form.on('submit',submitHandler);
71            }
72        });
73    });
Note: See TracBrowser for help on using the repository browser.