View.js 39 KB

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