Dictionary.js 58 KB

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