1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/Deferred','dojo/data/ObjectStore','rft/auth','rft/store','rft/content','rft/ui/_Page'], |
---|
2 | function(declare,lang,Deferred,ObjectStore,auth,store,content,_Page){ |
---|
3 | return declare('rft.pages.sessions',[_Page],{ |
---|
4 | selectedObject: null, |
---|
5 | onVisit: function() { |
---|
6 | this.grid.setStore( |
---|
7 | ObjectStore({objectStore: store}), |
---|
8 | "_design/default/_view/by_type",{key:'Survey'}); |
---|
9 | |
---|
10 | this.grid.on('rowclick',lang.hitch(this,function(evt){ |
---|
11 | this.selectedObject = evt.grid.getItem(evt.rowIndex); |
---|
12 | this.btnEdit.set('disabled',!this.selectedObject); |
---|
13 | })); |
---|
14 | |
---|
15 | this.grid.on('rowdblclick',lang.hitch(this,function(evt){ |
---|
16 | var obj = evt.grid.getItem(evt.rowIndex); |
---|
17 | content.goTo('/survey',{uid:store.getIdentity(obj)}); |
---|
18 | })); |
---|
19 | |
---|
20 | this.btnNew.on('click',lang.hitch(this,function(){ |
---|
21 | Deferred.when( store.add({type:'Survey',creator:auth.getUser()}) ) |
---|
22 | .then(function(obj) { |
---|
23 | content.goTo('/survey',{uid:store.getIdentity(obj)}); |
---|
24 | }); |
---|
25 | })); |
---|
26 | |
---|
27 | this.btnEdit.on('click',lang.hitch(this,function(){ |
---|
28 | if ( this.selectedObject ) { |
---|
29 | content.goTo('/survey',{uid:store.getIdentity(this.selectedObject)}); |
---|
30 | } |
---|
31 | |
---|
32 | })); |
---|
33 | } |
---|
34 | }); |
---|
35 | }); |
---|
36 | |
---|