Dictionary.js 60 KB

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