Dictionary.js 57 KB

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