[263] | 1 | <div> |
---|
| 2 | <script type="rft/method" data-rft-method="onVisit"> |
---|
| 3 | var that = this; |
---|
| 4 | require(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','rft/content', |
---|
| 5 | 'dojo/store/JsonRest','dojo/data/ObjectStore','rft/ui/_PageController','dijit/registry'], |
---|
| 6 | function(declare,lang,event,content,JsonRest,ObjectStore,_PageController,registry){ |
---|
| 7 | (lang.hitch(that,function(){ |
---|
| 8 | this._store = new JsonRest({ |
---|
| 9 | target:"../server/api.php/data/Session/", |
---|
| 10 | idProperty: 'uid' |
---|
| 11 | }); |
---|
| 12 | |
---|
| 13 | function setEnabledRecursive(node,value) { |
---|
| 14 | registry.findWidgets(node).forEach(function(w){ |
---|
| 15 | w.set('disabled',!value); |
---|
| 16 | setEnabledRecursive(w.domNode,value); |
---|
| 17 | }); |
---|
| 18 | }; |
---|
| 19 | |
---|
| 20 | setEnabledRecursive(this.form.domNode,false); |
---|
| 21 | |
---|
| 22 | var refreshGrid = lang.hitch(this,function(){ |
---|
| 23 | this.grid.setStore(ObjectStore({ |
---|
| 24 | objectStore: this._store |
---|
| 25 | }),''); |
---|
| 26 | }); |
---|
| 27 | refreshGrid(); |
---|
| 28 | |
---|
| 29 | var getSelectedItem = lang.hitch(this,function(evt){ |
---|
| 30 | var items = this.grid.selection.getSelected(); |
---|
| 31 | if (items.length) |
---|
| 32 | return items[0]; |
---|
| 33 | return null; |
---|
| 34 | }); |
---|
| 35 | |
---|
| 36 | this.grid.on('rowclick',lang.hitch(this,function(evt){ |
---|
| 37 | var obj = getSelectedItem(); |
---|
| 38 | if ( obj) { |
---|
| 39 | this.form.set('value', obj); |
---|
| 40 | setEnabledRecursive(this.form.domNode, true); |
---|
| 41 | } else { |
---|
| 42 | setEnabledRecursive(this.form.domNode, false); |
---|
| 43 | this.form.reset(); |
---|
| 44 | } |
---|
| 45 | })); |
---|
| 46 | |
---|
| 47 | this.grid.on('rowdblclick',lang.hitch(this,function(evt){ |
---|
| 48 | var obj = getSelectedItem(); |
---|
| 49 | content.goTo('/session',{ |
---|
| 50 | uid:obj.uid |
---|
| 51 | }); |
---|
| 52 | })); |
---|
| 53 | |
---|
| 54 | var submitHandler = lang.hitch(this,function(evt){ |
---|
| 55 | this.errors.innerHTML = ''; |
---|
| 56 | var newObj = this.form.get('value'); |
---|
| 57 | var obj = getSelectedItem(); |
---|
| 58 | obj = lang.mixin(obj,newObj); |
---|
| 59 | //this._store.put(newObj,{id:obj.uid}) |
---|
| 60 | this._store.put(obj,{ |
---|
| 61 | overwrite:true |
---|
| 62 | }) |
---|
| 63 | .then(lang.hitch(this,function(){ |
---|
| 64 | refreshGrid(); |
---|
| 65 | }),lang.hitch(this,function(e){ |
---|
| 66 | this.errors.innerHTML = e.toString(); |
---|
| 67 | })); |
---|
| 68 | event.stop(evt); |
---|
| 69 | return false; |
---|
| 70 | }); |
---|
| 71 | |
---|
| 72 | this.form.on('submit',submitHandler); |
---|
| 73 | }))(); |
---|
| 74 | }); |
---|
| 75 | </script> |
---|
| 76 | <h1>Embedded scripts</h1> |
---|
| 77 | <div data-dojo-type="dijit.layout.TabContainer" data-dojo-props="doLayout: false"> |
---|
| 78 | <div data-dojo-type="dijit.layout.ContentPane" title="Sessions"> |
---|
| 79 | <div data-dojo-type="dojox.grid.DataGrid" data-dojo-props="autoWidth:true,autoHeight:true,structure:[{name:'Title',field:'title'}]" data-dojo-attach-point="grid"></div> |
---|
| 80 | </div> |
---|
| 81 | <div data-dojo-type="dijit.layout.ContentPane" title="Details"> |
---|
| 82 | <form data-dojo-type="dijit.form.Form" data-dojo-attach-point="form"> |
---|
| 83 | <fieldset> |
---|
| 84 | <label for="title" class="loginLabel">Title</label> |
---|
| 85 | <input data-dojo-type="dijit.form.TextBox" name="title" type="text" class="loginInput" /> |
---|
| 86 | </fieldset> |
---|
| 87 | <button type="submit" data-dojo-type="dijit.form.Button" data-dojo-attach-point="btnSave">Save</button> |
---|
| 88 | </form> |
---|
| 89 | <div data-dojo-attach-point="errors"></div> |
---|
| 90 | </div> |
---|
| 91 | </div> |
---|
| 92 | </div> |
---|