Main.js 31 KB

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