Dictionary.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.process = MWF.xApplication.process || {};
  3. MWF.xApplication.process.DictionaryDesigner = MWF.xApplication.process.DictionaryDesigner || {};
  4. MWF.APPDD = MWF.xApplication.process.DictionaryDesigner;
  5. MWF.require("MWF.widget.Common", null, false);
  6. MWF.xDesktop.requireApp("process.DictionaryDesigner", "lp."+MWF.language, null, false);
  7. MWF.xApplication.process.DictionaryDesigner.Dictionary = new Class({
  8. Extends: MWF.widget.Common,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "isView": false,
  13. "showTab": true,
  14. "types": ["object", "array", "string", "number", "boolean"]
  15. },
  16. initialize: function(designer, data, options){
  17. this.setOptions(options);
  18. this.path = "../x_component_process_DictionaryDesigner/$Dictionary/";
  19. this.cssPath = "../x_component_process_DictionaryDesigner/$Dictionary/"+this.options.style+"/css.wcss";
  20. this._loadCss();
  21. this.designer = designer;
  22. this.data = data;
  23. if (!this.data.data) this.data.data = {};
  24. this.node = this.designer.designNode;
  25. this.tab = this.designer.tab;
  26. this.areaNode = new Element("div", {"styles": {"overflow": "auto"}});
  27. //MWF.require("MWF.widget.ScrollBar", function(){
  28. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  29. //}.bind(this));
  30. this.propertyListNode = this.designer.propertyDomArea;
  31. //this.propertyNode = this.designer.propertyContentArea;
  32. if(this.designer.application) this.data.applicationName = this.designer.application.name;
  33. if(this.designer.application) this.data.application = this.designer.application.id;
  34. this.isNewDictionary = (this.data.id) ? false : true;
  35. this.items = [];
  36. this.autoSave();
  37. this.designer.addEvent("queryClose", function(){
  38. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  39. }.bind(this));
  40. },
  41. autoSave: function(){
  42. this.autoSaveTimerID = window.setInterval(function(){
  43. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFDictionaryAutoSaveCheck");
  44. if (this.autoSaveCheckNode){
  45. if (this.autoSaveCheckNode.get("checked")){
  46. this.save();
  47. }
  48. }
  49. }.bind(this), 60000);
  50. },
  51. createTitle: function(){
  52. this.itemsNode = new Element("div", {"styles": this.css.itemsNode}).inject(this.areaNode);
  53. this.typesNode = new Element("div", {"styles": this.css.typesNode}).inject(this.areaNode);
  54. this.valuesNode = new Element("div", {"styles": this.css.valuesNode}).inject(this.areaNode);
  55. this.itemTitleNode = new Element("div", {"styles": this.css.itemTitleNode}).inject(this.itemsNode);
  56. this.typeTitleNode = new Element("div", {"styles": this.css.typeTitleNode}).inject(this.typesNode);
  57. this.valueTitleNode = new Element("div", {"styles": this.css.valueTitleNode}).inject(this.valuesNode);
  58. this.itemResizeNode = new Element("div", {"styles": this.css.itemResizeNode}).inject(this.itemTitleNode);
  59. this.typeResizeNode = new Element("div", {"styles": this.css.typeResizeNode}).inject(this.typeTitleNode);
  60. // this.addTopItemNode = new Element("div", {"styles": this.css.addTopItemNode}).inject(this.itemTitleNode);
  61. this.itemTitleTextNode = new Element("div", {"styles": this.css.itemTitleTextNode, "text": this.designer.lp.item}).inject(this.itemTitleNode);
  62. this.typeTitleTextNode = new Element("div", {"styles": this.css.typeTitleTextNode, "text": this.designer.lp.type}).inject(this.typeTitleNode);
  63. this.valueTitleTextNode = new Element("div", {"styles": this.css.valueTitleTextNode, "text": this.designer.lp.value}).inject(this.valueTitleNode);
  64. // this.addTopItemNode.addEvent("click", this.addTopItem.bind(this));
  65. },
  66. load : function(){
  67. this.setAreaNodeSize();
  68. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  69. this.page = this.tab.addTab(this.areaNode, this.data.name || this.designer.lp.newDictionary, (!this.data.isNewDictionary && this.data.id!=this.designer.options.id));
  70. this.page.dictionary = this;
  71. this.page.addEvent("show", function(){
  72. this.designer.dictionaryListAreaNode.getChildren().each(function(node){
  73. var dictionary = node.retrieve("dictionary");
  74. if (dictionary.id==this.data.id){
  75. if (this.designer.currentListDictionaryItem){
  76. this.designer.currentListDictionaryItem.setStyles(this.designer.css.listDictionaryItem);
  77. }
  78. node.setStyles(this.designer.css.listDictionaryItem_current);
  79. this.designer.currentListDictionaryItem = node;
  80. this.lisNode = node;
  81. }
  82. }.bind(this));
  83. this.setPropertyContent();
  84. }.bind(this));
  85. this.page.addEvent("queryClose", function(){
  86. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  87. this.saveSilence();
  88. if (this.lisNode) this.lisNode.setStyles(this.designer.css.listScriptItem);
  89. }.bind(this));
  90. this.page.tabNode.addEvent("dblclick", this.designer.maxOrReturnEditor.bind(this.designer));
  91. this.createTitle();
  92. this.createRootItem();
  93. if (this.options.showTab) this.page.showTabIm();
  94. },
  95. setPropertyContent: function(){
  96. this.designer.propertyIdNode.set("text", this.data.id);
  97. this.designer.propertyNameNode.set("value", this.data.name);
  98. this.designer.propertyAliasNode.set("value", this.data.alias);
  99. this.designer.propertyDescriptionNode.set("value", this.data.description);
  100. this.designer.jsonDomNode.empty();
  101. MWF.require("MWF.widget.JsonParse", function(){
  102. this.jsonParse = new MWF.widget.JsonParse(this.data.data, this.designer.jsonDomNode, this.designer.jsonTextAreaNode);
  103. window.setTimeout(function(){
  104. this.jsonParse.load();
  105. }.bind(this), 1);
  106. }.bind(this));
  107. },
  108. setAreaNodeSize: function(){
  109. var size = this.node.getSize();
  110. var tabSize = this.tab.tabNodeContainer.getSize();
  111. var searchY = 0;
  112. if (this.searchNode) searchY = this.searchNode.getSize().y;
  113. var y = size.y - tabSize.y - searchY;
  114. this.areaNode.setStyle("height", ""+y+"px");
  115. if (this.editor) if (this.editor.editor) this.editor.editor.resize();
  116. },
  117. createRootItem: function() {
  118. this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true));
  119. },
  120. saveSilence: function(){
  121. if (!this.isSave){
  122. var name = this.designer.propertyNameNode.get("value");
  123. var alias = this.designer.propertyAliasNode.get("value");
  124. var description = this.designer.propertyDescriptionNode.get("value");
  125. if (!name){
  126. this.designer.notice(this.designer.lp.notice.inputName, "error");
  127. return false;
  128. }
  129. this.data.name = name;
  130. this.data.alias = alias;
  131. this.data.description = description;
  132. this.isSave = true;
  133. this.designer.actions.saveDictionary(this.data, function(json){
  134. this.isSave = false;
  135. this.data.id = json.data.id;
  136. if (callback) callback();
  137. }.bind(this), function(xhr, text, error){
  138. this.isSave = false;
  139. //
  140. //var errorText = error+":"+text;
  141. //if (xhr) errorText = xhr.responseText;
  142. //MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  143. }.bind(this));
  144. }
  145. },
  146. save: function(callback){
  147. if (!this.isSave){
  148. if (this.designer.tab.showPage==this.page){
  149. var name = this.designer.propertyNameNode.get("value");
  150. var alias = this.designer.propertyAliasNode.get("value");
  151. var description = this.designer.propertyDescriptionNode.get("value");
  152. if (!name || !alias){
  153. this.designer.notice(this.designer.lp.notice.inputName, "error");
  154. return false;
  155. }
  156. this.data.name = name;
  157. this.data.alias = alias;
  158. this.data.description = description;
  159. }
  160. this.isSave = true;
  161. this.designer.actions.saveDictionary(this.data, function(json){
  162. this.isSave = false;
  163. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  164. this.data.isNewDictionary = false;
  165. this.isNewDictionary = false;
  166. this.data.id = json.data.id;
  167. this.page.textNode.set("text", this.data.name);
  168. if (this.lisNode) {
  169. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  170. }
  171. if (callback) callback();
  172. }.bind(this), function(xhr, text, error){
  173. this.isSave = false;
  174. var errorText = error+":"+text;
  175. if (xhr) errorText = xhr.responseText;
  176. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  177. }.bind(this));
  178. }else{
  179. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  180. }
  181. },
  182. loadSearch: function(){
  183. if (!this.searchNode){
  184. this.createSearchNode();
  185. }else{
  186. if (this.searchNode.getStyle("display")=="none"){
  187. this.searchNode.setStyle("display", "block");
  188. }else{
  189. this.searchNode.setStyle("display", "none");
  190. }
  191. }
  192. this.setAreaNodeSize();
  193. },
  194. createSearchNode: function(){
  195. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.areaNode, "before");
  196. this.searchInputNode = new Element("div", {"styles": this.css.searchInputNode}).inject(this.searchNode);
  197. this.searchInput = new Element("input", {"styles": this.css.searchInput}).inject(this.searchInputNode);
  198. this.searchAction = new Element("div", {"styles": this.css.searchAction, "text": this.designer.lp.search}).inject(this.searchNode);
  199. var lineNode = new Element("div", {"styles": this.css.searchLineNode,}).inject(this.searchNode);
  200. this.nextAction = new Element("div", {"styles": this.css.searchNextAction, "text": this.designer.lp.next}).inject(this.searchNode);
  201. this.searchAction.addEvent("click", function(){
  202. this.searchDictionary();
  203. }.bind(this));
  204. this.nextAction.addEvent("click", function(){
  205. this.searchDictionaryNext();
  206. }.bind(this));
  207. },
  208. searchDictionary: function(){
  209. var key = this.searchInput.get("value");
  210. if (key){
  211. this.currentSearchItem = null;
  212. if (!this.getSearchItem(key)){
  213. }
  214. }
  215. },
  216. searchDictionaryNext: function(){
  217. var key = this.searchInput.get("value");
  218. if (key){
  219. if (!this.getSearchItem(key, null, this.currentSearchItem)){
  220. if (!this.getSearchItem(key)){
  221. }
  222. }
  223. }
  224. },
  225. getSearchItem: function(key, rootItem, item){
  226. var fromItem = rootItem || this.items[0];
  227. var flag = true;
  228. if (item){
  229. if (item.type=="object"){
  230. if (!item.exp) item.expOrColChildren();
  231. if (this.getSearchItem(key, item)) return true;
  232. }
  233. fromItem = item.parent;
  234. flag = false;
  235. }
  236. if (fromItem.type=="object") {
  237. if (!fromItem.exp) fromItem.expOrColChildren();
  238. for (var i=0; i<fromItem.children.length; i++){
  239. var child = fromItem.children[i];
  240. if (flag){
  241. if (child.key.indexOf(key)!=-1){
  242. child.selected();
  243. this.currentSearchItem = child;
  244. new Fx.Scroll(this.areaNode).toElement(child.itemNode);
  245. return true;
  246. }else{
  247. if (child.type=="object"){
  248. if (!child.exp) child.expOrColChildren();
  249. if (child.children.length){
  250. if (this.getSearchItem(key, child)) return true;
  251. }
  252. }
  253. }
  254. }
  255. if (item) if (child==item) flag = true;
  256. }
  257. }else{
  258. if (fromItem.key.indexOf(key)!=-1){
  259. fromItem.selected();
  260. this.currentSearchItem = fromItem;
  261. return true;
  262. }
  263. }
  264. while ((fromItem) && fromItem.key!="ROOT"){
  265. if (fromItem.nextSibling){
  266. fromItem = fromItem.nextSibling;
  267. }else{
  268. fromItem = fromItem.parent;
  269. if (fromItem) fromItem = fromItem.nextSibling;
  270. }
  271. if (fromItem){
  272. if (this.getSearchItem(key, fromItem)) return true;
  273. }
  274. }
  275. return false;
  276. },
  277. saveAs: function(){},
  278. explode: function(){},
  279. implode: function(){}
  280. });
  281. MWF.xApplication.process.DictionaryDesigner.Dictionary.item = new Class({
  282. initialize: function(key, value, parent, level, dictionary, exp, nextSibling){
  283. this.key = key;
  284. this.value = value;
  285. this.parent = parent;
  286. this.level = level;
  287. this.dictionary = dictionary;
  288. this.exp = exp || false;
  289. this.nextSibling = nextSibling;
  290. this.children = [];
  291. this.childrenItemCreated = false;
  292. this.css = this.dictionary.css;
  293. this.type = typeOf(this.value);
  294. // if (this.parent) this.parent.children.push(this);
  295. this.load();
  296. },
  297. load: function(){
  298. this.createNodes();
  299. this.setNodeText();
  300. this.setEvent();
  301. if (this.exp) this.createChildrenItems();
  302. },
  303. createNodes: function() {
  304. this.itemNode = new Element("div", {"styles": this.css.itemNode});
  305. this.typeNode = new Element("div", {"styles": this.css.typeNode});
  306. this.valueNode = new Element("div", {"styles": this.css.valueNode});
  307. //var left = this.itemNode.getStyle("padding-left").toFloat();
  308. var left = 10;
  309. left = left + (this.level*20);
  310. this.itemNode.setStyle("padding-left", ""+left+"px");
  311. this.itemActionsAreaNode = new Element("div", {"styles": this.css.itemActionsAreaNode}).inject(this.itemNode);
  312. if (this.type=="array" || this.type=="object" || (this.parent && this.parent.type=="array")){
  313. this.itemAddActionNode = new Element("div", {"styles": this.css.itemAddActionNode}).inject(this.itemActionsAreaNode);
  314. }
  315. if (this.parent) this.itemDelActionNode = new Element("div", {"styles": this.css.itemDelActionNode}).inject(this.itemActionsAreaNode);
  316. if (this.type=="array" || this.type=="object"){
  317. this.itemExpColActionNode = new Element("div", {"styles": this.css.itemExpColActionNode}).inject(this.itemNode);
  318. if (this.exp){
  319. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_process_DictionaryDesigner/$Dictionary/default/icon/col.png)");
  320. }else{
  321. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_process_DictionaryDesigner/$Dictionary/default/icon/exp.png)");
  322. }
  323. }
  324. this.typeActionsAreaNode = new Element("div", {"styles": this.css.typeActionsAreaNode}).inject(this.typeNode);
  325. this.typeSelActionNode = new Element("div", {"styles": this.css.typeSelActionNode}).inject(this.typeActionsAreaNode);
  326. this.valueActionsAreaNode = new Element("div", {"styles": this.css.valueActionsAreaNode}).inject(this.valueNode);
  327. if (this.type=="boolean") this.valueSelActionNode = new Element("div", {"styles": this.css.valueSelActionNode}).inject(this.valueActionsAreaNode);
  328. this.itemTextNode = new Element("div", {"styles": this.css.itemTextNode}).inject(this.itemNode);
  329. this.typeTextNode = new Element("div", {"styles": this.css.typeTextNode}).inject(this.typeNode);
  330. this.valueTextNode = new Element("div", {"styles": this.css.valueTextNode}).inject(this.valueNode);
  331. if (this.nextSibling){
  332. this.itemNode.inject(this.nextSibling.itemNode, "before");
  333. this.typeNode.inject(this.nextSibling.typeNode, "before");
  334. this.valueNode.inject(this.nextSibling.valueNode, "before");
  335. }else{
  336. if (this.parent){
  337. if (this.parent.children.length){
  338. var injectItem = this.parent.children.getLast();
  339. this.itemNode.inject(injectItem.itemNode, "after");
  340. this.typeNode.inject(injectItem.typeNode, "after");
  341. this.valueNode.inject(injectItem.valueNode, "after");
  342. }else{
  343. this.itemNode.inject(this.parent.itemNode, "after");
  344. this.typeNode.inject(this.parent.typeNode, "after");
  345. this.valueNode.inject(this.parent.valueNode, "after");
  346. }
  347. }else{
  348. this.itemNode.inject(this.dictionary.itemsNode);
  349. this.typeNode.inject(this.dictionary.typesNode);
  350. this.valueNode.inject(this.dictionary.valuesNode);
  351. }
  352. }
  353. },
  354. resetNodes: function(){
  355. this.itemTextNode.removeEvents("mousedown");
  356. this.valueTextNode.removeEvents("mousedown");
  357. if (this.type=="array" || this.type=="object"){
  358. if (!this.itemExpColActionNode){
  359. this.itemExpColActionNode = new Element("div", {"styles": this.css.itemExpColActionNode}).inject(this.itemTextNode, "before");
  360. if (this.exp){
  361. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_process_DictionaryDesigner/$Dictionary/default/icon/col.png)");
  362. }else{
  363. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_process_DictionaryDesigner/$Dictionary/default/icon/exp.png)");
  364. }
  365. this.itemExpColActionNode.addEvents({
  366. "click": function(){this.expOrColChildren();}.bind(this)
  367. });
  368. }
  369. }else{
  370. if (this.itemExpColActionNode){
  371. this.itemExpColActionNode.destroy();
  372. this.itemExpColActionNode = null;
  373. }
  374. if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  375. }
  376. if (this.type=="array" || this.type=="object" || (this.parent && this.parent.type=="array")){
  377. if (!this.itemAddActionNode){
  378. this.itemAddActionNode = new Element("div", {"styles": this.css.itemAddActionNode}).inject(this.itemActionsAreaNode);
  379. this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this));
  380. }
  381. }else{
  382. if (this.itemAddActionNode) this.itemAddActionNode.destroy();
  383. this.itemAddActionNode = null;
  384. }
  385. if (this.type=="boolean"){
  386. if (!this.valueSelActionNode) this.valueSelActionNode = new Element("div", {"styles": this.css.valueSelActionNode}).inject(this.valueActionsAreaNode);
  387. this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  388. this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  389. }
  390. if (this.parent){
  391. if (this.parent.type!="array"){
  392. this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  393. }
  394. }
  395. },
  396. setNodeText: function(){
  397. var text = this.key;
  398. if (this.parent) if (this.parent.type=="array") text = "["+text+"]";
  399. this.itemTextNode.set("text", text);
  400. this.typeTextNode.set("text", this.type);
  401. switch(this.type){
  402. case "array":
  403. this.valueTextNode.setStyles(this.css.valueTextNode);
  404. this.valueTextNode.set("text", ""+this.value.length+" Items");
  405. break;
  406. case "object":
  407. var i=0;
  408. Object.each(this.value, function(){i++;});
  409. this.valueTextNode.setStyles(this.css.valueTextNode);
  410. this.valueTextNode.set("text", ""+i+" Items");
  411. break;
  412. default:
  413. this.valueTextNode.setStyles(this.css.valueTextNode_edit);
  414. this.valueTextNode.set("text", this.value);
  415. break;
  416. }
  417. },
  418. setEvent: function(){
  419. this.itemNode.addEvent("click", function(e){this.selected();}.bind(this));
  420. this.typeNode.addEvent("click", function(e){this.selected();}.bind(this));
  421. this.valueNode.addEvent("click", function(e){this.selected();}.bind(this));
  422. this.typeSelActionNode.addEvent("click", function(e){this.selectType();}.bind(this));
  423. this.typeTextNode.addEvent("click", function(e){this.selectType();}.bind(this));
  424. this.itemNode.addEvents({
  425. "mouseover": function(){this.itemActionsAreaNode.fade("in");}.bind(this),
  426. "mouseout": function(){this.itemActionsAreaNode.fade("out");}.bind(this)
  427. });
  428. if (this.itemAddActionNode) this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this));
  429. if (this.itemDelActionNode) this.itemDelActionNode.addEvent("click", function(e){this.delItem(e);}.bind(this));
  430. if (this.type=="array" || this.type=="object"){
  431. this.itemExpColActionNode.addEvents({
  432. "click": function(){this.expOrColChildren();}.bind(this)
  433. });
  434. }else{
  435. if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  436. }
  437. if (this.parent){
  438. if (this.parent.type!="array"){
  439. this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  440. }
  441. }
  442. if (this.type=="boolean"){
  443. this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  444. this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  445. }
  446. },
  447. expOrColChildren: function(){
  448. if (this.exp){
  449. this.colChildren();
  450. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_process_DictionaryDesigner/$Dictionary/default/icon/exp.png)");
  451. this.exp = false;
  452. }else{
  453. this.expChildren();
  454. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_process_DictionaryDesigner/$Dictionary/default/icon/col.png)");
  455. this.exp = true;
  456. }
  457. },
  458. colChildren: function(){
  459. this.children.each(function(item){
  460. item.colChildren();
  461. item.colChildrenNode();
  462. });
  463. },
  464. expChildren: function(){
  465. this.createChildrenItems();
  466. this.children.each(function(item){
  467. if (item.exp) item.expChildren();
  468. item.expChildrenNode();
  469. });
  470. },
  471. colChildrenNode: function(){
  472. this.itemNode.setStyle("display", "none");
  473. this.typeNode.setStyle("display", "none");
  474. this.valueNode.setStyle("display", "none");
  475. },
  476. expChildrenNode: function(){
  477. this.itemNode.setStyle("display", "block");
  478. this.typeNode.setStyle("display", "block");
  479. this.valueNode.setStyle("display", "block");
  480. },
  481. unSelected: function(){
  482. this.itemNode.setStyles(this.css.itemNode);
  483. this.typeNode.setStyles(this.css.typeNode);
  484. this.valueNode.setStyles(this.css.valueNode);
  485. this.dictionary.currentSelectedItem = null;
  486. },
  487. selected: function(){
  488. if (this.dictionary.currentSelectedItem!=this){
  489. if (this.dictionary.currentSelectedItem) this.dictionary.currentSelectedItem.unSelected();
  490. this.itemNode.setStyles(this.css.itemNode_selected);
  491. this.typeNode.setStyles(this.css.typeNode_selected);
  492. this.valueNode.setStyles(this.css.valueNode_selected);
  493. this.listDataItems();
  494. this.dictionary.currentSelectedItem = this;
  495. }
  496. },
  497. listDataItems: function(){
  498. this.dictionary.propertyListNode.empty();
  499. switch(this.type){
  500. case "array":
  501. this.value.each(function(v, idx){
  502. this.createDataListItem("["+idx+"]", v.toString());
  503. }.bind(this));
  504. break;
  505. case "object":
  506. Object.each(this.value, function(v, key){
  507. this.createDataListItem(key, v.toString());
  508. }.bind(this));
  509. break;
  510. }
  511. },
  512. createDataListItem: function(key, v){
  513. var node = new Element("div", {"styles": this.css.dataListItemNode}).inject(this.dictionary.propertyListNode);
  514. var keyNode = new Element("div", {"styles": this.css.dataListItemKeyNode, "text": key, "title": key}).inject(node);
  515. var vNode = new Element("div", {"styles": this.css.dataListItemValueNode, "text": v, "title": v}).inject(node);
  516. },
  517. createNewItem: function(key, value, parent, level, dictionary, exp, nextSibling){
  518. return new MWF.xApplication.process.DictionaryDesigner.Dictionary.item(key, value, parent, level, dictionary, exp, nextSibling);
  519. },
  520. createChildrenItems: function(){
  521. if (!this.childrenItemCreated){
  522. switch(this.type){
  523. case "array":
  524. this.value.each(function(v, idx){
  525. var item = this.createNewItem(idx, v, this, this.level+1, this.dictionary, false);
  526. if (this.children.length) this.children[this.children.length-1].nextSibling = item;
  527. this.children.push(item);
  528. }.bind(this));
  529. break;
  530. case "object":
  531. Object.each(this.value, function(v, key){
  532. var item = this.createNewItem(key, v, this, this.level+1, this.dictionary, false);
  533. if (this.children.length) this.children[this.children.length-1].nextSibling = item;
  534. this.children.push(item);
  535. }.bind(this));
  536. break;
  537. default:
  538. //nothing
  539. break;
  540. }
  541. this.childrenItemCreated = true;
  542. }
  543. },
  544. addItem: function(e){
  545. if (!this.parent){
  546. this.createChildrenItems();
  547. this.addChild();
  548. }else{
  549. if (this.exp){
  550. this.addChild();
  551. }else{
  552. this.addSibling();
  553. }
  554. }
  555. this.dictionary.jsonParse.loadObjectTree();
  556. },
  557. addChild: function(){
  558. var item;
  559. if (this.type=="array"){
  560. var idx = this.value.length;
  561. var arrayValue = "New Element Value";
  562. this.value.push(arrayValue);
  563. item = this.createNewItem(idx, arrayValue, this, this.level+1, this.dictionary, false);
  564. }
  565. if (this.type=="object") {
  566. var key = "NewItem";
  567. var i = 0;
  568. while (this.value[key] !== undefined) {
  569. i++;
  570. key = "NewItem" + i;
  571. }
  572. var objValue1 = "New Item Value";
  573. this.value[key] = objValue1;
  574. item = this.createNewItem(key, objValue1, this, this.level + 1, this.dictionary, false)
  575. }
  576. if (this.children.length) this.children[this.children.length-1].nextSibling = item;
  577. this.children.push(item);
  578. },
  579. addSibling: function(){
  580. var item = null;
  581. var idx;
  582. if (this.parent.type=="array"){
  583. idx = this.key;
  584. var value = "New Element Value";
  585. this.parent.value.splice(this.key, 0, value);
  586. for (var i=this.key; i<this.parent.children.length; i++){
  587. var item = this.parent.children[i];
  588. item.key = item.key+1;
  589. item.setNodeText();
  590. }
  591. item = this.createNewItem(idx, value, this.parent, this.level, this.dictionary, false, this);
  592. }else{
  593. var key = "NewItem";
  594. var i = 0;
  595. while (this.parent.value[key] != undefined) {
  596. i++;
  597. key = "NewItem" + i;
  598. }
  599. var value = "New Item Value";
  600. this.parent.value[key] = value;
  601. var item = this.createNewItem(key, value, this.parent, this.level, this.dictionary, false, this);
  602. idx = this.parent.children.indexOf(this);
  603. }
  604. if (idx) this.parent.children[idx-1].nextSibling = item;
  605. this.parent.children.splice(idx, 0, item);
  606. },
  607. delItem: function(e){
  608. var _self = this;
  609. this.dictionary.designer.shortcut = false;
  610. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.deleteDataTitle, this.dictionary.designer.lp.notice.deleteData, 300, 120, function(){
  611. _self.destroy();
  612. _self.dictionary.jsonParse.loadObjectTree();
  613. _self.dictionary.designer.shortcut = true;
  614. this.close();
  615. }, function(){
  616. _self.dictionary.designer.shortcut = true;
  617. this.close();
  618. });
  619. },
  620. destroy: function(){
  621. var idx = this.parent.children.indexOf(this);
  622. if (idx) this.parent.children[idx-1].nextSibling = this.nextSibling;
  623. this.destroyAllNodes();
  624. this.parent.children.erase(this);
  625. if (this.parent.type=="object"){
  626. delete this.parent.value[this.key];
  627. delete this;
  628. }
  629. if (this.parent.type=="array"){
  630. this.parent.value.splice(this.key, 1);
  631. for (var i=this.key; i<this.parent.children.length; i++){
  632. this.parent.children[i].key = this.parent.children[i].key-1;
  633. this.parent.children[i].setNodeText();
  634. }
  635. }
  636. this.dictionary.jsonParse.loadObjectTree();
  637. },
  638. destroyAllNodes: function(){
  639. this.children.each(function(item){
  640. item.destroyAllNodes();
  641. });
  642. this.itemNode.destroy();
  643. this.typeNode.destroy();
  644. this.valueNode.destroy();
  645. if (this.typeSelectNode) this.typeSelectNode.destroy();
  646. },
  647. selectType: function(){
  648. if (!this.typeSelectNode) this.createTypeSelectNode();
  649. this.typeSelectNode.setStyle("display", "block");
  650. var size = this.dictionary.node.getSize();
  651. var selSize = this.typeSelectNode.getSize();
  652. var itemNodes = this.typeSelectNode.getChildren();
  653. for (var i=0; i<itemNodes.length; i++){
  654. if (itemNodes[i].get("text")==this.type){
  655. itemNodes[i].setStyles(this.css.typeSelectItemNode_over);
  656. }else{
  657. itemNodes[i].setStyles(this.css.typeSelectItemNode);
  658. }
  659. };
  660. this.typeSelectNode.position({
  661. relativeTo: this.typeNode,
  662. position: 'upperLeft',
  663. edge: 'upperLeft'
  664. });
  665. var p = this.typeSelectNode.getPosition(this.typeSelectNode.getOffsetParent());
  666. if ((p.y+selSize.y)>size.y){
  667. this.typeSelectNode.position({
  668. relativeTo: this.typeNode,
  669. position: 'bottomLeft',
  670. edge: 'bottomLeft'
  671. });
  672. };
  673. this.closeTypeSelectNodeFun = this.closeTypeSelectNode.bind(this);
  674. $(document.body).addEvent("mousedown", this.closeTypeSelectNodeFun);
  675. },
  676. closeTypeSelectNode: function(){
  677. this.typeSelectNode.setStyle("display", "none");
  678. $(document.body).removeEvent("mousedown", this.closeTypeSelectNodeFun);
  679. },
  680. createTypeSelectNode: function(){
  681. var _self = this;
  682. this.typeSelectNode = new Element("div", {"styles": this.css.typeSelectNode});
  683. var types = this.dictionary.options.types;
  684. if (!this.parent){
  685. types = ["object", "array"];
  686. this.typeSelectNode.setStyle("height", "50px");
  687. }
  688. types.each(function(type){
  689. var itemNode = new Element("div", {"styles": this.css.typeSelectItemNode}).inject(this.typeSelectNode);
  690. itemNode.set("text", type);
  691. if (this.type==type) itemNode.setStyles(this.css.typeSelectItemNode_over);
  692. itemNode.addEvents({
  693. "mouseover": function(){this.setStyles(_self.css.typeSelectItemNode_over);},
  694. "mouseout": function(){this.setStyles(_self.css.typeSelectItemNode);},
  695. "mousedown": function(e){_self.selectedType(this, e);}
  696. })
  697. }.bind(this));
  698. this.typeSelectNode.inject(this.dictionary.node);
  699. },
  700. selectedType: function(itemNode, e){
  701. e.target = null;
  702. var type = itemNode.get("text");
  703. if (this.type!=type){
  704. var _self = this;
  705. switch(type){
  706. case "array":
  707. if (this.value!="New Item Value" && this.value!="New Element Value"){
  708. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeType, this.dictionary.designer.lp.notice.changeType, 300, 120, function(){
  709. if (_self.type=="object"){
  710. _self.changeTypeObjectToArray(type);
  711. }else{
  712. _self.changeTypePrimitiveToArray(type);
  713. }
  714. this.close();
  715. _self.dictionary.jsonParse.loadObjectTree();
  716. }, function(){
  717. this.close();
  718. });
  719. }else{
  720. if (this.type=="object"){
  721. this.changeTypeObjectToArray(type);
  722. }else{
  723. this.changeTypePrimitiveToArray(type);
  724. }
  725. this.dictionary.jsonParse.loadObjectTree();
  726. }
  727. break;
  728. case "object":
  729. if (this.value!="New Item Value" && this.value!="New Element Value") {
  730. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeType, this.dictionary.designer.lp.notice.changeType, 300, 120, function () {
  731. if (_self.type == "array") {
  732. _self.changeTypeArrayToObject(type);
  733. } else {
  734. _self.changeTypePrimitiveToObject(type);
  735. }
  736. this.close();
  737. _self.dictionary.jsonParse.loadObjectTree();
  738. }, function () {
  739. this.close();
  740. });
  741. }else{
  742. if (this.type == "array") {
  743. this.changeTypeArrayToObject(type);
  744. } else {
  745. this.changeTypePrimitiveToObject(type);
  746. }
  747. this.dictionary.jsonParse.loadObjectTree();
  748. }
  749. break;
  750. default:
  751. if (this.value!="New Item Value" && this.value!="New Element Value") {
  752. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeType, this.dictionary.designer.lp.notice.changeTypeDeleteChildren, 300, 120, function () {
  753. if (_self.type == "array") {
  754. _self.changeTypeArrayToPrimitive(type);
  755. } else if (_self.type == "object") {
  756. _self.changeTypeObjectToPrimitive(type);
  757. } else {
  758. _self.changeTypePrimitiveToPrimitive(type);
  759. }
  760. this.close();
  761. _self.dictionary.jsonParse.loadObjectTree();
  762. }, function () {
  763. this.close();
  764. });
  765. }else{
  766. if (this.type == "array") {
  767. this.changeTypeArrayToPrimitive(type);
  768. } else if (_self.type == "object") {
  769. this.changeTypeObjectToPrimitive(type);
  770. } else {
  771. this.changeTypePrimitiveToPrimitive(type);
  772. }
  773. this.dictionary.jsonParse.loadObjectTree();
  774. }
  775. break;
  776. }
  777. }
  778. },
  779. deleteAllChildren: function(){
  780. this.children.each(function(item){
  781. item.destroyAllNodes();
  782. });
  783. },
  784. changeTypeObjectToPrimitive: function(type){
  785. this.deleteAllChildren();
  786. this.children = [];
  787. this.childrenItemCreated = false;
  788. var value;
  789. switch(type){
  790. case "string":
  791. value = "";
  792. break;
  793. case "number":
  794. value = 0;
  795. break;
  796. case "boolean":
  797. value = true;
  798. break;
  799. }
  800. delete this.parent.value[this.key];
  801. this.parent.value[this.key] = value;
  802. this.value = value;
  803. this.type = type;
  804. this.exp = false;
  805. this.setNodeText();
  806. this.resetNodes();
  807. },
  808. changeTypeArrayToPrimitive: function(type){
  809. this.changeTypeObjectToPrimitive(type);
  810. },
  811. changeTypePrimitiveToPrimitive: function(type){
  812. switch(type){
  813. case "string":
  814. value = this.value.toString();
  815. break;
  816. case "number":
  817. value = this.value.toFloat();
  818. if (isNaN(value)) value = 0
  819. break;
  820. case "boolean":
  821. value = true;
  822. if (this.value=="false") value = false;
  823. break;
  824. }
  825. delete this.parent.value[this.key];
  826. this.parent.value[this.key] = value;
  827. this.value = value;
  828. this.type = type;
  829. this.exp = false;
  830. this.setNodeText();
  831. this.resetNodes();
  832. },
  833. changeTypePrimitiveToObject: function(type){
  834. value = {};
  835. delete this.parent.value[this.key];
  836. this.parent.value[this.key] = value;
  837. this.value = value;
  838. this.type = type;
  839. this.exp = false;
  840. this.setNodeText();
  841. this.resetNodes();
  842. },
  843. changeTypeArrayToObject: function(type){
  844. this.deleteAllChildren();
  845. this.children = [];
  846. this.childrenItemCreated = false;
  847. var value = {};
  848. this.value.each(function(v, idx){
  849. value["ITEM"+idx] = v;
  850. });
  851. if (this.parent){
  852. delete this.parent.value[this.key];
  853. this.parent.value[this.key] = value;
  854. this.value = value;
  855. this.type = type;
  856. this.setNodeText();
  857. this.resetNodes();
  858. if (this.exp) this.createChildrenItems();
  859. }else{
  860. this.dictionary.data.data = value;
  861. this.dictionary.jsonParse.json = value;
  862. this.value = value;
  863. this.type = type;
  864. this.setNodeText();
  865. this.resetNodes();
  866. if (this.exp) this.createChildrenItems();
  867. }
  868. },
  869. changeTypePrimitiveToArray: function(type) {
  870. value = [];
  871. delete this.parent.value[this.key];
  872. this.parent.value[this.key] = value;
  873. this.value = value;
  874. this.type = type;
  875. this.exp = false;
  876. this.setNodeText();
  877. this.resetNodes();
  878. },
  879. changeTypeObjectToArray: function(type){
  880. this.deleteAllChildren();
  881. this.children = [];
  882. this.childrenItemCreated = false;
  883. var value = [];
  884. Object.each(this.value, function(v, idx){
  885. value.push(v);
  886. });
  887. if (this.parent){
  888. delete this.parent.value[this.key];
  889. this.parent.value[this.key] = value;
  890. this.value = value;
  891. this.type = type;
  892. this.childrenItemCreated = false;
  893. this.setNodeText();
  894. this.resetNodes();
  895. if (this.exp) this.createChildrenItems();
  896. }else{
  897. this.dictionary.data.data = value;
  898. this.dictionary.jsonParse.json = value;
  899. this.value = value;
  900. this.type = type;
  901. this.childrenItemCreated = false;
  902. this.setNodeText();
  903. this.resetNodes();
  904. if (this.exp) this.createChildrenItems();
  905. }
  906. },
  907. editValue: function(){
  908. //this.inEdit
  909. this.valueTextNode.empty();
  910. // this.valueTextNode.removeEvents("mousedown");
  911. this.editValueNode = new Element("input", {"styles": this.css.itemEditValueNode}).inject(this.valueTextNode);
  912. this.editValueNode.set("value", this.value);
  913. window.setTimeout(function(){
  914. this.editValueNode.focus();
  915. this.editValueNode.select();
  916. this.editValueNode.addEvents({
  917. "blur": function(e){
  918. this.editValueConfirm(e);
  919. }.bind(this),
  920. "keydown": function(e){
  921. if (e.code==13){
  922. this.editValueConfirm(e);
  923. if (this.nextSibling){
  924. this.nextSibling.editKey();
  925. }
  926. }
  927. e.stopPropagation();
  928. }.bind(this),
  929. "mousedown": function(e){e.stopPropagation();}
  930. });
  931. }.bind(this), 10)
  932. },
  933. editValueConfirm: function(e){
  934. var value = this.editValueNode.get("Value");
  935. if (this.type=="number"){
  936. if (isNaN(parseFloat(value))){
  937. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.inputTypeError, "error", this.editValueNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  938. this.editValueNode.setStyles(this.css.itemEditValueNode_error);
  939. this.editValueNode.select();
  940. e.preventDefault();
  941. return false;
  942. }
  943. value = value.toFloat();
  944. }
  945. this.value = value;
  946. this.parent.value[this.key] = this.value;
  947. this.editValueNode.destroy();
  948. this.editValueNode = null;
  949. this.setNodeText();
  950. this.dictionary.jsonParse.loadObjectTree();
  951. // if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  952. },
  953. editKey: function(){
  954. this.itemTextNode.empty();
  955. // this.itemTextNode.removeEvents("mousedown");
  956. this.editKeyNode = new Element("input", {"styles": this.css.itemEditValueNode, "type": "text"}).inject(this.itemTextNode);
  957. this.editKeyNode.set("value", this.key);
  958. window.setTimeout(function(){
  959. this.editKeyNode.focus();
  960. this.editKeyNode.select();
  961. //this.editKeyNode.setSelectionRange(1,this.key.length-1);
  962. this.editKeyNode.addEvents({
  963. "blur": function(e){this.editKeyConfirm(e);}.bind(this),
  964. "keydown": function(e){
  965. if (e.code==13){
  966. this.editKeyConfirm(e);
  967. if (this.type!="array" && this.type!="object" && this.type!="boolean") {
  968. this.editValue();
  969. }else{
  970. if (this.nextSibling){
  971. this.nextSibling.editKey();
  972. }
  973. }
  974. }
  975. e.stopPropagation();
  976. }.bind(this),
  977. "mousedown": function(e){e.stopPropagation();}
  978. });
  979. }.bind(this), 10);
  980. },
  981. editKeyConfirm: function(e){
  982. var key = this.editKeyNode.get("Value");
  983. if (key!=this.key){
  984. if (this.parent.value[key]){
  985. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.sameKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  986. this.editKeyNode.setStyles(this.css.itemEditValueNode_error);
  987. this.editKeyNode.select();
  988. e.preventDefault();
  989. return false;
  990. }
  991. if (!isNaN(parseFloat(key))){
  992. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.numberKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  993. this.editKeyNode.setStyles(this.css.itemEditValueNode_error);
  994. this.editKeyNode.select();
  995. e.preventDefault();
  996. return false;
  997. }
  998. if (!key){
  999. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.emptyKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  1000. this.editKeyNode.setStyles(this.css.itemEditValueNode_error);
  1001. this.editKeyNode.select();
  1002. e.preventDefault();
  1003. return false;
  1004. }
  1005. delete this.parent.value[this.key];
  1006. this.parent.value[key] = this.value;
  1007. this.key = key;
  1008. }
  1009. this.editKeyNode.destroy();
  1010. this.editKeyNode = null;
  1011. this.setNodeText();
  1012. this.dictionary.jsonParse.loadObjectTree();
  1013. //if (this.parent){
  1014. // if (this.parent.type!="array"){
  1015. // this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  1016. // }
  1017. //}
  1018. },
  1019. selectBooleanValue: function(){
  1020. if (!this.booleanSelectNode) this.createBooleanSelectNode();
  1021. var size = this.dictionary.node.getSize();
  1022. this.booleanSelectNode.setStyle("display", "block");
  1023. var selSize = this.booleanSelectNode.getSize();
  1024. var itemNodes = this.booleanSelectNode.getChildren();
  1025. for (var i=0; i<itemNodes.length; i++){
  1026. if (itemNodes[i].get("text")==this.value.toString()){
  1027. itemNodes[i].setStyles(this.css.typeSelectItemNode_over);
  1028. }else{
  1029. itemNodes[i].setStyles(this.css.typeSelectItemNode);
  1030. }
  1031. };
  1032. this.booleanSelectNode.position({
  1033. relativeTo: this.valueNode,
  1034. position: 'upperLeft',
  1035. edge: 'upperLeft'
  1036. });
  1037. var p = this.booleanSelectNode.getPosition(this.booleanSelectNode.getOffsetParent());
  1038. if ((p.y+selSize.y)>size.y){
  1039. this.booleanSelectNode.position({
  1040. relativeTo: this.valueNode,
  1041. position: 'bottomLeft',
  1042. edge: 'bottomLeft'
  1043. });
  1044. };
  1045. this.closeBooleanSelectNodeFun = this.closeBooleanSelectNode.bind(this);
  1046. $(document.body).addEvent("mousedown", this.closeBooleanSelectNodeFun);
  1047. },
  1048. closeBooleanSelectNode: function(){
  1049. this.booleanSelectNode.setStyle("display", "none");
  1050. $(document.body).removeEvent("mousedown", this.closeBooleanSelectNodeFun);
  1051. },
  1052. createBooleanSelectNode: function(){
  1053. var _self = this;
  1054. this.booleanSelectNode = new Element("div", {"styles": this.css.booleanSelectNode});
  1055. ["true", "false"].each(function(type){
  1056. var itemNode = new Element("div", {"styles": this.css.typeSelectItemNode}).inject(this.booleanSelectNode);
  1057. itemNode.set("text", type);
  1058. if (this.value.toString()==type) itemNode.setStyles(this.css.typeSelectItemNode_over);
  1059. itemNode.addEvents({
  1060. "mouseover": function(){this.setStyles(_self.css.typeSelectItemNode_over);},
  1061. "mouseout": function(){this.setStyles(_self.css.typeSelectItemNode);},
  1062. "mousedown": function(e){_self.selectedBoolean(this, e);}
  1063. })
  1064. }.bind(this));
  1065. this.booleanSelectNode.inject(this.dictionary.node);
  1066. },
  1067. selectedBoolean: function(item, e){
  1068. var text = item.get("text");
  1069. var value = (text=="false") ? false : true;
  1070. this.value = value;
  1071. this.parent.value[this.key] = value;
  1072. this.setNodeText();
  1073. this.dictionary.jsonParse.loadObjectTree();
  1074. }
  1075. });
  1076. MWF.xApplication.process.DictionaryDesigner.DictionaryReader = new Class({
  1077. Extends: MWF.xApplication.process.DictionaryDesigner.Dictionary,
  1078. autoSave: function(){},
  1079. createRootItem: function() {
  1080. this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.ItemReader("ROOT", this.data.data, null, 0, this, true));
  1081. },
  1082. });
  1083. MWF.xApplication.process.DictionaryDesigner.Dictionary.ItemReader= new Class({
  1084. Extends: MWF.xApplication.process.DictionaryDesigner.Dictionary.item,
  1085. createNewItem: function(key, value, parent, level, dictionary, exp, nextSibling){
  1086. return new MWF.xApplication.process.DictionaryDesigner.Dictionary.ItemReader(key, value, parent, level, dictionary, exp, nextSibling);
  1087. },
  1088. setEvent: function(){
  1089. this.itemNode.addEvent("click", function(e){this.selected();}.bind(this));
  1090. this.typeNode.addEvent("click", function(e){this.selected();}.bind(this));
  1091. this.valueNode.addEvent("click", function(e){this.selected();}.bind(this));
  1092. //this.typeSelActionNode.addEvent("click", function(e){this.selectType();}.bind(this));
  1093. //this.typeTextNode.addEvent("click", function(e){this.selectType();}.bind(this));
  1094. //this.itemNode.addEvents({
  1095. // "mouseover": function(){this.itemActionsAreaNode.fade("in");}.bind(this),
  1096. // "mouseout": function(){this.itemActionsAreaNode.fade("out");}.bind(this)
  1097. //});
  1098. //if (this.itemAddActionNode) this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this));
  1099. //if (this.itemDelActionNode) this.itemDelActionNode.addEvent("click", function(e){this.delItem(e);}.bind(this));
  1100. if (this.type=="array" || this.type=="object"){
  1101. this.itemExpColActionNode.addEvents({
  1102. "click": function(){this.expOrColChildren();}.bind(this)
  1103. });
  1104. }else{
  1105. //if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  1106. }
  1107. //if (this.parent){
  1108. // if (this.parent.type!="array"){
  1109. // this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  1110. // }
  1111. //}
  1112. //if (this.type=="boolean"){
  1113. // this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  1114. // this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  1115. //}
  1116. },
  1117. });
  1118. //MWF.xApplication.process.ProcessDesigner.Process.Property = new Class({
  1119. // Implements: [Options, Events],
  1120. // Extends: MWF.APPPD.Property,
  1121. // initialize: function(process, options){
  1122. // this.setOptions(options);
  1123. // this.process = process;
  1124. // this.paper = this.process.paper;
  1125. // this.data = process.process;
  1126. // this.htmlPath = "../x_component_process_ProcessDesigner//$Process/process.html";
  1127. // }
  1128. //});