Dictionary.js 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  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. this.data.name = name;
  254. this.data.alias = alias;
  255. this.data.description = description;
  256. this.isSave = true;
  257. this.designer.actions.saveDictionary(this.data, function(json){
  258. this.isSave = false;
  259. this.data.id = json.data.id;
  260. if (callback) callback();
  261. }.bind(this), function(xhr, text, error){
  262. this.isSave = false;
  263. //
  264. //var errorText = error+":"+text;
  265. //if (xhr) errorText = xhr.responseText;
  266. //MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  267. }.bind(this));
  268. }
  269. },
  270. save: function(callback){
  271. if (!this.isSave){
  272. if (this.designer.tab.showPage==this.page){
  273. if( this.scriptPage.isShow ){
  274. if( this.scriptEditor ){
  275. var data = this.getEditorValidData();
  276. if( data !== false ){
  277. this.data.data = data;
  278. }else{
  279. return false;
  280. }
  281. }
  282. }
  283. var name = this.designer.propertyNameNode.get("value");
  284. var alias = this.designer.propertyAliasNode.get("value");
  285. var description = this.designer.propertyDescriptionNode.get("value");
  286. if (!name || !alias){
  287. this.designer.notice(this.designer.lp.notice.inputName, "error");
  288. return false;
  289. }
  290. this.data.name = name;
  291. this.data.alias = alias;
  292. this.data.description = description;
  293. this.data.appId = this.data.application;
  294. }
  295. this.isSave = true;
  296. this.designer.actions.saveDictionary(this.data, function(json){
  297. this.isSave = false;
  298. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  299. this.data.isNewDictionary = false;
  300. this.isNewDictionary = false;
  301. this.data.id = json.data.id;
  302. this.page.textNode.set("text", this.data.name);
  303. if (this.lisNode) {
  304. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  305. }
  306. if (callback) callback();
  307. }.bind(this), function(xhr, text, error){
  308. this.isSave = false;
  309. var errorText = error+":"+text;
  310. if (xhr) errorText = xhr.responseText;
  311. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  312. }.bind(this));
  313. }else{
  314. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  315. }
  316. },
  317. loadSearch: function(){
  318. if (!this.searchNode){
  319. this.createSearchNode();
  320. }else{
  321. if (this.searchNode.getStyle("display")=="none"){
  322. this.searchNode.setStyle("display", "block");
  323. }else{
  324. this.searchNode.setStyle("display", "none");
  325. }
  326. }
  327. this.setAreaNodeSize();
  328. },
  329. createSearchNode: function(){
  330. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.designNode, "before");
  331. this.searchInputNode = new Element("div", {"styles": this.css.searchInputNode}).inject(this.searchNode);
  332. this.searchInput = new Element("input", {"styles": this.css.searchInput}).inject(this.searchInputNode);
  333. this.searchAction = new Element("div", {"styles": this.css.searchAction, "text": this.designer.lp.search}).inject(this.searchNode);
  334. var lineNode = new Element("div", {"styles": this.css.searchLineNode,}).inject(this.searchNode);
  335. this.nextAction = new Element("div", {"styles": this.css.searchNextAction, "text": this.designer.lp.next}).inject(this.searchNode);
  336. this.searchAction.addEvent("click", function(){
  337. this.searchDictionary();
  338. }.bind(this));
  339. this.nextAction.addEvent("click", function(){
  340. this.searchDictionaryNext();
  341. }.bind(this));
  342. },
  343. searchDictionary: function(){
  344. var key = this.searchInput.get("value");
  345. if (key){
  346. this.currentSearchItem = null;
  347. if (!this.getSearchItem(key)){
  348. }
  349. }
  350. },
  351. searchDictionaryNext: function(){
  352. var key = this.searchInput.get("value");
  353. if (key){
  354. if (!this.getSearchItem(key, null, this.currentSearchItem)){
  355. if (!this.getSearchItem(key)){
  356. }
  357. }
  358. }
  359. },
  360. getSearchItem: function(key, rootItem, item){
  361. var fromItem = rootItem || this.items[0];
  362. var flag = true;
  363. if (item){
  364. if (item.type=="object"){
  365. if (!item.exp) item.expOrColChildren();
  366. if (this.getSearchItem(key, item)) return true;
  367. }
  368. fromItem = item.parent;
  369. flag = false;
  370. }
  371. if (fromItem.type=="object") {
  372. if (!fromItem.exp) fromItem.expOrColChildren();
  373. for (var i=0; i<fromItem.children.length; i++){
  374. var child = fromItem.children[i];
  375. if (flag){
  376. if (child.key.indexOf(key)!=-1){
  377. child.selected();
  378. this.currentSearchItem = child;
  379. new Fx.Scroll(this.designNode).toElement(child.itemNode);
  380. return true;
  381. }else{
  382. if (child.type=="object"){
  383. if (!child.exp) child.expOrColChildren();
  384. if (child.children.length){
  385. if (this.getSearchItem(key, child)) return true;
  386. }
  387. }
  388. }
  389. }
  390. if (item) if (child==item) flag = true;
  391. }
  392. }else{
  393. if (fromItem.key.indexOf(key)!=-1){
  394. fromItem.selected();
  395. this.currentSearchItem = fromItem;
  396. return true;
  397. }
  398. }
  399. while ((fromItem) && fromItem.key!="ROOT"){
  400. if (fromItem.nextSibling){
  401. fromItem = fromItem.nextSibling;
  402. }else{
  403. fromItem = fromItem.parent;
  404. if (fromItem) fromItem = fromItem.nextSibling;
  405. }
  406. if (fromItem){
  407. if (this.getSearchItem(key, fromItem)) return true;
  408. }
  409. }
  410. return false;
  411. },
  412. saveAs: function(){},
  413. explode: function(){},
  414. implode: function(){}
  415. });
  416. MWF.xApplication.cms.DictionaryDesigner.Dictionary.item = new Class({
  417. initialize: function(key, value, parent, level, dictionary, exp, nextSibling){
  418. this.key = key;
  419. this.value = value;
  420. this.parent = parent;
  421. this.level = level;
  422. this.dictionary = dictionary;
  423. this.exp = exp || false;
  424. this.nextSibling = nextSibling;
  425. this.children = [];
  426. this.childrenItemCreated = false;
  427. this.css = this.dictionary.css;
  428. this.type = typeOf(this.value);
  429. // if (this.parent) this.parent.children.push(this);
  430. this.load();
  431. },
  432. load: function(){
  433. this.createNodes();
  434. this.setNodeText();
  435. this.setEvent();
  436. if (this.exp) this.createChildrenItems();
  437. },
  438. createNodes: function() {
  439. this.itemNode = new Element("div", {"styles": this.css.itemNode});
  440. this.typeNode = new Element("div", {"styles": this.css.typeNode});
  441. this.valueNode = new Element("div", {"styles": this.css.valueNode});
  442. //var left = this.itemNode.getStyle("padding-left").toFloat();
  443. var left = 10;
  444. left = left + (this.level*20);
  445. this.itemNode.setStyle("padding-left", ""+left+"px");
  446. this.itemActionsAreaNode = new Element("div", {"styles": this.css.itemActionsAreaNode}).inject(this.itemNode);
  447. if (this.type=="array" || this.type=="object" || (this.parent && this.parent.type=="array")){
  448. this.itemAddActionNode = new Element("div", {"styles": this.css.itemAddActionNode}).inject(this.itemActionsAreaNode);
  449. }
  450. if (this.parent) this.itemDelActionNode = new Element("div", {"styles": this.css.itemDelActionNode}).inject(this.itemActionsAreaNode);
  451. if (this.type=="array" || this.type=="object"){
  452. this.itemExpColActionNode = new Element("div", {"styles": this.css.itemExpColActionNode}).inject(this.itemNode);
  453. if (this.exp){
  454. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_cms_DictionaryDesigner/$Dictionary/default/icon/col.png)");
  455. }else{
  456. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_cms_DictionaryDesigner/$Dictionary/default/icon/exp.png)");
  457. }
  458. }
  459. this.typeActionsAreaNode = new Element("div", {"styles": this.css.typeActionsAreaNode}).inject(this.typeNode);
  460. this.typeSelActionNode = new Element("div", {"styles": this.css.typeSelActionNode}).inject(this.typeActionsAreaNode);
  461. this.valueActionsAreaNode = new Element("div", {"styles": this.css.valueActionsAreaNode}).inject(this.valueNode);
  462. if (this.type=="boolean") this.valueSelActionNode = new Element("div", {"styles": this.css.valueSelActionNode}).inject(this.valueActionsAreaNode);
  463. this.itemTextNode = new Element("div", {"styles": this.css.itemTextNode}).inject(this.itemNode);
  464. this.typeTextNode = new Element("div", {"styles": this.css.typeTextNode}).inject(this.typeNode);
  465. this.valueTextNode = new Element("div", {"styles": this.css.valueTextNode}).inject(this.valueNode);
  466. if (this.nextSibling){
  467. this.itemNode.inject(this.nextSibling.itemNode, "before");
  468. this.typeNode.inject(this.nextSibling.typeNode, "before");
  469. this.valueNode.inject(this.nextSibling.valueNode, "before");
  470. }else{
  471. if (this.parent){
  472. if (this.parent.children.length){
  473. var injectItem = this.parent.children.getLast();
  474. this.itemNode.inject(injectItem.itemNode, "after");
  475. this.typeNode.inject(injectItem.typeNode, "after");
  476. this.valueNode.inject(injectItem.valueNode, "after");
  477. }else{
  478. this.itemNode.inject(this.parent.itemNode, "after");
  479. this.typeNode.inject(this.parent.typeNode, "after");
  480. this.valueNode.inject(this.parent.valueNode, "after");
  481. }
  482. }else{
  483. this.itemNode.inject(this.dictionary.itemsNode);
  484. this.typeNode.inject(this.dictionary.typesNode);
  485. this.valueNode.inject(this.dictionary.valuesNode);
  486. }
  487. }
  488. },
  489. resetNodes: function(){
  490. this.itemTextNode.removeEvents("mousedown");
  491. this.valueTextNode.removeEvents("mousedown");
  492. if (this.type=="array" || this.type=="object"){
  493. if (!this.itemExpColActionNode){
  494. this.itemExpColActionNode = new Element("div", {"styles": this.css.itemExpColActionNode}).inject(this.itemTextNode, "before");
  495. if (this.exp){
  496. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_cms_DictionaryDesigner/$Dictionary/default/icon/col.png)");
  497. }else{
  498. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_cms_DictionaryDesigner/$Dictionary/default/icon/exp.png)");
  499. }
  500. this.itemExpColActionNode.addEvents({
  501. "click": function(){this.expOrColChildren();}.bind(this)
  502. });
  503. }
  504. }else{
  505. if (this.itemExpColActionNode){
  506. this.itemExpColActionNode.destroy();
  507. this.itemExpColActionNode = null;
  508. }
  509. if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  510. }
  511. if (this.type=="array" || this.type=="object" || (this.parent && this.parent.type=="array")){
  512. if (!this.itemAddActionNode){
  513. this.itemAddActionNode = new Element("div", {"styles": this.css.itemAddActionNode}).inject(this.itemActionsAreaNode);
  514. this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this));
  515. }
  516. }else{
  517. if (this.itemAddActionNode) this.itemAddActionNode.destroy();
  518. this.itemAddActionNode = null;
  519. }
  520. if (this.type=="boolean"){
  521. if (!this.valueSelActionNode) this.valueSelActionNode = new Element("div", {"styles": this.css.valueSelActionNode}).inject(this.valueActionsAreaNode);
  522. this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  523. this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  524. }
  525. if (this.parent){
  526. if (this.parent.type!="array"){
  527. this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  528. }
  529. }
  530. },
  531. setNodeText: function(){
  532. var text = this.key;
  533. if (this.parent) if (this.parent.type=="array") text = "["+text+"]";
  534. this.itemTextNode.set("text", text);
  535. this.typeTextNode.set("text", this.type);
  536. switch(this.type){
  537. case "array":
  538. this.valueTextNode.setStyles(this.css.valueTextNode);
  539. this.valueTextNode.set("text", ""+this.value.length+" Items");
  540. break;
  541. case "object":
  542. var i=0;
  543. Object.each(this.value, function(){i++;});
  544. this.valueTextNode.setStyles(this.css.valueTextNode);
  545. this.valueTextNode.set("text", ""+i+" Items");
  546. break;
  547. default:
  548. this.valueTextNode.setStyles(this.css.valueTextNode_edit);
  549. this.valueTextNode.set("text", this.value);
  550. break;
  551. }
  552. },
  553. setEvent: function(){
  554. this.itemNode.addEvent("click", function(e){this.selected();}.bind(this));
  555. this.typeNode.addEvent("click", function(e){this.selected();}.bind(this));
  556. this.valueNode.addEvent("click", function(e){this.selected();}.bind(this));
  557. this.typeSelActionNode.addEvent("click", function(e){this.selectType();}.bind(this));
  558. this.typeTextNode.addEvent("click", function(e){this.selectType();}.bind(this));
  559. this.itemNode.addEvents({
  560. "mouseover": function(){this.itemActionsAreaNode.fade("in");}.bind(this),
  561. "mouseout": function(){this.itemActionsAreaNode.fade("out");}.bind(this)
  562. });
  563. if (this.itemAddActionNode) this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this));
  564. if (this.itemDelActionNode) this.itemDelActionNode.addEvent("click", function(e){this.delItem(e);}.bind(this));
  565. if (this.type=="array" || this.type=="object"){
  566. this.itemExpColActionNode.addEvents({
  567. "click": function(){this.expOrColChildren();}.bind(this)
  568. });
  569. }else{
  570. if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  571. }
  572. if (this.parent){
  573. if (this.parent.type!="array"){
  574. this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  575. }
  576. }
  577. if (this.type=="boolean"){
  578. this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  579. this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  580. }
  581. },
  582. expOrColChildren: function(){
  583. if (this.exp){
  584. this.colChildren();
  585. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_cms_DictionaryDesigner/$Dictionary/default/icon/exp.png)");
  586. this.exp = false;
  587. }else{
  588. this.expChildren();
  589. this.itemExpColActionNode.setStyle("background-image", "url("+"../x_component_cms_DictionaryDesigner/$Dictionary/default/icon/col.png)");
  590. this.exp = true;
  591. }
  592. },
  593. colChildren: function(){
  594. this.children.each(function(item){
  595. item.colChildren();
  596. item.colChildrenNode();
  597. });
  598. },
  599. expChildren: function(){
  600. this.createChildrenItems();
  601. this.children.each(function(item){
  602. if (item.exp) item.expChildren();
  603. item.expChildrenNode();
  604. });
  605. },
  606. colChildrenNode: function(){
  607. this.itemNode.setStyle("display", "none");
  608. this.typeNode.setStyle("display", "none");
  609. this.valueNode.setStyle("display", "none");
  610. },
  611. expChildrenNode: function(){
  612. this.itemNode.setStyle("display", "block");
  613. this.typeNode.setStyle("display", "block");
  614. this.valueNode.setStyle("display", "block");
  615. },
  616. unSelected: function(){
  617. this.itemNode.setStyles(this.css.itemNode);
  618. this.typeNode.setStyles(this.css.typeNode);
  619. this.valueNode.setStyles(this.css.valueNode);
  620. this.dictionary.currentSelectedItem = null;
  621. },
  622. selected: function(){
  623. if (this.dictionary.currentSelectedItem!=this){
  624. if (this.dictionary.currentSelectedItem) this.dictionary.currentSelectedItem.unSelected();
  625. this.itemNode.setStyles(this.css.itemNode_selected);
  626. this.typeNode.setStyles(this.css.typeNode_selected);
  627. this.valueNode.setStyles(this.css.valueNode_selected);
  628. this.listDataItems();
  629. this.dictionary.currentSelectedItem = this;
  630. }
  631. },
  632. listDataItems: function(){
  633. this.dictionary.propertyListNode.empty();
  634. switch(this.type){
  635. case "array":
  636. this.value.each(function(v, idx){
  637. this.createDataListItem("["+idx+"]", v.toString());
  638. }.bind(this));
  639. break;
  640. case "object":
  641. Object.each(this.value, function(v, key){
  642. this.createDataListItem(key, v.toString());
  643. }.bind(this));
  644. break;
  645. }
  646. },
  647. createDataListItem: function(key, v){
  648. var node = new Element("div", {"styles": this.css.dataListItemNode}).inject(this.dictionary.propertyListNode);
  649. var keyNode = new Element("div", {"styles": this.css.dataListItemKeyNode, "text": key, "title": key}).inject(node);
  650. var vNode = new Element("div", {"styles": this.css.dataListItemValueNode, "text": v, "title": v}).inject(node);
  651. },
  652. createNewItem: function(key, value, parent, level, dictionary, exp, nextSibling){
  653. return new MWF.xApplication.cms.DictionaryDesigner.Dictionary.item(key, value, parent, level, dictionary, exp, nextSibling);
  654. },
  655. createChildrenItems: function(){
  656. if (!this.childrenItemCreated){
  657. switch(this.type){
  658. case "array":
  659. this.value.each(function(v, idx){
  660. var item = this.createNewItem(idx, v, this, this.level+1, this.dictionary, false);
  661. if (this.children.length) this.children[this.children.length-1].nextSibling = item;
  662. this.children.push(item);
  663. }.bind(this));
  664. break;
  665. case "object":
  666. Object.each(this.value, function(v, key){
  667. var item = this.createNewItem(key, v, this, this.level+1, this.dictionary, false);
  668. if (this.children.length) this.children[this.children.length-1].nextSibling = item;
  669. this.children.push(item);
  670. }.bind(this));
  671. break;
  672. default:
  673. //nothing
  674. break;
  675. }
  676. this.childrenItemCreated = true;
  677. }
  678. },
  679. addItem: function(e){
  680. if (!this.parent){
  681. this.createChildrenItems();
  682. this.addChild();
  683. }else{
  684. if (this.exp){
  685. this.addChild();
  686. }else{
  687. this.addSibling();
  688. }
  689. }
  690. this.dictionary.jsonParse.loadObjectTree();
  691. },
  692. addChild: function(){
  693. var item;
  694. if (this.type=="array"){
  695. var idx = this.value.length;
  696. var arrayValue = "New Element Value";
  697. this.value.push(arrayValue);
  698. item = this.createNewItem(idx, arrayValue, this, this.level+1, this.dictionary, false);
  699. }
  700. if (this.type=="object") {
  701. var key = "NewItem";
  702. var i = 0;
  703. while (this.value[key] !== undefined) {
  704. i++;
  705. key = "NewItem" + i;
  706. }
  707. var objValue1 = "New Item Value";
  708. this.value[key] = objValue1;
  709. item = this.createNewItem(key, objValue1, this, this.level + 1, this.dictionary, false)
  710. }
  711. if (this.children.length) this.children[this.children.length-1].nextSibling = item;
  712. this.children.push(item);
  713. },
  714. addSibling: function(){
  715. var item = null;
  716. var idx;
  717. if (this.parent.type=="array"){
  718. idx = this.key;
  719. var value = "New Element Value";
  720. this.parent.value.splice(this.key, 0, value);
  721. for (var i=this.key; i<this.parent.children.length; i++){
  722. var item = this.parent.children[i];
  723. item.key = item.key+1;
  724. item.setNodeText();
  725. }
  726. item = this.createNewItem(idx, value, this.parent, this.level, this.dictionary, false, this);
  727. }else{
  728. var key = "NewItem";
  729. var i = 0;
  730. while (this.parent.value[key] != undefined) {
  731. i++;
  732. key = "NewItem" + i;
  733. }
  734. var value = "New Item Value";
  735. this.parent.value[key] = value;
  736. var item = this.createNewItem(key, value, this.parent, this.level, this.dictionary, false, this);
  737. idx = this.parent.children.indexOf(this);
  738. }
  739. if (idx) this.parent.children[idx-1].nextSibling = item;
  740. this.parent.children.splice(idx, 0, item);
  741. },
  742. delItem: function(e){
  743. var _self = this;
  744. this.dictionary.designer.shortcut = false;
  745. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.deleteDataTitle, this.dictionary.designer.lp.notice.deleteData, 300, 120, function(){
  746. _self.destroy();
  747. _self.dictionary.jsonParse.loadObjectTree();
  748. _self.dictionary.designer.shortcut = true;
  749. this.close();
  750. }, function(){
  751. _self.dictionary.designer.shortcut = true;
  752. this.close();
  753. });
  754. },
  755. destroy: function(){
  756. var idx = this.parent.children.indexOf(this);
  757. if (idx) this.parent.children[idx-1].nextSibling = this.nextSibling;
  758. this.destroyAllNodes();
  759. this.parent.children.erase(this);
  760. if (this.parent.type=="object"){
  761. delete this.parent.value[this.key];
  762. delete this;
  763. }
  764. if (this.parent.type=="array"){
  765. this.parent.value.splice(this.key, 1);
  766. for (var i=this.key; i<this.parent.children.length; i++){
  767. this.parent.children[i].key = this.parent.children[i].key-1;
  768. this.parent.children[i].setNodeText();
  769. }
  770. }
  771. this.dictionary.jsonParse.loadObjectTree();
  772. },
  773. destroyAllNodes: function(){
  774. this.children.each(function(item){
  775. item.destroyAllNodes();
  776. });
  777. this.itemNode.destroy();
  778. this.typeNode.destroy();
  779. this.valueNode.destroy();
  780. if (this.typeSelectNode) this.typeSelectNode.destroy();
  781. },
  782. selectType: function(){
  783. if (!this.typeSelectNode) this.createTypeSelectNode();
  784. this.typeSelectNode.setStyle("display", "block");
  785. var size = this.dictionary.node.getSize();
  786. var selSize = this.typeSelectNode.getSize();
  787. var itemNodes = this.typeSelectNode.getChildren();
  788. for (var i=0; i<itemNodes.length; i++){
  789. if (itemNodes[i].get("text")==this.type){
  790. itemNodes[i].setStyles(this.css.typeSelectItemNode_over);
  791. }else{
  792. itemNodes[i].setStyles(this.css.typeSelectItemNode);
  793. }
  794. };
  795. this.typeSelectNode.position({
  796. relativeTo: this.typeNode,
  797. position: 'upperLeft',
  798. edge: 'upperLeft'
  799. });
  800. var p = this.typeSelectNode.getPosition(this.typeSelectNode.getOffsetParent());
  801. if ((p.y+selSize.y)>size.y){
  802. this.typeSelectNode.position({
  803. relativeTo: this.typeNode,
  804. position: 'bottomLeft',
  805. edge: 'bottomLeft'
  806. });
  807. };
  808. this.closeTypeSelectNodeFun = this.closeTypeSelectNode.bind(this);
  809. $(document.body).addEvent("mousedown", this.closeTypeSelectNodeFun);
  810. },
  811. closeTypeSelectNode: function(){
  812. this.typeSelectNode.setStyle("display", "none");
  813. $(document.body).removeEvent("mousedown", this.closeTypeSelectNodeFun);
  814. },
  815. createTypeSelectNode: function(){
  816. var _self = this;
  817. this.typeSelectNode = new Element("div", {"styles": this.css.typeSelectNode});
  818. var types = this.dictionary.options.types;
  819. if (!this.parent){
  820. types = ["object", "array"];
  821. this.typeSelectNode.setStyle("height", "50px");
  822. }
  823. types.each(function(type){
  824. var itemNode = new Element("div", {"styles": this.css.typeSelectItemNode}).inject(this.typeSelectNode);
  825. itemNode.set("text", type);
  826. if (this.type==type) itemNode.setStyles(this.css.typeSelectItemNode_over);
  827. itemNode.addEvents({
  828. "mouseover": function(){this.setStyles(_self.css.typeSelectItemNode_over);},
  829. "mouseout": function(){this.setStyles(_self.css.typeSelectItemNode);},
  830. "mousedown": function(e){_self.selectedType(this, e);}
  831. })
  832. }.bind(this));
  833. this.typeSelectNode.inject(this.dictionary.node);
  834. },
  835. selectedType: function(itemNode, e){
  836. e.target = null;
  837. var type = itemNode.get("text");
  838. if (this.type!=type){
  839. var _self = this;
  840. switch(type){
  841. case "array":
  842. if (this.value!="New Item Value" && this.value!="New Element Value"){
  843. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeTypeTitle, this.dictionary.designer.lp.notice.changeType, 300, 120, function(){
  844. if (_self.type=="object"){
  845. _self.changeTypeObjectToArray(type);
  846. }else{
  847. _self.changeTypePrimitiveToArray(type);
  848. }
  849. this.close();
  850. _self.dictionary.jsonParse.loadObjectTree();
  851. }, function(){
  852. this.close();
  853. });
  854. }else{
  855. if (this.type=="object"){
  856. this.changeTypeObjectToArray(type);
  857. }else{
  858. this.changeTypePrimitiveToArray(type);
  859. }
  860. this.dictionary.jsonParse.loadObjectTree();
  861. }
  862. break;
  863. case "object":
  864. if (this.value!="New Item Value" && this.value!="New Element Value") {
  865. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeTypeTitle, this.dictionary.designer.lp.notice.changeType, 300, 120, function () {
  866. if (_self.type == "array") {
  867. _self.changeTypeArrayToObject(type);
  868. } else {
  869. _self.changeTypePrimitiveToObject(type);
  870. }
  871. this.close();
  872. _self.dictionary.jsonParse.loadObjectTree();
  873. }, function () {
  874. this.close();
  875. });
  876. }else{
  877. if (this.type == "array") {
  878. this.changeTypeArrayToObject(type);
  879. } else {
  880. this.changeTypePrimitiveToObject(type);
  881. }
  882. this.dictionary.jsonParse.loadObjectTree();
  883. }
  884. break;
  885. default:
  886. if (this.value!="New Item Value" && this.value!="New Element Value") {
  887. this.dictionary.designer.confirm("warn", e, this.dictionary.designer.lp.notice.changeTypeTitle, this.dictionary.designer.lp.notice.changeTypeDeleteChildren, 300, 120, function () {
  888. if (_self.type == "array") {
  889. _self.changeTypeArrayToPrimitive(type);
  890. } else if (_self.type == "object") {
  891. _self.changeTypeObjectToPrimitive(type);
  892. } else {
  893. _self.changeTypePrimitiveToPrimitive(type);
  894. }
  895. this.close();
  896. _self.dictionary.jsonParse.loadObjectTree();
  897. }, function () {
  898. this.close();
  899. });
  900. }else{
  901. if (this.type == "array") {
  902. this.changeTypeArrayToPrimitive(type);
  903. } else if (_self.type == "object") {
  904. this.changeTypeObjectToPrimitive(type);
  905. } else {
  906. this.changeTypePrimitiveToPrimitive(type);
  907. }
  908. this.dictionary.jsonParse.loadObjectTree();
  909. }
  910. break;
  911. }
  912. }
  913. },
  914. deleteAllChildren: function(){
  915. this.children.each(function(item){
  916. item.destroyAllNodes();
  917. });
  918. },
  919. changeTypeObjectToPrimitive: function(type){
  920. this.deleteAllChildren();
  921. this.children = [];
  922. this.childrenItemCreated = false;
  923. var value;
  924. switch(type){
  925. case "string":
  926. value = "";
  927. break;
  928. case "number":
  929. value = 0;
  930. break;
  931. case "boolean":
  932. value = true;
  933. break;
  934. }
  935. delete this.parent.value[this.key];
  936. this.parent.value[this.key] = value;
  937. this.value = value;
  938. this.type = type;
  939. this.exp = false;
  940. this.setNodeText();
  941. this.resetNodes();
  942. },
  943. changeTypeArrayToPrimitive: function(type){
  944. this.changeTypeObjectToPrimitive(type);
  945. },
  946. changeTypePrimitiveToPrimitive: function(type){
  947. switch(type){
  948. case "string":
  949. value = this.value.toString();
  950. break;
  951. case "number":
  952. value = this.value.toFloat();
  953. if (isNaN(value)) value = 0;
  954. break;
  955. case "boolean":
  956. value = true;
  957. if (this.value=="false") value = false;
  958. break;
  959. }
  960. delete this.parent.value[this.key];
  961. this.parent.value[this.key] = value;
  962. this.value = value;
  963. this.type = type;
  964. this.exp = false;
  965. this.setNodeText();
  966. this.resetNodes();
  967. },
  968. changeTypePrimitiveToObject: function(type){
  969. value = {};
  970. delete this.parent.value[this.key];
  971. this.parent.value[this.key] = value;
  972. this.value = value;
  973. this.type = type;
  974. this.exp = false;
  975. this.setNodeText();
  976. this.resetNodes();
  977. },
  978. changeTypeArrayToObject: function(type){
  979. this.deleteAllChildren();
  980. this.children = [];
  981. this.childrenItemCreated = false;
  982. var value = {};
  983. this.value.each(function(v, idx){
  984. value["ITEM"+idx] = v;
  985. });
  986. if (this.parent){
  987. delete this.parent.value[this.key];
  988. this.parent.value[this.key] = value;
  989. this.value = value;
  990. this.type = type;
  991. this.setNodeText();
  992. this.resetNodes();
  993. if (this.exp) this.createChildrenItems();
  994. }else{
  995. this.dictionary.data.data = value;
  996. this.dictionary.jsonParse.json = value;
  997. this.value = value;
  998. this.type = type;
  999. this.setNodeText();
  1000. this.resetNodes();
  1001. if (this.exp) this.createChildrenItems();
  1002. }
  1003. },
  1004. changeTypePrimitiveToArray: function(type) {
  1005. value = [];
  1006. delete this.parent.value[this.key];
  1007. this.parent.value[this.key] = value;
  1008. this.value = value;
  1009. this.type = type;
  1010. this.exp = false;
  1011. this.setNodeText();
  1012. this.resetNodes();
  1013. },
  1014. changeTypeObjectToArray: function(type){
  1015. this.deleteAllChildren();
  1016. this.children = [];
  1017. this.childrenItemCreated = false;
  1018. var value = [];
  1019. Object.each(this.value, function(v, idx){
  1020. value.push(v);
  1021. });
  1022. if (this.parent){
  1023. delete this.parent.value[this.key];
  1024. this.parent.value[this.key] = value;
  1025. this.value = value;
  1026. this.type = type;
  1027. this.childrenItemCreated = false;
  1028. this.setNodeText();
  1029. this.resetNodes();
  1030. if (this.exp) this.createChildrenItems();
  1031. }else{
  1032. this.dictionary.data.data = value;
  1033. this.dictionary.jsonParse.json = value;
  1034. this.value = value;
  1035. this.type = type;
  1036. this.childrenItemCreated = false;
  1037. this.setNodeText();
  1038. this.resetNodes();
  1039. if (this.exp) this.createChildrenItems();
  1040. }
  1041. },
  1042. editValue: function(){
  1043. //debugger;
  1044. //this.inEdit
  1045. this.valueTextNode.empty();
  1046. // this.valueTextNode.removeEvents("mousedown");
  1047. this.editValueNode = new Element("input", {"styles": this.css.itemEditValueNode}).inject(this.valueTextNode);
  1048. this.editValueNode.set("value", this.value);
  1049. if( this.type === "string" ){
  1050. this.selectOrgNode = new Element("span", {
  1051. "styles": this.css.itemSelectOrgNode,
  1052. "title" : this.dictionary.designer.lp.selectOrganizationByDblclick,
  1053. "events" : {
  1054. dblclick : function(ev){
  1055. var opt = {
  1056. "type": "",
  1057. "types" : ["person","identity","unit","group"],
  1058. "title": "select",
  1059. "count" : "0",
  1060. "values": this.value.replace("New Item Value","").split(", "),
  1061. "expand" : false,
  1062. "onComplete": function( array ){
  1063. var v = [];
  1064. array.each( function(d){
  1065. v.push( d.data.distinguishedName );
  1066. }.bind(this));
  1067. this.value = v.join(", ");
  1068. this.parent.value[this.key] = this.value;
  1069. this.setNodeText();
  1070. this.dictionary.jsonParse.loadObjectTree();
  1071. }.bind(this)
  1072. };
  1073. var selector = new MWF.O2Selector(this.dictionary.designer.content, opt );
  1074. ev.stopPropagation();
  1075. }.bind(this)
  1076. }
  1077. }).inject(this.valueTextNode);
  1078. }
  1079. window.setTimeout(function(){
  1080. this.editValueNode.focus();
  1081. this.editValueNode.select();
  1082. this.editValueNode.addEvents({
  1083. "blur": function(e){
  1084. this.editValueConfirm(e);
  1085. }.bind(this),
  1086. "keydown": function(e){
  1087. if (e.code==13){
  1088. this.editValueConfirm(e);
  1089. if (this.nextSibling){
  1090. this.nextSibling.editKey();
  1091. }
  1092. }
  1093. e.stopPropagation();
  1094. }.bind(this),
  1095. "mousedown": function(e){
  1096. e.stopPropagation();
  1097. }
  1098. });
  1099. }.bind(this), 10);
  1100. },
  1101. editValueConfirm: function(e){
  1102. var value = this.editValueNode.get("Value");
  1103. if (this.type=="number"){
  1104. if (isNaN(parseFloat(value))){
  1105. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.inputTypeError, "error", this.editValueNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  1106. this.editValueNode.setStyles(this.css.itemEditValueNode_error);
  1107. this.editValueNode.select();
  1108. e.preventDefault();
  1109. return false;
  1110. }
  1111. value = value.toFloat();
  1112. }
  1113. this.value = value;
  1114. this.parent.value[this.key] = this.value;
  1115. this.editValueNode.destroy();
  1116. this.editValueNode = null;
  1117. this.setNodeText();
  1118. this.dictionary.jsonParse.loadObjectTree();
  1119. // if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  1120. },
  1121. editKey: function(){
  1122. this.itemTextNode.empty();
  1123. // this.itemTextNode.removeEvents("mousedown");
  1124. this.editKeyNode = new Element("input", {"styles": this.css.itemEditValueNode, "type": "text"}).inject(this.itemTextNode);
  1125. this.editKeyNode.set("value", this.key);
  1126. window.setTimeout(function(){
  1127. this.editKeyNode.focus();
  1128. this.editKeyNode.select();
  1129. //this.editKeyNode.setSelectionRange(1,this.key.length-1);
  1130. this.editKeyNode.addEvents({
  1131. "blur": function(e){this.editKeyConfirm(e);}.bind(this),
  1132. "keydown": function(e){
  1133. if (e.code==13){
  1134. this.editKeyConfirm(e);
  1135. if (this.type!="array" && this.type!="object" && this.type!="boolean") {
  1136. this.editValue();
  1137. }else{
  1138. if (this.nextSibling){
  1139. this.nextSibling.editKey();
  1140. }
  1141. }
  1142. }
  1143. e.stopPropagation();
  1144. }.bind(this),
  1145. "mousedown": function(e){e.stopPropagation();}
  1146. });
  1147. }.bind(this), 10);
  1148. },
  1149. editKeyConfirm: function(e){
  1150. var key = this.editKeyNode.get("Value");
  1151. if (key!=this.key){
  1152. if (this.parent.value[key]){
  1153. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.sameKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  1154. this.editKeyNode.setStyles(this.css.itemEditValueNode_error);
  1155. this.editKeyNode.select();
  1156. e.preventDefault();
  1157. return false;
  1158. }
  1159. if (!isNaN(parseFloat(key))){
  1160. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.numberKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  1161. this.editKeyNode.setStyles(this.css.itemEditValueNode_error);
  1162. this.editKeyNode.select();
  1163. e.preventDefault();
  1164. return false;
  1165. }
  1166. if (!key){
  1167. this.dictionary.designer.notice(this.dictionary.designer.lp.notice.emptyKey, "error", this.editKeyNode, {"x": "left", "y": "bottom"}, {"x": 0, "y": 24});
  1168. this.editKeyNode.setStyles(this.css.itemEditValueNode_error);
  1169. this.editKeyNode.select();
  1170. e.preventDefault();
  1171. return false;
  1172. }
  1173. delete this.parent.value[this.key];
  1174. this.parent.value[key] = this.value;
  1175. this.key = key;
  1176. }
  1177. this.editKeyNode.destroy();
  1178. this.editKeyNode = null;
  1179. this.setNodeText();
  1180. this.dictionary.jsonParse.loadObjectTree();
  1181. //if (this.parent){
  1182. // if (this.parent.type!="array"){
  1183. // this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  1184. // }
  1185. //}
  1186. },
  1187. selectBooleanValue: function(){
  1188. if (!this.booleanSelectNode) this.createBooleanSelectNode();
  1189. var size = this.dictionary.node.getSize();
  1190. this.booleanSelectNode.setStyle("display", "block");
  1191. var selSize = this.booleanSelectNode.getSize();
  1192. var itemNodes = this.booleanSelectNode.getChildren();
  1193. for (var i=0; i<itemNodes.length; i++){
  1194. if (itemNodes[i].get("text")==this.value.toString()){
  1195. itemNodes[i].setStyles(this.css.typeSelectItemNode_over);
  1196. }else{
  1197. itemNodes[i].setStyles(this.css.typeSelectItemNode);
  1198. }
  1199. };
  1200. this.booleanSelectNode.position({
  1201. relativeTo: this.valueNode,
  1202. position: 'upperLeft',
  1203. edge: 'upperLeft'
  1204. });
  1205. var p = this.booleanSelectNode.getPosition(this.booleanSelectNode.getOffsetParent());
  1206. if ((p.y+selSize.y)>size.y){
  1207. this.booleanSelectNode.position({
  1208. relativeTo: this.valueNode,
  1209. position: 'bottomLeft',
  1210. edge: 'bottomLeft'
  1211. });
  1212. };
  1213. this.closeBooleanSelectNodeFun = this.closeBooleanSelectNode.bind(this);
  1214. $(document.body).addEvent("mousedown", this.closeBooleanSelectNodeFun);
  1215. },
  1216. closeBooleanSelectNode: function(){
  1217. this.booleanSelectNode.setStyle("display", "none");
  1218. $(document.body).removeEvent("mousedown", this.closeBooleanSelectNodeFun);
  1219. },
  1220. createBooleanSelectNode: function(){
  1221. var _self = this;
  1222. this.booleanSelectNode = new Element("div", {"styles": this.css.booleanSelectNode});
  1223. ["true", "false"].each(function(type){
  1224. var itemNode = new Element("div", {"styles": this.css.typeSelectItemNode}).inject(this.booleanSelectNode);
  1225. itemNode.set("text", type);
  1226. if (this.value.toString()==type) itemNode.setStyles(this.css.typeSelectItemNode_over);
  1227. itemNode.addEvents({
  1228. "mouseover": function(){this.setStyles(_self.css.typeSelectItemNode_over);},
  1229. "mouseout": function(){this.setStyles(_self.css.typeSelectItemNode);},
  1230. "mousedown": function(e){_self.selectedBoolean(this, e);}
  1231. })
  1232. }.bind(this));
  1233. this.booleanSelectNode.inject(this.dictionary.node);
  1234. },
  1235. selectedBoolean: function(item, e){
  1236. var text = item.get("text");
  1237. var value = (text=="false") ? false : true;
  1238. this.value = value;
  1239. this.parent.value[this.key] = value;
  1240. this.setNodeText();
  1241. this.dictionary.jsonParse.loadObjectTree();
  1242. }
  1243. });
  1244. MWF.xApplication.cms.DictionaryDesigner.DictionaryReader = new Class({
  1245. Extends: MWF.xApplication.cms.DictionaryDesigner.Dictionary,
  1246. autoSave: function(){},
  1247. createRootItem: function() {
  1248. this.items.push(new MWF.xApplication.cms.DictionaryDesigner.Dictionary.ItemReader("ROOT", this.data.data, null, 0, this, true));
  1249. }
  1250. });
  1251. MWF.xApplication.cms.DictionaryDesigner.Dictionary.ItemReader= new Class({
  1252. Extends: MWF.xApplication.cms.DictionaryDesigner.Dictionary.item,
  1253. createNewItem: function(key, value, parent, level, dictionary, exp, nextSibling){
  1254. return new MWF.xApplication.cms.DictionaryDesigner.Dictionary.ItemReader(key, value, parent, level, dictionary, exp, nextSibling);
  1255. },
  1256. setEvent: function(){
  1257. this.itemNode.addEvent("click", function(e){this.selected();}.bind(this));
  1258. this.typeNode.addEvent("click", function(e){this.selected();}.bind(this));
  1259. this.valueNode.addEvent("click", function(e){this.selected();}.bind(this));
  1260. //this.typeSelActionNode.addEvent("click", function(e){this.selectType();}.bind(this));
  1261. //this.typeTextNode.addEvent("click", function(e){this.selectType();}.bind(this));
  1262. //this.itemNode.addEvents({
  1263. // "mouseover": function(){this.itemActionsAreaNode.fade("in");}.bind(this),
  1264. // "mouseout": function(){this.itemActionsAreaNode.fade("out");}.bind(this)
  1265. //});
  1266. //if (this.itemAddActionNode) this.itemAddActionNode.addEvent("click", function(e){this.addItem(e);}.bind(this));
  1267. //if (this.itemDelActionNode) this.itemDelActionNode.addEvent("click", function(e){this.delItem(e);}.bind(this));
  1268. if (this.type=="array" || this.type=="object"){
  1269. this.itemExpColActionNode.addEvents({
  1270. "click": function(){this.expOrColChildren();}.bind(this)
  1271. });
  1272. }else{
  1273. //if (this.type!="boolean") this.valueTextNode.addEvent("mousedown", function(e){this.editValue();}.bind(this));
  1274. }
  1275. //if (this.parent){
  1276. // if (this.parent.type!="array"){
  1277. // this.itemTextNode.addEvent("mousedown", function(e){this.editKey();}.bind(this));
  1278. // }
  1279. //}
  1280. //if (this.type=="boolean"){
  1281. // this.valueSelActionNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  1282. // this.valueTextNode.addEvent("click", function(){this.selectBooleanValue();}.bind(this));
  1283. //}
  1284. }
  1285. });
  1286. //MWF.xApplication.cms.ProcessDesigner.Process.Property = new Class({
  1287. // Implements: [Options, Events],
  1288. // Extends: MWF.APPPD.Property,
  1289. // initialize: function(process, options){
  1290. // this.setOptions(options);
  1291. // this.process = process;
  1292. // this.paper = this.process.paper;
  1293. // this.data = process.process;
  1294. // this.htmlPath = "../x_component_process_ProcessDesigner//$Process/process.html";
  1295. // }
  1296. //});