Main.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. MWF.APPDD = MWF.xApplication.process.DictionaryDesigner;
  2. MWF.APPDD.options = {
  3. "multitask": true,
  4. "executable": false
  5. };
  6. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", null, false);
  7. MWF.xDesktop.requireApp("process.DictionaryDesigner", "Dictionary", null, false);
  8. MWF.xApplication.process.DictionaryDesigner.Main = new Class({
  9. Extends: MWF.xApplication.Common.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "name": "process.DictionaryDesigner",
  14. "icon": "icon.png",
  15. "title": MWF.APPDD.LP.title,
  16. "appTitle": MWF.APPDD.LP.title,
  17. "id": "",
  18. "width": "1200",
  19. "height": "600",
  20. "actions": null,
  21. "category": null,
  22. "processData": null
  23. },
  24. onQueryLoad: function(){
  25. this.shortcut = true;
  26. if (this.status){
  27. this.options.application = this.status.applicationId;
  28. this.application = this.status.application || this.status.applicationId;
  29. this.options.id = this.status.id;
  30. this.setOptions(this.status.options);
  31. }
  32. if( !this.application && this.options.application ){
  33. this.application = this.options.application;
  34. }
  35. if (!this.options.id){
  36. this.options.desktopReload = false;
  37. this.options.title = this.options.title + "-"+MWF.APPDD.LP.newDictionary;
  38. }
  39. if (!this.actions){
  40. // if (this.options.action){
  41. // MWF.xDesktop.requireApp("process."+this.options.action, "Actions.RestActions", function(){
  42. // this.actions = new MWF.xApplication.process[this.options.action].Actions.RestActions();
  43. // }.bind(this), false);
  44. // }else{
  45. this.actions = MWF.Actions.get("x_processplatform_assemble_designer");
  46. //this.actions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  47. // }
  48. this.actions.application = this.application;
  49. }
  50. this.lp = MWF.xApplication.process.DictionaryDesigner.LP;
  51. this.addEvent("queryClose", function(e){
  52. if (this.explorer && this.explorer.reload){
  53. this.explorer.reload();
  54. }
  55. }.bind(this));
  56. // this.processData = this.options.processData;
  57. },
  58. loadApplication: function(callback){
  59. this.createNode();
  60. if (!this.options.isRefresh){
  61. this.maxSize(function(){
  62. this.openForm();
  63. }.bind(this));
  64. }else{
  65. this.openForm();
  66. }
  67. if (!this.options.readMode) this.addKeyboardEvents();
  68. if (callback) callback();
  69. },
  70. addKeyboardEvents: function(){
  71. this.addEvent("copy", function(){
  72. this.copyModule();
  73. }.bind(this));
  74. this.addEvent("paste", function(){
  75. this.pasteModule();
  76. }.bind(this));
  77. this.addEvent("cut", function(){
  78. this.cutModule();
  79. }.bind(this));
  80. this.addEvent("keySave", function(e){
  81. this.keySave(e);
  82. }.bind(this));
  83. this.addEvent("keyDelete", function(e){
  84. this.keyDelete(e);
  85. }.bind(this));
  86. },
  87. keySave: function(e){
  88. if (this.shortcut) {
  89. if (this.tab.showPage) {
  90. var dictionary = this.tab.showPage.dictionary;
  91. if (dictionary) {
  92. dictionary.save();
  93. e.preventDefault();
  94. }
  95. }
  96. }
  97. },
  98. keyDelete: function(){
  99. if (this.shortcut) {
  100. if (this.tab.showPage) {
  101. var dictionary = this.tab.showPage.dictionary;
  102. if (dictionary) {
  103. if (dictionary.currentSelectedItem) {
  104. var item = dictionary.currentSelectedItem;
  105. item.delItem(item.itemTextNode);
  106. }
  107. }
  108. }
  109. }
  110. },
  111. copyModule: function(){
  112. if (this.shortcut) {
  113. if (this.tab.showPage) {
  114. var dictionary = this.tab.showPage.dictionary;
  115. if (dictionary) {
  116. if (dictionary.currentSelectedItem) {
  117. var item = dictionary.currentSelectedItem;
  118. MWF.clipboard.data = {
  119. "type": "dictionary",
  120. "data": {
  121. "key": item.key,
  122. "value": (typeOf(item.value)=="object") ? Object.clone(item.value) : item.value
  123. }
  124. };
  125. }
  126. }
  127. }
  128. }
  129. },
  130. cutModule: function(){
  131. if (this.shortcut) {
  132. if (this.tab.showPage) {
  133. var dictionary = this.tab.showPage.dictionary;
  134. if (dictionary) {
  135. if (dictionary.currentSelectedItem) {
  136. this.copyModule();
  137. var item = dictionary.currentSelectedItem;
  138. item.destroy();
  139. }
  140. }
  141. }
  142. }
  143. },
  144. pasteModule: function(){
  145. if (this.shortcut) {
  146. if (MWF.clipboard.data) {
  147. if (MWF.clipboard.data.type == "dictionary") {
  148. if (this.tab.showPage) {
  149. var dictionary = this.tab.showPage.dictionary;
  150. if (dictionary) {
  151. if (dictionary.currentSelectedItem) {
  152. var item = dictionary.currentSelectedItem;
  153. var key = MWF.clipboard.data.data.key;
  154. var value = (typeOf(MWF.clipboard.data.data.value)=="object") ? Object.clone(MWF.clipboard.data.data.value) : MWF.clipboard.data.data.value;
  155. var level = item.level;
  156. var parent = item;
  157. var nextSibling = null;
  158. if (!item.parent){//top level
  159. level = 1;
  160. }else{
  161. if (item.type!="array" && item.type!="object"){
  162. parent = item.parent;
  163. nextSibling = item;
  164. }else{
  165. if (item.exp){
  166. level = item.level+1;
  167. }else{
  168. parent = item.parent;
  169. nextSibling = item;
  170. }
  171. }
  172. }
  173. var idx = parent.children.length;
  174. if (item.type=="array"){
  175. if (nextSibling){
  176. key = nextSibling.key;
  177. parent.value.splice(nextSibling.key, 0, value);
  178. for (var i=nextSibling.key; i<parent.children.length; i++){
  179. subItem = parent.children[i];
  180. subItem.key = subItem.key+1;
  181. subItem.setNodeText();
  182. }
  183. }else{
  184. var key = parent.value.length;
  185. parent.value.push(value);
  186. }
  187. idx = key;
  188. }else{
  189. var oldKey = key;
  190. var i = 0;
  191. while (parent.value[key] != undefined) {
  192. i++;
  193. key = oldKey + i;
  194. }
  195. parent.value[key] = value;
  196. if (nextSibling) var idx = parent.children.indexOf(nextSibling);
  197. }
  198. var item = new MWF.xApplication.process.DictionaryDesigner.Dictionary.item(key, value, parent, level, this.dictionary, true, nextSibling);
  199. if (idx) parent.children[idx-1].nextSibling = item;
  200. parent.children.splice(idx, 0, item);
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. },
  208. createNode: function(){
  209. this.content.setStyle("overflow", "hidden");
  210. this.node = new Element("div", {
  211. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  212. }).inject(this.content);
  213. },
  214. getApplication:function(callback){
  215. if (!this.application){
  216. this.actions.getApplication(this.options.application, function(json){
  217. this.application = {"name": json.data.name, "id": json.data.id};
  218. if (callback) callback();
  219. }.bind(this));
  220. }else{
  221. if (callback) callback();
  222. }
  223. },
  224. openForm: function(){
  225. this.getApplication(function(){
  226. this.initOptions();
  227. this.loadNodes();
  228. this.loadDictionaryListNodes();
  229. // this.loadToolbar();
  230. this.loadContentNode();
  231. this.loadProperty();
  232. // this.loadTools();
  233. this.resizeNode();
  234. this.addEvent("resize", this.resizeNode.bind(this));
  235. this.loadDictionary();
  236. if (this.toolbarContentNode){
  237. this.setScrollBar(this.toolbarContentNode, null, {
  238. "V": {"x": 0, "y": 0},
  239. "H": {"x": 0, "y": 0}
  240. });
  241. this.setScrollBar(this.propertyDomArea, null, {
  242. "V": {"x": 0, "y": 0},
  243. "H": {"x": 0, "y": 0}
  244. });
  245. }
  246. }.bind(this));
  247. },
  248. initOptions: function(){
  249. //this.toolsData = null;
  250. //this.toolbarMode = "all";
  251. //this.tools = [];
  252. //this.toolbarDecrease = 0;
  253. //
  254. //this.designNode = null;
  255. //this.form = null;
  256. },
  257. loadNodes: function(){
  258. this.dictionaryListNode = new Element("div", {
  259. "styles": this.css.dictionaryListNode
  260. }).inject(this.node);
  261. this.propertyNode = new Element("div", {
  262. "styles": this.css.propertyNode
  263. }).inject(this.node);
  264. this.contentNode = new Element("div", {
  265. "styles": this.css.contentNode
  266. }).inject(this.node);
  267. },
  268. //loadDictionaryListNodes-------------------------------
  269. loadDictionaryListNodes: function(){
  270. this.dictionaryListTitleNode = new Element("div", {
  271. "styles": this.css.dictionaryListTitleNode,
  272. "text": MWF.APPDD.LP.dictionary
  273. }).inject(this.dictionaryListNode);
  274. this.dictionaryListResizeNode = new Element("div", {"styles": this.css.dictionaryListResizeNode}).inject(this.dictionaryListNode);
  275. this.dictionaryListAreaSccrollNode = new Element("div", {"styles": this.css.dictionaryListAreaSccrollNode}).inject(this.dictionaryListNode);
  276. this.dictionaryListAreaNode = new Element("div", {"styles": this.css.dictionaryListAreaNode}).inject(this.dictionaryListAreaSccrollNode);
  277. this.loadDictionaryListResize();
  278. this.loadDictionaryList();
  279. },
  280. loadDictionaryListResize: function(){
  281. this.dictionaryListResize = new Drag(this.dictionaryListResizeNode,{
  282. "snap": 1,
  283. "onStart": function(el, e){
  284. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  285. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  286. el.store("position", {"x": x, "y": y});
  287. var size = this.dictionaryListAreaSccrollNode.getSize();
  288. el.store("initialWidth", size.x);
  289. }.bind(this),
  290. "onDrag": function(el, e){
  291. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  292. // var y = e.event.y;
  293. var bodySize = this.content.getSize();
  294. var position = el.retrieve("position");
  295. var initialWidth = el.retrieve("initialWidth").toFloat();
  296. var dx = x.toFloat() - position.x.toFloat();
  297. var width = initialWidth+dx;
  298. if (width> bodySize.x/2) width = bodySize.x/2;
  299. if (width<40) width = 40;
  300. this.contentNode.setStyle("margin-left", width+1);
  301. this.dictionaryListNode.setStyle("width", width);
  302. }.bind(this)
  303. });
  304. },
  305. loadDictionaryList: function(){
  306. this.actions.listDictionary(this.application.id || this.application, function (json) {
  307. json.data.each(function(dictionary){
  308. this.createListDictionaryItem(dictionary);
  309. }.bind(this));
  310. }.bind(this), null, false);
  311. },
  312. createListDictionaryItem: function(dictionary, isNew){
  313. var _self = this;
  314. var listDictionaryItem = new Element("div", {"styles": this.css.listDictionaryItem}).inject(this.dictionaryListAreaNode, (isNew) ? "top": "bottom");
  315. var listDictionaryItemIcon = new Element("div", {"styles": this.css.listDictionaryItemIcon}).inject(listDictionaryItem);
  316. var listDictionaryItemText = new Element("div", {"styles": this.css.listDictionaryItemText, "text": (dictionary.name) ? dictionary.name+" ("+dictionary.alias+")" : this.lp.newDictionary}).inject(listDictionaryItem);
  317. listDictionaryItem.store("dictionary", dictionary);
  318. listDictionaryItem.addEvents({
  319. "click": function(e){_self.loadDictionaryByData(this, e);},
  320. "mouseover": function(){if (_self.currentListDictionaryItem!=this) this.setStyles(_self.css.listDictionaryItem_over);},
  321. "mouseout": function(){if (_self.currentListDictionaryItem!=this) this.setStyles(_self.css.listDictionaryItem);}
  322. });
  323. },
  324. loadDictionaryByData: function(node, e){
  325. var dictionary = node.retrieve("dictionary");
  326. var openNew = true;
  327. for (var i = 0; i<this.tab.pages.length; i++){
  328. if (dictionary.id==this.tab.pages[i].dictionary.data.id){
  329. this.tab.pages[i].showTabIm();
  330. openNew = false;
  331. break;
  332. }
  333. }
  334. if (openNew){
  335. this.loadDictionaryData(dictionary.id, function(data){
  336. var dictionary = new MWF.xApplication.process.DictionaryDesigner.Dictionary(this, data);
  337. dictionary.load();
  338. }.bind(this), true);
  339. }
  340. },
  341. //loadContentNode------------------------------
  342. loadContentNode: function(){
  343. this.contentToolbarNode = new Element("div#contentToolbarNode", {
  344. "styles": this.css.contentToolbarNode
  345. }).inject(this.contentNode);
  346. if (!this.options.readMode) this.loadContentToolbar();
  347. this.editContentNode = new Element("div", {
  348. "styles": this.css.editContentNode
  349. }).inject(this.contentNode);
  350. this.loadEditContent(function(){
  351. // if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  352. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  353. }.bind(this));
  354. },
  355. loadContentToolbar: function(callback){
  356. this.getFormToolbarHTML(function(toolbarNode){
  357. var spans = toolbarNode.getElements("span");
  358. spans.each(function(item, idx){
  359. var img = item.get("MWFButtonImage");
  360. if (img){
  361. item.set("MWFButtonImage", this.path+""+this.options.style+"/toolbar/"+img);
  362. }
  363. }.bind(this));
  364. $(toolbarNode).inject(this.contentToolbarNode);
  365. MWF.require("MWF.widget.Toolbar", function(){
  366. this.toolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  367. this.toolbar.load();
  368. if (callback) callback();
  369. }.bind(this));
  370. }.bind(this));
  371. },
  372. getFormToolbarHTML: function(callback){
  373. var toolbarUrl = this.path+this.options.style+"/toolbars.html";
  374. MWF.getRequestText(toolbarUrl, function(responseText, responseXML){
  375. var htmlString = responseText;
  376. htmlString = o2.bindJson(htmlString, {"lp": this.lp.formToolbar});
  377. var temp = new Element('div').set('html', htmlString);
  378. if (callback) callback( temp.childNodes[0] );
  379. }.bind(this));
  380. },
  381. maxOrReturnEditor: function(){
  382. if (!this.isMax){
  383. this.designNode.inject(this.node);
  384. this.designNode.setStyles({
  385. "position": "absolute",
  386. "width": "100%",
  387. "height": "100%",
  388. "top": "0px",
  389. "margin": "0px",
  390. "left": "0px"
  391. });
  392. this.tab.pages.each(function(page){
  393. page.dictionary.setAreaNodeSize();
  394. });
  395. this.isMax = true;
  396. }else{
  397. this.isMax = false;
  398. this.designNode.inject(this.editContentNode);
  399. this.designNode.setStyles(this.css.designNode);
  400. this.designNode.setStyles({
  401. "position": "static"
  402. });
  403. this.resizeNode();
  404. this.tab.pages.each(function(page){
  405. page.dictionary.setAreaNodeSize();
  406. });
  407. }
  408. },
  409. loadEditContent: function(callback){
  410. this.designNode = new Element("div", {
  411. "styles": this.css.designNode
  412. }).inject(this.editContentNode);
  413. MWF.require("MWF.widget.Tab", function(){
  414. this.tab = new MWF.widget.Tab(this.designNode, {"style": "dictionary"});
  415. this.tab.load();
  416. }.bind(this), false);
  417. // MWF.require("MWF.widget.ScrollBar", function(){
  418. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  419. // }.bind(this));
  420. },
  421. //loadProperty------------------------
  422. loadProperty: function(){
  423. this.propertyTitleNode = new Element("div", {
  424. "styles": this.css.propertyTitleNode,
  425. "text": MWF.APPDD.LP.property
  426. }).inject(this.propertyNode);
  427. this.propertyResizeBar = new Element("div", {
  428. "styles": this.css.propertyResizeBar
  429. }).inject(this.propertyNode);
  430. this.loadPropertyResize();
  431. this.propertyContentNode = new Element("div", {
  432. "styles": this.css.propertyContentNode
  433. }).inject(this.propertyNode);
  434. this.propertyDomArea = new Element("div", {
  435. "styles": this.css.propertyDomArea
  436. }).inject(this.propertyContentNode);
  437. this.propertyDomPercent = 0.3;
  438. this.propertyContentResizeNode = new Element("div", {
  439. "styles": this.css.propertyContentResizeNode
  440. }).inject(this.propertyContentNode);
  441. this.propertyContentArea = new Element("div", {
  442. "styles": this.css.propertyContentArea
  443. }).inject(this.propertyContentNode);
  444. this.loadPropertyContentResize();
  445. this.setPropertyContent();
  446. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  447. },
  448. setPropertyContent: function(){
  449. this.dictionaryPropertyNode = new Element("div", {"styles": this.css.dictionaryPropertyNode});
  450. this.jsonDomNode = new Element("div", {"styles": this.css.jsonDomNode});
  451. this.jsonTextNode = new Element("div", {"styles": this.css.jsonTextNode});
  452. this.jsonTextAreaNode = new Element("textarea", {"styles": this.css.jsonTextAreaNode}).inject(this.jsonTextNode);
  453. MWF.require("MWF.widget.Tab", function(){
  454. var tab = new MWF.widget.Tab(this.propertyContentArea, {"style": "moduleList"});
  455. tab.load();
  456. tab.addTab(this.dictionaryPropertyNode, this.lp.property, false);
  457. tab.addTab(this.jsonDomNode, "JSON", false);
  458. tab.addTab(this.jsonTextNode, "TEXT", false);
  459. tab.pages[0].showTab();
  460. }.bind(this));
  461. var node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.id+":"}).inject(this.dictionaryPropertyNode);
  462. this.propertyIdNode = new Element("div", {"styles": this.css.propertyTextNode}).inject(this.dictionaryPropertyNode);
  463. node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.name+":"}).inject(this.dictionaryPropertyNode);
  464. this.propertyNameNode = new Element("input", {"styles": this.css.propertyInputNode}).inject(this.dictionaryPropertyNode);
  465. if (this.options.noModifyName || this.options.readMode){
  466. this.propertyNameNode.set("readonly", true);
  467. this.propertyNameNode.addEvent("keydown", function(){
  468. this.notice(this.lp.notice.noModifyName, "error");
  469. }.bind(this));
  470. }
  471. node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.alias+":"}).inject(this.dictionaryPropertyNode);
  472. this.propertyAliasNode = new Element("input", {"styles": this.css.propertyInputNode}).inject(this.dictionaryPropertyNode);
  473. if (this.options.noModifyName || this.options.readMode){
  474. this.propertyAliasNode.set("readonly", true);
  475. this.propertyAliasNode.addEvent("keydown", function(){
  476. this.notice(this.lp.notice.noModifyName, "error");
  477. }.bind(this));
  478. }
  479. node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.description+":"}).inject(this.dictionaryPropertyNode);
  480. this.propertyDescriptionNode = new Element("textarea", {"styles": this.css.propertyInputAreaNode}).inject(this.dictionaryPropertyNode);
  481. if (this.options.noModifyName || this.options.readMode){
  482. this.propertyDescriptionNode.set("readonly", true);
  483. }
  484. },
  485. loadPropertyResize: function(){
  486. // var size = this.propertyNode.getSize();
  487. // var position = this.propertyResizeBar.getPosition();
  488. this.propertyResize = new Drag(this.propertyResizeBar,{
  489. "snap": 1,
  490. "onStart": function(el, e){
  491. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  492. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  493. el.store("position", {"x": x, "y": y});
  494. var size = this.propertyNode.getSize();
  495. el.store("initialWidth", size.x);
  496. }.bind(this),
  497. "onDrag": function(el, e){
  498. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  499. // var y = e.event.y;
  500. var bodySize = this.content.getSize();
  501. var position = el.retrieve("position");
  502. var initialWidth = el.retrieve("initialWidth").toFloat();
  503. var dx = position.x.toFloat()-x.toFloat();
  504. var width = initialWidth+dx;
  505. if (width> bodySize.x/2) width = bodySize.x/2;
  506. if (width<40) width = 40;
  507. this.contentNode.setStyle("margin-right", width+1);
  508. this.propertyNode.setStyle("width", width);
  509. }.bind(this)
  510. });
  511. },
  512. loadPropertyContentResize: function(){
  513. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  514. "snap": 1,
  515. "onStart": function(el, e){
  516. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  517. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  518. el.store("position", {"x": x, "y": y});
  519. var size = this.propertyDomArea.getSize();
  520. el.store("initialHeight", size.y);
  521. }.bind(this),
  522. "onDrag": function(el, e){
  523. var size = this.propertyContentNode.getSize();
  524. // var x = e.event.x;
  525. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  526. var position = el.retrieve("position");
  527. var dy = y.toFloat()-position.y.toFloat();
  528. var initialHeight = el.retrieve("initialHeight").toFloat();
  529. var height = initialHeight+dy;
  530. if (height<40) height = 40;
  531. if (height> size.y-40) height = size.y-40;
  532. this.propertyDomPercent = height/size.y;
  533. this.setPropertyContentResize();
  534. }.bind(this)
  535. });
  536. },
  537. setPropertyContentResize: function(){
  538. var size = this.propertyContentNode.getSize();
  539. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  540. var height = size.y-resizeNodeSize.y;
  541. var domHeight = this.propertyDomPercent*height;
  542. var contentHeight = height-domHeight;
  543. this.propertyDomArea.setStyle("height", ""+domHeight+"px");
  544. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  545. if (this.form){
  546. if (this.form.currentSelectedModule){
  547. if (this.form.currentSelectedModule.property){
  548. var tab = this.form.currentSelectedModule.property.propertyTab;
  549. if (tab){
  550. var tabTitleSize = tab.tabNodeContainer.getSize();
  551. tab.pages.each(function(page){
  552. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  553. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  554. var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  555. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  556. }.bind(this));
  557. }
  558. }
  559. }
  560. }
  561. },
  562. //resizeNode------------------------------------------------
  563. resizeNode: function(){
  564. var nodeSize = this.node.getSize();
  565. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  566. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  567. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  568. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  569. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  570. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  571. this.editContentNode.setStyle("height", ""+y+"px");
  572. if (this.designNode){
  573. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  574. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  575. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  576. this.designNode.setStyle("height", ""+y+"px");
  577. }
  578. titleSize = this.propertyTitleNode.getSize();
  579. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  580. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  581. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  582. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  583. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  584. y = nodeSize.y-y;
  585. this.propertyContentNode.setStyle("height", ""+y+"px");
  586. this.propertyResizeBar.setStyle("height", ""+y+"px");
  587. this.setPropertyContentResize();
  588. titleSize = this.dictionaryListTitleNode.getSize();
  589. titleMarginTop = this.dictionaryListTitleNode.getStyle("margin-top").toFloat();
  590. titleMarginBottom = this.dictionaryListTitleNode.getStyle("margin-bottom").toFloat();
  591. titlePaddingTop = this.dictionaryListTitleNode.getStyle("padding-top").toFloat();
  592. titlePaddingBottom = this.dictionaryListTitleNode.getStyle("padding-bottom").toFloat();
  593. nodeMarginTop = this.dictionaryListAreaSccrollNode.getStyle("margin-top").toFloat();
  594. nodeMarginBottom = this.dictionaryListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  595. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  596. y = nodeSize.y-y;
  597. this.dictionaryListAreaSccrollNode.setStyle("height", ""+y+"px");
  598. this.dictionaryListResizeNode.setStyle("height", ""+y+"px");
  599. },
  600. //loadForm------------------------------------------
  601. loadDictionary: function(){
  602. this.getDictionaryData(this.options.id, function(ddata){
  603. this.setTitle(this.options.appTitle + "-"+ddata.name);
  604. if (this.taskitem) this.taskitem.setText(this.options.appTitle + "-"+ddata.name);
  605. this.options.appTitle = this.options.appTitle + "-"+ddata.name;
  606. if (this.options.readMode){
  607. this.dictionary = new MWF.xApplication.process.DictionaryDesigner.DictionaryReader(this, ddata);
  608. }else{
  609. this.dictionary = new MWF.xApplication.process.DictionaryDesigner.Dictionary(this, ddata);
  610. }
  611. this.dictionary.load();
  612. if (this.status){
  613. if (this.status.openDictionarys){
  614. this.status.openDictionarys.each(function(id){
  615. this.loadDictionaryData(id, function(data){
  616. var showTab = true;
  617. if (this.status.currentId){
  618. if (this.status.currentId!=data.id) showTab = false;
  619. }
  620. if (this.options.readMode){
  621. var dictionary = new MWF.xApplication.process.DictionaryDesigner.DictionaryReader(this, data, {"showTab": showTab});
  622. }else{
  623. var dictionary = new MWF.xApplication.process.DictionaryDesigner.Dictionary(this, data, {"showTab": showTab});
  624. }
  625. dictionary.load();
  626. }.bind(this), true);
  627. }.bind(this));
  628. }
  629. }
  630. }.bind(this));
  631. },
  632. getDictionaryData: function(id, callback){
  633. if (!this.options.id){
  634. this.loadNewDictionaryData(callback);
  635. }else{
  636. this.loadDictionaryData(id, callback);
  637. }
  638. },
  639. loadNewDictionaryData: function(callback){
  640. var data = {
  641. "name": "",
  642. "id": "",
  643. "application": this.application.id,
  644. "alias": "",
  645. "description": "",
  646. "data": {}
  647. };
  648. this.createListDictionaryItem(data, true);
  649. if (callback) callback(data);
  650. },
  651. loadDictionaryData: function(id, callback){
  652. this.actions.getDictionary(id, function(json){
  653. if (json){
  654. var data = json.data;
  655. if (!this.application){
  656. this.actions.getApplication(data.application, function(json){
  657. this.application = {"name": json.data.name, "id": json.data.id};
  658. if (callback) callback(data);
  659. }.bind(this));
  660. }else{
  661. if (callback) callback(data);
  662. }
  663. }
  664. }.bind(this));
  665. },
  666. saveDictionary: function(){
  667. if (this.tab.showPage){
  668. var dictionary = this.tab.showPage.dictionary;
  669. dictionary.save(function(){
  670. if (dictionary==this.dictionary){
  671. var name = dictionary.data.name;
  672. this.setTitle(MWF.APPDD.LP.title + "-"+name);
  673. this.options.desktopReload = true;
  674. this.options.id = dictionary.data.id;
  675. }
  676. }.bind(this));
  677. }
  678. },
  679. saveDictionaryAs: function(){
  680. this.dictionary.saveAs();
  681. },
  682. dictionaryExplode: function(){
  683. this.dictionary.explode();
  684. },
  685. dictionaryImplode: function(){
  686. this.dictionary.implode();
  687. },
  688. //recordStatus: function(){
  689. // return {"id": this.options.id};
  690. //},
  691. dictionarySearch: function(){
  692. this.dictionary.loadSearch();
  693. },
  694. recordStatus: function(){
  695. if (this.tab){
  696. var openDictionarys = [];
  697. this.tab.pages.each(function(page){
  698. if (page.dictionary.data.id!=this.options.id) openDictionarys.push(page.dictionary.data.id);
  699. }.bind(this));
  700. var currentId = this.tab.showPage.dictionary.data.id;
  701. var application = o2.typeOf(this.application) === "object" ? {
  702. name: this.application.name,
  703. id: this.application.id
  704. } : this.application;
  705. var status = {
  706. "id": this.options.id,
  707. "application": application,
  708. "applicationId": application.id || application,
  709. "openDictionarys": openDictionarys,
  710. "currentId": currentId,
  711. "options": {
  712. "action": this.options.action,
  713. "noCreate": this.options.noCreate,
  714. "noDelete": this.options.noDelete,
  715. "noModifyName": this.options.noModifyName,
  716. "readMode": this.options.readMode
  717. }
  718. };
  719. return status;
  720. }
  721. return {"id": this.options.id, "application": application};
  722. }
  723. });