View.js 40 KB

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