Dictionary.js 60 KB

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