1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| //>>built
| define(["dojo","dijit","dojox","dojo/require!dijit/Tree,dijit/Dialog,dijit/Menu,dijit/form/ValidationTextBox,dijit/form/Textarea,dijit/form/Button,dijit/form/RadioButton,dijit/form/FilteringSelect"],function(c,e,v){c.provide("dojox.data.ItemExplorer");c.require("dijit.Tree");c.require("dijit.Dialog");c.require("dijit.Menu");c.require("dijit.form.ValidationTextBox");c.require("dijit.form.Textarea");c.require("dijit.form.Button");c.require("dijit.form.RadioButton");c.require("dijit.form.FilteringSelect");
| (function(){var p=function(b,a,c){var d=b.getValues(a,c);2>d.length&&(d=b.getValue(a,c));return d};c.declare("dojox.data.ItemExplorer",e.Tree,{useSelect:!1,refSelectSearchAttr:null,constructor:function(b){c.mixin(this,b);var a=this,g={},d=this.rootModelNode={value:g,id:"root"};this._modelNodeIdMap={};this._modelNodePropMap={};var f=1;this.model={getRoot:function(a){a(d)},mayHaveChildren:function(a){return a.value&&"object"==typeof a.value&&!(a.value instanceof Date)},getChildren:function(b,c,d){function l(){if(n)f=
| a.store.getAttributes(h),e=h;else if(h&&"object"==typeof h){e=b.value;f=[];for(var d in h)h.hasOwnProperty(d)&&"__id"!=d&&"__clientId"!=d&&f.push(d)}if(f){for(var g=0;d=f[g++];)q.push({property:d,value:n?p(a.store,h,d):h[d],parent:e});q.push({addNew:!0,parent:e,parentNode:b})}c(q)}var f,e,h=b.value,q=[];if(h==g)c([]);else{var n=a.store&&a.store.isItem(h,!0);n&&!a.store.isItemLoaded(h)?a.store.loadItem({item:h,onItem:function(a){h=a;l()}}):l()}},getIdentity:function(b){if(!b.id&&(b.addNew&&(b.property=
| "--addNew"),b.id=f++,a.store)){if(a.store.isItem(b.value)){var c=a.store.getIdentity(b.value);(a._modelNodeIdMap[c]=a._modelNodeIdMap[c]||[]).push(b)}b.parent&&(c=a.store.getIdentity(b.parent)+"."+b.property,(a._modelNodePropMap[c]=a._modelNodePropMap[c]||[]).push(b))}return b.id},getLabel:function(a){return a===d?"Object Properties":a.addNew?a.parent instanceof Array?"Add new value":"Add new property":a.property+": "+(a.value instanceof Array?"("+a.value.length+" elements)":a.value)},onChildrenChange:function(a){},
| onChange:function(a){}}},postCreate:function(){this.inherited(arguments);c.connect(this,"onClick",function(a,b){this.lastFocused=b;a.addNew?this._addProperty():this._editProperty()});var b=new e.Menu({targetNodeIds:[this.rootNode.domNode],id:"contextMenu"});c.connect(b,"_openMyself",this,function(a){if(a=e.getEnclosingWidget(a.target)){var g=a.item;this.store.isItem(g.value,!0)&&!g.parent?(c.forEach(b.getChildren(),function(a){a.attr("disabled","Add"!=a.label)}),this.lastFocused=a):!g.value||"object"!=
| typeof g.value||g.value instanceof Date?g.property&&0<=c.indexOf(this.store.getIdentityAttributes(),g.property)?(this.focusNode(a),alert("Cannot modify an Identifier node.")):g.addNew?this.focusNode(a):(c.forEach(b.getChildren(),function(a){a.attr("disabled","Edit"!=a.label&&"Delete"!=a.label)}),this.lastFocused=a):(c.forEach(b.getChildren(),function(a){a.attr("disabled","Add"!=a.label&&"Delete"!=a.label)}),this.lastFocused=a)}});b.addChild(new e.MenuItem({label:"Add",onClick:c.hitch(this,"_addProperty")}));
| b.addChild(new e.MenuItem({label:"Edit",onClick:c.hitch(this,"_editProperty")}));b.addChild(new e.MenuItem({label:"Delete",onClick:c.hitch(this,"_destroyProperty")}));b.startup()},store:null,setStore:function(b){this.store=b;var a=this;this._editDialog&&(this._editDialog.destroyRecursive(),delete this._editDialog);c.connect(b,"onSet",function(b,c,f,e){var d=a.store.getIdentity(b);if((b=a._modelNodeIdMap[d])&&(void 0===f||void 0===e||f instanceof Array||e instanceof Array||"object"==typeof f||"object"==
| typeof e))for(f=0;f<b.length;f++)(function(b){a.model.getChildren(b,function(c){a.model.onChildrenChange(b,c)})})(b[f]);if(b=a._modelNodePropMap[d+"."+c])for(f=0;f<b.length;f++)b[f].value=e,a.model.onChange(b[f])});this.rootNode.setChildItems([])},setItem:function(b){(this._modelNodeIdMap={})[this.store.getIdentity(b)]=[this.rootModelNode];this._modelNodePropMap={};this.rootModelNode.value=b;var a=this;this.model.getChildren(this.rootModelNode,function(b){a.rootNode.setChildItems(b)})},refreshItem:function(){this.setItem(this.rootModelNode.value)},
| _createEditDialog:function(){this._editDialog=new e.Dialog({title:"Edit Property",execute:c.hitch(this,"_updateItem"),preload:!0});this._editDialog.placeAt(c.body());this._editDialog.startup();var b=c.doc.createElement("div"),a=c.doc.createElement("label");c.attr(a,"for","property");c.style(a,"fontWeight","bold");c.attr(a,"innerHTML","Property:");b.appendChild(a);(new e.form.ValidationTextBox({name:"property",value:"",required:!0,disabled:!0})).placeAt(b);b.appendChild(c.doc.createElement("br"));
| b.appendChild(c.doc.createElement("br"));(new e.form.RadioButton({name:"itemType",value:"value",onClick:c.hitch(this,function(){this._enableFields("value")})})).placeAt(b);a=c.doc.createElement("label");c.attr(a,"for","value");c.attr(a,"innerHTML","Value (JSON):");b.appendChild(a);a=c.doc.createElement("div");c.addClass(a,"value");(new e.form.Textarea({name:"jsonVal"})).placeAt(a);b.appendChild(a);(new e.form.RadioButton({name:"itemType",value:"reference",onClick:c.hitch(this,function(){this._enableFields("reference")})})).placeAt(b);
| a=c.doc.createElement("label");c.attr(a,"for","_reference");c.attr(a,"innerHTML","Reference (ID):");b.appendChild(a);b.appendChild(c.doc.createElement("br"));a=c.doc.createElement("div");c.addClass(a,"reference");this.useSelect?(new e.form.FilteringSelect({name:"_reference",store:this.store,searchAttr:this.refSelectSearchAttr||this.store.getIdentityAttributes()[0],required:!1,value:null,pageSize:10})).placeAt(a):(new e.form.ValidationTextBox({name:"_reference",value:"",promptMessage:"Enter the ID of the item to reference",
| isValid:c.hitch(this,function(a){return!0})})).placeAt(a);b.appendChild(a);b.appendChild(c.doc.createElement("br"));b.appendChild(c.doc.createElement("br"));a=document.createElement("div");a.setAttribute("dir","rtl");(new e.form.Button({type:"reset",label:"Cancel"})).placeAt(a).onClick=c.hitch(this._editDialog,"onCancel");(new e.form.Button({type:"submit",label:"OK"})).placeAt(a);b.appendChild(a);this._editDialog.attr("content",b)},_enableFields:function(b){switch(b){case "reference":c.query(".value [widgetId]",
| this._editDialog.containerNode).forEach(function(a){e.getEnclosingWidget(a).attr("disabled",!0)});c.query(".reference [widgetId]",this._editDialog.containerNode).forEach(function(a){e.getEnclosingWidget(a).attr("disabled",!1)});break;case "value":c.query(".value [widgetId]",this._editDialog.containerNode).forEach(function(a){e.getEnclosingWidget(a).attr("disabled",!1)}),c.query(".reference [widgetId]",this._editDialog.containerNode).forEach(function(a){e.getEnclosingWidget(a).attr("disabled",!0)})}},
| _updateItem:function(b){function a(){try{var a,c=[],l=b.property;if(n){for(;!k.isItem(d.parent,!0);)g=g.getParent(),c.push(d.property),d=g.item;if(0==c.length)k.setValue(d.parent,d.property,f);else{e=p(k,d.parent,d.property);e instanceof Array&&(e=e.concat());for(a=e;1<c.length;)a=a[c.pop()];a[c]=f;k.setValue(d.parent,d.property,e)}}else if(k.isItem(m,!0))k.isItemLoaded(m)?(m instanceof Array&&(l=m.length),k.setValue(m,l,f)):k.loadItem({item:m,onItem:function(a){a instanceof Array&&(l=a.length);k.setValue(a,
| l,f)}});else{for(d.value instanceof Array?c.push(d.value.length):c.push(b.property);!k.isItem(d.parent,!0);)g=g.getParent(),c.push(d.property),d=g.item;for(a=e=p(k,d.parent,d.property);1<c.length;)a=a[c.pop()];a[c]=f;k.setValue(d.parent,d.property,e)}}catch(u){alert(u)}}var g,d,f,e,n="Edit Property"==this._editDialog.attr("title"),r=this._editDialog,k=this.store;if(r.validate()){g=this.lastFocused;d=g.item;var m=d.value;d.addNew&&(m=g.item.parent,g=g.getParent(),d=g.item);f=null;switch(b.itemType){case "reference":this.store.fetchItemByIdentity({identity:b._reference,
| onItem:function(b){f=b;a()},onError:function(){alert("The id could not be found")}});break;case "value":var t=b.jsonVal;f=c.fromJson(t);"function"==typeof f&&(f.toString=function(){return t});a()}}else r.show()},_editProperty:function(){var b=c.mixin({},this.lastFocused.item);this._editDialog?this._editDialog.reset():this._createEditDialog();if(0<=c.indexOf(this.store.getIdentityAttributes(),b.property))alert("Cannot Edit an Identifier!");else if(this._editDialog.attr("title","Edit Property"),e.getEnclosingWidget(c.query("input",
| this._editDialog.containerNode)[0]).attr("disabled",!0),this.store.isItem(b.value,!0))b.parent&&(b.itemType="reference",this._enableFields(b.itemType),b._reference=this.store.getIdentity(b.value),this._editDialog.attr("value",b),this._editDialog.show());else if(!b.value||"object"!=typeof b.value||b.value instanceof Date)b.itemType="value",this._enableFields(b.itemType),b.jsonVal="function"==typeof b.value?b.value.toString():b.value instanceof Date?'new Date("'+b.value+'")':c.toJson(b.value),this._editDialog.attr("value",
| b),this._editDialog.show()},_destroyProperty:function(){for(var b=this.lastFocused,a=b.item,e=[];!this.store.isItem(a.parent,!0)||a.parent instanceof Array;)b=b.getParent(),e.push(a.property),a=b.item;if(0<=c.indexOf(this.store.getIdentityAttributes(),a.property))alert("Cannot Delete an Identifier!");else try{if(0<e.length){var d,f=p(this.store,a.parent,a.property);for(d=f;1<e.length;)d=d[e.pop()];c.isArray(d)?d.splice(e,1):delete d[e];this.store.setValue(a.parent,a.property,f)}else this.store.unsetAttribute(a.parent,
| a.property)}catch(l){alert(l)}},_addProperty:function(){var b=this.lastFocused.item,a=b.value,g=c.hitch(this,function(){var b=null;this._editDialog?this._editDialog.reset():this._createEditDialog();a instanceof Array?(b=a.length,e.getEnclosingWidget(c.query("input",this._editDialog.containerNode)[0]).attr("disabled",!0)):e.getEnclosingWidget(c.query("input",this._editDialog.containerNode)[0]).attr("disabled",!1);this._editDialog.attr("title","Add Property");this._enableFields("value");this._editDialog.attr("value",
| {itemType:"value",property:b});this._editDialog.show()});b.addNew&&(b=this.lastFocused.getParent().item,a=this.lastFocused.item.parent);b.property&&0<=c.indexOf(this.store.getIdentityAttributes(),b.property)?alert("Cannot add properties to an ID node!"):this.store.isItem(a,!0)&&!this.store.isItemLoaded(a)?this.store.loadItem({item:a,onItem:function(b){a=b;g()}}):g()}})})()});
|
|