Dictionary.js 53 KB

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