View.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.QueryViewDesigner = MWF.xApplication.cms.QueryViewDesigner || {};
  4. MWF.CMSQVD = MWF.xApplication.cms.QueryViewDesigner;
  5. MWF.require("MWF.xScript.CMSMacro", null, false);
  6. MWF.xDesktop.requireApp("cms.QueryViewDesigner", "lp."+MWF.language, null, false);
  7. MWF.xDesktop.requireApp("cms.QueryViewDesigner", "Property", null, false);
  8. MWF.xDesktop.requireApp("process.ViewDesigner", "View", null, false);
  9. MWF.xApplication.cms.QueryViewDesigner.View = new Class({
  10. Extends: MWF.xApplication.process.ViewDesigner.View,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "isView": false,
  15. "showTab": true,
  16. "propertyPath": "/x_component_cms_QueryViewDesigner/$View/view.html"
  17. },
  18. initialize: function(designer, data, options){
  19. this.setOptions(options);
  20. this.path = "/x_component_process_ViewDesigner/$View/";
  21. this.cssPath = "/x_component_process_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){
  36. this.data.appId = this.designer.application.id;
  37. this.data.appName = this.designer.application.appName || this.designer.application.appName;
  38. if( !this.data.creatorPerson )this.data.creatorPerson = layout.desktop.session.user.distinguishedName;
  39. }
  40. this.isNewView = (this.data.id) ? false : true;
  41. this.items = [];
  42. this.view = this;
  43. this.autoSave();
  44. this.designer.addEvent("queryClose", function(){
  45. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  46. }.bind(this));
  47. },
  48. showProperty: function(){
  49. if (!this.property){
  50. this.property = new MWF.xApplication.cms.QueryViewDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  51. "path": this.options.propertyPath,
  52. "onPostLoad": function(){
  53. this.property.show();
  54. }.bind(this)
  55. });
  56. this.property.load();
  57. }else{
  58. this.property.show();
  59. }
  60. },
  61. loadViewData: function(){
  62. if (this.data.id){
  63. this.saveSilence(function(){
  64. this.viewContentBodyNode.empty();
  65. this.viewContentTableNode = new Element("table", {
  66. "styles": this.css.viewContentTableNode,
  67. "border": "0px",
  68. "cellPadding": "0",
  69. "cellSpacing": "0"
  70. }).inject(this.viewContentBodyNode);
  71. this.designer.actions.loadQueryView(this.data.id, function(json){
  72. var entries = {};
  73. json.data.selectEntryList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  74. if (this.json.data.groupEntry.column){
  75. if (json.data.groupGrid.length){
  76. json.data.groupGrid.each(function(line, idx){
  77. var groupTr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  78. var colSpan = this.items.length;
  79. var td = new Element("td", {"styles": this.css.viewContentGroupTdNode, "colSpan": colSpan}).inject(groupTr);
  80. var groupAreaNode = new Element("div", {"styles": this.css.viewContentTdGroupNode}).inject(td);
  81. var groupIconNode = new Element("div", {"styles": this.css.viewContentTdGroupIconNode}).inject(groupAreaNode);
  82. var groupTextNode = new Element("div", {"styles": this.css.viewContentTdGroupTextNode}).inject(groupAreaNode);
  83. groupTextNode.set("text", line.group);
  84. var subtrs = [];
  85. line.list.each(function(entry){
  86. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  87. tr.setStyle("display", "none");
  88. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  89. Object.each(entry.data, function(d, k){
  90. if (k!=this.json.data.groupEntry.column){
  91. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  92. td.set("text", (entries[k].code) ? MWF.CMSMacro.exec(entries[k].code, {"value": d, "data": json.data}) : d);
  93. }
  94. }.bind(this));
  95. subtrs.push(tr)
  96. }.bind(this));
  97. groupAreaNode.store("subtrs", subtrs);
  98. var _self = this;
  99. groupAreaNode.addEvent("click", function(){
  100. var subtrs = this.retrieve("subtrs");
  101. var iconNode = groupAreaNode.getFirst("div");
  102. if (subtrs[0]){
  103. if (subtrs[0].getStyle("display")=="none"){
  104. subtrs.each(function(subtr){ subtr.setStyle("display", "table-row"); });
  105. iconNode.setStyle("background", "url("+"/x_component_process_ViewDesigner/$View/default/icon/down.png) center center no-repeat");
  106. }else{
  107. subtrs.each(function(subtr){ subtr.setStyle("display", "none"); });
  108. iconNode.setStyle("background", "url("+"/x_component_process_ViewDesigner/$View/default/icon/right.png) center center no-repeat");
  109. }
  110. }
  111. _self.setContentHeight();
  112. });
  113. }.bind(this));
  114. this.setContentColumnWidth();
  115. this.setContentHeight();
  116. }
  117. }else{
  118. if (json.data.grid.length){
  119. json.data.grid.each(function(line, idx){
  120. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  121. Object.each(line.data, function(d, k){
  122. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  123. td.set("text", (entries[k].code) ? MWF.CMSMacro.exec(entries[k].code, {"value": d, "data": json.data}) : d);
  124. }.bind(this));
  125. }.bind(this));
  126. this.setContentColumnWidth();
  127. this.setContentHeight();
  128. }
  129. }
  130. }.bind(this));
  131. }.bind(this));
  132. }
  133. },
  134. addColumn: function(){
  135. MWF.require("MWF.widget.UUID", function(){
  136. var id = (new MWF.widget.UUID).id;
  137. var json = {
  138. "id": id,
  139. "column": id,
  140. "displayName": this.designer.lp.unnamed,
  141. "selectType": "attribute",
  142. "orderType": "original"
  143. };
  144. if (!this.json.data.selectEntryList) this.json.data.selectEntryList = [];
  145. this.json.data.selectEntryList.push(json);
  146. var column = new MWF.xApplication.cms.QueryViewDesigner.View.Column(json, this);
  147. this.items.push(column);
  148. column.selected();
  149. if (this.viewContentTableNode){
  150. var trs = this.viewContentTableNode.getElements("tr");
  151. trs.each(function(tr){
  152. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  153. }.bind(this));
  154. //this.setContentColumnWidth();
  155. }
  156. this.setViewWidth();
  157. this.addColumnNode.scrollIntoView(true);
  158. }.bind(this));
  159. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  160. },
  161. loadViewColumns: function(){
  162. // for (var i=0; i<10; i++){
  163. if (this.json.data.selectEntryList) {
  164. this.json.data.selectEntryList.each(function (json) {
  165. this.items.push(new MWF.xApplication.cms.QueryViewDesigner.View.Column(json, this));
  166. }.bind(this));
  167. }
  168. // }
  169. },
  170. createRootItem: function() {
  171. this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true));
  172. },
  173. saveSilence: function(callback){
  174. if (!this.data.name){
  175. this.designer.notice(this.designer.lp.notice.inputName, "error");
  176. return false;
  177. }
  178. if( this.isNewView ){
  179. this.data.isNewView = true
  180. }
  181. this.designer.actions.saveQueryView(this.data, function(json){
  182. this.isNewView = false;
  183. this.data.id = json.data.id;
  184. //this.page.textNode.set("text", this.data.name);
  185. if (this.lisNode) {
  186. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  187. }
  188. if (callback) callback();
  189. }.bind(this));
  190. },
  191. save: function(callback){
  192. //if (this.designer.tab.showPage==this.page){
  193. if (!this.data.name){
  194. this.designer.notice(this.designer.lp.notice.inputName, "error");
  195. return false;
  196. }
  197. //}
  198. if( this.isNewView ){
  199. this.data.isNewView = true
  200. }
  201. this.designer.actions.saveQueryView(this.data, function(json){
  202. this.isNewView = false;
  203. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  204. this.data.id = json.data.id;
  205. //this.page.textNode.set("text", this.data.name);
  206. if (this.lisNode) {
  207. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  208. }
  209. if (callback) callback();
  210. }.bind(this));
  211. },
  212. saveAs: function(){
  213. var form = new MWF.xApplication.cms.QueryViewDesigner.View.NewName(this, {
  214. name : this.data.name + "_副本"
  215. }, {
  216. onSave : function( data, callback ){
  217. this._saveAs( data.name, callback );
  218. }.bind(this)
  219. }, {
  220. app: this.designer
  221. });
  222. form.edit()
  223. },
  224. clone : function( obj ){
  225. if (null == obj || "object" != typeof obj) return obj;
  226. if ( typeof obj.length==='number'){ //数组
  227. //print( "array" );
  228. var copy = [];
  229. for (var i = 0, len = obj.length; i < len; ++i) {
  230. copy[i] = this.clone(obj[i]);
  231. }
  232. return copy;
  233. }else{
  234. var copy = {};
  235. for (var attr in obj) {
  236. copy[attr] = this.clone(obj[attr]);
  237. }
  238. return copy;
  239. }
  240. },
  241. _saveAs : function( name , callback){
  242. var _self = this;
  243. var d = this.clone( this.data );
  244. d.isNewView = true;
  245. d.id = this.designer.actions.getUUID();
  246. d.name = name;
  247. d.alias = "";
  248. delete d[this.data.id+"viewFilterType"];
  249. d[d.id+"viewFilterType"]="custom";
  250. d.data.selectEntryList.each( function( entry ){
  251. entry.id = (new MWF.widget.UUID).id;
  252. }.bind(this));
  253. this.designer.actions.saveQueryView(d, function(json){
  254. this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  255. if (callback) callback();
  256. }.bind(this));
  257. }
  258. });
  259. MWF.xApplication.cms.QueryViewDesigner.View.Column = new Class({
  260. Extends : MWF.xApplication.process.ViewDesigner.View.Column,
  261. initialize: function(json, view, next){
  262. this.propertyPath = "/x_component_cms_QueryViewDesigner/$View/column.html";
  263. this.view = view;
  264. this.json = json;
  265. this.next = next;
  266. this.css = this.view.css;
  267. this.content = this.view.viewTitleTrNode;
  268. this.domListNode = this.view.domListNode;
  269. this.load();
  270. },
  271. showProperty: function(){
  272. if (!this.property){
  273. this.property = new MWF.xApplication.cms.QueryViewDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  274. "path": this.propertyPath,
  275. "onPostLoad": function(){
  276. this.property.show();
  277. }.bind(this)
  278. });
  279. this.property.load();
  280. }else{
  281. this.property.show();
  282. }
  283. }
  284. });
  285. MWF.xApplication.cms.QueryViewDesigner.View.NewName = new Class({
  286. Extends: MPopupForm,
  287. Implements: [Options, Events],
  288. options: {
  289. "style": "blue",
  290. "width": 700,
  291. //"height": 300,
  292. "height": "220",
  293. "hasTop": true,
  294. "hasIcon": false,
  295. "draggable": true,
  296. "title" : "新数据视图名称"
  297. },
  298. _createTableContent: function () {
  299. var html = "<table width='80%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin: 20px auto 0px auto; '>" +
  300. "<tr><td styles='formTableTitle' lable='name' width='25%'></td>" +
  301. " <td styles='formTableValue' item='name' colspan='3'></td></tr>" +
  302. "</table>";
  303. this.formTableArea.set("html", html);
  304. MWF.xDesktop.requireApp("Template", "MForm", function () {
  305. this.form = new MForm(this.formTableArea, this.data || {}, {
  306. isEdited: true,
  307. style: "cms",
  308. hasColon: true,
  309. itemTemplate: {
  310. name: {text: "名称", notEmpty: true}
  311. }
  312. }, this.app);
  313. this.form.load();
  314. }.bind(this),null, true)
  315. },
  316. ok: function(){
  317. var data = this.form.getResult(true,null,true,false,true);
  318. if( data ){
  319. this.fireEvent("save", [data , function(){
  320. this.close();
  321. }.bind(this)])
  322. }
  323. }
  324. });