Dictionary.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  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. debugger;
  227. var fromItem = rootItem || this.items[0];
  228. var flag = true;
  229. if (item){
  230. if (item.type=="object"){
  231. if (!item.exp) item.expOrColChildren();
  232. if (this.getSearchItem(key, item)) return true;
  233. }
  234. fromItem = item.parent;
  235. flag = false;
  236. }
  237. if (fromItem.type=="object") {
  238. if (!fromItem.exp) fromItem.expOrColChildren();
  239. for (var i=0; i<fromItem.children.length; i++){
  240. var child = fromItem.children[i];
  241. if (flag){
  242. if (child.key.indexOf(key)!=-1){
  243. child.selected();
  244. this.currentSearchItem = child;
  245. new Fx.Scroll(this.areaNode).toElement(child.itemNode);
  246. return true;
  247. }else{
  248. if (child.type=="object"){
  249. if (!child.exp) child.expOrColChildren();
  250. if (child.children.length){
  251. if (this.getSearchItem(key, child)) return true;
  252. }
  253. }
  254. }
  255. }
  256. if (item) if (child==item) flag = true;
  257. }
  258. }else{
  259. if (fromItem.key.indexOf(key)!=-1){
  260. fromItem.selected();
  261. this.currentSearchItem = fromItem;
  262. return true;
  263. }
  264. }
  265. debugger;
  266. while ((fromItem) && fromItem.key!="ROOT"){
  267. if (fromItem.nextSibling){
  268. fromItem = fromItem.nextSibling;
  269. }else{
  270. fromItem = fromItem.parent;
  271. if (fromItem) fromItem = fromItem.nextSibling;
  272. }
  273. if (fromItem){
  274. if (this.getSearchItem(key, fromItem)) return true;
  275. }
  276. }
  277. return false;
  278. },
  279. saveAs: function(){},
  280. explode: function(){},
  281. implode: function(){}
  282. });
  283. MWF.xApplication.process.DictionaryDesigner.Dictionary.item = new Class({
  284. initialize: function(key, value, parent, level, dictionary, exp, nextSibling){
  285. this.key = key;
  286. this.value = value;
  287. this.parent = parent;
  288. this.level = level;
  289. this.dictionary = dictionary;
  290. this.exp = exp || false;
  291. this.nextSibling = nextSibling;
  292. this.children = [];
  293. this.childrenItemCreated = false;
  294. this.css = this.dictionary.css;
  295. this.type = typeOf(this.value);
  296. // if (this.parent) this.parent.children.push(this);
  297. this.load();
  298. },
  299. load: function(){
  300. this.createNodes();
  301. this.setNodeText();
  302. this.setEvent();
  303. if (this.exp) this.createChildrenItems();
  304. },
  305. createNodes: function() {
  306. this.itemNode = new Element("div", {"styles": this.css.itemNode});
  307. this.typeNode = new Element("div", {"styles": this.css.typeNode});
  308. this.valueNode = new Element("div", {"styles": this.css.valueNode});
  309. //var left = this.itemNode.getStyle("padding-left").toFloat();
  310. var left = 10;
  311. left = left + (this.level*20);
  312. this.itemNode.setStyle("padding-left", ""+left+"px");
  313. this.itemActionsAreaNode = new Element("div", {"styles": this.css.itemActionsAreaNode}).inject(this.itemNode);
  314. if (this.type=="array" || this.type=="object" || (this.parent && this.parent.type=="array")){
  315. this.itemAddActionNode = new Element("div", {"styles": this.css.itemAddActionNode}).inject(this.itemActionsAreaNode);
  316. }
  317. if (this.parent) this.itemDelActionNode = new Element("div", {"styles": this.css.itemDelActionNode}).inject(this.itemActionsAreaNode);
  318. if (this.type=="array" || this.type=="object"){
  319. this.itemExpColActionNode = new Element("div", {"styles": this.css.itemExpColActionNode}).inject(this.itemNode);
  320. if (this.exp){
  321. this.itemExpColActionNode.setStyle("background-image", "url("+"/x_component_process_DictionaryDesigner/$Dictionary/default/icon/col.png)");
  322. }else{
  323. this.itemExpColActionNode.setStyle("background-image", "url("+"/x_component_process_DictionaryDesigner/$Dictionary/default/icon/exp.png)");
  324. }
  325. }
  326. this.typeActionsAreaNode = new Element("div", {"styles": this.css.typeActionsAreaNode}).inject(this.typeNode);
  327. this.typeSelActionNode = new Element("div", {"styles": this.css.typeSelActionNode}).inject(this.typeActionsAreaNode);
  328. this.valueActionsAreaNode = new Element("div", {"styles": this.css.valueActionsAreaNode}).inject(this.valueNode);
  329. if (this.type=="boolean") this.valueSelActionNode = new Element("div", {"styles": this.css.valueSelActionNode}).inject(this.valueActionsAreaNode);
  330. this.itemTextNode = new Element("div", {"styles": this.css.itemTextNode}).inject(this.itemNode);
  331. this.typeTextNode = new Element("div", {"styles": this.css.typeTextNode}).inject(this.typeNode);
  332. this.valueTextNode = new Element("div", {"styles": this.css.valueTextNode}).inject(this.valueNode);
  333. if (this.nextSibling){
  334. this.itemNode.inject(this.nextSibling.itemNode, "before");
  335. this.typeNode.inject(this.nextSibling.typeNode, "before");
  336. this.valueNode.inject(this.nextSibling.valueNode, "before");
  337. }else{
  338. if (this.parent){
  339. if (this.parent.children.length){
  340. var injectItem = this.parent.children.getLast();
  341. this.itemNode.inject(injectItem.itemNode, "after");
  342. this.typeNode.inject(injectItem.typeNode, "after");
  343. this.valueNode.inject(injectItem.valueNode, "after");
  344. }else{
  345. this.itemNode.inject(this.parent.itemNode, "after");
  346. this.typeNode.inject(this.parent.typeNode, "after");
  347. this.valueNode.inject(this.parent.valueNode, "after");
  348. }
  349. }else{
  350. this.itemNode.inject(this.dictionary.itemsNode);
  351. this.typeNode.inject(this.dictionary.typesNode);
  352. this.valueNode.inject(this.dictionary.valuesNode);
  353. }
  354. }
  355. },
  356. resetNodes: function(){
  357. this.itemTextNode.removeEvents("mousedown");
  358. this.valueTextNode.removeEvents("mousedown");
  359. if (this.type=="array" || this.type=="object"){
  360. if (!this.itemExpColActionNode){
  361. this.itemExpColActionNode = new Element("div", {"styles": this.css.itemExpColActionNode}).inject(this.itemTextNode, "before");
  362. if (this.exp){
  363. this.itemExpColActionNode.setStyle("background-image", "url("+"/x_component_process_DictionaryDesigner/$Dictionary/default/icon/col.png)");
  364. }else{
  365. this.itemExpColActionNode.setStyle("background-image", "url("+"/x_component_process_DictionaryDesigner/$Dictionary/default/icon/exp.png)");
  366. }
  367. this.itemExpColActionNode.addEvents({
  368. "click": function(){this.expOrColChildren();}.bind(this)
  369. });
  370. }
  371. }else{
  372. if (this.itemExpColActionNode){
  373. this.itemExpColActionNode.destroy();
  374. this.itemExpColActionNode = null;
  375. }
  376. if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  377. }
  378. if (this.type=="array" || this.type=="object" || (this.parent && this.parent.type=="array")){
  379. if (!this.itemAddActionNode){
  380. this.itemAddActionNode = new Element("div", {"styles": this.css.itemAddActionNode}).inject(this.itemActionsAreaNode);
  381. this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this));
  382. }
  383. }else{
  384. if (this.itemAddActionNode) this.itemAddActionNode.destroy();
  385. this.itemAddActionNode = null;
  386. }
  387. if (this.type=="boolean"){
  388. if (!this.valueSelActionNode) this.valueSelActionNode = new Element("div", {"styles": this.css.valueSelActionNode}).inject(this.valueActionsAreaNode);
  389. this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  390. this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  391. }
  392. if (this.parent){
  393. if (this.parent.type!="array"){
  394. this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  395. }
  396. }
  397. },
  398. setNodeText: function(){
  399. var text = this.key;
  400. if (this.parent) if (this.parent.type=="array") text = "["+text+"]";
  401. this.itemTextNode.set("text", text);
  402. this.typeTextNode.set("text", this.type);
  403. switch(this.type){
  404. case "array":
  405. this.valueTextNode.setStyles(this.css.valueTextNode);
  406. this.valueTextNode.set("text", ""+this.value.length+" Items");
  407. break;
  408. case "object":
  409. var i=0;
  410. Object.each(this.value, function(){i++;});
  411. this.valueTextNode.setStyles(this.css.valueTextNode);
  412. this.valueTextNode.set("text", ""+i+" Items");
  413. break;
  414. default:
  415. this.valueTextNode.setStyles(this.css.valueTextNode_edit);
  416. this.valueTextNode.set("text", this.value);
  417. break;
  418. }
  419. },
  420. setEvent: function(){
  421. this.itemNode.addEvent("click", function(e){this.selected();}.bind(this));
  422. this.typeNode.addEvent("click", function(e){this.selected();}.bind(this));
  423. this.valueNode.addEvent("click", function(e){this.selected();}.bind(this));
  424. this.typeSelActionNode.addEvent("click", function(e){this.selectType();}.bind(this));
  425. this.typeTextNode.addEvent("click", function(e){this.selectType();}.bind(this));
  426. this.itemNode.addEvents({
  427. "mouseover": function(){this.itemActionsAreaNode.fade("in");}.bind(this),
  428. "mouseout": function(){this.itemActionsAreaNode.fade("out");}.bind(this)
  429. });
  430. if (this.itemAddActionNode) this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this));
  431. if (this.itemDelActionNode) this.itemDelActionNode.addEvent("click", function(e){this.delItem(e);}.bind(this));
  432. if (this.type=="array" || this.type=="object"){
  433. this.itemExpColActionNode.addEvents({
  434. "click": function(){this.expOrColChildren();}.bind(this)
  435. });
  436. }else{
  437. if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  438. }
  439. if (this.parent){
  440. if (this.parent.type!="array"){
  441. this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  442. }
  443. }
  444. if (this.type=="boolean"){
  445. this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  446. this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  447. }
  448. },
  449. expOrColChildren: function(){
  450. if (this.exp){
  451. this.colChildren();
  452. this.itemExpColActionNode.setStyle("background-image", "url("+"/x_component_process_DictionaryDesigner/$Dictionary/default/icon/exp.png)");
  453. this.exp = false;
  454. }else{
  455. this.expChildren();
  456. this.itemExpColActionNode.setStyle("background-image", "url("+"/x_component_process_DictionaryDesigner/$Dictionary/default/icon/col.png)");
  457. this.exp = true;
  458. }
  459. },
  460. colChildren: function(){
  461. this.children.each(function(item){
  462. item.colChildren();
  463. item.colChildrenNode();
  464. });
  465. },
  466. expChildren: function(){
  467. this.createChildrenItems();
  468. this.children.each(function(item){
  469. if (item.exp) item.expChildren();
  470. item.expChildrenNode();
  471. });
  472. },
  473. colChildrenNode: function(){
  474. this.itemNode.setStyle("display", "none");
  475. this.typeNode.setStyle("display", "none");
  476. this.valueNode.setStyle("display", "none");
  477. },
  478. expChildrenNode: function(){
  479. this.itemNode.setStyle("display", "block");
  480. this.typeNode.setStyle("display", "block");
  481. this.valueNode.setStyle("display", "block");
  482. },
  483. unSelected: function(){
  484. this.itemNode.setStyles(this.css.itemNode);
  485. this.typeNode.setStyles(this.css.typeNode);
  486. this.valueNode.setStyles(this.css.valueNode);
  487. this.dictionary.currentSelectedItem = null;
  488. },
  489. selected: function(){
  490. if (this.dictionary.currentSelectedItem!=this){
  491. if (this.dictionary.currentSelectedItem) this.dictionary.currentSelectedItem.unSelected();
  492. this.itemNode.setStyles(this.css.itemNode_selected);
  493. this.typeNode.setStyles(this.css.typeNode_selected);
  494. this.valueNode.setStyles(this.css.valueNode_selected);
  495. this.listDataItems();
  496. this.dictionary.currentSelectedItem = this;
  497. }
  498. },
  499. listDataItems: function(){
  500. this.dictionary.propertyListNode.empty();
  501. switch(this.type){
  502. case "array":
  503. this.value.each(function(v, idx){
  504. this.createDataListItem("["+idx+"]", v.toString());
  505. }.bind(this));
  506. break;
  507. case "object":
  508. Object.each(this.value, function(v, key){
  509. this.createDataListItem(key, v.toString());
  510. }.bind(this));
  511. break;
  512. }
  513. },
  514. createDataListItem: function(key, v){
  515. var node = new Element("div", {"styles": this.css.dataListItemNode}).inject(this.dictionary.propertyListNode);
  516. var keyNode = new Element("div", {"styles": this.css.dataListItemKeyNode, "text": key, "title": key}).inject(node);
  517. var vNode = new Element("div", {"styles": this.css.dataListItemValueNode, "text": v, "title": v}).inject(node);
  518. },
  519. createNewItem: function(key, value, parent, level, dictionary, exp, nextSibling){
  520. return new MWF.xApplication.process.DictionaryDesigner.Dictionary.item(key, value, parent, level, dictionary, exp, nextSibling);
  521. },
  522. createChildrenItems: function(){
  523. if (!this.childrenItemCreated){
  524. switch(this.type){
  525. case "array":
  526. this.value.each(function(v, idx){
  527. var item = this.createNewItem(idx, v, this, this.level+1, this.dictionary, false);
  528. if (this.children.length) this.children[this.children.length-1].nextSibling = item;
  529. this.children.push(item);
  530. }.bind(this));
  531. break;
  532. case "object":
  533. Object.each(this.value, function(v, key){
  534. var item = this.createNewItem(key, v, this, this.level+1, this.dictionary, false);
  535. if (this.children.length) this.children[this.children.length-1].nextSibling = item;
  536. this.children.push(item);
  537. }.bind(this));
  538. break;
  539. default:
  540. //nothing
  541. break;
  542. }
  543. this.childrenItemCreated = true;
  544. }
  545. },
  546. addItem: function(e){
  547. if (!this.parent){
  548. this.createChildrenItems();
  549. this.addChild();
  550. }else{
  551. if (this.exp){
  552. this.addChild();
  553. }else{
  554. this.addSibling();
  555. }
  556. }
  557. this.dictionary.jsonParse.loadObjectTree();
  558. },
  559. addChild: function(){
  560. var item;
  561. if (this.type=="array"){
  562. var idx = this.value.length;
  563. var arrayValue = "New Element Value";
  564. this.value.push(arrayValue);
  565. item = this.createNewItem(idx, arrayValue, this, this.level+1, this.dictionary, false);
  566. }
  567. if (this.type=="object") {
  568. var key = "NewItem";
  569. var i = 0;
  570. while (this.value[key] !== undefined) {
  571. i++;
  572. key = "NewItem" + i;
  573. }
  574. var objValue1 = "New Item Value";
  575. this.value[key] = objValue1;
  576. item = this.createNewItem(key, objValue1, this, this.level + 1, this.dictionary, false)
  577. }
  578. if (this.children.length) this.children[this.children.length-1].nextSibling = item;
  579. this.children.push(item);
  580. },
  581. addSibling: function(){
  582. var item = null;
  583. var idx;
  584. if (this.parent.type=="array"){
  585. idx = this.key;
  586. var value = "New Element Value";
  587. this.parent.value.splice(this.key, 0, value);
  588. for (var i=this.key; i<this.parent.children.length; i++){
  589. var item = this.parent.children[i];
  590. item.key = item.key+1;
  591. item.setNodeText();
  592. }
  593. item = this.createNewItem(idx, value, this.parent, this.level, this.dictionary, false, this);
  594. }else{
  595. var key = "NewItem";
  596. var i = 0;
  597. while (this.parent.value[key] != undefined) {
  598. i++;
  599. key = "NewItem" + i;
  600. }
  601. var value = "New Item Value";
  602. this.parent.value[key] = value;
  603. var item = this.createNewItem(key, value, this.parent, this.level, this.dictionary, false, this);
  604. idx = this.parent.children.indexOf(this);
  605. }
  606. if (idx) this.parent.children[idx-1].nextSibling = item;
  607. this.parent.children.splice(idx, 0, item);
  608. },
  609. delItem: function(e){
  610. var _self = this;
  611. this.dictionary.designer.shortcut = false;
  612. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.deleteDataTitle, this.dictionary.designer.lp.notice.deleteData, 300, 120, function(){
  613. _self.destroy();
  614. _self.dictionary.jsonParse.loadObjectTree();
  615. _self.dictionary.designer.shortcut = true;
  616. this.close();
  617. }, function(){
  618. _self.dictionary.designer.shortcut = true;
  619. this.close();
  620. });
  621. },
  622. destroy: function(){
  623. var idx = this.parent.children.indexOf(this);
  624. if (idx) this.parent.children[idx-1].nextSibling = this.nextSibling;
  625. this.destroyAllNodes();
  626. this.parent.children.erase(this);
  627. if (this.parent.type=="object"){
  628. delete this.parent.value[this.key];
  629. delete this;
  630. }
  631. if (this.parent.type=="array"){
  632. this.parent.value.splice(this.key, 1);
  633. for (var i=this.key; i<this.parent.children.length; i++){
  634. this.parent.children[i].key = this.parent.children[i].key-1;
  635. this.parent.children[i].setNodeText();
  636. }
  637. }
  638. this.dictionary.jsonParse.loadObjectTree();
  639. },
  640. destroyAllNodes: function(){
  641. this.children.each(function(item){
  642. item.destroyAllNodes();
  643. });
  644. this.itemNode.destroy();
  645. this.typeNode.destroy();
  646. this.valueNode.destroy();
  647. if (this.typeSelectNode) this.typeSelectNode.destroy();
  648. },
  649. selectType: function(){
  650. if (!this.typeSelectNode) this.createTypeSelectNode();
  651. this.typeSelectNode.setStyle("display", "block");
  652. var size = this.dictionary.node.getSize();
  653. var selSize = this.typeSelectNode.getSize();
  654. var itemNodes = this.typeSelectNode.getChildren();
  655. for (var i=0; i<itemNodes.length; i++){
  656. if (itemNodes[i].get("text")==this.type){
  657. itemNodes[i].setStyles(this.css.typeSelectItemNode_over);
  658. }else{
  659. itemNodes[i].setStyles(this.css.typeSelectItemNode);
  660. }
  661. };
  662. this.typeSelectNode.position({
  663. relativeTo: this.typeNode,
  664. position: 'upperLeft',
  665. edge: 'upperLeft'
  666. });
  667. var p = this.typeSelectNode.getPosition(this.typeSelectNode.getOffsetParent());
  668. if ((p.y+selSize.y)>size.y){
  669. this.typeSelectNode.position({
  670. relativeTo: this.typeNode,
  671. position: 'bottomLeft',
  672. edge: 'bottomLeft'
  673. });
  674. };
  675. this.closeTypeSelectNodeFun = this.closeTypeSelectNode.bind(this);
  676. $(document.body).addEvent("mousedown", this.closeTypeSelectNodeFun);
  677. },
  678. closeTypeSelectNode: function(){
  679. this.typeSelectNode.setStyle("display", "none");
  680. $(document.body).removeEvent("mousedown", this.closeTypeSelectNodeFun);
  681. },
  682. createTypeSelectNode: function(){
  683. var _self = this;
  684. this.typeSelectNode = new Element("div", {"styles": this.css.typeSelectNode});
  685. var types = this.dictionary.options.types;
  686. if (!this.parent){
  687. types = ["object", "array"];
  688. this.typeSelectNode.setStyle("height", "50px");
  689. }
  690. types.each(function(type){
  691. var itemNode = new Element("div", {"styles": this.css.typeSelectItemNode}).inject(this.typeSelectNode);
  692. itemNode.set("text", type);
  693. if (this.type==type) itemNode.setStyles(this.css.typeSelectItemNode_over);
  694. itemNode.addEvents({
  695. "mouseover": function(){this.setStyles(_self.css.typeSelectItemNode_over);},
  696. "mouseout": function(){this.setStyles(_self.css.typeSelectItemNode);},
  697. "mousedown": function(e){_self.selectedType(this, e);}
  698. })
  699. }.bind(this));
  700. this.typeSelectNode.inject(this.dictionary.node);
  701. },
  702. selectedType: function(itemNode, e){
  703. e.target = null;
  704. var type = itemNode.get("text");
  705. if (this.type!=type){
  706. var _self = this;
  707. switch(type){
  708. case "array":
  709. if (this.value!="New Item Value" && this.value!="New Element Value"){
  710. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeType, this.dictionary.designer.lp.notice.changeType, 300, 120, function(){
  711. if (_self.type=="object"){
  712. _self.changeTypeObjectToArray(type);
  713. }else{
  714. _self.changeTypePrimitiveToArray(type);
  715. }
  716. this.close();
  717. _self.dictionary.jsonParse.loadObjectTree();
  718. }, function(){
  719. this.close();
  720. });
  721. }else{
  722. if (this.type=="object"){
  723. this.changeTypeObjectToArray(type);
  724. }else{
  725. this.changeTypePrimitiveToArray(type);
  726. }
  727. this.dictionary.jsonParse.loadObjectTree();
  728. }
  729. break;
  730. case "object":
  731. if (this.value!="New Item Value" && this.value!="New Element Value") {
  732. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeType, this.dictionary.designer.lp.notice.changeType, 300, 120, function () {
  733. if (_self.type == "array") {
  734. _self.changeTypeArrayToObject(type);
  735. } else {
  736. _self.changeTypePrimitiveToObject(type);
  737. }
  738. this.close();
  739. _self.dictionary.jsonParse.loadObjectTree();
  740. }, function () {
  741. this.close();
  742. });
  743. }else{
  744. if (this.type == "array") {
  745. this.changeTypeArrayToObject(type);
  746. } else {
  747. this.changeTypePrimitiveToObject(type);
  748. }
  749. this.dictionary.jsonParse.loadObjectTree();
  750. }
  751. break;
  752. default:
  753. if (this.value!="New Item Value" && this.value!="New Element Value") {
  754. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeType, this.dictionary.designer.lp.notice.changeTypeDeleteChildren, 300, 120, function () {
  755. if (_self.type == "array") {
  756. _self.changeTypeArrayToPrimitive(type);
  757. } else if (_self.type == "object") {
  758. _self.changeTypeObjectToPrimitive(type);
  759. } else {
  760. _self.changeTypePrimitiveToPrimitive(type);
  761. }
  762. this.close();
  763. _self.dictionary.jsonParse.loadObjectTree();
  764. }, function () {
  765. this.close();
  766. });
  767. }else{
  768. if (this.type == "array") {
  769. this.changeTypeArrayToPrimitive(type);
  770. } else if (_self.type == "object") {
  771. this.changeTypeObjectToPrimitive(type);
  772. } else {
  773. this.changeTypePrimitiveToPrimitive(type);
  774. }
  775. this.dictionary.jsonParse.loadObjectTree();
  776. }
  777. break;
  778. }
  779. }
  780. },
  781. deleteAllChildren: function(){
  782. this.children.each(function(item){
  783. item.destroyAllNodes();
  784. });
  785. },
  786. changeTypeObjectToPrimitive: function(type){
  787. this.deleteAllChildren();
  788. this.children = [];
  789. this.childrenItemCreated = false;
  790. var value;
  791. switch(type){
  792. case "string":
  793. value = "";
  794. break;
  795. case "number":
  796. value = 0;
  797. break;
  798. case "boolean":
  799. value = true;
  800. break;
  801. }
  802. delete this.parent.value[this.key];
  803. this.parent.value[this.key] = value;
  804. this.value = value;
  805. this.type = type;
  806. this.exp = false;
  807. this.setNodeText();
  808. this.resetNodes();
  809. },
  810. changeTypeArrayToPrimitive: function(type){
  811. this.changeTypeObjectToPrimitive(type);
  812. },
  813. changeTypePrimitiveToPrimitive: function(type){
  814. switch(type){
  815. case "string":
  816. value = this.value.toString();
  817. break;
  818. case "number":
  819. value = this.value.toFloat();
  820. if (isNaN(value)) value = 0
  821. break;
  822. case "boolean":
  823. value = true;
  824. if (this.value=="false") value = false;
  825. break;
  826. }
  827. delete this.parent.value[this.key];
  828. this.parent.value[this.key] = value;
  829. this.value = value;
  830. this.type = type;
  831. this.exp = false;
  832. this.setNodeText();
  833. this.resetNodes();
  834. },
  835. changeTypePrimitiveToObject: function(type){
  836. value = {};
  837. delete this.parent.value[this.key];
  838. this.parent.value[this.key] = value;
  839. this.value = value;
  840. this.type = type;
  841. this.exp = false;
  842. this.setNodeText();
  843. this.resetNodes();
  844. },
  845. changeTypeArrayToObject: function(type){
  846. this.deleteAllChildren();
  847. this.children = [];
  848. this.childrenItemCreated = false;
  849. var value = {};
  850. this.value.each(function(v, idx){
  851. value["ITEM"+idx] = v;
  852. });
  853. if (this.parent){
  854. delete this.parent.value[this.key];
  855. this.parent.value[this.key] = value;
  856. this.value = value;
  857. this.type = type;
  858. this.setNodeText();
  859. this.resetNodes();
  860. if (this.exp) this.createChildrenItems();
  861. }else{
  862. this.dictionary.data.data = value;
  863. this.dictionary.jsonParse.json = value;
  864. this.value = value;
  865. this.type = type;
  866. this.setNodeText();
  867. this.resetNodes();
  868. if (this.exp) this.createChildrenItems();
  869. }
  870. },
  871. changeTypePrimitiveToArray: function(type) {
  872. value = [];
  873. delete this.parent.value[this.key];
  874. this.parent.value[this.key] = value;
  875. this.value = value;
  876. this.type = type;
  877. this.exp = false;
  878. this.setNodeText();
  879. this.resetNodes();
  880. },
  881. changeTypeObjectToArray: function(type){
  882. this.deleteAllChildren();
  883. this.children = [];
  884. this.childrenItemCreated = false;
  885. var value = [];
  886. Object.each(this.value, function(v, idx){
  887. value.push(v);
  888. });
  889. if (this.parent){
  890. delete this.parent.value[this.key];
  891. this.parent.value[this.key] = value;
  892. this.value = value;
  893. this.type = type;
  894. this.childrenItemCreated = false;
  895. this.setNodeText();
  896. this.resetNodes();
  897. if (this.exp) this.createChildrenItems();
  898. }else{
  899. this.dictionary.data.data = value;
  900. this.dictionary.jsonParse.json = value;
  901. this.value = value;
  902. this.type = type;
  903. this.childrenItemCreated = false;
  904. this.setNodeText();
  905. this.resetNodes();
  906. if (this.exp) this.createChildrenItems();
  907. }
  908. },
  909. editValue: function(){
  910. debugger;
  911. //this.inEdit
  912. this.valueTextNode.empty();
  913. // this.valueTextNode.removeEvents("mousedown");
  914. this.editValueNode = new Element("input", {"styles": this.css.itemEditValueNode}).inject(this.valueTextNode);
  915. this.editValueNode.set("value", this.value);
  916. window.setTimeout(function(){
  917. this.editValueNode.focus();
  918. this.editValueNode.select();
  919. this.editValueNode.addEvents({
  920. "blur": function(e){
  921. this.editValueConfirm(e);
  922. }.bind(this),
  923. "keydown": function(e){
  924. if (e.code==13){
  925. this.editValueConfirm(e);
  926. if (this.nextSibling){
  927. this.nextSibling.editKey();
  928. }
  929. }
  930. e.stopPropagation();
  931. }.bind(this),
  932. "mousedown": function(e){e.stopPropagation();}
  933. });
  934. }.bind(this), 10)
  935. },
  936. editValueConfirm: function(e){
  937. var value = this.editValueNode.get("Value");
  938. if (this.type=="number"){
  939. if (isNaN(parseFloat(value))){
  940. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.inputTypeError, "error", this.editValueNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  941. this.editValueNode.setStyles(this.css.itemEditValueNode_error);
  942. this.editValueNode.select();
  943. e.preventDefault();
  944. return false;
  945. }
  946. value = value.toFloat();
  947. }
  948. this.value = value;
  949. this.parent.value[this.key] = this.value;
  950. this.editValueNode.destroy();
  951. this.editValueNode = null;
  952. this.setNodeText();
  953. this.dictionary.jsonParse.loadObjectTree();
  954. // if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  955. },
  956. editKey: function(){
  957. this.itemTextNode.empty();
  958. // this.itemTextNode.removeEvents("mousedown");
  959. this.editKeyNode = new Element("input", {"styles": this.css.itemEditValueNode, "type": "text"}).inject(this.itemTextNode);
  960. this.editKeyNode.set("value", this.key);
  961. window.setTimeout(function(){
  962. this.editKeyNode.focus();
  963. this.editKeyNode.select();
  964. //this.editKeyNode.setSelectionRange(1,this.key.length-1);
  965. this.editKeyNode.addEvents({
  966. "blur": function(e){this.editKeyConfirm(e);}.bind(this),
  967. "keydown": function(e){
  968. if (e.code==13){
  969. this.editKeyConfirm(e);
  970. if (this.type!="array" && this.type!="object" && this.type!="boolean") {
  971. this.editValue();
  972. }else{
  973. if (this.nextSibling){
  974. this.nextSibling.editKey();
  975. }
  976. }
  977. }
  978. e.stopPropagation();
  979. }.bind(this),
  980. "mousedown": function(e){e.stopPropagation();}
  981. });
  982. }.bind(this), 10);
  983. },
  984. editKeyConfirm: function(e){
  985. var key = this.editKeyNode.get("Value");
  986. if (key!=this.key){
  987. if (this.parent.value[key]){
  988. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.sameKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  989. this.editKeyNode.setStyles(this.css.itemEditValueNode_error);
  990. this.editKeyNode.select();
  991. e.preventDefault();
  992. return false;
  993. }
  994. if (!isNaN(parseFloat(key))){
  995. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.numberKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  996. this.editKeyNode.setStyles(this.css.itemEditValueNode_error);
  997. this.editKeyNode.select();
  998. e.preventDefault();
  999. return false;
  1000. }
  1001. if (!key){
  1002. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.emptyKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  1003. this.editKeyNode.setStyles(this.css.itemEditValueNode_error);
  1004. this.editKeyNode.select();
  1005. e.preventDefault();
  1006. return false;
  1007. }
  1008. delete this.parent.value[this.key];
  1009. this.parent.value[key] = this.value;
  1010. this.key = key;
  1011. }
  1012. this.editKeyNode.destroy();
  1013. this.editKeyNode = null;
  1014. this.setNodeText();
  1015. this.dictionary.jsonParse.loadObjectTree();
  1016. //if (this.parent){
  1017. // if (this.parent.type!="array"){
  1018. // this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  1019. // }
  1020. //}
  1021. },
  1022. selectBooleanValue: function(){
  1023. if (!this.booleanSelectNode) this.createBooleanSelectNode();
  1024. var size = this.dictionary.node.getSize();
  1025. this.booleanSelectNode.setStyle("display", "block");
  1026. var selSize = this.booleanSelectNode.getSize();
  1027. var itemNodes = this.booleanSelectNode.getChildren();
  1028. for (var i=0; i<itemNodes.length; i++){
  1029. if (itemNodes[i].get("text")==this.value.toString()){
  1030. itemNodes[i].setStyles(this.css.typeSelectItemNode_over);
  1031. }else{
  1032. itemNodes[i].setStyles(this.css.typeSelectItemNode);
  1033. }
  1034. };
  1035. this.booleanSelectNode.position({
  1036. relativeTo: this.valueNode,
  1037. position: 'upperLeft',
  1038. edge: 'upperLeft'
  1039. });
  1040. var p = this.booleanSelectNode.getPosition(this.booleanSelectNode.getOffsetParent());
  1041. if ((p.y+selSize.y)>size.y){
  1042. this.booleanSelectNode.position({
  1043. relativeTo: this.valueNode,
  1044. position: 'bottomLeft',
  1045. edge: 'bottomLeft'
  1046. });
  1047. };
  1048. this.closeBooleanSelectNodeFun = this.closeBooleanSelectNode.bind(this);
  1049. $(document.body).addEvent("mousedown", this.closeBooleanSelectNodeFun);
  1050. },
  1051. closeBooleanSelectNode: function(){
  1052. this.booleanSelectNode.setStyle("display", "none");
  1053. $(document.body).removeEvent("mousedown", this.closeBooleanSelectNodeFun);
  1054. },
  1055. createBooleanSelectNode: function(){
  1056. var _self = this;
  1057. this.booleanSelectNode = new Element("div", {"styles": this.css.booleanSelectNode});
  1058. ["true", "false"].each(function(type){
  1059. var itemNode = new Element("div", {"styles": this.css.typeSelectItemNode}).inject(this.booleanSelectNode);
  1060. itemNode.set("text", type);
  1061. if (this.value.toString()==type) itemNode.setStyles(this.css.typeSelectItemNode_over);
  1062. itemNode.addEvents({
  1063. "mouseover": function(){this.setStyles(_self.css.typeSelectItemNode_over);},
  1064. "mouseout": function(){this.setStyles(_self.css.typeSelectItemNode);},
  1065. "mousedown": function(e){_self.selectedBoolean(this, e);}
  1066. })
  1067. }.bind(this));
  1068. this.booleanSelectNode.inject(this.dictionary.node);
  1069. },
  1070. selectedBoolean: function(item, e){
  1071. var text = item.get("text");
  1072. var value = (text=="false") ? false : true;
  1073. this.value = value;
  1074. this.parent.value[this.key] = value;
  1075. this.setNodeText();
  1076. this.dictionary.jsonParse.loadObjectTree();
  1077. }
  1078. });
  1079. MWF.xApplication.process.DictionaryDesigner.DictionaryReader = new Class({
  1080. Extends: MWF.xApplication.process.DictionaryDesigner.Dictionary,
  1081. autoSave: function(){},
  1082. createRootItem: function() {
  1083. this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.ItemReader("ROOT", this.data.data, null, 0, this, true));
  1084. },
  1085. });
  1086. MWF.xApplication.process.DictionaryDesigner.Dictionary.ItemReader= new Class({
  1087. Extends: MWF.xApplication.process.DictionaryDesigner.Dictionary.item,
  1088. createNewItem: function(key, value, parent, level, dictionary, exp, nextSibling){
  1089. return new MWF.xApplication.process.DictionaryDesigner.Dictionary.ItemReader(key, value, parent, level, dictionary, exp, nextSibling);
  1090. },
  1091. setEvent: function(){
  1092. this.itemNode.addEvent("click", function(e){this.selected();}.bind(this));
  1093. this.typeNode.addEvent("click", function(e){this.selected();}.bind(this));
  1094. this.valueNode.addEvent("click", function(e){this.selected();}.bind(this));
  1095. //this.typeSelActionNode.addEvent("click", function(e){this.selectType();}.bind(this));
  1096. //this.typeTextNode.addEvent("click", function(e){this.selectType();}.bind(this));
  1097. //this.itemNode.addEvents({
  1098. // "mouseover": function(){this.itemActionsAreaNode.fade("in");}.bind(this),
  1099. // "mouseout": function(){this.itemActionsAreaNode.fade("out");}.bind(this)
  1100. //});
  1101. //if (this.itemAddActionNode) this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this));
  1102. //if (this.itemDelActionNode) this.itemDelActionNode.addEvent("click", function(e){this.delItem(e);}.bind(this));
  1103. if (this.type=="array" || this.type=="object"){
  1104. this.itemExpColActionNode.addEvents({
  1105. "click": function(){this.expOrColChildren();}.bind(this)
  1106. });
  1107. }else{
  1108. //if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  1109. }
  1110. //if (this.parent){
  1111. // if (this.parent.type!="array"){
  1112. // this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  1113. // }
  1114. //}
  1115. //if (this.type=="boolean"){
  1116. // this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  1117. // this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  1118. //}
  1119. },
  1120. });
  1121. //MWF.xApplication.process.ProcessDesigner.Process.Property = new Class({
  1122. // Implements: [Options, Events],
  1123. // Extends: MWF.APPPD.Property,
  1124. // initialize: function(process, options){
  1125. // this.setOptions(options);
  1126. // this.process = process;
  1127. // this.paper = this.process.paper;
  1128. // this.data = process.process;
  1129. // this.htmlPath = "/x_component_process_ProcessDesigner//$Process/process.html";
  1130. // }
  1131. //});