View.js 40 KB

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