1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/store/JsonRest','dojo/data/ObjectStore','rft/content','rft/ui/_Page'], |
---|
2 | function(declare,lang,JsonRest,ObjectStore,content,_Page){ |
---|
3 | return declare('rft.pages.surveys',[_Page],{ |
---|
4 | selectedObject: null, |
---|
5 | postCreate: function() { |
---|
6 | this._store = new JsonRest({ |
---|
7 | target:"../server/api.php/data/Survey/", |
---|
8 | idProperty: 'uid' |
---|
9 | }); |
---|
10 | }, |
---|
11 | onVisit: function() { |
---|
12 | this.grid.setStore(ObjectStore({objectStore: this._store})); |
---|
13 | |
---|
14 | this.grid.on('rowclick',lang.hitch(this,function(evt){ |
---|
15 | this.selectedObject = evt.grid.getItem(evt.rowIndex); |
---|
16 | this.btnEdit.set('disabled',!!this.selectedObject); |
---|
17 | })); |
---|
18 | |
---|
19 | this.grid.on('rowdblclick',lang.hitch(this,function(evt){ |
---|
20 | var obj = evt.grid.getItem(evt.rowIndex); |
---|
21 | content.goTo('/survey',{uid:obj.uid}); |
---|
22 | })); |
---|
23 | |
---|
24 | this.btnNew.on('click',lang.hitch(this,function(){ |
---|
25 | this._store.add({},function(obj) { |
---|
26 | content.goTo('/survey',{uid:this.selectedObject.uid}); |
---|
27 | }); |
---|
28 | })); |
---|
29 | |
---|
30 | this.btnEdit.on('click',lang.hitch(this,function(){ |
---|
31 | if ( this.selectedObject ) { |
---|
32 | content.goTo('/survey',{uid:this.selectedObject.uid}); |
---|
33 | } |
---|
34 | |
---|
35 | })); |
---|
36 | } |
---|
37 | }); |
---|
38 | }); |
---|
39 | |
---|