Dictionary.js 58 KB

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