View.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.process = MWF.xApplication.process || {};
  3. MWF.xApplication.process.ViewDesigner = MWF.xApplication.process.ViewDesigner || {};
  4. MWF.APPVD = MWF.xApplication.process.ViewDesigner;
  5. MWF.require("MWF.widget.Common", null, false);
  6. MWF.require("MWF.xScript.Macro", null, false);
  7. MWF.xDesktop.requireApp("process.ViewDesigner", "lp."+MWF.language, null, false);
  8. MWF.xDesktop.requireApp("process.ViewDesigner", "Property", null, false);
  9. MWF.xApplication.process.ViewDesigner.View = new Class({
  10. Extends: MWF.widget.Common,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "isView": false,
  15. "showTab": true,
  16. "propertyPath": "/x_component_process_ViewDesigner/$View/view.html"
  17. },
  18. initialize: function(designer, data, options){
  19. this.setOptions(options);
  20. this.path = "/x_component_process_ViewDesigner/$View/";
  21. this.cssPath = "/x_component_process_ViewDesigner/$View/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. this.designer = designer;
  24. this.data = data;
  25. if (!this.data.data) this.data.data = {};
  26. this.parseData();
  27. this.node = this.designer.designNode;
  28. //this.tab = this.designer.tab;
  29. this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}});
  30. //MWF.require("MWF.widget.ScrollBar", function(){
  31. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  32. //}.bind(this));
  33. this.propertyListNode = this.designer.propertyDomArea;
  34. //this.propertyNode = this.designer.propertyContentArea;
  35. if(this.designer.application) this.data.applicationName = this.designer.application.name;
  36. if(this.designer.application) this.data.application = this.designer.application.id;
  37. this.isNewView = (this.data.id) ? false : true;
  38. this.items = [];
  39. this.view = this;
  40. this.autoSave();
  41. this.designer.addEvent("queryClose", function(){
  42. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  43. }.bind(this));
  44. },
  45. autoSave: function(){
  46. this.autoSaveTimerID = window.setInterval(function(){
  47. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFDictionaryAutoSaveCheck");
  48. if (this.autoSaveCheckNode){
  49. if (this.autoSaveCheckNode.get("checked")){
  50. this.save();
  51. }
  52. }
  53. }.bind(this), 60000);
  54. },
  55. parseData: function(){
  56. this.json = this.data;
  57. },
  58. showProperty: function(){
  59. if (!this.property){
  60. this.property = new MWF.xApplication.process.ViewDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  61. "path": this.options.propertyPath,
  62. "onPostLoad": function(){
  63. this.property.show();
  64. }.bind(this)
  65. });
  66. this.property.load();
  67. }else{
  68. this.property.show();
  69. }
  70. },
  71. hideProperty: function(){
  72. if (this.property) this.property.hide();
  73. },
  74. load : function(){
  75. this.setAreaNodeSize();
  76. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  77. this.areaNode.inject(this.node);
  78. //this.page = this.tab.addTab(this.areaNode, this.data.name || this.designer.lp.newView, (!this.data.isNewView && this.data.id!=this.designer.options.id));
  79. //this.page.view = this;
  80. //this.page.addEvent("show", function(){
  81. this.designer.viewListAreaNode.getChildren().each(function(node){
  82. var view = node.retrieve("view");
  83. if (view.id==this.data.id){
  84. if (this.designer.currentListViewItem){
  85. this.designer.currentListViewItem.setStyles(this.designer.css.listViewItem);
  86. }
  87. node.setStyles(this.designer.css.listViewItem_current);
  88. this.designer.currentListViewItem = node;
  89. this.lisNode = node;
  90. }
  91. }.bind(this));
  92. // this.setPropertyContent();
  93. //}.bind(this));
  94. //this.page.addEvent("queryClose", function(){
  95. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  96. // this.saveSilence();
  97. // if (this.lisNode) this.lisNode.setStyles(this.designer.css.listViewItem);
  98. //}.bind(this));
  99. //this.page.tabNode.addEvent("dblclick", this.designer.maxOrReturnEditor.bind(this.designer));
  100. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  101. this.loadView();
  102. this.selected();
  103. this.setEvent();
  104. //if (this.options.showTab) this.page.showTabIm();
  105. this.setViewWidth();
  106. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  107. },
  108. setEvent: function(){
  109. this.areaNode.addEvent("click", this.selected.bind(this));
  110. this.refreshNode.addEvent("click", function(e){
  111. this.loadViewData();
  112. e.stopPropagation();
  113. }.bind(this));
  114. this.addColumnNode.addEvent("click", function(e){
  115. this.addColumn();
  116. e.stopPropagation();
  117. }.bind(this));
  118. },
  119. loadViewData: function(){
  120. if (this.data.id){
  121. this.saveSilence(function(){
  122. this.viewContentBodyNode.empty();
  123. this.viewContentTableNode = new Element("table", {
  124. "styles": this.css.viewContentTableNode,
  125. "border": "0px",
  126. "cellPadding": "0",
  127. "cellSpacing": "0"
  128. }).inject(this.viewContentBodyNode);
  129. this.designer.actions.loadView(this.data.id, function(json){
  130. var entries = {};
  131. json.data.selectEntryList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  132. if (this.json.data.groupEntry.column){
  133. if (json.data.groupGrid.length){
  134. var groupColumn = null;
  135. for (var c = 0; c<json.data.selectEntryList.length; c++){
  136. if (json.data.selectEntryList[c].column === json.data.groupEntry.column){
  137. groupColumn = json.data.selectEntryList[c];
  138. break;
  139. }
  140. }
  141. json.data.groupGrid.each(function(line, idx){
  142. var groupTr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  143. var colSpan = this.items.length;
  144. var td = new Element("td", {"styles": this.css.viewContentGroupTdNode, "colSpan": colSpan}).inject(groupTr);
  145. var groupAreaNode = new Element("div", {"styles": this.css.viewContentTdGroupNode}).inject(td);
  146. var groupIconNode = new Element("div", {"styles": this.css.viewContentTdGroupIconNode}).inject(groupAreaNode);
  147. var groupTextNode = new Element("div", {"styles": this.css.viewContentTdGroupTextNode}).inject(groupAreaNode);
  148. if (groupColumn){
  149. groupTextNode.set("text", (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": line.group, "gridData": json.data.groupGrid, "data": json.data, "entry": line}) : line.group);
  150. }else{
  151. groupTextNode.set("text", line.group);
  152. }
  153. var subtrs = [];
  154. line.list.each(function(entry){
  155. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  156. tr.setStyle("display", "none");
  157. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  158. Object.each(entry.data, function(d, k){
  159. if (k!=this.json.data.groupEntry.column){
  160. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  161. td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  162. }
  163. }.bind(this));
  164. subtrs.push(tr)
  165. }.bind(this));
  166. groupAreaNode.store("subtrs", subtrs);
  167. var _self = this;
  168. groupAreaNode.addEvent("click", function(){
  169. var subtrs = this.retrieve("subtrs");
  170. var iconNode = groupAreaNode.getFirst("div");
  171. if (subtrs[0]){
  172. if (subtrs[0].getStyle("display")=="none"){
  173. subtrs.each(function(subtr){ subtr.setStyle("display", "table-row"); });
  174. iconNode.setStyle("background", "url("+"/x_component_process_ViewDesigner/$View/default/icon/down.png) center center no-repeat");
  175. }else{
  176. subtrs.each(function(subtr){ subtr.setStyle("display", "none"); });
  177. iconNode.setStyle("background", "url("+"/x_component_process_ViewDesigner/$View/default/icon/right.png) center center no-repeat");
  178. }
  179. }
  180. _self.setContentHeight();
  181. });
  182. }.bind(this));
  183. this.setContentColumnWidth();
  184. this.setContentHeight();
  185. }
  186. }else{
  187. if (json.data.grid.length){
  188. json.data.grid.each(function(line, idx){
  189. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  190. Object.each(line.data, function(d, k){
  191. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  192. td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  193. }.bind(this));
  194. }.bind(this));
  195. this.setContentColumnWidth();
  196. this.setContentHeight();
  197. }
  198. }
  199. }.bind(this));
  200. //this.getLookupAction(function(){
  201. // this.lookupAction.invoke({"name": "lookup","async": true, "parameter": {"id": this.data.id},"success": function(json){
  202. // if (json.data.length){
  203. // json.data.each(function(line, idx){
  204. // var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  205. // line.each(function(cell, i){
  206. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  207. // td.set("text", cell);
  208. // }.bind(this));
  209. // }.bind(this));
  210. // this.setContentColumnWidth();
  211. // this.setContentHeight();
  212. // }
  213. //
  214. // }.bind(this)});
  215. //}.bind(this));
  216. }.bind(this));
  217. }
  218. },
  219. setContentColumnWidth: function(){
  220. var titleTds = this.viewTitleTrNode.getElements("td");
  221. var widthList = [];
  222. titleTds.each(function(td){widthList.push(td.getSize().x);});
  223. var flag = false;
  224. if (this.viewContentTableNode){
  225. trs = this.viewContentTableNode.getElements("tr");
  226. for (var i=0; i<trs.length; i++){
  227. var tr = trs[i];
  228. var tds = tr.getElements("td");
  229. tds.each(function(contentTd, i){
  230. if (contentTd.get("colSpan")==1){
  231. contentTd.setStyle("width", ""+widthList[i]+"px");
  232. flag = true;
  233. }
  234. });
  235. if (flag) break;
  236. }
  237. //var tr = this.viewContentTableNode.getFirst("tr");
  238. //if (tr){
  239. // var tds = tr.getElements("td");
  240. // tds.each(function(contentTd, i){
  241. // if (!contentTd.get("colSpan")){
  242. // contentTd.setStyle("width", ""+widthList[i]+"px");
  243. // }
  244. // });
  245. //}
  246. }
  247. },
  248. //getLookupAction: function(callback){
  249. // if (!this.lookupAction){
  250. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  251. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface_lookup", "");
  252. // this.lookupAction.getActions = function(actionCallback){
  253. // debugger;
  254. // this.actions = {"lookup": {"uri": "/jaxrs/view/{id}"}};
  255. // if (actionCallback) actionCallback();
  256. // }
  257. // if (callback) callback();
  258. // }.bind(this));
  259. // }else{
  260. // if (callback) callback();
  261. // }
  262. //},
  263. addColumn: function(){
  264. MWF.require("MWF.widget.UUID", function(){
  265. var id = (new MWF.widget.UUID).id;
  266. var json = {
  267. "id": id,
  268. "column": id,
  269. "displayName": this.designer.lp.unnamed,
  270. "selectType": "attribute",
  271. "orderType": "original"
  272. };
  273. if (!this.json.data.selectEntryList) this.json.data.selectEntryList = [];
  274. this.json.data.selectEntryList.push(json);
  275. var column = new MWF.xApplication.process.ViewDesigner.View.Column(json, this);
  276. this.items.push(column);
  277. column.selected();
  278. if (this.viewContentTableNode){
  279. var trs = this.viewContentTableNode.getElements("tr");
  280. trs.each(function(tr){
  281. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  282. }.bind(this));
  283. //this.setContentColumnWidth();
  284. }
  285. this.setViewWidth();
  286. this.addColumnNode.scrollIntoView(true);
  287. }.bind(this));
  288. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  289. },
  290. selected: function(){
  291. if (this.currentSelectedModule){
  292. if (this.currentSelectedModule==this){
  293. return true;
  294. }else{
  295. this.currentSelectedModule.unSelected();
  296. }
  297. }
  298. this.currentSelectedModule = this;
  299. this.showProperty();
  300. },
  301. unSelected: function(){
  302. this.currentSelectedModule = null;
  303. this.hideProperty();
  304. },
  305. loadViewNodes: function(){
  306. this.viewAreaNode = new Element("div#viewAreaNode", {"styles": this.css.viewAreaNode}).inject(this.areaNode);
  307. this.viewTitleNode = new Element("div#viewTitleNode", {"styles": this.css.viewTitleNode}).inject(this.viewAreaNode);
  308. this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.viewTitleNode);
  309. this.addColumnNode = new Element("div", {"styles": this.css.addColumnNode}).inject(this.viewTitleNode);
  310. this.viewTitleContentNode = new Element("div", {"styles": this.css.viewTitleContentNode}).inject(this.viewTitleNode);
  311. this.viewTitleTableNode = new Element("table", {
  312. "styles": this.css.viewTitleTableNode,
  313. "border": "0px",
  314. "cellPadding": "0",
  315. "cellSpacing": "0"
  316. }).inject(this.viewTitleContentNode);
  317. this.viewTitleTrNode = new Element("tr", {"styles": this.css.viewTitleTrNode}).inject(this.viewTitleTableNode);
  318. this.viewContentScrollNode = new Element("div", {"styles": this.css.viewContentScrollNode}).inject(this.viewAreaNode);
  319. this.viewContentNode = new Element("div", {"styles": this.css.viewContentNode}).inject(this.viewContentScrollNode);
  320. MWF.require("MWF.widget.ScrollBar", function(){
  321. new MWF.widget.ScrollBar(this.viewContentScrollNode, {"style": "view", "distance": 100, "indent": false});
  322. }.bind(this));
  323. this.contentLeftNode = new Element("div", {"styles": this.css.contentLeftNode}).inject(this.viewContentNode);
  324. this.contentRightNode = new Element("div", {"styles": this.css.contentRightNode}).inject(this.viewContentNode);
  325. this.viewContentBodyNode = new Element("div", {"styles": this.css.viewContentBodyNode}).inject(this.viewContentNode);
  326. this.viewContentTableNode = new Element("table", {
  327. "styles": this.css.viewContentTableNode,
  328. "border": "0px",
  329. "cellPadding": "0",
  330. "cellSpacing": "0"
  331. }).inject(this.viewContentBodyNode);
  332. //this.designer.addEvent("resize", this.setContentHeight.bind(this));
  333. },
  334. setContentHeight: function(){
  335. var size = this.areaNode.getSize();
  336. var titleSize = this.viewTitleNode.getSize();
  337. var height = size.y-titleSize.y-2;
  338. this.viewContentScrollNode.setStyle("height", height);
  339. var contentSize = this.viewContentBodyNode.getSize();
  340. if (height<contentSize.y) height = contentSize.y+10;
  341. this.viewContentNode.setStyle("height", height);
  342. this.contentLeftNode.setStyle("height", height);
  343. this.contentRightNode.setStyle("height", height);
  344. //this.viewContentBodyNode.setStyle("min-height", height);
  345. },
  346. loadViewColumns: function(){
  347. // for (var i=0; i<10; i++){
  348. if (this.json.data.selectEntryList) {
  349. this.json.data.selectEntryList.each(function (json) {
  350. this.items.push(new MWF.xApplication.process.ViewDesigner.View.Column(json, this));
  351. }.bind(this));
  352. }
  353. // }
  354. },
  355. loadView: function(){
  356. this.loadViewNodes();
  357. this.loadViewColumns();
  358. // this.addTopItemNode.addEvent("click", this.addTopItem.bind(this));
  359. },
  360. setViewWidth: function(){
  361. this.viewAreaNode.setStyle("width", "auto");
  362. this.viewTitleNode.setStyle("width", "auto");
  363. var s1 = this.viewTitleTableNode.getSize();
  364. var s2 = this.refreshNode.getSize();
  365. var s3 = this.addColumnNode.getSize();
  366. var width = s1.x+s2.x+s2.x;
  367. var size = this.areaNode.getSize();
  368. if (width>size.x){
  369. this.viewTitleNode.setStyle("width", ""+width+"px");
  370. this.viewAreaNode.setStyle("width", ""+width+"px");
  371. }else{
  372. this.viewTitleNode.setStyle("width", ""+size.x+"px");
  373. this.viewAreaNode.setStyle("width", ""+size.x+"px");
  374. }
  375. this.setContentColumnWidth();
  376. this.setContentHeight();
  377. },
  378. //setPropertyContent: function(){
  379. // this.designer.propertyIdNode.set("text", this.data.id);
  380. // this.designer.propertyNameNode.set("value", this.data.name);
  381. // this.designer.propertyAliasNode.set("value", this.data.alias);
  382. // this.designer.propertyDescriptionNode.set("value", this.data.description);
  383. //
  384. // this.designer.jsonDomNode.empty();
  385. // MWF.require("MWF.widget.JsonParse", function(){
  386. // this.jsonParse = new MWF.widget.JsonParse(this.data.data, this.designer.jsonDomNode, this.designer.jsonTextAreaNode);
  387. // window.setTimeout(function(){
  388. // this.jsonParse.load();
  389. // }.bind(this), 1);
  390. // }.bind(this));
  391. //},
  392. setAreaNodeSize: function(){
  393. //var size = this.node.getSize();
  394. ////var tabSize = this.tab.tabNodeContainer.getSize();
  395. //var tabSize = this.node.getSize();
  396. //var y = size.y - tabSize.y;
  397. //this.areaNode.setStyle("height", ""+y+"px");
  398. //if (this.editor) if (this.editor.editor) this.editor.editor.resize();
  399. },
  400. createRootItem: function() {
  401. this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true));
  402. },
  403. saveSilence: function(callback){
  404. if (!this.data.name){
  405. this.designer.notice(this.designer.lp.notice.inputName, "error");
  406. return false;
  407. }
  408. this.designer.actions.saveView(this.data, function(json){
  409. this.data.id = json.data.id;
  410. //this.page.textNode.set("text", this.data.name);
  411. if (this.lisNode) {
  412. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  413. }
  414. if (callback) callback();
  415. }.bind(this));
  416. },
  417. save: function(callback){
  418. //if (this.designer.tab.showPage==this.page){
  419. if (!this.data.name){
  420. this.designer.notice(this.designer.lp.notice.inputName, "error");
  421. return false;
  422. }
  423. //}
  424. this.designer.actions.saveView(this.data, function(json){
  425. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  426. this.data.id = json.data.id;
  427. //this.page.textNode.set("text", this.data.name);
  428. if (this.lisNode) {
  429. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  430. }
  431. if (callback) callback();
  432. }.bind(this));
  433. },
  434. saveAs: function(){},
  435. explode: function(){},
  436. implode: function(){},
  437. _setEditStyle: function(){}
  438. });
  439. MWF.xApplication.process.ViewDesigner.View.Column = new Class({
  440. initialize: function(json, view, next){
  441. this.propertyPath = "/x_component_process_ViewDesigner/$View/column.html"
  442. this.view = view;
  443. this.json = json;
  444. this.next = next;
  445. this.css = this.view.css;
  446. this.content = this.view.viewTitleTrNode;
  447. this.domListNode = this.view.domListNode;
  448. this.load();
  449. },
  450. load: function(){
  451. this.areaNode = new Element("td", {"styles": this.css.viewTitleColumnAreaNode});
  452. this.areaNode.store("column", this);
  453. if (this.next){
  454. this.areaNode.inject(this.next.areaNode, "before");
  455. }else{
  456. this.areaNode.inject(this.content);
  457. }
  458. this.node = new Element("div", {
  459. "styles": this.css.viewTitleColumnNode
  460. }).inject(this.areaNode);
  461. this.textNode = new Element("div", {
  462. "styles": this.css.viewTitleColumnTextNode,
  463. "text": this.json.displayName
  464. }).inject(this.node);
  465. this.listNode = new Element("div", {"styles": this.css.cloumnListNode});
  466. if (this.next){
  467. this.listNode.inject(this.next.listNode, "before");
  468. }else{
  469. this.listNode.inject(this.domListNode);
  470. }
  471. var listIconNode = new Element("div", {"styles": this.css.cloumnListIconNode}).inject(this.listNode);
  472. var listTextNode = new Element("div", {"styles": this.css.cloumnListTextNode}).inject(this.listNode);
  473. //var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  474. //if (!listText) listText = "unnamed";
  475. //
  476. //listTextNode.set("text", this.json.displayName+"("+listText+")");
  477. this.resetTextNode();
  478. this._createIconAction();
  479. //if (!this.json.export) this.hideMode();
  480. this.setEvent();
  481. },
  482. setEvent: function(){
  483. this.node.addEvents({
  484. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  485. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_over)}.bind(this),
  486. "mouseout": function(){if (!this.isSelected) if (this.isError){
  487. this.node.setStyles(this.css.viewTitleColumnNode_error)
  488. }else{
  489. this.node.setStyles(this.css.viewTitleColumnNode)
  490. }}.bind(this)
  491. });
  492. this.listNode.addEvents({
  493. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  494. "mouseover": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode_over)}.bind(this),
  495. "mouseout": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode)}.bind(this)
  496. });
  497. },
  498. _createIconAction: function(){
  499. if (!this.actionArea){
  500. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  501. this._createAction({
  502. "name": "move",
  503. "icon": "move1.png",
  504. "event": "mousedown",
  505. "action": "move",
  506. "title": MWF.APPVD.LP.action.move
  507. });
  508. this._createAction({
  509. "name": "add",
  510. "icon": "add.png",
  511. "event": "click",
  512. "action": "addColumn",
  513. "title": MWF.APPVD.LP.action.add
  514. });
  515. this._createAction({
  516. "name": "delete",
  517. "icon": "delete1.png",
  518. "event": "click",
  519. "action": "delete",
  520. "title": MWF.APPVD.LP.action["delete"]
  521. });
  522. }
  523. },
  524. _createAction: function(action){
  525. var actionNode = new Element("div", {
  526. "styles": this.css.actionNodeStyles,
  527. "title": action.title
  528. }).inject(this.actionArea);
  529. actionNode.setStyle("background", "url("+this.view.path+this.view.options.style+"/action/"+action.icon+") no-repeat left center");
  530. actionNode.addEvent(action.event, function(e){
  531. this[action.action](e);
  532. }.bind(this));
  533. actionNode.addEvents({
  534. "mouseover": function(e){
  535. e.target.setStyle("border", "1px solid #999");
  536. }.bind(this),
  537. "mouseout": function(e){
  538. e.target.setStyle("border", "1px solid #F1F1F1");
  539. }.bind(this)
  540. });
  541. },
  542. _setActionAreaPosition: function(){
  543. var p = this.node.getPosition(this.view.areaNode.getOffsetParent());
  544. var y = p.y-25;
  545. var x = p.x;
  546. this.actionArea.setPosition({"x": x, "y": y});
  547. },
  548. _showActions: function(){
  549. if (this.actionArea){
  550. this._setActionAreaPosition();
  551. this.actionArea.setStyle("display", "block");
  552. }
  553. },
  554. _hideActions: function(){
  555. if (this.actionArea) this.actionArea.setStyle("display", "none");
  556. },
  557. selected: function(){
  558. if (this.view.currentSelectedModule){
  559. if (this.view.currentSelectedModule==this){
  560. return true;
  561. }else{
  562. this.view.currentSelectedModule.unSelected();
  563. }
  564. }
  565. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  566. this.listNode.setStyles(this.css.cloumnListNode_selected);
  567. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  568. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  569. this.view.currentSelectedModule = this;
  570. this.isSelected = true;
  571. this._showActions();
  572. this.showProperty();
  573. },
  574. unSelected: function(){
  575. this.view.currentSelectedModule = null;
  576. //this.node.setStyles(this.css.viewTitleColumnNode);
  577. if (this.isError){
  578. this.node.setStyles(this.css.viewTitleColumnNode_error)
  579. }else{
  580. this.node.setStyles(this.css.viewTitleColumnNode)
  581. }
  582. this.listNode.setStyles(this.css.cloumnListNode);
  583. this.isSelected = false;
  584. this._hideActions();
  585. this.hideProperty();
  586. },
  587. showProperty: function(){
  588. if (!this.property){
  589. this.property = new MWF.xApplication.process.ViewDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  590. "path": this.propertyPath,
  591. "onPostLoad": function(){
  592. this.property.show();
  593. }.bind(this)
  594. });
  595. this.property.load();
  596. }else{
  597. this.property.show();
  598. }
  599. },
  600. hideProperty: function(){
  601. if (this.property) this.property.hide();
  602. },
  603. _setEditStyle: function(name, input, oldValue){
  604. if (name=="displayName") this.resetTextNode();
  605. if (name=="selectType") this.resetTextNode();
  606. if (name=="attribute") this.resetTextNode();
  607. if (name=="path") this.resetTextNode();
  608. if (name=="column"){
  609. this.view.json.data.orderEntryList.each(function(order){
  610. if (order.column==oldValue) order.column = this.json.column
  611. }.bind(this));
  612. if (this.view.json.data.groupEntry.column == oldValue) this.view.json.data.groupEntry.column = this.json.column;
  613. }
  614. },
  615. resetTextNode: function(){
  616. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  617. if (!listText) listText = "unnamed";
  618. this.textNode.set("text", this.json.displayName);
  619. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  620. },
  621. "delete": function(e){
  622. var _self = this;
  623. if (!e) e = this.node;
  624. this.view.designer.confirm("warn", e, MWF.APPVD.LP.notice.deleteColumnTitle, MWF.APPVD.LP.notice.deleteColumn, 300, 120, function(){
  625. _self.destroy();
  626. this.close();
  627. }, function(){
  628. this.close();
  629. }, null);
  630. },
  631. destroy: function(){
  632. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  633. if (this.actionArea) this.actionArea.destroy();
  634. if (this.listNode) this.listNode.destroy();
  635. if (this.property) this.property.propertyContent.destroy();
  636. var idx = this.view.items.indexOf(this);
  637. if (this.view.viewContentTableNode){
  638. var trs = this.view.viewContentTableNode.getElements("tr");
  639. trs.each(function(tr){
  640. tr.deleteCell(idx);
  641. }.bind(this));
  642. }
  643. if (this.view.json.data.selectEntryList) this.view.json.data.selectEntryList.erase(this.json);
  644. if (this.view.json.data.calculate.calculateEntryList) this.view.json.data.calculate.calculateEntryList.erase(this.json);
  645. this.view.items.erase(this);
  646. this.areaNode.destroy();
  647. this.view.selected();
  648. this.view.setViewWidth();
  649. MWF.release(this);
  650. delete this;
  651. },
  652. addColumn: function(e, data){
  653. MWF.require("MWF.widget.UUID", function(){
  654. var json;
  655. if (data){
  656. json = Object.clone(data);
  657. json.id = (new MWF.widget.UUID).id;
  658. json.column = (new MWF.widget.UUID).id;
  659. }else{
  660. var id = (new MWF.widget.UUID).id;
  661. json = {
  662. "id": id,
  663. "column": id,
  664. "displayName": this.view.designer.lp.unnamed,
  665. "selectType": "attribute",
  666. "orderType": "original"
  667. };
  668. }
  669. var idx = this.view.json.data.selectEntryList.indexOf(this.json);
  670. this.view.json.data.selectEntryList.splice(idx, 0, json);
  671. var column = new MWF.xApplication.process.ViewDesigner.View.Column(json, this.view, this);
  672. this.view.items.splice(idx, 0, column);
  673. column.selected();
  674. if (this.view.viewContentTableNode){
  675. var trs = this.view.viewContentTableNode.getElements("tr");
  676. trs.each(function(tr){
  677. var td = tr.insertCell(idx);
  678. td.setStyles(this.css.viewContentTdNode);
  679. }.bind(this));
  680. }
  681. this.view.setViewWidth();
  682. }.bind(this));
  683. },
  684. move: function(e){
  685. var columnNodes = [];
  686. this.view.items.each(function(item){
  687. if (item!=this){
  688. columnNodes.push(item.areaNode);
  689. }
  690. }.bind(this));
  691. this._createMoveNode();
  692. this._setNodeMove(columnNodes, e);
  693. },
  694. _createMoveNode: function(){
  695. this.moveNode = new Element("div", {"text": this.node.get("text")});
  696. this.moveNode.inject(this.view.designer.content);
  697. this.moveNode.setStyles({
  698. "border": "2px dashed #ffa200",
  699. "opacity": 0.7,
  700. "height": "30px",
  701. "line-height": "30px",
  702. "padding": "0px 10px",
  703. "position": "absolute"
  704. });
  705. },
  706. _setMoveNodePosition: function(e){
  707. var x = e.page.x+2;
  708. var y = e.page.y+2;
  709. this.moveNode.positionTo(x, y);
  710. },
  711. createMoveFlagNode: function(){
  712. this.moveFlagNode = new Element("td", {"styles": this.css.moveFlagNode});
  713. },
  714. _setNodeMove: function(droppables, e){
  715. this._setMoveNodePosition(e);
  716. var movePosition = this.moveNode.getPosition();
  717. var moveSize = this.moveNode.getSize();
  718. var contentPosition = this.content.getPosition();
  719. var contentSize = this.content.getSize();
  720. var nodeDrag = new Drag.Move(this.moveNode, {
  721. "droppables": droppables,
  722. "limit": {
  723. "x": [contentPosition.x, contentPosition.x+contentSize.x],
  724. "y": [movePosition.y, movePosition.y+moveSize.y]
  725. },
  726. "onEnter": function(dragging, inObj){
  727. if (!this.moveFlagNode) this.createMoveFlagNode();
  728. this.moveFlagNode.inject(inObj, "before");
  729. }.bind(this),
  730. "onLeave": function(dragging, inObj){
  731. if (this.moveFlagNode){
  732. this.moveFlagNode.dispose();
  733. }
  734. }.bind(this),
  735. "onDrop": function(dragging, inObj){
  736. if (inObj){
  737. this.areaNode.inject(inObj, "before");
  738. var column = inObj.retrieve("column");
  739. this.listNode.inject(column.listNode, "before");
  740. var idx = this.view.json.data.selectEntryList.indexOf(column.json);
  741. this.view.json.data.selectEntryList.erase(this.json);
  742. this.view.items.erase(this);
  743. this.view.json.data.selectEntryList.splice(idx, 0, this.json);
  744. this.view.items.splice(idx, 0, this);
  745. if (this.moveNode) this.moveNode.destroy();
  746. if (this.moveFlagNode) this.moveFlagNode.destroy();
  747. this._setActionAreaPosition();
  748. }else{
  749. if (this.moveNode) this.moveNode.destroy();
  750. if (this.moveFlagNode) this.moveFlagNode.destroy();
  751. }
  752. }.bind(this),
  753. "onCancel": function(dragging){
  754. if (this.moveNode) this.moveNode.destroy();
  755. if (this.moveFlagNode) this.moveFlagNode.destroy();
  756. }.bind(this)
  757. });
  758. nodeDrag.start(e);
  759. }
  760. //hideMode: function(){
  761. // if (!this.columnHideFlagNode){
  762. // this.columnHideFlagNode = new Element("div", {"styles": this.view.css.columnHideFlagNode}).inject(this.node);
  763. // }
  764. //},
  765. //showMode: function(){
  766. // if (this.columnHideFlagNode) this.columnHideFlagNode.destroy();
  767. // this.columnHideFlagNode = null;
  768. //}
  769. });