Main.js 30 KB

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