Main.js 40 KB

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