Changeset 316 for Dev/branches/rest-dojo-ui/client/rft
- Timestamp:
- 03/23/12 17:26:55 (13 years ago)
- Location:
- Dev/branches/rest-dojo-ui/client/rft
- Files:
-
- 4 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/pages/questions.js
r305 r316 10 10 this._store = store.getStore('Question'); 11 11 this._list = new AccordionList({ 12 store: this._store,13 12 actions: { 14 13 'Edit': lang.hitch(this,'_editQuestion') 15 14 }, 15 idProperty: this._store.idProperty, 16 16 categoryProperty: 'category', 17 17 titleProperty: 'title' … … 21 21 }, 22 22 _refresh: function() { 23 this._list.refresh(); 23 Deferred.when(this._store.query()) 24 .then(lang.hitch(this,function(items){ 25 this._list.setItems(items); 26 })); 24 27 }, 25 28 onNewQuestion: function() { -
Dev/branches/rest-dojo-ui/client/rft/pages/survey.html
r303 r316 1 1 <div data-dojo-type="rft.pages.survey"> 2 2 <h1 data-rft-attach-point="header">(default)</h1> 3 <div>Created by <span data-rft-attach-point="creator"></span>< div>3 <div>Created by <span data-rft-attach-point="creator"></span></div> 4 4 <form data-dojo-type="dijit.form.Form" data-rft-attach-point="form" data-rft-attach-event="onSubmit:onSave"> 5 5 <div style="display: block; clear: both;"> … … 11 11 <label for="description" class="loginLabel">Description</label> 12 12 <textarea name="description" data-dojo-type="dijit.form.SimpleTextarea" class="loginInput"></textarea> 13 <div> 14 <div style="width: 45%; float: left; clear: left;"><div data-rft-attach-point="allQuestions"></div></div> 15 <div style="width: 45%; float: left;"><div data-rft-attach-point="surveyQuestions"></div></div> 16 </div> 13 17 </form> 14 18 </div> -
Dev/branches/rest-dojo-ui/client/rft/pages/survey.js
r311 r316 1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event','dojo/_base/Deferred','rft/store','rft/ui/_Page','rft/api'], 2 function(declare,lang,event,Deferred,store,_Page,api){ 1 define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event', 2 'dojo/_base/Deferred','rft/ui/AccordionList','rft/ui/LineWithActionsWidget', 3 'rft/store','rft/ui/_Page','rft/api'], 4 function(declare,lang,event,Deferred,AccordionList,LineWithActionsWidget,store,_Page,api){ 3 5 return declare('rft.pages.survey',[_Page],{ 4 6 object: null, 5 7 postCreate: function() { 6 8 this.inherited(arguments); 7 this._store = store.getStore('Survey'); 9 this._surveyStore = store.getStore('Survey'); 10 this._questionStore = store.getStore('Question'); 8 11 }, 9 12 onVisit: function() { 10 13 if ( this.pageArgs.uid ) { 11 Deferred.when(this._s tore.get(this.pageArgs.uid))14 Deferred.when(this._surveyStore.get(this.pageArgs.uid)) 12 15 .then(lang.hitch(this,function(obj){ 13 16 this.object = obj; … … 17 20 .then(lang.hitch(this,function(obj){ 18 21 this.creator.innerHTML = (obj && obj.email) || 'unknown'; 22 })); 23 Deferred.when(this._questionStore.query()) 24 .then(lang.hitch(this,function(items){ 25 this._questionList = new AccordionList({ 26 store: this._surveyStore, 27 actions: { 28 'Add': lang.hitch(this,'_addQuestion') 29 }, 30 idProperty: this._questionStore.idProperty, 31 categoryProperty: 'category', 32 titleProperty: 'title' 33 },this.allQuestions); 34 this._questionList.startup(); 35 this._questionList.setItems(items); 19 36 })); 20 37 } else { … … 42 59 this.header.innerHTML = "Edit survey '"+(obj.title || '(undefined)')+"'"; 43 60 obj && this.form.set('value',obj); 61 }, 62 _addQuestion: function(obj) { 63 var d = {}; 64 d.widget = new LineWithActionsWidget({ 65 title:obj.title, 66 userObj: obj, 67 actions:{ 68 "Remove": lang.hitch(this,'_removeQuestion',d) 69 } 70 }); 71 d.widget.placeAt(this.surveyQuestions); 72 }, 73 _removeQuestion: function(data,obj) { 74 data.widget.destroy(); 44 75 } 45 76 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/AccordionList.js
r311 r316 9 9 return declare('rft.ui.AccordionList',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{ 10 10 templateString: template, 11 store: null,12 11 idProperty: null, 13 12 categoryProperty: null, … … 18 17 this._widgets = {}; 19 18 }, 20 postCreate: function() { 21 this.idProperty = this.idProperty || this.store.idProperty; 22 this.refresh(true); 23 }, 24 refresh: function(initial) { 25 Deferred.when( this.store.query() ) 26 .then(lang.hitch(this,'_addItems',initial)); 27 }, 28 _addItems: function(initial,items) { 29 var newWidgets = {}; 30 array.forEach(this._widgets,domConstruct.destroy); // get everything out of the dom 31 array.forEach(items,lang.hitch(this,function(item){ 32 var widget = this._getWidgetForItem(item); 33 var id = this._getItemProperty(this.idProperty,item); 34 var container = this._getContainerForItem(item); 35 widget.placeAt(container.containerNode); 36 newWidgets[id] = widget; 37 })); 38 var oldWidgets = array.filter(this.items,function(widget){ 39 return array.indexOf(newWidgets,widget) < 0; 19 setItems: function(items) { 20 var obsoleteWidgets = array.filter(this.widgets,function(item){ 21 return array.indexOf(items,item) < 0; 40 22 }); 41 array.forEach(o ldWidgets,function(widget){23 array.forEach(obsoleteWidgets,function(widget){ 42 24 widget.destroy(); 43 25 }); 44 this._widgets = newWidgets; // overwrite, releasing any non-existing items45 initial && this.accordion.selectChild(true);26 array.forEach(this._widgets,domConstruct.destroy); // get everything out of the dom 27 array.forEach(items,lang.hitch(this,"_addItem")); 46 28 this._cleanupEmptyContainers(); 29 }, 30 addItems: function(items) { 31 array.forEach(items,lang.hitch(this,"_addItem")); 32 this._cleanupEmptyContainers(); 33 }, 34 addItem: function(item) { 35 this._addItem(item); 36 this._cleanupEmptyContainers(); 37 }, 38 _addItem: function(item) { 39 var widget = this._getWidgetForItem(item); 40 var container = this._getContainerForItem(item); 41 widget.placeAt(container.containerNode); 42 }, 43 removeItem: function(item) { 44 var id = this._getItemProperty(this.idProperty,item); 45 var widget = this._getWidgetForItem(item); 46 widget && widget.destroy(); 47 delete this._widgets[id]; 47 48 }, 48 49 _getWidgetForItem: function(item) { -
Dev/branches/rest-dojo-ui/client/rft/ui/LineWithActionsWidget.js
r288 r316 1 define(['dojo/_base/declare','dojo/_base/lang','d ijit/form/Button',1 define(['dojo/_base/declare','dojo/_base/lang','dojo/on','dojo/dom','dijit/form/Button', 2 2 'dijit/_WidgetBase','dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin', 3 3 'dojo/text!./templates/LineWithActionsWidget.html'], 4 function(declare,lang, Button,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString){4 function(declare,lang,on,dom,Button,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString){ 5 5 return declare('rft.ui.LineWithActionsWidget',[_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{ 6 6 templateString: templateString, 7 baseClass: 'rftLineWithButtons', 7 8 title: '', 8 9 userObject: null, 9 10 actions: {}, 11 postCreate: function() { 12 dom.setSelectable(this.domNode, false); 13 on(this.titleNode,'click',lang.hitch(this,'_onClick')); 14 }, 10 15 startup: function() { 11 16 this.inherited(arguments); … … 17 22 new Button({ 18 23 label: action, 24 //iconClass: 'dijitIconSearch', 25 //showLabel: false, 19 26 onClick: lang.hitch(this,function(){ 20 27 this.actions[action](this.userObject); 21 28 }) 22 }).placeAt(this. actionBar);29 }).placeAt(this.buttonsNode); 23 30 } 24 31 }, 25 32 refresh: function() { 26 33 this.titleNode.innerHTML = this.title; 27 } 34 }, 35 _onClick: function(e){ 36 var preventDefault = this.onClick(e) === false; 37 if(preventDefault){ 38 e.preventDefault(); 39 } 40 return !preventDefault; 41 }, 42 onClick: function(e) {} 28 43 }); 29 44 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/templates/LineWithActionsWidget.html
r288 r316 1 <div >2 <span data-dojo-attach-point="actionBar"></span>3 <span data-dojo-attach-point="titleNode"></span>1 <div class="${baseClass}"> 2 <span class="${baseClass}Title" data-dojo-attach-point="titleNode"></span> 3 <span class="${baseClass}Buttons" data-dojo-attach-point="buttonsNode"></span> 4 4 </div>
Note: See TracChangeset
for help on using the changeset viewer.