View.js 35 KB

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