View.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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. debugger;
  225. if (this.viewContentTableNode){
  226. trs = this.viewContentTableNode.getElements("tr");
  227. for (var i=0; i<trs.length; i++){
  228. var tr = trs[i];
  229. var tds = tr.getElements("td");
  230. tds.each(function(contentTd, i){
  231. if (contentTd.get("colSpan")==1){
  232. contentTd.setStyle("width", ""+widthList[i]+"px");
  233. flag = true;
  234. }
  235. });
  236. if (flag) break;
  237. }
  238. //var tr = this.viewContentTableNode.getFirst("tr");
  239. //if (tr){
  240. // var tds = tr.getElements("td");
  241. // tds.each(function(contentTd, i){
  242. // if (!contentTd.get("colSpan")){
  243. // contentTd.setStyle("width", ""+widthList[i]+"px");
  244. // }
  245. // });
  246. //}
  247. }
  248. },
  249. //getLookupAction: function(callback){
  250. // if (!this.lookupAction){
  251. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  252. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface_lookup", "");
  253. // this.lookupAction.getActions = function(actionCallback){
  254. // debugger;
  255. // this.actions = {"lookup": {"uri": "/jaxrs/view/{id}"}};
  256. // if (actionCallback) actionCallback();
  257. // }
  258. // if (callback) callback();
  259. // }.bind(this));
  260. // }else{
  261. // if (callback) callback();
  262. // }
  263. //},
  264. addColumn: function(){
  265. debugger;
  266. MWF.require("MWF.widget.UUID", function(){
  267. var id = (new MWF.widget.UUID).id;
  268. var json = {
  269. "id": id,
  270. "column": id,
  271. "displayName": this.designer.lp.unnamed,
  272. "selectType": "attribute",
  273. "orderType": "original"
  274. };
  275. if (!this.json.data.selectEntryList) this.json.data.selectEntryList = [];
  276. this.json.data.selectEntryList.push(json);
  277. var column = new MWF.xApplication.process.ViewDesigner.View.Column(json, this);
  278. this.items.push(column);
  279. column.selected();
  280. if (this.viewContentTableNode){
  281. var trs = this.viewContentTableNode.getElements("tr");
  282. trs.each(function(tr){
  283. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  284. }.bind(this));
  285. //this.setContentColumnWidth();
  286. }
  287. this.setViewWidth();
  288. this.addColumnNode.scrollIntoView(true);
  289. }.bind(this));
  290. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  291. },
  292. selected: function(){
  293. if (this.currentSelectedModule){
  294. if (this.currentSelectedModule==this){
  295. return true;
  296. }else{
  297. this.currentSelectedModule.unSelected();
  298. }
  299. }
  300. this.currentSelectedModule = this;
  301. this.showProperty();
  302. },
  303. unSelected: function(){
  304. this.currentSelectedModule = null;
  305. this.hideProperty();
  306. },
  307. loadViewNodes: function(){
  308. this.viewAreaNode = new Element("div#viewAreaNode", {"styles": this.css.viewAreaNode}).inject(this.areaNode);
  309. this.viewTitleNode = new Element("div#viewTitleNode", {"styles": this.css.viewTitleNode}).inject(this.viewAreaNode);
  310. this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.viewTitleNode);
  311. this.addColumnNode = new Element("div", {"styles": this.css.addColumnNode}).inject(this.viewTitleNode);
  312. this.viewTitleContentNode = new Element("div", {"styles": this.css.viewTitleContentNode}).inject(this.viewTitleNode);
  313. this.viewTitleTableNode = new Element("table", {
  314. "styles": this.css.viewTitleTableNode,
  315. "border": "0px",
  316. "cellPadding": "0",
  317. "cellSpacing": "0"
  318. }).inject(this.viewTitleContentNode);
  319. this.viewTitleTrNode = new Element("tr", {"styles": this.css.viewTitleTrNode}).inject(this.viewTitleTableNode);
  320. this.viewContentScrollNode = new Element("div", {"styles": this.css.viewContentScrollNode}).inject(this.viewAreaNode);
  321. this.viewContentNode = new Element("div", {"styles": this.css.viewContentNode}).inject(this.viewContentScrollNode);
  322. MWF.require("MWF.widget.ScrollBar", function(){
  323. new MWF.widget.ScrollBar(this.viewContentScrollNode, {"style": "view", "distance": 100, "indent": false});
  324. }.bind(this));
  325. this.contentLeftNode = new Element("div", {"styles": this.css.contentLeftNode}).inject(this.viewContentNode);
  326. this.contentRightNode = new Element("div", {"styles": this.css.contentRightNode}).inject(this.viewContentNode);
  327. this.viewContentBodyNode = new Element("div", {"styles": this.css.viewContentBodyNode}).inject(this.viewContentNode);
  328. this.viewContentTableNode = new Element("table", {
  329. "styles": this.css.viewContentTableNode,
  330. "border": "0px",
  331. "cellPadding": "0",
  332. "cellSpacing": "0"
  333. }).inject(this.viewContentBodyNode);
  334. //this.designer.addEvent("resize", this.setContentHeight.bind(this));
  335. },
  336. setContentHeight: function(){
  337. var size = this.areaNode.getSize();
  338. var titleSize = this.viewTitleNode.getSize();
  339. var height = size.y-titleSize.y-2;
  340. this.viewContentScrollNode.setStyle("height", height);
  341. var contentSize = this.viewContentBodyNode.getSize();
  342. if (height<contentSize.y) height = contentSize.y+10;
  343. this.viewContentNode.setStyle("height", height);
  344. this.contentLeftNode.setStyle("height", height);
  345. this.contentRightNode.setStyle("height", height);
  346. //this.viewContentBodyNode.setStyle("min-height", height);
  347. },
  348. loadViewColumns: function(){
  349. // for (var i=0; i<10; i++){
  350. if (this.json.data.selectEntryList) {
  351. this.json.data.selectEntryList.each(function (json) {
  352. this.items.push(new MWF.xApplication.process.ViewDesigner.View.Column(json, this));
  353. }.bind(this));
  354. }
  355. // }
  356. },
  357. loadView: function(){
  358. this.loadViewNodes();
  359. this.loadViewColumns();
  360. // this.addTopItemNode.addEvent("click", this.addTopItem.bind(this));
  361. },
  362. setViewWidth: function(){
  363. this.viewAreaNode.setStyle("width", "auto");
  364. this.viewTitleNode.setStyle("width", "auto");
  365. var s1 = this.viewTitleTableNode.getSize();
  366. var s2 = this.refreshNode.getSize();
  367. var s3 = this.addColumnNode.getSize();
  368. var width = s1.x+s2.x+s2.x;
  369. var size = this.areaNode.getSize();
  370. if (width>size.x){
  371. this.viewTitleNode.setStyle("width", ""+width+"px");
  372. this.viewAreaNode.setStyle("width", ""+width+"px");
  373. }else{
  374. this.viewTitleNode.setStyle("width", ""+size.x+"px");
  375. this.viewAreaNode.setStyle("width", ""+size.x+"px");
  376. }
  377. this.setContentColumnWidth();
  378. this.setContentHeight();
  379. },
  380. //setPropertyContent: function(){
  381. // this.designer.propertyIdNode.set("text", this.data.id);
  382. // this.designer.propertyNameNode.set("value", this.data.name);
  383. // this.designer.propertyAliasNode.set("value", this.data.alias);
  384. // this.designer.propertyDescriptionNode.set("value", this.data.description);
  385. //
  386. // this.designer.jsonDomNode.empty();
  387. // MWF.require("MWF.widget.JsonParse", function(){
  388. // this.jsonParse = new MWF.widget.JsonParse(this.data.data, this.designer.jsonDomNode, this.designer.jsonTextAreaNode);
  389. // window.setTimeout(function(){
  390. // this.jsonParse.load();
  391. // }.bind(this), 1);
  392. // }.bind(this));
  393. //},
  394. setAreaNodeSize: function(){
  395. //var size = this.node.getSize();
  396. ////var tabSize = this.tab.tabNodeContainer.getSize();
  397. //var tabSize = this.node.getSize();
  398. //var y = size.y - tabSize.y;
  399. //this.areaNode.setStyle("height", ""+y+"px");
  400. //if (this.editor) if (this.editor.editor) this.editor.editor.resize();
  401. },
  402. createRootItem: function() {
  403. this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true));
  404. },
  405. saveSilence: function(callback){
  406. if (!this.data.name){
  407. this.designer.notice(this.designer.lp.notice.inputName, "error");
  408. return false;
  409. }
  410. this.designer.actions.saveView(this.data, function(json){
  411. this.data.id = json.data.id;
  412. //this.page.textNode.set("text", this.data.name);
  413. if (this.lisNode) {
  414. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  415. }
  416. if (callback) callback();
  417. }.bind(this));
  418. },
  419. save: function(callback){
  420. //if (this.designer.tab.showPage==this.page){
  421. if (!this.data.name){
  422. this.designer.notice(this.designer.lp.notice.inputName, "error");
  423. return false;
  424. }
  425. //}
  426. this.designer.actions.saveView(this.data, function(json){
  427. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  428. this.data.id = json.data.id;
  429. //this.page.textNode.set("text", this.data.name);
  430. if (this.lisNode) {
  431. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  432. }
  433. if (callback) callback();
  434. }.bind(this));
  435. },
  436. saveAs: function(){},
  437. explode: function(){},
  438. implode: function(){},
  439. _setEditStyle: function(){}
  440. });
  441. MWF.xApplication.process.ViewDesigner.View.Column = new Class({
  442. initialize: function(json, view, next){
  443. this.propertyPath = "/x_component_process_ViewDesigner/$View/column.html"
  444. this.view = view;
  445. this.json = json;
  446. this.next = next;
  447. this.css = this.view.css;
  448. this.content = this.view.viewTitleTrNode;
  449. this.domListNode = this.view.domListNode;
  450. this.load();
  451. },
  452. load: function(){
  453. this.areaNode = new Element("td", {"styles": this.css.viewTitleColumnAreaNode});
  454. this.areaNode.store("column", this);
  455. if (this.next){
  456. this.areaNode.inject(this.next.areaNode, "before");
  457. }else{
  458. this.areaNode.inject(this.content);
  459. }
  460. this.node = new Element("div", {
  461. "styles": this.css.viewTitleColumnNode
  462. }).inject(this.areaNode);
  463. this.textNode = new Element("div", {
  464. "styles": this.css.viewTitleColumnTextNode,
  465. "text": this.json.displayName
  466. }).inject(this.node);
  467. this.listNode = new Element("div", {"styles": this.css.cloumnListNode});
  468. if (this.next){
  469. this.listNode.inject(this.next.listNode, "before");
  470. }else{
  471. this.listNode.inject(this.domListNode);
  472. }
  473. var listIconNode = new Element("div", {"styles": this.css.cloumnListIconNode}).inject(this.listNode);
  474. var listTextNode = new Element("div", {"styles": this.css.cloumnListTextNode}).inject(this.listNode);
  475. //var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  476. //if (!listText) listText = "unnamed";
  477. //
  478. //listTextNode.set("text", this.json.displayName+"("+listText+")");
  479. this.resetTextNode();
  480. this._createIconAction();
  481. //if (!this.json.export) this.hideMode();
  482. this.setEvent();
  483. },
  484. setEvent: function(){
  485. this.node.addEvents({
  486. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  487. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_over)}.bind(this),
  488. "mouseout": function(){if (!this.isSelected) if (this.isError){
  489. this.node.setStyles(this.css.viewTitleColumnNode_error)
  490. }else{
  491. this.node.setStyles(this.css.viewTitleColumnNode)
  492. }}.bind(this)
  493. });
  494. this.listNode.addEvents({
  495. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  496. "mouseover": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode_over)}.bind(this),
  497. "mouseout": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode)}.bind(this)
  498. });
  499. },
  500. _createIconAction: function(){
  501. if (!this.actionArea){
  502. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  503. this._createAction({
  504. "name": "move",
  505. "icon": "move1.png",
  506. "event": "mousedown",
  507. "action": "move",
  508. "title": MWF.APPVD.LP.action.move
  509. });
  510. this._createAction({
  511. "name": "add",
  512. "icon": "add.png",
  513. "event": "click",
  514. "action": "addColumn",
  515. "title": MWF.APPVD.LP.action.add
  516. });
  517. this._createAction({
  518. "name": "delete",
  519. "icon": "delete1.png",
  520. "event": "click",
  521. "action": "delete",
  522. "title": MWF.APPVD.LP.action["delete"]
  523. });
  524. }
  525. },
  526. _createAction: function(action){
  527. var actionNode = new Element("div", {
  528. "styles": this.css.actionNodeStyles,
  529. "title": action.title
  530. }).inject(this.actionArea);
  531. actionNode.setStyle("background", "url("+this.view.path+this.view.options.style+"/action/"+action.icon+") no-repeat left center");
  532. actionNode.addEvent(action.event, function(e){
  533. this[action.action](e);
  534. }.bind(this));
  535. actionNode.addEvents({
  536. "mouseover": function(e){
  537. e.target.setStyle("border", "1px solid #999");
  538. }.bind(this),
  539. "mouseout": function(e){
  540. e.target.setStyle("border", "1px solid #F1F1F1");
  541. }.bind(this)
  542. });
  543. },
  544. _setActionAreaPosition: function(){
  545. var p = this.node.getPosition(this.view.areaNode.getOffsetParent());
  546. var y = p.y-25;
  547. var x = p.x;
  548. this.actionArea.setPosition({"x": x, "y": y});
  549. },
  550. _showActions: function(){
  551. if (this.actionArea){
  552. this._setActionAreaPosition();
  553. this.actionArea.setStyle("display", "block");
  554. }
  555. },
  556. _hideActions: function(){
  557. if (this.actionArea) this.actionArea.setStyle("display", "none");
  558. },
  559. selected: function(){
  560. if (this.view.currentSelectedModule){
  561. if (this.view.currentSelectedModule==this){
  562. return true;
  563. }else{
  564. this.view.currentSelectedModule.unSelected();
  565. }
  566. }
  567. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  568. this.listNode.setStyles(this.css.cloumnListNode_selected);
  569. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  570. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  571. this.view.currentSelectedModule = this;
  572. this.isSelected = true;
  573. this._showActions();
  574. this.showProperty();
  575. },
  576. unSelected: function(){
  577. this.view.currentSelectedModule = null;
  578. //this.node.setStyles(this.css.viewTitleColumnNode);
  579. if (this.isError){
  580. this.node.setStyles(this.css.viewTitleColumnNode_error)
  581. }else{
  582. this.node.setStyles(this.css.viewTitleColumnNode)
  583. }
  584. this.listNode.setStyles(this.css.cloumnListNode);
  585. this.isSelected = false;
  586. this._hideActions();
  587. this.hideProperty();
  588. },
  589. showProperty: function(){
  590. if (!this.property){
  591. this.property = new MWF.xApplication.process.ViewDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  592. "path": this.propertyPath,
  593. "onPostLoad": function(){
  594. this.property.show();
  595. }.bind(this)
  596. });
  597. this.property.load();
  598. }else{
  599. this.property.show();
  600. }
  601. },
  602. hideProperty: function(){
  603. if (this.property) this.property.hide();
  604. },
  605. _setEditStyle: function(name, input, oldValue){
  606. if (name=="displayName") this.resetTextNode();
  607. if (name=="selectType") this.resetTextNode();
  608. if (name=="attribute") this.resetTextNode();
  609. if (name=="path") this.resetTextNode();
  610. if (name=="column"){
  611. this.view.json.data.orderEntryList.each(function(order){
  612. if (order.column==oldValue) order.column = this.json.column
  613. }.bind(this));
  614. if (this.view.json.data.groupEntry.column == oldValue) this.view.json.data.groupEntry.column = this.json.column;
  615. }
  616. },
  617. resetTextNode: function(){
  618. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  619. if (!listText) listText = "unnamed";
  620. this.textNode.set("text", this.json.displayName);
  621. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  622. },
  623. "delete": function(e){
  624. var _self = this;
  625. if (!e) e = this.node;
  626. this.view.designer.confirm("warn", e, MWF.APPVD.LP.notice.deleteColumnTitle, MWF.APPVD.LP.notice.deleteColumn, 300, 120, function(){
  627. _self.destroy();
  628. this.close();
  629. }, function(){
  630. this.close();
  631. }, null);
  632. },
  633. destroy: function(){
  634. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  635. if (this.actionArea) this.actionArea.destroy();
  636. if (this.listNode) this.listNode.destroy();
  637. if (this.property) this.property.propertyContent.destroy();
  638. var idx = this.view.items.indexOf(this);
  639. if (this.view.viewContentTableNode){
  640. var trs = this.view.viewContentTableNode.getElements("tr");
  641. trs.each(function(tr){
  642. tr.deleteCell(idx);
  643. }.bind(this));
  644. }
  645. if (this.view.json.data.selectEntryList) this.view.json.data.selectEntryList.erase(this.json);
  646. if (this.view.json.data.calculate.calculateEntryList) this.view.json.data.calculate.calculateEntryList.erase(this.json);
  647. this.view.items.erase(this);
  648. this.areaNode.destroy();
  649. this.view.selected();
  650. this.view.setViewWidth();
  651. MWF.release(this);
  652. delete this;
  653. },
  654. addColumn: function(e, data){
  655. MWF.require("MWF.widget.UUID", function(){
  656. var json;
  657. if (data){
  658. json = Object.clone(data);
  659. json.id = (new MWF.widget.UUID).id;
  660. json.column = (new MWF.widget.UUID).id;
  661. }else{
  662. var id = (new MWF.widget.UUID).id;
  663. json = {
  664. "id": id,
  665. "column": id,
  666. "displayName": this.view.designer.lp.unnamed,
  667. "selectType": "attribute",
  668. "orderType": "original"
  669. };
  670. }
  671. var idx = this.view.json.data.selectEntryList.indexOf(this.json);
  672. this.view.json.data.selectEntryList.splice(idx, 0, json);
  673. var column = new MWF.xApplication.process.ViewDesigner.View.Column(json, this.view, this);
  674. this.view.items.splice(idx, 0, column);
  675. column.selected();
  676. if (this.view.viewContentTableNode){
  677. var trs = this.view.viewContentTableNode.getElements("tr");
  678. trs.each(function(tr){
  679. var td = tr.insertCell(idx);
  680. td.setStyles(this.css.viewContentTdNode);
  681. }.bind(this));
  682. }
  683. this.view.setViewWidth();
  684. }.bind(this));
  685. },
  686. move: function(e){
  687. var columnNodes = [];
  688. this.view.items.each(function(item){
  689. if (item!=this){
  690. columnNodes.push(item.areaNode);
  691. }
  692. }.bind(this));
  693. this._createMoveNode();
  694. this._setNodeMove(columnNodes, e);
  695. },
  696. _createMoveNode: function(){
  697. this.moveNode = new Element("div", {"text": this.node.get("text")});
  698. this.moveNode.inject(this.view.designer.content);
  699. this.moveNode.setStyles({
  700. "border": "2px dashed #ffa200",
  701. "opacity": 0.7,
  702. "height": "30px",
  703. "line-height": "30px",
  704. "padding": "0px 10px",
  705. "position": "absolute"
  706. });
  707. },
  708. _setMoveNodePosition: function(e){
  709. var x = e.page.x+2;
  710. var y = e.page.y+2;
  711. this.moveNode.positionTo(x, y);
  712. },
  713. createMoveFlagNode: function(){
  714. this.moveFlagNode = new Element("td", {"styles": this.css.moveFlagNode});
  715. },
  716. _setNodeMove: function(droppables, e){
  717. this._setMoveNodePosition(e);
  718. var movePosition = this.moveNode.getPosition();
  719. var moveSize = this.moveNode.getSize();
  720. var contentPosition = this.content.getPosition();
  721. var contentSize = this.content.getSize();
  722. var nodeDrag = new Drag.Move(this.moveNode, {
  723. "droppables": droppables,
  724. "limit": {
  725. "x": [contentPosition.x, contentPosition.x+contentSize.x],
  726. "y": [movePosition.y, movePosition.y+moveSize.y]
  727. },
  728. "onEnter": function(dragging, inObj){
  729. if (!this.moveFlagNode) this.createMoveFlagNode();
  730. this.moveFlagNode.inject(inObj, "before");
  731. }.bind(this),
  732. "onLeave": function(dragging, inObj){
  733. if (this.moveFlagNode){
  734. this.moveFlagNode.dispose();
  735. }
  736. }.bind(this),
  737. "onDrop": function(dragging, inObj){
  738. if (inObj){
  739. this.areaNode.inject(inObj, "before");
  740. var column = inObj.retrieve("column");
  741. this.listNode.inject(column.listNode, "before");
  742. var idx = this.view.json.data.selectEntryList.indexOf(column.json);
  743. this.view.json.data.selectEntryList.erase(this.json);
  744. this.view.items.erase(this);
  745. this.view.json.data.selectEntryList.splice(idx, 0, this.json);
  746. this.view.items.splice(idx, 0, this);
  747. if (this.moveNode) this.moveNode.destroy();
  748. if (this.moveFlagNode) this.moveFlagNode.destroy();
  749. this._setActionAreaPosition();
  750. }else{
  751. if (this.moveNode) this.moveNode.destroy();
  752. if (this.moveFlagNode) this.moveFlagNode.destroy();
  753. }
  754. }.bind(this),
  755. "onCancel": function(dragging){
  756. if (this.moveNode) this.moveNode.destroy();
  757. if (this.moveFlagNode) this.moveFlagNode.destroy();
  758. }.bind(this)
  759. });
  760. nodeDrag.start(e);
  761. }
  762. //hideMode: function(){
  763. // if (!this.columnHideFlagNode){
  764. // this.columnHideFlagNode = new Element("div", {"styles": this.view.css.columnHideFlagNode}).inject(this.node);
  765. // }
  766. //},
  767. //showMode: function(){
  768. // if (this.columnHideFlagNode) this.columnHideFlagNode.destroy();
  769. // this.columnHideFlagNode = null;
  770. //}
  771. });