Dictionary.js 56 KB

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