View.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.query = MWF.xApplication.query || {};
  3. MWF.xApplication.query.ViewDesigner = MWF.xApplication.query.ViewDesigner || {};
  4. MWF.APPDVD = MWF.xApplication.query.ViewDesigner;
  5. MWF.require("MWF.widget.Common", null, false);
  6. MWF.require("MWF.xScript.Macro", null, false);
  7. MWF.xDesktop.requireApp("query.ViewDesigner", "lp."+MWF.language, null, false);
  8. MWF.xDesktop.requireApp("query.ViewDesigner", "Property", null, false);
  9. MWF.xApplication.query.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_query_ViewDesigner/$View/view.html"
  17. },
  18. initialize: function(designer, data, options){
  19. this.setOptions(options);
  20. this.path = "/x_component_query_ViewDesigner/$View/";
  21. this.cssPath = "/x_component_query_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.query.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, null,function(json){
  130. var entries = {};
  131. json.data.selectList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  132. if (this.json.data.group.column){
  133. if (json.data.groupGrid.length){
  134. var groupColumn = null;
  135. for (var c = 0; c<json.data.selectList.length; c++){
  136. if (json.data.selectList[c].column === json.data.group.column){
  137. groupColumn = json.data.selectList[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. groupTextNode.set("text", line.group);
  151. }else{
  152. groupTextNode.set("text", line.group);
  153. }
  154. var subtrs = [];
  155. line.list.each(function(entry){
  156. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  157. tr.setStyle("display", "none");
  158. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  159. Object.each(entries, function(c, k){
  160. var d = entry.data[k];
  161. if (d!=undefined){
  162. if (k!=this.json.data.group.column){
  163. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  164. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  165. td.set("text", d);
  166. }
  167. }
  168. }.bind(this));
  169. // Object.each(entry.data, function(d, k){
  170. // if (k!=this.json.data.group.column){
  171. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  172. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  173. // }
  174. // }.bind(this));
  175. subtrs.push(tr)
  176. }.bind(this));
  177. groupAreaNode.store("subtrs", subtrs);
  178. var _self = this;
  179. groupAreaNode.addEvent("click", function(){
  180. var subtrs = this.retrieve("subtrs");
  181. var iconNode = groupAreaNode.getFirst("div");
  182. if (subtrs[0]){
  183. if (subtrs[0].getStyle("display")=="none"){
  184. subtrs.each(function(subtr){ subtr.setStyle("display", "table-row"); });
  185. iconNode.setStyle("background", "url("+"/x_component_process_ViewDesigner/$View/default/icon/down.png) center center no-repeat");
  186. }else{
  187. subtrs.each(function(subtr){ subtr.setStyle("display", "none"); });
  188. iconNode.setStyle("background", "url("+"/x_component_process_ViewDesigner/$View/default/icon/right.png) center center no-repeat");
  189. }
  190. }
  191. _self.setContentHeight();
  192. });
  193. }.bind(this));
  194. this.setContentColumnWidth();
  195. this.setContentHeight();
  196. }
  197. }else{
  198. if (json.data.grid.length){
  199. json.data.grid.each(function(line, idx){
  200. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  201. Object.each(entries, function(c, k){
  202. var d = line.data[k];
  203. if (d!=undefined){
  204. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  205. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  206. td.set("text", d);
  207. }
  208. }.bind(this));
  209. // Object.each(line.data, function(d, k){
  210. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  211. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  212. // }.bind(this));
  213. }.bind(this));
  214. this.setContentColumnWidth();
  215. this.setContentHeight();
  216. }
  217. }
  218. }.bind(this));
  219. //this.getLookupAction(function(){
  220. // this.lookupAction.invoke({"name": "lookup","async": true, "parameter": {"id": this.data.id},"success": function(json){
  221. // if (json.data.length){
  222. // json.data.each(function(line, idx){
  223. // var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  224. // line.each(function(cell, i){
  225. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  226. // td.set("text", cell);
  227. // }.bind(this));
  228. // }.bind(this));
  229. // this.setContentColumnWidth();
  230. // this.setContentHeight();
  231. // }
  232. //
  233. // }.bind(this)});
  234. //}.bind(this));
  235. }.bind(this));
  236. }
  237. },
  238. setContentColumnWidth: function(){
  239. var titleTds = this.viewTitleTrNode.getElements("td");
  240. var widthList = [];
  241. titleTds.each(function(td){widthList.push(td.getSize().x);});
  242. var flag = false;
  243. if (this.viewContentTableNode){
  244. trs = this.viewContentTableNode.getElements("tr");
  245. for (var i=0; i<trs.length; i++){
  246. var tr = trs[i];
  247. var tds = tr.getElements("td");
  248. tds.each(function(contentTd, i){
  249. if (contentTd.get("colSpan")==1){
  250. contentTd.setStyle("width", ""+widthList[i]+"px");
  251. flag = true;
  252. }
  253. });
  254. if (flag) break;
  255. }
  256. //var tr = this.viewContentTableNode.getFirst("tr");
  257. //if (tr){
  258. // var tds = tr.getElements("td");
  259. // tds.each(function(contentTd, i){
  260. // if (!contentTd.get("colSpan")){
  261. // contentTd.setStyle("width", ""+widthList[i]+"px");
  262. // }
  263. // });
  264. //}
  265. }
  266. },
  267. //getLookupAction: function(callback){
  268. // if (!this.lookupAction){
  269. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  270. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface_lookup", "");
  271. // this.lookupAction.getActions = function(actionCallback){
  272. //
  273. // this.actions = {"lookup": {"uri": "/jaxrs/view/{id}"}};
  274. // if (actionCallback) actionCallback();
  275. // }
  276. // if (callback) callback();
  277. // }.bind(this));
  278. // }else{
  279. // if (callback) callback();
  280. // }
  281. //},
  282. addColumn: function(){
  283. MWF.require("MWF.widget.UUID", function(){
  284. var id = (new MWF.widget.UUID).id;
  285. var json = {
  286. "id": id,
  287. "column": id,
  288. "displayName": this.designer.lp.unnamed,
  289. "orderType": "original"
  290. };
  291. if (!this.json.data.selectList) this.json.data.selectList = [];
  292. this.json.data.selectList.push(json);
  293. var column = new MWF.xApplication.query.ViewDesigner.View.Column(json, this);
  294. this.items.push(column);
  295. column.selected();
  296. if (this.viewContentTableNode){
  297. var trs = this.viewContentTableNode.getElements("tr");
  298. trs.each(function(tr){
  299. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  300. }.bind(this));
  301. //this.setContentColumnWidth();
  302. }
  303. this.setViewWidth();
  304. this.addColumnNode.scrollIntoView(true);
  305. }.bind(this));
  306. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  307. },
  308. selected: function(){
  309. if (this.currentSelectedModule){
  310. if (this.currentSelectedModule==this){
  311. return true;
  312. }else{
  313. this.currentSelectedModule.unSelected();
  314. }
  315. }
  316. this.currentSelectedModule = this;
  317. this.showProperty();
  318. },
  319. unSelected: function(){
  320. this.currentSelectedModule = null;
  321. this.hideProperty();
  322. },
  323. loadViewNodes: function(){
  324. this.viewAreaNode = new Element("div#viewAreaNode", {"styles": this.css.viewAreaNode}).inject(this.areaNode);
  325. this.viewTitleNode = new Element("div#viewTitleNode", {"styles": this.css.viewTitleNode}).inject(this.viewAreaNode);
  326. this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.viewTitleNode);
  327. this.addColumnNode = new Element("div", {"styles": this.css.addColumnNode}).inject(this.viewTitleNode);
  328. this.viewTitleContentNode = new Element("div", {"styles": this.css.viewTitleContentNode}).inject(this.viewTitleNode);
  329. this.viewTitleTableNode = new Element("table", {
  330. "styles": this.css.viewTitleTableNode,
  331. "border": "0px",
  332. "cellPadding": "0",
  333. "cellSpacing": "0"
  334. }).inject(this.viewTitleContentNode);
  335. this.viewTitleTrNode = new Element("tr", {"styles": this.css.viewTitleTrNode}).inject(this.viewTitleTableNode);
  336. this.viewContentScrollNode = new Element("div", {"styles": this.css.viewContentScrollNode}).inject(this.viewAreaNode);
  337. this.viewContentNode = new Element("div", {"styles": this.css.viewContentNode}).inject(this.viewContentScrollNode);
  338. MWF.require("MWF.widget.ScrollBar", function(){
  339. new MWF.widget.ScrollBar(this.viewContentScrollNode, {"style": "view", "distance": 100, "indent": false});
  340. }.bind(this));
  341. this.contentLeftNode = new Element("div", {"styles": this.css.contentLeftNode}).inject(this.viewContentNode);
  342. this.contentRightNode = new Element("div", {"styles": this.css.contentRightNode}).inject(this.viewContentNode);
  343. this.viewContentBodyNode = new Element("div", {"styles": this.css.viewContentBodyNode}).inject(this.viewContentNode);
  344. this.viewContentTableNode = new Element("table", {
  345. "styles": this.css.viewContentTableNode,
  346. "border": "0px",
  347. "cellPadding": "0",
  348. "cellSpacing": "0"
  349. }).inject(this.viewContentBodyNode);
  350. //this.designer.addEvent("resize", this.setContentHeight.bind(this));
  351. },
  352. setContentHeight: function(){
  353. var size = this.areaNode.getSize();
  354. var titleSize = this.viewTitleNode.getSize();
  355. var height = size.y-titleSize.y-2;
  356. this.viewContentScrollNode.setStyle("height", height);
  357. var contentSize = this.viewContentBodyNode.getSize();
  358. if (height<contentSize.y) height = contentSize.y+10;
  359. this.viewContentNode.setStyle("height", height);
  360. this.contentLeftNode.setStyle("height", height);
  361. this.contentRightNode.setStyle("height", height);
  362. //this.viewContentBodyNode.setStyle("min-height", height);
  363. },
  364. loadViewColumns: function(){
  365. // for (var i=0; i<10; i++){
  366. if (this.json.data.selectList) {
  367. this.json.data.selectList.each(function (json) {
  368. this.items.push(new MWF.xApplication.query.ViewDesigner.View.Column(json, this));
  369. }.bind(this));
  370. }
  371. // }
  372. },
  373. loadView: function(){
  374. this.loadViewNodes();
  375. this.loadViewColumns();
  376. // this.addTopItemNode.addEvent("click", this.addTopItem.bind(this));
  377. },
  378. setViewWidth: function(){
  379. this.viewAreaNode.setStyle("width", "auto");
  380. this.viewTitleNode.setStyle("width", "auto");
  381. var s1 = this.viewTitleTableNode.getSize();
  382. var s2 = this.refreshNode.getSize();
  383. var s3 = this.addColumnNode.getSize();
  384. var width = s1.x+s2.x+s2.x;
  385. var size = this.areaNode.getSize();
  386. if (width>size.x){
  387. this.viewTitleNode.setStyle("width", ""+width+"px");
  388. this.viewAreaNode.setStyle("width", ""+width+"px");
  389. }else{
  390. this.viewTitleNode.setStyle("width", ""+size.x+"px");
  391. this.viewAreaNode.setStyle("width", ""+size.x+"px");
  392. }
  393. this.setContentColumnWidth();
  394. this.setContentHeight();
  395. },
  396. //setPropertyContent: function(){
  397. // this.designer.propertyIdNode.set("text", this.data.id);
  398. // this.designer.propertyNameNode.set("value", this.data.name);
  399. // this.designer.propertyAliasNode.set("value", this.data.alias);
  400. // this.designer.propertyDescriptionNode.set("value", this.data.description);
  401. //
  402. // this.designer.jsonDomNode.empty();
  403. // MWF.require("MWF.widget.JsonParse", function(){
  404. // this.jsonParse = new MWF.widget.JsonParse(this.data.data, this.designer.jsonDomNode, this.designer.jsonTextAreaNode);
  405. // window.setTimeout(function(){
  406. // this.jsonParse.load();
  407. // }.bind(this), 1);
  408. // }.bind(this));
  409. //},
  410. setAreaNodeSize: function(){
  411. //var size = this.node.getSize();
  412. ////var tabSize = this.tab.tabNodeContainer.getSize();
  413. //var tabSize = this.node.getSize();
  414. //var y = size.y - tabSize.y;
  415. //this.areaNode.setStyle("height", ""+y+"px");
  416. //if (this.editor) if (this.editor.editor) this.editor.editor.resize();
  417. },
  418. // createRootItem: function() {
  419. // this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true));
  420. // },
  421. saveSilence: function(callback){
  422. if (!this.data.name){
  423. this.designer.notice(this.designer.lp.notice.inputName, "error");
  424. return false;
  425. }
  426. this.designer.actions.saveView(this.data, function(json){
  427. this.data.id = json.data.id;
  428. //this.page.textNode.set("text", this.data.name);
  429. if (this.lisNode) {
  430. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  431. }
  432. if (callback) callback();
  433. }.bind(this));
  434. },
  435. save: function(callback){
  436. //if (this.designer.tab.showPage==this.page){
  437. if (!this.data.name){
  438. this.designer.notice(this.designer.lp.notice.inputName, "error");
  439. return false;
  440. }
  441. //}
  442. this.designer.actions.saveView(this.data, function(json){
  443. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  444. this.data.id = json.data.id;
  445. //this.page.textNode.set("text", this.data.name);
  446. if (this.lisNode) {
  447. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  448. }
  449. if (callback) callback();
  450. }.bind(this));
  451. },
  452. explode: function(){},
  453. implode: function(){},
  454. _setEditStyle: function(name, input, oldValue){
  455. if (name=="type"){
  456. this.items.each(function(item){
  457. if (item.property){
  458. var processDiv = item.property.propertyContent.getElements("#"+item.json.id+"dataPathSelectedProcessArea");
  459. var cmsDiv = item.property.propertyContent.getElements("#"+item.json.id+"dataPathSelectedCMSArea");
  460. if (this.json[name]=="cms"){
  461. cmsDiv.setStyle("display", "block");
  462. processDiv.setStyle("display", "none");
  463. }else{
  464. cmsDiv.setStyle("display", "none");
  465. processDiv.setStyle("display", "block");
  466. }
  467. }
  468. }.bind(this));
  469. }
  470. },
  471. saveAs: function(){
  472. var form = new MWF.xApplication.query.ViewDesigner.View.NewNameForm(this, {
  473. name : this.data.name + "_" + MWF.xApplication.query.ViewDesigner.LP.copy,
  474. query : this.data.query || this.data.application,
  475. queryName : this.data.queryName || this.data.applicationName
  476. }, {
  477. onSave : function( data, callback ){
  478. this._saveAs( data, callback );
  479. }.bind(this)
  480. }, {
  481. app: this.designer
  482. });
  483. form.edit()
  484. },
  485. cloneObject : function( obj ){
  486. if (null == obj || "object" != typeof obj) return obj;
  487. if ( typeof obj.length==='number'){ //数组
  488. //print( "array" );
  489. var copy = [];
  490. for (var i = 0, len = obj.length; i < len; ++i) {
  491. copy[i] = this.cloneObject(obj[i]);
  492. }
  493. return copy;
  494. }else{
  495. var copy = {};
  496. for (var attr in obj) {
  497. copy[attr] = this.cloneObject(obj[attr]);
  498. }
  499. return copy;
  500. }
  501. },
  502. _saveAs : function( data , callback){
  503. var _self = this;
  504. var d = this.cloneObject( this.data );
  505. d.isNewView = true;
  506. d.id = this.designer.actions.getUUID();
  507. d.name = data.name;
  508. d.alias = "";
  509. d.query = data.query;
  510. d.queryName = data.queryName;
  511. d.application = data.query;
  512. d.applicationName = data.queryName;
  513. d.pid = d.id + d.id;
  514. delete d[this.data.id+"viewFilterType"];
  515. d[d.id+"viewFilterType"]="custom";
  516. d.data.selectList.each( function( entry ){
  517. entry.id = (new MWF.widget.UUID).id;
  518. }.bind(this));
  519. this.designer.actions.saveView(d, function(json){
  520. this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  521. if (callback) callback();
  522. }.bind(this));
  523. }
  524. });
  525. MWF.xApplication.query.ViewDesigner.View.Column = new Class({
  526. initialize: function(json, view, next){
  527. this.propertyPath = "/x_component_query_ViewDesigner/$View/column.html";
  528. this.view = view;
  529. this.json = json;
  530. this.next = next;
  531. this.css = this.view.css;
  532. this.content = this.view.viewTitleTrNode;
  533. this.domListNode = this.view.domListNode;
  534. this.load();
  535. },
  536. load: function(){
  537. this.areaNode = new Element("td", {"styles": this.css.viewTitleColumnAreaNode});
  538. this.areaNode.store("column", this);
  539. if (this.next){
  540. this.areaNode.inject(this.next.areaNode, "before");
  541. }else{
  542. this.areaNode.inject(this.content);
  543. }
  544. this.node = new Element("div", {
  545. "styles": this.css.viewTitleColumnNode
  546. }).inject(this.areaNode);
  547. this.textNode = new Element("div", {
  548. "styles": this.css.viewTitleColumnTextNode,
  549. "text": this.json.displayName
  550. }).inject(this.node);
  551. this.listNode = new Element("div", {"styles": this.css.cloumnListNode});
  552. if (this.next){
  553. this.listNode.inject(this.next.listNode, "before");
  554. }else{
  555. this.listNode.inject(this.domListNode);
  556. }
  557. var listIconNode = new Element("div", {"styles": this.css.cloumnListIconNode}).inject(this.listNode);
  558. var listTextNode = new Element("div", {"styles": this.css.cloumnListTextNode}).inject(this.listNode);
  559. //var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  560. //if (!listText) listText = "unnamed";
  561. //
  562. //listTextNode.set("text", this.json.displayName+"("+listText+")");
  563. this.resetTextNode();
  564. this._createIconAction();
  565. //if (!this.json.export) this.hideMode();
  566. this.setEvent();
  567. },
  568. setEvent: function(){
  569. this.node.addEvents({
  570. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  571. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_over)}.bind(this),
  572. "mouseout": function(){if (!this.isSelected) if (this.isError){
  573. this.node.setStyles(this.css.viewTitleColumnNode_error)
  574. }else{
  575. this.node.setStyles(this.css.viewTitleColumnNode)
  576. }}.bind(this)
  577. });
  578. this.listNode.addEvents({
  579. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  580. "mouseover": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode_over)}.bind(this),
  581. "mouseout": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode)}.bind(this)
  582. });
  583. },
  584. _createIconAction: function(){
  585. if (!this.actionArea){
  586. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  587. this._createAction({
  588. "name": "move",
  589. "icon": "move1.png",
  590. "event": "mousedown",
  591. "action": "move",
  592. "title": MWF.APPDVD.LP.action.move
  593. });
  594. this._createAction({
  595. "name": "add",
  596. "icon": "add.png",
  597. "event": "click",
  598. "action": "addColumn",
  599. "title": MWF.APPDVD.LP.action.add
  600. });
  601. this._createAction({
  602. "name": "delete",
  603. "icon": "delete1.png",
  604. "event": "click",
  605. "action": "delete",
  606. "title": MWF.APPDVD.LP.action["delete"]
  607. });
  608. }
  609. },
  610. _createAction: function(action){
  611. var actionNode = new Element("div", {
  612. "styles": this.css.actionNodeStyles,
  613. "title": action.title
  614. }).inject(this.actionArea);
  615. actionNode.setStyle("background", "url("+this.view.path+this.view.options.style+"/action/"+action.icon+") no-repeat left center");
  616. actionNode.addEvent(action.event, function(e){
  617. this[action.action](e);
  618. }.bind(this));
  619. actionNode.addEvents({
  620. "mouseover": function(e){
  621. e.target.setStyle("border", "1px solid #999");
  622. }.bind(this),
  623. "mouseout": function(e){
  624. e.target.setStyle("border", "1px solid #F1F1F1");
  625. }.bind(this)
  626. });
  627. },
  628. _setActionAreaPosition: function(){
  629. var p = this.node.getPosition(this.view.areaNode.getOffsetParent());
  630. var y = p.y-25;
  631. var x = p.x;
  632. this.actionArea.setPosition({"x": x, "y": y});
  633. },
  634. _showActions: function(){
  635. if (this.actionArea){
  636. this._setActionAreaPosition();
  637. this.actionArea.setStyle("display", "block");
  638. }
  639. },
  640. _hideActions: function(){
  641. if (this.actionArea) this.actionArea.setStyle("display", "none");
  642. },
  643. selected: function(){
  644. if (this.view.currentSelectedModule){
  645. if (this.view.currentSelectedModule==this){
  646. return true;
  647. }else{
  648. this.view.currentSelectedModule.unSelected();
  649. }
  650. }
  651. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  652. this.listNode.setStyles(this.css.cloumnListNode_selected);
  653. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  654. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  655. this.view.currentSelectedModule = this;
  656. this.isSelected = true;
  657. this._showActions();
  658. this.showProperty();
  659. },
  660. unSelected: function(){
  661. this.view.currentSelectedModule = null;
  662. //this.node.setStyles(this.css.viewTitleColumnNode);
  663. if (this.isError){
  664. this.node.setStyles(this.css.viewTitleColumnNode_error)
  665. }else{
  666. this.node.setStyles(this.css.viewTitleColumnNode)
  667. }
  668. this.listNode.setStyles(this.css.cloumnListNode);
  669. this.isSelected = false;
  670. this._hideActions();
  671. this.hideProperty();
  672. },
  673. showProperty: function(){
  674. if (!this.property){
  675. this.property = new MWF.xApplication.query.ViewDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  676. "path": this.propertyPath,
  677. "onPostLoad": function(){
  678. this.property.show();
  679. var processDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedProcessArea");
  680. var cmsDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedCMSArea");
  681. if (this.view.json.type=="cms"){
  682. processDiv.setStyle("display", "none");
  683. cmsDiv.setStyle("display", "block");
  684. }else{
  685. processDiv.setStyle("display", "block");
  686. cmsDiv.setStyle("display", "none");
  687. }
  688. }.bind(this)
  689. });
  690. this.property.load();
  691. }else{
  692. this.property.show();
  693. }
  694. },
  695. hideProperty: function(){
  696. if (this.property) this.property.hide();
  697. },
  698. _setEditStyle: function(name, input, oldValue){
  699. if (name=="displayName") this.resetTextNode();
  700. if (name=="selectType") this.resetTextNode();
  701. if (name=="attribute") this.resetTextNode();
  702. if (name=="path") this.resetTextNode();
  703. if (name=="column"){
  704. this.view.json.data.orderList.each(function(order){
  705. if (order.column==oldValue) order.column = this.json.column
  706. }.bind(this));
  707. if (this.view.json.data.group.column == oldValue) this.view.json.data.group.column = this.json.column;
  708. }
  709. },
  710. resetTextNode: function(){
  711. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  712. if (!listText) listText = "unnamed";
  713. this.textNode.set("text", this.json.displayName);
  714. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  715. },
  716. "delete": function(e){
  717. var _self = this;
  718. if (!e) e = this.node;
  719. this.view.designer.confirm("warn", e, MWF.APPDVD.LP.notice.deleteColumnTitle, MWF.APPDVD.LP.notice.deleteColumn, 300, 120, function(){
  720. _self.destroy();
  721. this.close();
  722. }, function(){
  723. this.close();
  724. }, null);
  725. },
  726. destroy: function(){
  727. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  728. if (this.actionArea) this.actionArea.destroy();
  729. if (this.listNode) this.listNode.destroy();
  730. if (this.property) this.property.propertyContent.destroy();
  731. var idx = this.view.items.indexOf(this);
  732. if (this.view.viewContentTableNode){
  733. var trs = this.view.viewContentTableNode.getElements("tr");
  734. trs.each(function(tr){
  735. tr.deleteCell(idx);
  736. }.bind(this));
  737. }
  738. if (this.view.json.data.selectList) this.view.json.data.selectList.erase(this.json);
  739. if (this.view.json.data.calculate) if (this.view.json.data.calculate.calculateList) this.view.json.data.calculate.calculateList.erase(this.json);
  740. this.view.items.erase(this);
  741. if (this.view.property) this.view.property.loadStatColumnSelect();
  742. this.areaNode.destroy();
  743. this.view.selected();
  744. this.view.setViewWidth();
  745. MWF.release(this);
  746. delete this;
  747. },
  748. addColumn: function(e, data){
  749. MWF.require("MWF.widget.UUID", function(){
  750. var json;
  751. if (data){
  752. json = Object.clone(data);
  753. json.id = (new MWF.widget.UUID).id;
  754. json.column = (new MWF.widget.UUID).id;
  755. }else{
  756. var id = (new MWF.widget.UUID).id;
  757. json = {
  758. "id": id,
  759. "column": id,
  760. "displayName": this.view.designer.lp.unnamed,
  761. "orderType": "original"
  762. };
  763. }
  764. var idx = this.view.json.data.selectList.indexOf(this.json);
  765. this.view.json.data.selectList.splice(idx, 0, json);
  766. var column = new MWF.xApplication.query.ViewDesigner.View.Column(json, this.view, this);
  767. this.view.items.splice(idx, 0, column);
  768. column.selected();
  769. if (this.view.viewContentTableNode){
  770. var trs = this.view.viewContentTableNode.getElements("tr");
  771. trs.each(function(tr){
  772. var td = tr.insertCell(idx);
  773. td.setStyles(this.css.viewContentTdNode);
  774. }.bind(this));
  775. }
  776. this.view.setViewWidth();
  777. }.bind(this));
  778. },
  779. move: function(e){
  780. var columnNodes = [];
  781. this.view.items.each(function(item){
  782. if (item!=this){
  783. columnNodes.push(item.areaNode);
  784. }
  785. }.bind(this));
  786. this._createMoveNode();
  787. this._setNodeMove(columnNodes, e);
  788. },
  789. _createMoveNode: function(){
  790. this.moveNode = new Element("div", {"text": this.node.get("text")});
  791. this.moveNode.inject(this.view.designer.content);
  792. this.moveNode.setStyles({
  793. "border": "2px dashed #ffa200",
  794. "opacity": 0.7,
  795. "height": "30px",
  796. "line-height": "30px",
  797. "padding": "0px 10px",
  798. "position": "absolute"
  799. });
  800. },
  801. _setMoveNodePosition: function(e){
  802. var x = e.page.x+2;
  803. var y = e.page.y+2;
  804. this.moveNode.positionTo(x, y);
  805. },
  806. createMoveFlagNode: function(){
  807. this.moveFlagNode = new Element("td", {"styles": this.css.moveFlagNode});
  808. },
  809. _setNodeMove: function(droppables, e){
  810. this._setMoveNodePosition(e);
  811. var movePosition = this.moveNode.getPosition();
  812. var moveSize = this.moveNode.getSize();
  813. var contentPosition = this.content.getPosition();
  814. var contentSize = this.content.getSize();
  815. var nodeDrag = new Drag.Move(this.moveNode, {
  816. "droppables": droppables,
  817. "limit": {
  818. "x": [contentPosition.x, contentPosition.x+contentSize.x],
  819. "y": [movePosition.y, movePosition.y+moveSize.y]
  820. },
  821. "onEnter": function(dragging, inObj){
  822. if (!this.moveFlagNode) this.createMoveFlagNode();
  823. this.moveFlagNode.inject(inObj, "before");
  824. }.bind(this),
  825. "onLeave": function(dragging, inObj){
  826. if (this.moveFlagNode){
  827. this.moveFlagNode.dispose();
  828. }
  829. }.bind(this),
  830. "onDrop": function(dragging, inObj){
  831. if (inObj){
  832. this.areaNode.inject(inObj, "before");
  833. var column = inObj.retrieve("column");
  834. this.listNode.inject(column.listNode, "before");
  835. var idx = this.view.json.data.selectList.indexOf(column.json);
  836. this.view.json.data.selectList.erase(this.json);
  837. this.view.items.erase(this);
  838. this.view.json.data.selectList.splice(idx, 0, this.json);
  839. this.view.items.splice(idx, 0, this);
  840. if (this.moveNode) this.moveNode.destroy();
  841. if (this.moveFlagNode) this.moveFlagNode.destroy();
  842. this._setActionAreaPosition();
  843. }else{
  844. if (this.moveNode) this.moveNode.destroy();
  845. if (this.moveFlagNode) this.moveFlagNode.destroy();
  846. }
  847. }.bind(this),
  848. "onCancel": function(dragging){
  849. if (this.moveNode) this.moveNode.destroy();
  850. if (this.moveFlagNode) this.moveFlagNode.destroy();
  851. }.bind(this)
  852. });
  853. nodeDrag.start(e);
  854. }
  855. //hideMode: function(){
  856. // if (!this.columnHideFlagNode){
  857. // this.columnHideFlagNode = new Element("div", {"styles": this.view.css.columnHideFlagNode}).inject(this.node);
  858. // }
  859. //},
  860. //showMode: function(){
  861. // if (this.columnHideFlagNode) this.columnHideFlagNode.destroy();
  862. // this.columnHideFlagNode = null;
  863. //}
  864. });