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