Main.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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. "width": "1200",
  19. "height": "600",
  20. "actions": null,
  21. "category": null,
  22. "processData": null,
  23. "sortKeys": ['name', 'alias', 'createTime', 'updateTime'],
  24. "sortKey": '',
  25. "listToolbarExpanded": false
  26. },
  27. onQueryLoad: function(){
  28. this.shortcut = true;
  29. if (this.status){
  30. this.options.application = this.status.applicationId;
  31. this.application = this.status.application || this.status.applicationId;
  32. this.options.id = this.status.id;
  33. this.setOptions(this.status.options);
  34. }
  35. if( this.options.application ){
  36. if( !this.application )this.application = this.options.application;
  37. if( !this.column )this.column = this.options.application;
  38. }
  39. if (!this.options.id){
  40. this.options.desktopReload = false;
  41. this.options.title = this.options.title + "-"+MWF.CMSDD.LP.newDictionary;
  42. }
  43. this.actions = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.ColumnManager.Actions.RestActions();
  44. this.lp = MWF.xApplication.cms.DictionaryDesigner.LP;
  45. // this.cmsData = this.options.processData;
  46. this.actions.application = this.application;
  47. this.addEvent("queryClose", function(e){
  48. if (this.explorer && this.explorer.reload){
  49. this.explorer.reload();
  50. }
  51. }.bind(this));
  52. },
  53. loadApplication: function(callback){
  54. this.createNode();
  55. if (!this.options.isRefresh){
  56. this.maxSize(function(){
  57. this.openForm();
  58. }.bind(this));
  59. }else{
  60. this.openForm();
  61. }
  62. if (!this.options.readMode) this.addKeyboardEvents();
  63. if (callback) callback();
  64. },
  65. addKeyboardEvents: function(){
  66. this.addEvent("copy", function(){
  67. this.copyModule();
  68. }.bind(this));
  69. this.addEvent("paste", function(){
  70. this.pasteModule();
  71. }.bind(this));
  72. this.addEvent("cut", function(){
  73. this.cutModule();
  74. }.bind(this));
  75. this.addEvent("keySave", function(e){
  76. this.keySave(e);
  77. }.bind(this));
  78. this.addEvent("keyDelete", function(e){
  79. this.keyDelete(e);
  80. }.bind(this));
  81. },
  82. keySave: function(e){
  83. if (this.shortcut) {
  84. if (this.tab.showPage) {
  85. var dictionary = this.tab.showPage.dictionary;
  86. if (dictionary) {
  87. dictionary.save();
  88. e.preventDefault();
  89. }
  90. }
  91. }
  92. },
  93. keyDelete: function(){
  94. if (this.shortcut) {
  95. if (this.tab.showPage) {
  96. var dictionary = this.tab.showPage.dictionary;
  97. if (dictionary) {
  98. if (dictionary.currentSelectedItem) {
  99. var item = dictionary.currentSelectedItem;
  100. item.delItem(item.itemTextNode);
  101. }
  102. }
  103. }
  104. }
  105. },
  106. copyModule: function(){
  107. if (this.shortcut) {
  108. if (this.tab.showPage) {
  109. var dictionary = this.tab.showPage.dictionary;
  110. if (dictionary) {
  111. if (dictionary.currentSelectedItem) {
  112. var item = dictionary.currentSelectedItem;
  113. MWF.clipboard.data = {
  114. "type": "dictionary",
  115. "data": {
  116. "key": item.key,
  117. "value": (typeOf(item.value)=="object") ? Object.clone(item.value) : item.value
  118. }
  119. };
  120. }
  121. }
  122. }
  123. }
  124. },
  125. cutModule: function(){
  126. if (this.shortcut) {
  127. if (this.tab.showPage) {
  128. var dictionary = this.tab.showPage.dictionary;
  129. if (dictionary) {
  130. if (dictionary.currentSelectedItem) {
  131. this.copyModule();
  132. var item = dictionary.currentSelectedItem;
  133. item.destroy();
  134. }
  135. }
  136. }
  137. }
  138. },
  139. pasteModule: function(){
  140. if (this.shortcut) {
  141. if (MWF.clipboard.data) {
  142. if (MWF.clipboard.data.type == "dictionary") {
  143. if (this.tab.showPage) {
  144. var dictionary = this.tab.showPage.dictionary;
  145. if (dictionary) {
  146. if (dictionary.currentSelectedItem) {
  147. var item = dictionary.currentSelectedItem;
  148. var key = MWF.clipboard.data.data.key;
  149. var value = (typeOf(MWF.clipboard.data.data.value)=="object") ? Object.clone(MWF.clipboard.data.data.value) : MWF.clipboard.data.data.value;
  150. var level = item.level;
  151. var parent = item;
  152. var nextSibling = null;
  153. if (!item.parent){//top level
  154. level = 1;
  155. }else{
  156. if (item.type!="array" && item.type!="object"){
  157. parent = item.parent;
  158. nextSibling = item;
  159. }else{
  160. if (item.exp){
  161. level = item.level+1;
  162. }else{
  163. parent = item.parent;
  164. nextSibling = item;
  165. }
  166. }
  167. }
  168. var idx = parent.children.length;
  169. if (item.type=="array"){
  170. if (nextSibling){
  171. key = nextSibling.key;
  172. parent.value.splice(nextSibling.key, 0, value);
  173. for (var i=nextSibling.key; i<parent.children.length; i++){
  174. subItem = parent.children[i];
  175. subItem.key = subItem.key+1;
  176. subItem.setNodeText();
  177. }
  178. }else{
  179. var key = parent.value.length;
  180. parent.value.push(value);
  181. }
  182. idx = key;
  183. }else{
  184. var oldKey = key;
  185. var i = 0;
  186. while (parent.value[key] != undefined) {
  187. i++;
  188. key = oldKey + i;
  189. }
  190. parent.value[key] = value;
  191. if (nextSibling) var idx = parent.children.indexOf(nextSibling);
  192. }
  193. var item = new MWF.xApplication.cms.DictionaryDesigner.Dictionary.item(key, value, parent, level, this.dictionary, true, nextSibling);
  194. if (idx) parent.children[idx-1].nextSibling = item;
  195. parent.children.splice(idx, 0, item);
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. },
  203. createNode: function(){
  204. this.content.setStyle("overflow", "hidden");
  205. this.node = new Element("div", {
  206. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  207. }).inject(this.content);
  208. },
  209. getApplication:function(callback){
  210. if (!this.application){
  211. this.actions.getApplication(this.options.application, function(json){
  212. this.application = {"name": json.data.name || json.data.appName, "id": json.data.id};
  213. if (callback) callback();
  214. }.bind(this));
  215. }else{
  216. if (callback) callback();
  217. }
  218. },
  219. openForm: function(){
  220. this.getApplication(function(){
  221. this.getUd(function (){
  222. this.initOptions();
  223. this.loadNodes();
  224. this.loadDictionaryListNodes();
  225. // this.loadToolbar();
  226. this.loadContentNode();
  227. this.loadProperty();
  228. // this.loadTools();
  229. this.resizeNode();
  230. this.addEvent("resize", this.resizeNode.bind(this));
  231. this.loadDictionary();
  232. if (this.toolbarContentNode){
  233. this.setScrollBar(this.toolbarContentNode, null, {
  234. "V": {"x": 0, "y": 0},
  235. "H": {"x": 0, "y": 0}
  236. });
  237. this.setScrollBar(this.propertyDomArea, null, {
  238. "V": {"x": 0, "y": 0},
  239. "H": {"x": 0, "y": 0}
  240. });
  241. }
  242. }.bind(this))
  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.CMSDD.LP.dictionary
  270. }).inject(this.dictionaryListNode);
  271. this.dictionaryListResizeNode = new Element("div", {"styles": this.css.dictionaryListResizeNode}).inject(this.dictionaryListNode);
  272. this.createListTitleNodes();
  273. this.dictionaryListAreaSccrollNode = new Element("div", {"styles": this.css.dictionaryListAreaSccrollNode}).inject(this.dictionaryListNode);
  274. this.dictionaryListAreaNode = new Element("div", {"styles": this.css.dictionaryListAreaNode}).inject(this.dictionaryListAreaSccrollNode);
  275. this.loadDictionaryListResize();
  276. this.loadDictionaryList();
  277. },
  278. createListTitleNodes: function (){
  279. this.dictionaryListTitleNode.setStyle("display", 'flex');
  280. this.titleActionArea = new Element("div", {
  281. styles: this.css.titleActionArea
  282. }).inject(this.dictionaryListTitleNode);
  283. this.moreAction = new Element("div", {
  284. styles: this.css.moreAction,
  285. title: this.lp.searchAndSort
  286. }).inject(this.titleActionArea);
  287. this.moreAction.addEvent("click", function(){
  288. var isHidden = this.toolbarNode.getStyle("display") === "none";
  289. this.toolbarNode.setStyle("display", isHidden ? "" : "none" );
  290. this.resizeNode();
  291. this.options.listToolbarExpanded = isHidden;
  292. this.setUd();
  293. }.bind(this));
  294. this.toolbarNode = new Element("div", {
  295. styles: this.css.toolbarNode
  296. }).inject(this.dictionaryListNode);
  297. if( this.options.listToolbarExpanded )this.toolbarNode.show();
  298. this.createSortNode();
  299. this.createSearchNode();
  300. },
  301. getUd: function ( callback ){
  302. MWF.UD.getDataJson(this.options.name + "_" + this.application.id, function (data){
  303. if( data ){
  304. this.options.sortKey = data.sortKey;
  305. this.options.listToolbarExpanded = data.listToolbarExpanded || false;
  306. }
  307. callback();
  308. }.bind(this));
  309. },
  310. setUd: function (){
  311. var data = {
  312. sortKey: this.options.sortKey,
  313. listToolbarExpanded: this.options.listToolbarExpanded
  314. };
  315. MWF.UD.putData(this.options.name + "_" + this.application.id, data);
  316. },
  317. openApp: function (){
  318. layout.openApplication(null, 'cms.ColumnManager', {
  319. column: this.application,
  320. appId: 'cms.ColumnManager'+this.application.id
  321. }, {
  322. "navi": "dataConfig"
  323. });
  324. },
  325. createElement: function(){
  326. var flag = true;
  327. this.itemArray.each(function(i){
  328. if( !i.data.id ){
  329. flag = false;
  330. return;
  331. }
  332. });
  333. if( !flag ){
  334. this.notice(this.lp.duplicateNewNote, 'info');
  335. return;
  336. }
  337. if( this.currentListDictionaryItem ){
  338. this.currentListDictionaryItem.setStyles(this.css.listDictionaryItem);
  339. }
  340. this.options.id = "";
  341. this.loadDictionary();
  342. },
  343. createSortNode: function(){
  344. this.itemSortArea = new Element("div.itemSortArea", {
  345. styles: this.css.itemSortArea
  346. }).inject(this.toolbarNode);
  347. this.itemSortSelect = new Element('select.itemSortSelect', {
  348. styles: this.css.itemSortSelect,
  349. events: {
  350. change: function(){
  351. this.options.sortKey = this.itemSortSelect[ this.itemSortSelect.selectedIndex ].value;
  352. this.setUd();
  353. this.loadDictionaryList();
  354. }.bind(this)
  355. }
  356. }).inject(this.itemSortArea);
  357. new Element('option',{ 'text': this.lp.sorkKeyNote, 'value': "" }).inject(this.itemSortSelect);
  358. this.options.sortKeys.each(function (key){
  359. var opt = new Element('option',{ 'text': this.lp[key] + " " + this.lp.asc, 'value': key+"-asc" }).inject(this.itemSortSelect);
  360. if( this.options.sortKey === opt.get('value') )opt.set('selected', true);
  361. opt = new Element('option',{ 'text': this.lp[key] + " " + this.lp.desc, 'value': key+"-desc" }).inject(this.itemSortSelect);
  362. if( this.options.sortKey === opt.get('value') )opt.set('selected', true);
  363. }.bind(this));
  364. },
  365. createSearchNode: function (){
  366. this.searchNode = new Element("div.searchNode", {
  367. "styles": this.css.searchArea
  368. }).inject(this.toolbarNode);
  369. this.searchInput = new Element("input.searchInput", {
  370. "styles": this.css.searchInput,
  371. "placeholder": this.lp.searchPlacholder,
  372. "value": this.options.searchKey || ""
  373. }).inject(this.searchNode);
  374. this.searchButton = new Element("i", {
  375. "styles": this.css.searchButton
  376. }).inject(this.searchNode);
  377. this.searchCancelButton = new Element("i", {
  378. "styles": this.css.searchCancelButton
  379. }).inject(this.searchNode);
  380. this.searchInput.addEvents({
  381. focus: function(){
  382. this.searchNode.addClass("mainColor_border");
  383. this.searchButton.addClass("mainColor_color");
  384. }.bind(this),
  385. blur: function () {
  386. this.searchNode.removeClass("mainColor_border");
  387. this.searchButton.removeClass("mainColor_color");
  388. }.bind(this),
  389. keydown: function (e) {
  390. if( (e.keyCode || e.code) === 13 ){
  391. this.search();
  392. }
  393. }.bind(this),
  394. keyup: function (e){
  395. this.searchCancelButton.setStyle('display', this.searchInput.get('value') ? '' : 'none');
  396. }.bind(this)
  397. });
  398. this.searchCancelButton.addEvent("click", function (e) {
  399. this.searchInput.set("value", "");
  400. this.searchCancelButton.hide();
  401. this.search();
  402. }.bind(this));
  403. this.searchButton.addEvent("click", function (e) {
  404. this.search();
  405. }.bind(this));
  406. },
  407. checkSort: function (data){
  408. if( !!this.options.sortKey ){
  409. var sortKey = this.options.sortKey.split("-");
  410. var key = sortKey[0], isDesc = sortKey[1] === 'desc';
  411. data.sort(function (a, b){
  412. var av = a[key];
  413. var bv = b[key];
  414. if( typeOf(av) === 'string' && typeOf(bv) === 'string' ){
  415. var isLetterA = /^[a-zA-Z0-9]/.test(av);
  416. var isLetterB = /^[a-zA-Z0-9]/.test(bv);
  417. if (isLetterA && !isLetterB) return isDesc ? 1 : -1; // a是字母,b不是,a排在前面
  418. if (!isLetterA && isLetterB) return isDesc ? -1 : 1; // a不是字母,b是,b排在前面
  419. return isDesc ? bv.localeCompare(av) : av.localeCompare(bv);
  420. }
  421. return isDesc ? (bv - av) : (av - bv);
  422. }.bind(this));
  423. }
  424. },
  425. checkShow: function (i){
  426. if( this.options.searchKey ){
  427. var v = this.options.searchKey;
  428. if( i.data.name.contains(v) || (i.data.alias || "").contains(v) || i.data.id.contains(v) ){
  429. //i.node.setStyle("display", "");
  430. }else{
  431. i.node.setStyle("display", "none");
  432. }
  433. }
  434. },
  435. search: function (){
  436. var v = this.searchInput.get("value");
  437. this.options.searchKey = v;
  438. this.itemArray.each(function (i){
  439. if( !v ){
  440. i.node.setStyle("display", "");
  441. }else if( i.data.name.contains(v) || (i.data.alias || "").contains(v) || i.data.id.contains(v) ){
  442. i.node.setStyle("display", "");
  443. }else{
  444. i.node.setStyle("display", "none");
  445. }
  446. }.bind(this));
  447. },
  448. loadDictionaryListResize: function(){
  449. this.dictionaryListResize = new Drag(this.dictionaryListResizeNode,{
  450. "snap": 1,
  451. "onStart": function(el, e){
  452. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  453. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  454. el.store("position", {"x": x, "y": y});
  455. var size = this.dictionaryListAreaSccrollNode.getSize();
  456. el.store("initialWidth", size.x);
  457. }.bind(this),
  458. "onDrag": function(el, e){
  459. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  460. // var y = e.event.y;
  461. var bodySize = this.content.getSize();
  462. var position = el.retrieve("position");
  463. var initialWidth = el.retrieve("initialWidth").toFloat();
  464. var dx = x.toFloat() - position.x.toFloat();
  465. var width = initialWidth+dx;
  466. if (width> bodySize.x/2) width = bodySize.x/2;
  467. if (width<40) width = 40;
  468. this.contentNode.setStyle("margin-left", width+1);
  469. this.dictionaryListNode.setStyle("width", width);
  470. }.bind(this)
  471. });
  472. },
  473. loadDictionaryList: function(){
  474. if( this.currentListDictionaryItem ){
  475. var d = this.currentListDictionaryItem.retrieve('dictionary');
  476. this.options.id = d.id;
  477. }
  478. if( this.itemArray && this.itemArray.length ){
  479. this.itemArray = this.itemArray.filter(function(i){
  480. if(i.data.id)i.node.destroy();
  481. return !i.data.id;
  482. });
  483. }else{
  484. this.itemArray = [];
  485. }
  486. this.actions.listDictionary(this.application.id || this.application, function (json) {
  487. this.checkSort(json.data);
  488. json.data.each(function(dictionary){
  489. this.createListDictionaryItem(dictionary);
  490. }.bind(this));
  491. }.bind(this), null, false);
  492. },
  493. createListDictionaryItem: function(dictionary, isNew){
  494. var _self = this;
  495. var listDictionaryItem = new Element("div", {"styles": this.css.listDictionaryItem}).inject(this.dictionaryListAreaNode, (isNew) ? "top": "bottom");
  496. var listDictionaryItemIcon = new Element("div", {"styles": this.css.listDictionaryItemIcon}).inject(listDictionaryItem);
  497. var listDictionaryItemText = new Element("div", {"styles": this.css.listDictionaryItemText, "text": (dictionary.name) ? dictionary.name+" ("+dictionary.alias+")" : this.lp.newDictionary}).inject(listDictionaryItem);
  498. listDictionaryItem.store("dictionary", dictionary);
  499. listDictionaryItem.addEvents({
  500. "click": function(e){_self.loadDictionaryByData(this, e);},
  501. "mouseover": function(){if (_self.currentListDictionaryItem!=this) this.setStyles(_self.css.listDictionaryItem_over);},
  502. "mouseout": function(){if (_self.currentListDictionaryItem!=this) this.setStyles(_self.css.listDictionaryItem);}
  503. });
  504. if( dictionary.id === this.options.id ){
  505. listDictionaryItem.setStyles(this.css.listDictionaryItem_current);
  506. this.currentListDictionaryItem = listDictionaryItem;
  507. }
  508. var itemObj = {
  509. node: listDictionaryItem,
  510. data: dictionary
  511. };
  512. this.itemArray.push(itemObj);
  513. this.checkShow(itemObj);
  514. },
  515. loadDictionaryByData: function(node, e){
  516. var dictionary = node.retrieve("dictionary");
  517. var openNew = true;
  518. for (var i = 0; i<this.tab.pages.length; i++){
  519. if (dictionary.id==this.tab.pages[i].dictionary.data.id){
  520. this.tab.pages[i].showTabIm();
  521. openNew = false;
  522. break;
  523. }
  524. }
  525. if (openNew){
  526. this.loadDictionaryData(dictionary.id, function(data){
  527. var dictionary = new MWF.xApplication.cms.DictionaryDesigner.Dictionary(this, data);
  528. dictionary.load();
  529. }.bind(this), true);
  530. }
  531. },
  532. //loadContentNode------------------------------
  533. loadContentNode: function(){
  534. this.contentToolbarNode = new Element("div#contentToolbarNode", {
  535. "styles": this.css.contentToolbarNode
  536. }).inject(this.contentNode);
  537. if (!this.options.readMode) this.loadContentToolbar();
  538. this.editContentNode = new Element("div", {
  539. "styles": this.css.editContentNode
  540. }).inject(this.contentNode);
  541. this.loadEditContent(function(){
  542. // if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  543. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  544. }.bind(this));
  545. },
  546. loadContentToolbar: function(callback){
  547. this.getFormToolbarHTML(function(toolbarNode){
  548. var spans = toolbarNode.getElements("span");
  549. spans.each(function(item, idx){
  550. var img = item.get("MWFButtonImage");
  551. if (img){
  552. item.set("MWFButtonImage", this.path+""+this.options.style+"/toolbar/"+img);
  553. }
  554. }.bind(this));
  555. $(toolbarNode).inject(this.contentToolbarNode);
  556. MWF.require("MWF.widget.Toolbar", function(){
  557. this.toolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  558. this.toolbar.load();
  559. if (callback) callback();
  560. }.bind(this));
  561. }.bind(this));
  562. },
  563. getFormToolbarHTML: function(callback){
  564. var toolbarUrl = this.path+this.options.style+"/toolbars.html";
  565. MWF.getRequestText(toolbarUrl, function(responseText, responseXML){
  566. var htmlString = responseText;
  567. htmlString = o2.bindJson(htmlString, {"lp": this.lp.formToolbar});
  568. var temp = new Element('div').set('html', htmlString);
  569. if (callback) callback( temp.childNodes[0] );
  570. }.bind(this));
  571. // var r = new Request.HTML({
  572. // url: toolbarUrl,
  573. // method: "get",
  574. // onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  575. // var toolbarNode = responseTree[0];
  576. // if (callback) callback(toolbarNode);
  577. // }.bind(this),
  578. // onFailure: function(xhr){
  579. // this.notice("request cmsToolbars error: "+xhr.responseText, "error");
  580. // }.bind(this)
  581. // });
  582. // r.send();
  583. },
  584. maxOrReturnEditor: function(){
  585. if (!this.isMax){
  586. this.designNode.inject(this.node);
  587. this.designNode.setStyles({
  588. "position": "absolute",
  589. "width": "100%",
  590. "height": "100%",
  591. "top": "0px",
  592. "margin": "0px",
  593. "left": "0px"
  594. });
  595. this.tab.pages.each(function(page){
  596. page.dictionary.setAreaNodeSize();
  597. });
  598. this.isMax = true;
  599. }else{
  600. this.isMax = false;
  601. this.designNode.inject(this.editContentNode);
  602. this.designNode.setStyles(this.css.designNode);
  603. this.designNode.setStyles({
  604. "position": "static"
  605. });
  606. this.resizeNode();
  607. this.tab.pages.each(function(page){
  608. page.dictionary.setAreaNodeSize();
  609. });
  610. }
  611. },
  612. loadEditContent: function(callback){
  613. this.designNode = new Element("div", {
  614. "styles": this.css.designNode
  615. }).inject(this.editContentNode);
  616. MWF.require("MWF.widget.Tab", function(){
  617. this.tab = new MWF.widget.Tab(this.designNode, {"style": "dictionary"});
  618. this.tab.load();
  619. }.bind(this), false);
  620. // MWF.require("MWF.widget.ScrollBar", function(){
  621. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  622. // }.bind(this));
  623. },
  624. //loadProperty------------------------
  625. loadProperty: function(){
  626. this.propertyTitleNode = new Element("div", {
  627. "styles": this.css.propertyTitleNode,
  628. "text": MWF.CMSDD.LP.property
  629. }).inject(this.propertyNode);
  630. this.propertyResizeBar = new Element("div", {
  631. "styles": this.css.propertyResizeBar
  632. }).inject(this.propertyNode);
  633. this.loadPropertyResize();
  634. this.propertyContentNode = new Element("div", {
  635. "styles": this.css.propertyContentNode
  636. }).inject(this.propertyNode);
  637. this.propertyDomArea = new Element("div", {
  638. "styles": this.css.propertyDomArea
  639. }).inject(this.propertyContentNode);
  640. this.propertyDomPercent = 0.3;
  641. this.propertyContentResizeNode = new Element("div", {
  642. "styles": this.css.propertyContentResizeNode
  643. }).inject(this.propertyContentNode);
  644. this.propertyContentArea = new Element("div", {
  645. "styles": this.css.propertyContentArea
  646. }).inject(this.propertyContentNode);
  647. this.loadPropertyContentResize();
  648. this.setPropertyContent();
  649. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  650. },
  651. setPropertyContent: function(){
  652. this.dictionaryPropertyNode = new Element("div", {"styles": this.css.dictionaryPropertyNode});
  653. this.jsonDomNode = new Element("div", {"styles": this.css.jsonDomNode});
  654. this.jsonTextNode = new Element("div", {"styles": this.css.jsonTextNode});
  655. this.jsonTextAreaNode = new Element("textarea", {"styles": this.css.jsonTextAreaNode}).inject(this.jsonTextNode);
  656. MWF.require("MWF.widget.Tab", function(){
  657. var tab = new MWF.widget.Tab(this.propertyContentArea, {"style": "moduleList"});
  658. tab.load();
  659. tab.addTab(this.dictionaryPropertyNode, this.lp.property, false);
  660. tab.addTab(this.jsonDomNode, "JSON", false);
  661. tab.addTab(this.jsonTextNode, "TEXT", false);
  662. tab.pages[0].showTab();
  663. }.bind(this));
  664. var node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.id+":"}).inject(this.dictionaryPropertyNode);
  665. this.propertyIdNode = new Element("div", {"styles": this.css.propertyTextNode}).inject(this.dictionaryPropertyNode);
  666. node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.name+":"}).inject(this.dictionaryPropertyNode);
  667. this.propertyNameNode = new Element("input", {"styles": this.css.propertyInputNode}).inject(this.dictionaryPropertyNode);
  668. if (this.options.noModifyName || this.options.readMode){
  669. this.propertyNameNode.set("readonly", true);
  670. this.propertyNameNode.addEvent("keydown", function(){
  671. this.notice(this.lp.notice.noModifyName, "error");
  672. }.bind(this));
  673. }
  674. node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.alias+":"}).inject(this.dictionaryPropertyNode);
  675. this.propertyAliasNode = new Element("input", {"styles": this.css.propertyInputNode}).inject(this.dictionaryPropertyNode);
  676. if (this.options.noModifyName || this.options.readMode){
  677. this.propertyAliasNode.set("readonly", true);
  678. this.propertyAliasNode.addEvent("keydown", function(){
  679. this.notice(this.lp.notice.noModifyName, "error");
  680. }.bind(this));
  681. }
  682. node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.description+":"}).inject(this.dictionaryPropertyNode);
  683. this.propertyDescriptionNode = new Element("textarea", {"styles": this.css.propertyInputAreaNode}).inject(this.dictionaryPropertyNode);
  684. if (this.options.noModifyName || this.options.readMode){
  685. this.propertyDescriptionNode.set("readonly", true);
  686. }
  687. },
  688. loadPropertyResize: function(){
  689. // var size = this.propertyNode.getSize();
  690. // var position = this.propertyResizeBar.getPosition();
  691. this.propertyResize = new Drag(this.propertyResizeBar,{
  692. "snap": 1,
  693. "onStart": function(el, e){
  694. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  695. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  696. el.store("position", {"x": x, "y": y});
  697. var size = this.propertyNode.getSize();
  698. el.store("initialWidth", size.x);
  699. }.bind(this),
  700. "onDrag": function(el, e){
  701. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  702. // var y = e.event.y;
  703. var bodySize = this.content.getSize();
  704. var position = el.retrieve("position");
  705. var initialWidth = el.retrieve("initialWidth").toFloat();
  706. var dx = position.x.toFloat()-x.toFloat();
  707. var width = initialWidth+dx;
  708. if (width> bodySize.x/2) width = bodySize.x/2;
  709. if (width<40) width = 40;
  710. this.contentNode.setStyle("margin-right", width+1);
  711. this.propertyNode.setStyle("width", width);
  712. }.bind(this)
  713. });
  714. },
  715. loadPropertyContentResize: function(){
  716. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  717. "snap": 1,
  718. "onStart": function(el, e){
  719. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  720. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  721. el.store("position", {"x": x, "y": y});
  722. var size = this.propertyDomArea.getSize();
  723. el.store("initialHeight", size.y);
  724. }.bind(this),
  725. "onDrag": function(el, e){
  726. var size = this.propertyContentNode.getSize();
  727. // var x = e.event.x;
  728. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  729. var position = el.retrieve("position");
  730. var dy = y.toFloat()-position.y.toFloat();
  731. var initialHeight = el.retrieve("initialHeight").toFloat();
  732. var height = initialHeight+dy;
  733. if (height<40) height = 40;
  734. if (height> size.y-40) height = size.y-40;
  735. this.propertyDomPercent = height/size.y;
  736. this.setPropertyContentResize();
  737. }.bind(this)
  738. });
  739. },
  740. setPropertyContentResize: function(){
  741. var size = this.propertyContentNode.getSize();
  742. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  743. var height = size.y-resizeNodeSize.y;
  744. var domHeight = this.propertyDomPercent*height;
  745. var contentHeight = height-domHeight;
  746. this.propertyDomArea.setStyle("height", ""+domHeight+"px");
  747. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  748. if (this.form){
  749. if (this.form.currentSelectedModule){
  750. if (this.form.currentSelectedModule.property){
  751. var tab = this.form.currentSelectedModule.property.propertyTab;
  752. if (tab){
  753. var tabTitleSize = tab.tabNodeContainer.getSize();
  754. tab.pages.each(function(page){
  755. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  756. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  757. var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  758. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  759. }.bind(this));
  760. }
  761. }
  762. }
  763. }
  764. },
  765. //resizeNode------------------------------------------------
  766. resizeNode: function(){
  767. var nodeSize = this.node.getSize();
  768. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  769. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  770. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  771. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  772. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  773. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  774. this.editContentNode.setStyle("height", ""+y+"px");
  775. if (this.designNode){
  776. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  777. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  778. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  779. this.designNode.setStyle("height", ""+y+"px");
  780. }
  781. titleSize = this.propertyTitleNode.getSize();
  782. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  783. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  784. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  785. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  786. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  787. y = nodeSize.y-y;
  788. this.propertyContentNode.setStyle("height", ""+y+"px");
  789. this.propertyResizeBar.setStyle("height", ""+y+"px");
  790. this.setPropertyContentResize();
  791. titleSize = this.dictionaryListTitleNode.getSize();
  792. titleMarginTop = this.dictionaryListTitleNode.getStyle("margin-top").toFloat();
  793. titleMarginBottom = this.dictionaryListTitleNode.getStyle("margin-bottom").toFloat();
  794. titlePaddingTop = this.dictionaryListTitleNode.getStyle("padding-top").toFloat();
  795. titlePaddingBottom = this.dictionaryListTitleNode.getStyle("padding-bottom").toFloat();
  796. nodeMarginTop = this.dictionaryListAreaSccrollNode.getStyle("margin-top").toFloat();
  797. nodeMarginBottom = this.dictionaryListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  798. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  799. y = nodeSize.y-y;
  800. var leftToolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : {x:0,y:0};
  801. this.dictionaryListAreaSccrollNode.setStyle("height", ""+(y-leftToolbarSize.y)+"px");
  802. this.dictionaryListResizeNode.setStyle("height", ""+y+"px");
  803. },
  804. //loadForm------------------------------------------
  805. loadDictionary: function(){
  806. //debugger;
  807. this.getDictionaryData(this.options.id, function(ddata){
  808. this.setTitle(this.options.appTitle + "-"+ddata.name);
  809. if(this.taskitem)this.taskitem.setText(this.options.appTitle + "-"+ddata.name);
  810. this.options.appTitle = this.options.appTitle + "-"+ddata.name;
  811. if (this.options.readMode){
  812. this.dictionary = new MWF.xApplication.cms.DictionaryDesigner.DictionaryReader(this, ddata);
  813. }else{
  814. this.dictionary = new MWF.xApplication.cms.DictionaryDesigner.Dictionary(this, ddata);
  815. }
  816. this.dictionary.load();
  817. if (this.status){
  818. if (this.status.openDictionarys){
  819. this.status.openDictionarys.each(function(id){
  820. this.loadDictionaryData(id, function(data){
  821. var showTab = true;
  822. if (this.status.currentId){
  823. if (this.status.currentId!=data.id) showTab = false;
  824. }
  825. if (this.options.readMode){
  826. var dictionary = new MWF.xApplication.cms.DictionaryDesigner.DictionaryReader(this, data, {"showTab": showTab});
  827. }else{
  828. var dictionary = new MWF.xApplication.cms.DictionaryDesigner.Dictionary(this, data, {"showTab": showTab});
  829. }
  830. dictionary.load();
  831. }.bind(this), true);
  832. }.bind(this));
  833. this.status.openDictionarys = [];
  834. }
  835. }
  836. }.bind(this));
  837. },
  838. getDictionaryData: function(id, callback){
  839. if (!this.options.id){
  840. this.loadNewDictionaryData(callback);
  841. }else{
  842. this.loadDictionaryData(id, callback);
  843. }
  844. },
  845. loadNewDictionaryData: function(callback){
  846. var data = {
  847. "name": "",
  848. "id": "",
  849. "application": this.application.id,
  850. "alias": "",
  851. "description": "",
  852. "data": {}
  853. };
  854. this.createListDictionaryItem(data, true);
  855. if (callback) callback(data);
  856. },
  857. loadDictionaryData: function(id, callback){
  858. //debugger;
  859. this.actions.getDictionary(id, function(json){
  860. if (json){
  861. var data = json.data;
  862. if (!this.application){
  863. this.actions.getApplication(data.application, function(json){
  864. this.application = {"name": json.data.name, "id": json.data.id};
  865. if (callback) callback(data);
  866. }.bind(this));
  867. }else{
  868. if (callback) callback(data);
  869. }
  870. }
  871. }.bind(this));
  872. },
  873. saveDictionary: function(){
  874. if (this.tab.showPage){
  875. var dictionary = this.tab.showPage.dictionary;
  876. dictionary.save(function(){
  877. if (dictionary==this.dictionary){
  878. var name = dictionary.data.name;
  879. this.setTitle(MWF.CMSDD.LP.title + "-"+name);
  880. this.options.desktopReload = true;
  881. this.options.id = dictionary.data.id;
  882. }
  883. this.fireAppEvent("postSave")
  884. }.bind(this));
  885. }
  886. },
  887. saveDictionaryAs: function(){
  888. this.dictionary.saveAs();
  889. },
  890. dictionaryExplode: function(){
  891. this.dictionary.explode();
  892. },
  893. dictionaryImplode: function(){
  894. this.dictionary.implode();
  895. },
  896. //recordStatus: function(){
  897. // return {"id": this.options.id};
  898. //},
  899. dictionarySearch: function(){
  900. this.dictionary.loadSearch();
  901. },
  902. recordStatus: function(){
  903. if (this.tab){
  904. var openDictionarys = [];
  905. this.tab.pages.each(function(page){
  906. if (page.dictionary.data.id!=this.options.id) openDictionarys.push(page.dictionary.data.id);
  907. }.bind(this));
  908. var currentId = this.tab.showPage.dictionary.data.id;
  909. var application = o2.typeOf(this.application) === "object" ? {
  910. name: this.application.name,
  911. id: this.application.id
  912. } : this.application;
  913. var status = {
  914. "id": this.options.id,
  915. "application": application,
  916. "applicationId": application.id || application,
  917. "openDictionarys": openDictionarys,
  918. "currentId": currentId,
  919. "options": {
  920. "action": this.options.action,
  921. "noCreate": this.options.noCreate,
  922. "noDelete": this.options.noDelete,
  923. "noModifyName": this.options.noModifyName,
  924. "readMode": this.options.readMode
  925. }
  926. };
  927. return status;
  928. }
  929. return {"id": this.options.id, "application": application};
  930. }
  931. });