Dictionary.js 57 KB

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