ItemExplorer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. // wrapped by build app
  2. define("dojox/data/ItemExplorer", ["dijit","dojo","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(dijit,dojo,dojox){
  3. dojo.provide("dojox.data.ItemExplorer");
  4. dojo.require("dijit.Tree");
  5. dojo.require("dijit.Dialog");
  6. dojo.require("dijit.Menu");
  7. dojo.require("dijit.form.ValidationTextBox");
  8. dojo.require("dijit.form.Textarea");
  9. dojo.require("dijit.form.Button");
  10. dojo.require("dijit.form.RadioButton");
  11. dojo.require("dijit.form.FilteringSelect");
  12. (function(){
  13. var getValue = function(store, item, prop){
  14. var value = store.getValues(item, prop);
  15. if(value.length < 2){
  16. value = store.getValue(item, prop);
  17. }
  18. return value;
  19. }
  20. dojo.declare("dojox.data.ItemExplorer", dijit.Tree, {
  21. useSelect: false,
  22. refSelectSearchAttr: null,
  23. constructor: function(options){
  24. dojo.mixin(this, options);
  25. var self = this;
  26. var initialRootValue = {};
  27. var root = (this.rootModelNode = {value:initialRootValue,id:"root"});
  28. this._modelNodeIdMap = {};
  29. this._modelNodePropMap = {};
  30. var nextId = 1;
  31. this.model = {
  32. getRoot: function(onItem){
  33. onItem(root);
  34. },
  35. mayHaveChildren: function(modelNode){
  36. return modelNode.value && typeof modelNode.value == 'object' && !(modelNode.value instanceof Date);
  37. },
  38. getChildren: function(parentModelNode, onComplete, onError){
  39. var keys, parent, item = parentModelNode.value;
  40. var children = [];
  41. if(item == initialRootValue){
  42. onComplete([]);
  43. return;
  44. }
  45. var isItem = self.store && self.store.isItem(item, true);
  46. if(isItem && !self.store.isItemLoaded(item)){
  47. // if it is not loaded, do so now.
  48. self.store.loadItem({
  49. item:item,
  50. onItem:function(loadedItem){
  51. item = loadedItem;
  52. enumerate();
  53. }
  54. });
  55. }else{
  56. enumerate();
  57. }
  58. function enumerate(){
  59. // once loaded, enumerate the keys
  60. if(isItem){
  61. // get the properties through the dojo data API
  62. keys = self.store.getAttributes(item);
  63. parent = item;
  64. }else if(item && typeof item == 'object'){
  65. parent = parentModelNode.value;
  66. keys = [];
  67. // also we want to be able to drill down into plain JS objects/arrays
  68. for(var i in item){
  69. if(item.hasOwnProperty(i) && i != '__id' && i != '__clientId'){
  70. keys.push(i);
  71. }
  72. }
  73. }
  74. if(keys){
  75. for(var key, k=0; key = keys[k++];){
  76. children.push({
  77. property:key,
  78. value: isItem ? getValue(self.store, item, key) : item[key],
  79. parent: parent});
  80. }
  81. children.push({addNew:true, parent: parent, parentNode : parentModelNode});
  82. }
  83. onComplete(children);
  84. }
  85. },
  86. getIdentity: function(modelNode){
  87. if(!modelNode.id){
  88. if(modelNode.addNew){
  89. modelNode.property = "--addNew";
  90. }
  91. modelNode.id = nextId++;
  92. if(self.store){
  93. if(self.store.isItem(modelNode.value)){
  94. var identity = self.store.getIdentity(modelNode.value);
  95. (self._modelNodeIdMap[identity] = self._modelNodeIdMap[identity] || []).push(modelNode);
  96. }
  97. if(modelNode.parent){
  98. identity = self.store.getIdentity(modelNode.parent) + '.' + modelNode.property;
  99. (self._modelNodePropMap[identity] = self._modelNodePropMap[identity] || []).push(modelNode);
  100. }
  101. }
  102. }
  103. return modelNode.id;
  104. },
  105. getLabel: function(modelNode){
  106. return modelNode === root ?
  107. "Object Properties" :
  108. modelNode.addNew ? (modelNode.parent instanceof Array ? "Add new value" : "Add new property") :
  109. modelNode.property + ": " +
  110. (modelNode.value instanceof Array ? "(" + modelNode.value.length + " elements)" : modelNode.value);
  111. },
  112. onChildrenChange: function(modelNode){
  113. },
  114. onChange: function(modelNode){
  115. }
  116. };
  117. },
  118. postCreate: function(){
  119. this.inherited(arguments);
  120. // handle the clicking on the "add new property item"
  121. dojo.connect(this, "onClick", function(modelNode, treeNode){
  122. this.lastFocused = treeNode;
  123. if(modelNode.addNew){
  124. //this.focusNode(treeNode.getParent());
  125. this._addProperty();
  126. }else{
  127. this._editProperty();
  128. }
  129. });
  130. var contextMenu = new dijit.Menu({
  131. targetNodeIds: [this.rootNode.domNode],
  132. id: "contextMenu"
  133. });
  134. dojo.connect(contextMenu, "_openMyself", this, function(e){
  135. var node = dijit.getEnclosingWidget(e.target);
  136. if(node){
  137. var item = node.item;
  138. if(this.store.isItem(item.value, true) && !item.parent){
  139. dojo.forEach(contextMenu.getChildren(), function(widget){
  140. widget.attr("disabled", (widget.label != "Add"));
  141. });
  142. this.lastFocused = node;
  143. // TODO: Root Node - allow Edit when mutli-value editing is possible
  144. }else if(item.value && typeof item.value == 'object' && !(item.value instanceof Date)){
  145. // an object that's not a Date - could be a store item
  146. dojo.forEach(contextMenu.getChildren(), function(widget){
  147. widget.attr("disabled", (widget.label != "Add") && (widget.label != "Delete"));
  148. });
  149. this.lastFocused = node;
  150. // TODO: Object - allow Edit when mutli-value editing is possible
  151. }else if(item.property && dojo.indexOf(this.store.getIdentityAttributes(), item.property) >= 0){ // id node
  152. this.focusNode(node);
  153. alert("Cannot modify an Identifier node.");
  154. }else if(item.addNew){
  155. this.focusNode(node);
  156. }else{
  157. dojo.forEach(contextMenu.getChildren(), function(widget){
  158. widget.attr("disabled", (widget.label != "Edit") && (widget.label != "Delete"));
  159. })
  160. // this won't focus the node but gives us a way to reference the node
  161. this.lastFocused = node;
  162. }
  163. }
  164. });
  165. contextMenu.addChild(new dijit.MenuItem({label: "Add", onClick: dojo.hitch(this, "_addProperty")}));
  166. contextMenu.addChild(new dijit.MenuItem({label: "Edit", onClick: dojo.hitch(this, "_editProperty")}));
  167. contextMenu.addChild(new dijit.MenuItem({label: "Delete", onClick: dojo.hitch(this, "_destroyProperty")}));
  168. contextMenu.startup();
  169. },
  170. store: null,
  171. setStore: function(store){
  172. this.store = store;
  173. var self = this;
  174. if(this._editDialog){
  175. this._editDialog.destroyRecursive();
  176. delete this._editDialog;
  177. }
  178. // i think we should just destroy this._editDialog and let _createEditDialog take care of everything
  179. // once it gets called again by either _editProperty or _addProperty - it will create everything again
  180. // using the new store. this way we don't need to keep track of what is in the dialog if we change it.
  181. /*if(this._editDialog && this.useSelect){
  182. dojo.query(".reference [widgetId]", this._editDialog.containerNode).forEach(function(node){
  183. dijit.getEnclosingWidget(node).attr("store", store);
  184. });
  185. }*/
  186. dojo.connect(store, "onSet", function(item, attribute, oldValue, newValue){
  187. var nodes, i, identity = self.store.getIdentity(item);
  188. nodes = self._modelNodeIdMap[identity];
  189. if(nodes &&
  190. (oldValue === undefined || newValue === undefined ||
  191. oldValue instanceof Array || newValue instanceof Array || typeof oldValue == 'object' || typeof newValue == 'object')){
  192. for(i = 0; i < nodes.length; i++){
  193. (function(node){
  194. self.model.getChildren(node, function(children){
  195. self.model.onChildrenChange(node, children);
  196. });
  197. })(nodes[i]);
  198. }
  199. }
  200. nodes = self._modelNodePropMap[identity + "." + attribute];
  201. if(nodes){
  202. for(i = 0; i < nodes.length; i++){
  203. nodes[i].value = newValue;
  204. self.model.onChange(nodes[i]);
  205. }
  206. }
  207. });
  208. this.rootNode.setChildItems([]);
  209. },
  210. setItem: function(item){
  211. // this is called to show a different item
  212. // reset the maps, for the root getIdentity is not called, so we pre-initialize it here
  213. (this._modelNodeIdMap = {})[this.store.getIdentity(item)] = [this.rootModelNode];
  214. this._modelNodePropMap = {};
  215. this.rootModelNode.value = item;
  216. var self = this;
  217. this.model.getChildren(this.rootModelNode, function(children){
  218. self.rootNode.setChildItems(children);
  219. });
  220. },
  221. refreshItem: function(){
  222. this.setItem(this.rootModelNode.value);
  223. },
  224. _createEditDialog: function(){
  225. this._editDialog = new dijit.Dialog({
  226. title: "Edit Property",
  227. execute: dojo.hitch(this, "_updateItem"),
  228. preload: true
  229. });
  230. this._editDialog.placeAt(dojo.body());
  231. this._editDialog.startup();
  232. // handle for dialog content
  233. var pane = dojo.doc.createElement('div');
  234. // label for property
  235. var labelProp = dojo.doc.createElement('label');
  236. dojo.attr(labelProp, "for", "property");
  237. dojo.style(labelProp, "fontWeight", "bold");
  238. dojo.attr(labelProp, "innerHTML", "Property:")
  239. pane.appendChild(labelProp);
  240. // property name field
  241. var propName = new dijit.form.ValidationTextBox({
  242. name: "property",
  243. value: "",
  244. required: true,
  245. disabled: true
  246. }).placeAt(pane);
  247. pane.appendChild(dojo.doc.createElement("br"));
  248. pane.appendChild(dojo.doc.createElement("br"));
  249. // radio button for "value"
  250. var value = new dijit.form.RadioButton({
  251. name: "itemType",
  252. value: "value",
  253. onClick: dojo.hitch(this, function(){this._enableFields("value");})
  254. }).placeAt(pane);
  255. // label for value
  256. var labelVal = dojo.doc.createElement('label');
  257. dojo.attr(labelVal, "for", "value");
  258. dojo.attr(labelVal, "innerHTML", "Value (JSON):")
  259. pane.appendChild(labelVal);
  260. // container for value fields
  261. var valueDiv = dojo.doc.createElement("div");
  262. dojo.addClass(valueDiv, "value");
  263. // textarea
  264. var textarea = new dijit.form.Textarea({
  265. name: "jsonVal"
  266. }).placeAt(valueDiv);
  267. pane.appendChild(valueDiv);
  268. // radio button for "reference"
  269. var reference = new dijit.form.RadioButton({
  270. name: "itemType",
  271. value: "reference",
  272. onClick: dojo.hitch(this, function(){this._enableFields("reference");})
  273. }).placeAt(pane);
  274. // label for reference
  275. var labelRef = dojo.doc.createElement('label');
  276. dojo.attr(labelRef, "for", "_reference");
  277. dojo.attr(labelRef, "innerHTML", "Reference (ID):")
  278. pane.appendChild(labelRef);
  279. pane.appendChild(dojo.doc.createElement("br"));
  280. // container for reference fields
  281. var refDiv = dojo.doc.createElement("div");
  282. dojo.addClass(refDiv, "reference");
  283. if(this.useSelect){
  284. // filteringselect
  285. // TODO: see if there is a way to sort the items in this list
  286. var refSelect = new dijit.form.FilteringSelect({
  287. name: "_reference",
  288. store: this.store,
  289. searchAttr: this.refSelectSearchAttr || this.store.getIdentityAttributes()[0],
  290. required: false,
  291. value: null, // need to file a ticket about the fetch that happens when declared with value: null
  292. pageSize: 10
  293. }).placeAt(refDiv);
  294. }else{
  295. var refTextbox = new dijit.form.ValidationTextBox({
  296. name: "_reference",
  297. value: "",
  298. promptMessage: "Enter the ID of the item to reference",
  299. isValid: dojo.hitch(this, function(isFocused){
  300. // don't validate while it's focused
  301. return true;//isFocused || this.store.getItemByIdentity(this._editDialog.attr("value")._reference);
  302. })
  303. }).placeAt(refDiv);
  304. }
  305. pane.appendChild(refDiv);
  306. pane.appendChild(dojo.doc.createElement("br"));
  307. pane.appendChild(dojo.doc.createElement("br"));
  308. // buttons
  309. var buttons = document.createElement('div');
  310. buttons.setAttribute("dir", "rtl");
  311. var cancelButton = new dijit.form.Button({type: "reset", label: "Cancel"}).placeAt(buttons);
  312. cancelButton.onClick = dojo.hitch(this._editDialog, "onCancel");
  313. var okButton = new dijit.form.Button({type: "submit", label: "OK"}).placeAt(buttons);
  314. pane.appendChild(buttons);
  315. this._editDialog.attr("content", pane);
  316. },
  317. _enableFields: function(selection){
  318. // enables/disables fields based on whether the value in this._editDialog is a reference or a primitive value
  319. switch(selection){
  320. case "reference":
  321. dojo.query(".value [widgetId]", this._editDialog.containerNode).forEach(function(node){
  322. dijit.getEnclosingWidget(node).attr("disabled", true);
  323. });
  324. dojo.query(".reference [widgetId]", this._editDialog.containerNode).forEach(function(node){
  325. dijit.getEnclosingWidget(node).attr("disabled", false);
  326. });
  327. break;
  328. case "value":
  329. dojo.query(".value [widgetId]", this._editDialog.containerNode).forEach(function(node){
  330. dijit.getEnclosingWidget(node).attr("disabled", false);
  331. });
  332. dojo.query(".reference [widgetId]", this._editDialog.containerNode).forEach(function(node){
  333. dijit.getEnclosingWidget(node).attr("disabled", true);
  334. });
  335. break;
  336. }
  337. },
  338. _updateItem: function(vals){
  339. // a single "execute" function that handles adding and editing of values and references.
  340. var node, item, val, storeItemVal, editingItem = this._editDialog.attr("title") == "Edit Property";
  341. var editDialog = this._editDialog;
  342. var store = this.store;
  343. function setValue(){
  344. try{
  345. var itemVal, propPath = [];
  346. var prop = vals.property;
  347. if(editingItem){
  348. while(!store.isItem(item.parent, true)){
  349. node = node.getParent();
  350. propPath.push(item.property);
  351. item = node.item;
  352. }
  353. if(propPath.length == 0){
  354. // working with an item attribute already
  355. store.setValue(item.parent, item.property, val);
  356. }else{
  357. // need to walk back down the item property to the object
  358. storeItemVal = getValue(store, item.parent, item.property);
  359. if(storeItemVal instanceof Array){
  360. // create a copy for modification
  361. storeItemVal = storeItemVal.concat();
  362. }
  363. itemVal = storeItemVal;
  364. while(propPath.length > 1){
  365. itemVal = itemVal[propPath.pop()];
  366. }
  367. itemVal[propPath] = val; // this change is reflected in storeItemVal as well
  368. store.setValue(item.parent, item.property, storeItemVal);
  369. }
  370. }else{
  371. // adding a property
  372. if(store.isItem(value, true)){
  373. // adding a top-level property to an item
  374. if(!store.isItemLoaded(value)){
  375. // fetch the value and see if it is an array
  376. store.loadItem({
  377. item: value,
  378. onItem: function(loadedItem){
  379. if(loadedItem instanceof Array){
  380. prop = loadedItem.length;
  381. }
  382. store.setValue(loadedItem, prop, val);
  383. }
  384. });
  385. }else{
  386. if(value instanceof Array){
  387. prop = value.length;
  388. }
  389. store.setValue(value, prop, val);
  390. }
  391. }else{
  392. // adding a property to a lower level in an item
  393. if(item.value instanceof Array){
  394. propPath.push(item.value.length);
  395. }else{
  396. propPath.push(vals.property);
  397. }
  398. while(!store.isItem(item.parent, true)){
  399. node = node.getParent();
  400. propPath.push(item.property);
  401. item = node.item;
  402. }
  403. storeItemVal = getValue(store, item.parent, item.property);
  404. itemVal = storeItemVal;
  405. while(propPath.length > 1){
  406. itemVal = itemVal[propPath.pop()];
  407. }
  408. itemVal[propPath] = val;
  409. store.setValue(item.parent, item.property, storeItemVal);
  410. }
  411. }
  412. }catch(e){
  413. alert(e);
  414. }
  415. }
  416. if(editDialog.validate()){
  417. node = this.lastFocused;
  418. item = node.item;
  419. var value = item.value;
  420. // var property = null;
  421. if(item.addNew){
  422. // we are adding a property to the parent item
  423. // the real value of the parent is in the parent property of the lastFocused item
  424. // this.lastFocused.getParent().item.value may be a reference to an item
  425. value = node.item.parent;
  426. node = node.getParent();
  427. item = node.item;
  428. }
  429. val = null;
  430. switch(vals.itemType){
  431. case "reference":
  432. this.store.fetchItemByIdentity({identity:vals._reference,
  433. onItem:function(item){
  434. val = item;
  435. setValue();
  436. },
  437. onError:function(){
  438. alert("The id could not be found");
  439. }
  440. });
  441. break;
  442. case "value":
  443. var jsonVal = vals.jsonVal;
  444. val = dojo.fromJson(jsonVal);
  445. // ifit is a function we want to preserve the source (comments, et al)
  446. if(typeof val == 'function'){
  447. val.toString = function(){
  448. return jsonVal;
  449. }
  450. }
  451. setValue();
  452. break;
  453. }
  454. }else{
  455. // the form didn't validate - show it again.
  456. editDialog.show();
  457. }
  458. },
  459. _editProperty: function(){
  460. // this mixin stops us polluting the tree item with jsonVal etc.
  461. // FIXME: if a store identifies items by instanceof checks, this will fail
  462. var item = dojo.mixin({}, this.lastFocused.item);
  463. // create the dialog or reset it if it already exists
  464. if(!this._editDialog){
  465. this._createEditDialog();
  466. }else{
  467. this._editDialog.reset();
  468. }
  469. // not allowed to edit an item's id - so check for that and stop it.
  470. if(dojo.indexOf(this.store.getIdentityAttributes(), item.property) >= 0){
  471. alert("Cannot Edit an Identifier!");
  472. }else{
  473. this._editDialog.attr("title", "Edit Property");
  474. // make sure the property input is disabled
  475. dijit.getEnclosingWidget(dojo.query("input", this._editDialog.containerNode)[0]).attr("disabled", true);
  476. if(this.store.isItem(item.value, true)){
  477. // root node || Item reference
  478. if(item.parent){
  479. // Item reference
  480. item.itemType = "reference";
  481. this._enableFields(item.itemType);
  482. item._reference = this.store.getIdentity(item.value);
  483. this._editDialog.attr("value", item);
  484. this._editDialog.show();
  485. } // else root node
  486. }else{
  487. if(item.value && typeof item.value == 'object' && !(item.value instanceof Date)){
  488. // item.value is an object but it's NOT an item from the store - no-op
  489. // only allow editing on a property not on the node that represents the object/array
  490. }else{
  491. // this is a primitive
  492. item.itemType = "value";
  493. this._enableFields(item.itemType);
  494. item.jsonVal = typeof item.value == 'function' ?
  495. // use the plain toString for functions, dojo.toJson doesn't support functions
  496. item.value.toString() :
  497. item.value instanceof Date ?
  498. // A json-ish form of a date:
  499. 'new Date("' + item.value + '")' :
  500. dojo.toJson(item.value);
  501. this._editDialog.attr("value", item);
  502. this._editDialog.show();
  503. }
  504. }
  505. }
  506. },
  507. _destroyProperty: function(){
  508. var node = this.lastFocused;
  509. var item = node.item;
  510. var propPath = [];
  511. // we have to walk up the tree to the item before we can know if we're working with the identifier
  512. while(!this.store.isItem(item.parent, true) || item.parent instanceof Array){
  513. node = node.getParent();
  514. propPath.push(item.property);
  515. item = node.item;
  516. }
  517. // this will prevent any part of the identifier from being changed
  518. if(dojo.indexOf(this.store.getIdentityAttributes(), item.property) >= 0){
  519. alert("Cannot Delete an Identifier!");
  520. }else{
  521. try{
  522. if(propPath.length > 0){
  523. // not deleting a top-level property of an item so get the top-level store item to change
  524. var itemVal, storeItemVal = getValue(this.store, item.parent, item.property);
  525. itemVal = storeItemVal;
  526. // walk back down the object if needed
  527. while(propPath.length > 1){
  528. itemVal = itemVal[propPath.pop()];
  529. }
  530. // delete the property
  531. if(dojo.isArray(itemVal)){
  532. // the value being deleted represents an array element
  533. itemVal.splice(propPath, 1);
  534. }else{
  535. // object property
  536. delete itemVal[propPath];
  537. }
  538. // save it back to the store
  539. this.store.setValue(item.parent, item.property, storeItemVal);
  540. }else{
  541. // deleting an item property
  542. this.store.unsetAttribute(item.parent, item.property);
  543. }
  544. }catch(e){
  545. alert(e);
  546. }
  547. }
  548. },
  549. _addProperty: function(){
  550. // item is what we are adding a property to
  551. var item = this.lastFocused.item;
  552. // value is the real value of the item - not a reference to a store item
  553. var value = item.value;
  554. var showDialog = dojo.hitch(this, function(){
  555. var property = null;
  556. if(!this._editDialog){
  557. this._createEditDialog();
  558. }else{
  559. this._editDialog.reset();
  560. }
  561. // are we adding another item to an array?
  562. if(value instanceof Array){
  563. // preset the property to the next index in the array and disable the property field
  564. property = value.length;
  565. dijit.getEnclosingWidget(dojo.query("input", this._editDialog.containerNode)[0]).attr("disabled", true);
  566. }else{
  567. // enable the property TextBox
  568. dijit.getEnclosingWidget(dojo.query("input", this._editDialog.containerNode)[0]).attr("disabled", false);
  569. }
  570. this._editDialog.attr("title", "Add Property");
  571. // default to a value type
  572. this._enableFields("value");
  573. this._editDialog.attr("value", {itemType: "value", property: property});
  574. this._editDialog.show();
  575. });
  576. if(item.addNew){
  577. // we are adding a property to the parent item
  578. item = this.lastFocused.getParent().item;
  579. // the real value of the parent is in the parent property of the lastFocused item
  580. // this.lastFocused.getParent().item.value may be a reference to an item
  581. value = this.lastFocused.item.parent;
  582. }
  583. if(item.property && dojo.indexOf(this.store.getIdentityAttributes(), item.property) >= 0){
  584. alert("Cannot add properties to an ID node!");
  585. }else{
  586. // ifthe value is an item then we need to get the item's value
  587. if(this.store.isItem(value, true) && !this.store.isItemLoaded(value)){
  588. // fetch the value and see if it is an array
  589. this.store.loadItem({
  590. item: value,
  591. onItem: function(loadedItem){
  592. value = loadedItem;
  593. showDialog();
  594. }
  595. });
  596. }else{
  597. showDialog();
  598. }
  599. //
  600. }
  601. }
  602. });
  603. })();
  604. });