ViewExplorer.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. MWF.xApplication.cms.Module = MWF.xApplication.cms.Module || {};
  3. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  4. MWF.xDesktop.requireApp("cms.Module", "lp."+MWF.language, null, false);
  5. MWF.xDesktop.requireApp("cms.Module", "package", null, false);
  6. MWF.xDesktop.requireApp("process.Application", "Viewer", null, false);
  7. MWF.xDesktop.requireApp("query.Query", "Viewer", null, false);
  8. MWF.xApplication.cms.Module.ViewExplorer = new Class({
  9. Extends: MWF.widget.Common,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "isAdmin": false,
  14. "searchKey" : ""
  15. },
  16. initialize: function( node, app, columnData, categoryData, revealData, options, searchNode ){
  17. this.setOptions(options);
  18. this.node = node;
  19. this.app = app;
  20. this.columnData = columnData;
  21. this.categoryData = categoryData;
  22. this.revealData = revealData;
  23. this.searchNode = searchNode;
  24. this.path = "/x_component_cms_Module/$ViewExplorer/";
  25. this.cssPath = "/x_component_cms_Module/$ViewExplorer/"+this.options.style+"/css.wcss";
  26. this._loadCss();
  27. },
  28. load : function(){
  29. this.loadContentNode();
  30. if( this.revealData.viewType ){
  31. this.loadQuryView(); //QeuryView
  32. }else{
  33. this.loadView(); //CMSView
  34. }
  35. },
  36. loadContentNode: function(){
  37. this.elementContentNode = new Element("div", {
  38. "styles": this.css.elementContentNode
  39. }).inject(this.node);
  40. this.searchContainer = new Element("div",{
  41. "styles" : this.css.searchContainer
  42. }).inject( this.searchNode );
  43. this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  44. },
  45. loadQuryView : function(){
  46. var viewJson = {
  47. "application": this.revealData.appName,
  48. "viewName": this.revealData.name,
  49. "isTitle": "yes",
  50. "select": "none",
  51. "titleStyles": this.css.normalThNode,
  52. "itemStyles": {},
  53. "isExpand": "no",
  54. "filter": []
  55. };
  56. this.view = new MWF.xApplication.cms.Module.QueryViewer(this.elementContentNode, viewJson, {
  57. "hasAction" : this.options.isAdmin,
  58. "resizeNode": true,
  59. "onSelect": function(){
  60. this.fireEvent("select");
  61. }.bind(this)
  62. }, this.app, this.searchContainer);
  63. this.setContentSize();
  64. },
  65. loadView : function(){
  66. var viewJson = {
  67. "application": this.columnData.id,
  68. "viewName": this.revealData.name,
  69. "isTitle": "yes",
  70. "select": "none", //none , single, multi
  71. "titleStyles": this.css.normalThNode,
  72. "isExpand": "no",
  73. "itemStyles": {}
  74. };
  75. this.view = new MWF.xApplication.cms.Module.Viewer(this.elementContentNode, viewJson, {
  76. "type" : "cms",
  77. "hasAction" : this.options.isAdmin,
  78. "actions": {
  79. //"lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  80. //"getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"},
  81. "lookup": {"uri": "/jaxrs/view/{view}/execute", "method":"PUT"},
  82. "getView": {"uri": "/jaxrs/view/{view}"},
  83. "deleteDocument" : {"uri":"/jaxrs/document/{id}","method": "DELETE"}
  84. },
  85. "actionRoot": "x_query_assemble_surface",
  86. "resizeNode": true,
  87. "onSelect": function(){
  88. this.fireEvent("select");
  89. }.bind(this)
  90. }, this.app, this.searchContainer);
  91. this.setContentSize();
  92. },
  93. setContentSize: function(){
  94. var toolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : {"x":0,"y":0};
  95. var titlebarSize = {"x":0,"y":0}; //this.app.titleBar ? this.app.titleBar.getSize() : {"x":0,"y":0};
  96. var nodeSize = this.app.node.getSize();
  97. var pt = 0; //this.elementContentNode.getStyle("padding-top").toFloat();
  98. var pb = 0; // this.elementContentNode.getStyle("padding-bottom").toFloat();
  99. var filterConditionSize = this.filterConditionNode ? this.filterConditionNode.getSize() : {"x":0,"y":0};
  100. var height = nodeSize.y-toolbarSize.y-pt-pb-filterConditionSize.y-titlebarSize.y;
  101. this.elementContentNode.setStyle("height", ""+height+"px");
  102. if( this.view )this.view.setContentHeight();
  103. }
  104. });
  105. MWF.xApplication.cms.Module.Viewer = new Class({
  106. Implements: [Options, Events],
  107. Extends: MWF.xApplication.process.Application.Viewer,
  108. options: {
  109. "style": "default",
  110. "hasAction" : false, //cxy add
  111. "resizeNode": true,
  112. "actions": {
  113. //"lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  114. //"getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"},
  115. "lookup": {"uri": "/jaxrs/view/{view}/execute", "method":"PUT"},
  116. "getView": {"uri": "/jaxrs/view/{view}"},
  117. "listWorkByJob": {"uri": "/jaxrs/job/{job}/find/work/workcompleted"},
  118. "listTaskByWork": {"uri": "/jaxrs/work/{id}/assignment/manage"}
  119. },
  120. "actionRoot": "x_processplatform_assemble_surface"
  121. },
  122. initialize: function(container, json, options, app, searchContainer){
  123. this.setOptions(options);
  124. this.app = app;
  125. this.searchContainer = searchContainer;
  126. this.path = "/x_component_cms_Module/$ViewExplorer/";
  127. this.cssPath = "/x_component_cms_Module/$ViewExplorer/"+this.options.style+"/viewer.wcss";
  128. this._loadCss();
  129. this.lp = MWF.xApplication.process.Application.LP;
  130. this.container = $(container);
  131. this.json = json;
  132. this.viewJson = null;
  133. this.filterItems = [];
  134. this.searchStatus = "none"; //none, custom, default
  135. this.items = [];
  136. this.selectedItems = [];
  137. this.hideColumns = [];
  138. this.openColumns = [];
  139. this.gridJson = null;
  140. this.init(function(){
  141. this.load();
  142. }.bind(this));
  143. },
  144. createViewNode: function(data){
  145. this.viewAreaNode.empty();
  146. this.contentAreaNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
  147. this.viewTable = new Element("table", {
  148. "styles": this.css.viewTitleTableNode,
  149. "border": "0px",
  150. "cellPadding": "0",
  151. "cellSpacing": "0"
  152. }).inject(this.contentAreaNode);
  153. this.createLoadding();
  154. if (this.json.isTitle!=="no"){
  155. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  156. //if (this.json.select==="single" || this.json.select==="multi") {
  157. this.selectTitleCell = new Element("td", {
  158. "styles": this.css.viewTitleCellNode
  159. }).inject(this.viewTitleLine);
  160. this.selectTitleCell.setStyle("width", "10px");
  161. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  162. //}
  163. this.entries = {};
  164. this.viewJson.selectList.each(function(column){
  165. this.entries[column.column] = column;
  166. if (!column.hideColumn){
  167. var viewCell = new Element("td", {
  168. "styles": this.css.viewTitleCellNode,
  169. "text": column.displayName
  170. }).inject(this.viewTitleLine);
  171. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  172. }else{
  173. this.hideColumns.push(column.column);
  174. }
  175. if (column.allowOpen) this.openColumns.push(column.column);
  176. }.bind(this));
  177. if( this.options.hasAction ){
  178. var viewCell = new Element("td", {
  179. "styles": this.css.viewTitleCellNode,
  180. "text": "操作"
  181. }).inject(this.viewTitleLine);
  182. viewCell.setStyle("width","40px");
  183. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  184. }
  185. this.lookup(data);
  186. }else{
  187. this.viewJson.selectEntryList.each(function(column){
  188. if (column.hideColumn) this.hideColumns.push(column.column);
  189. if (!column.allowOpen) this.openColumns.push(column.column);
  190. }.bind(this));
  191. this.lookup(data);
  192. }
  193. },
  194. lookup: function(data){
  195. this.getLookupAction(function(){
  196. if (this.json.application){
  197. this.lookupAction.invoke({"name": "lookup","async": true, "data": (data || null), "parameter": {"view": this.json.name, "application": this.json.application},"success": function(json){
  198. this.viewData = json.data;
  199. if (this.viewJson.group.column){
  200. this.gridJson = json.data.groupGrid;
  201. this.loadGroupData();
  202. }else{
  203. this.gridJson = json.data.grid;
  204. this.loadData();
  205. }
  206. if (this.loadingAreaNode){
  207. this.loadingAreaNode.destroy();
  208. this.loadingAreaNode = null;
  209. }
  210. }.bind(this)});
  211. }
  212. }.bind(this));
  213. },
  214. loadLayout: function(){
  215. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  216. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.searchContainer || this.node );
  217. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  218. },
  219. loadData: function(){
  220. if (this.gridJson.length){
  221. this.gridJson.each(function(line, i){
  222. this.items.push(new MWF.xApplication.cms.Module.Viewer.Item(this, line, null, i));
  223. }.bind(this));
  224. }
  225. },
  226. loadGroupData: function(){
  227. if (this.selectTitleCell){
  228. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_process_Application/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  229. this.selectTitleCell.setStyle("cursor", "pointer");
  230. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  231. }
  232. if (this.gridJson.length){
  233. this.gridJson.each(function(data){
  234. this.items.push(new MWF.xApplication.cms.Module.Viewer.ItemCategory(this, data));
  235. }.bind(this));
  236. if (this.json.isExpand=="yes")this.expandOrCollapseAll();
  237. }
  238. },
  239. setContentHeight: function(){
  240. if( this.node && this.searchAreaNode && this.viewAreaNode ){
  241. var size = this.node.getSize();
  242. var searchSize = this.searchAreaNode.getSize();
  243. var h = size.y-searchSize.y;
  244. this.viewAreaNode.setStyle("height", ""+h+"px");
  245. }
  246. }
  247. });
  248. MWF.xApplication.cms.Module.Viewer.Item = new Class({
  249. Extends : MWF.xApplication.process.Application.Viewer.Item,
  250. load: function(){
  251. var _self = this;
  252. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  253. if (this.prev){
  254. this.node.inject(this.prev.node, "after");
  255. }else{
  256. this.node.inject(this.view.viewTable);
  257. }
  258. this.node.addEvents({
  259. mouseover : function(){ this.setStyles(_self.css.viewContentTrNode_over) },
  260. mouseout : function(){ this.setStyles(_self.css.viewContentTrNode) }
  261. });
  262. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  263. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  264. this.selectTd.setStyles({"cursor": "pointer"});
  265. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  266. //}
  267. Object.each(this.data.data, function(cell, k){
  268. if (this.view.hideColumns.indexOf(k)===-1){
  269. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  270. if (k!== this.view.viewJson.group.column){
  271. var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  272. td.set("text", v);
  273. }
  274. if (this.view.openColumns.indexOf(k)!==-1){
  275. this.setOpenWork(td)
  276. }
  277. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  278. }
  279. }.bind(this));
  280. if( this.view.options.hasAction ){
  281. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  282. this.loadActions( td );
  283. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  284. }
  285. this.setEvent();
  286. },
  287. loadActions : function( container ){
  288. this.deleteNode = new Element("div", {"styles": this.css.actionDeleteNode, "title": "删除"}).inject(container);
  289. this.deleteNode.addEvents({
  290. "mouseover": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  291. "mouseout": function(){this.deleteNode.setStyles(this.css.actionDeleteNode);}.bind(this),
  292. "mousedown": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_down);}.bind(this),
  293. "mouseup": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  294. "click": function(e){
  295. this.remove(e);
  296. e.stopPropagation();
  297. }.bind(this)
  298. });
  299. this.editNode = new Element("div", {"styles": this.css.actionEditNode, "title": "编辑"}).inject(container);
  300. this.editNode.addEvents({
  301. "mouseover": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  302. "mouseout": function(){this.editNode.setStyles(this.css.actionEditNode);}.bind(this),
  303. "mousedown": function(){this.editNode.setStyles(this.css.actionEditNode_down);}.bind(this),
  304. "mouseup": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  305. "click": function(e){
  306. this.editCMSDocument();
  307. e.stopPropagation();
  308. }.bind(this)
  309. });
  310. },
  311. setOpenWork: function(td){
  312. td.setStyle("cursor", "pointer");
  313. td.addEvent("click", function(){
  314. this.openCMSDocument()
  315. }.bind(this));
  316. },
  317. openCMSDocument : function( isEdited ){
  318. var appId = "cms.Document"+this.data.bundle;
  319. if (layout.desktop.apps[appId]){
  320. layout.desktop.apps[appId].setCurrent();
  321. }else {
  322. var options = {
  323. "documentId": this.data.bundle,
  324. "readonly" : !isEdited
  325. };
  326. layout.desktop.openApplication(null, "cms.Document", options);
  327. }
  328. },
  329. editCMSDocument : function(){
  330. this.openCMSDocument( true );
  331. },
  332. remove: function(e){
  333. var text = "删除后不能恢复,你确定要删除该文档?";
  334. var _self = this;
  335. this.node.setStyles(this.css.viewContentTrNode_delete);
  336. this.readyRemove = true;
  337. this.view.app.confirm("warn", e, "删除确认", text, 350, 120, function(){
  338. _self.removeCMSDocument(_self, false);
  339. this.close();
  340. }, function(){
  341. _self.node.setStyles(_self.css.viewContentTrNode );
  342. _self.readyRemove = false;
  343. this.close();
  344. });
  345. },
  346. removeCMSDocument: function(){
  347. var id = this.data.bundle;
  348. MWF.Actions.get("x_cms_assemble_control").removeDocument(id, function(json){
  349. //this.viewJson = JSON.decode(json.data.data);
  350. //this.json = Object.merge(this.json, json.data);
  351. this.readyRemove = false;
  352. this.node.destroy();
  353. this.view.app.notice("删除成功", "success");
  354. MWF.release(this);
  355. }.bind(this));
  356. }
  357. });
  358. MWF.xApplication.cms.Module.Viewer.ItemCategory = new Class({
  359. Extends : MWF.xApplication.process.Application.Viewer.ItemCategory,
  360. load: function(){
  361. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  362. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  363. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  364. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  365. //}
  366. var colsapn = this.view.viewJson.selectList.length;
  367. if( this.view.options.hasAction ){
  368. colsapn ++
  369. }
  370. this.categoryTd = new Element("td", {
  371. "styles": this.css.viewContentCategoryTdNode,
  372. "colspan": colsapn
  373. }).inject(this.node);
  374. this.groupColumn = null;
  375. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  376. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  377. this.groupColumn = this.view.viewJson.selectList[c];
  378. break;
  379. }
  380. }
  381. if (this.groupColumn){
  382. var text = (this.groupColumn.code) ? MWF.Macro.exec(this.groupColumn.code, {"value": this.data.group, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : this.data.group;
  383. }else{
  384. var text = this.data.group;
  385. }
  386. this.categoryTd.set("html", "<span style='font-family: Webdings'><img src='/x_component_process_Application/$Viewer/"+this.view.options.style+"/icon/expand.png'/></span> "+text);
  387. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  388. this.setEvent();
  389. },
  390. expand: function(){
  391. this.items.each(function(item){
  392. item.node.setStyle("display", "table-row");
  393. }.bind(this));
  394. this.node.getElement("span").set("html", "<img src='/x_component_process_Application/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  395. if (!this.loadChild){
  396. //window.setTimeout(function(){
  397. this.data.list.each(function(line){
  398. this.items.push(new MWF.xApplication.cms.Module.Viewer.Item(this.view, line, this));
  399. }.bind(this));
  400. this.loadChild = true;
  401. //}.bind(this), 10);
  402. }
  403. }
  404. });
  405. MWF.xApplication.cms.Module.QueryViewer = new Class({
  406. Implements: [Options, Events],
  407. Extends: MWF.QViewer,
  408. options: {
  409. "style": "default",
  410. "hasAction" : false, //cxy add
  411. "resizeNode": true,
  412. "paging" : "scroll",
  413. "perPageCount" : 50
  414. },
  415. initialize: function(container, json, options, app, searchContainer){
  416. this.setOptions(options);
  417. this.app = app;
  418. this.searchContainer = searchContainer;
  419. this.path = "/x_component_cms_Module/$ViewExplorer/";
  420. this.cssPath = "/x_component_cms_Module/$ViewExplorer/"+this.options.style+"/viewer.wcss";
  421. this._loadCss();
  422. this.lp = MWF.xApplication.query.Query.LP;
  423. this.container = $(container);
  424. this.json = json;
  425. this.viewJson = null;
  426. this.filterItems = [];
  427. this.searchStatus = "none"; //none, custom, default
  428. this.items = [];
  429. this.selectedItems = [];
  430. this.hideColumns = [];
  431. this.openColumns = [];
  432. this.gridJson = null;
  433. this.init(function(){
  434. this.load();
  435. }.bind(this));
  436. },
  437. createViewNode: function(data){
  438. this.viewAreaNode.empty();
  439. this.contentAreaNode = new Element("div.contentAreaNode", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
  440. this.viewTable = new Element("table.viewTable", {
  441. "styles": this.css.viewTitleTableNode,
  442. "border": "0px",
  443. "cellPadding": "0",
  444. "cellSpacing": "0"
  445. }).inject(this.contentAreaNode);
  446. this.createLoadding();
  447. if (this.json.isTitle!=="no"){
  448. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  449. //if (this.json.select==="single" || this.json.select==="multi") {
  450. this.selectTitleCell = new Element("td", {
  451. "styles": this.css.viewTitleCellNode
  452. }).inject(this.viewTitleLine);
  453. this.selectTitleCell.setStyle("width", "10px");
  454. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  455. //}
  456. this.entries = {};
  457. this.viewJson.selectList.each(function(column){
  458. this.entries[column.column] = column;
  459. if (!column.hideColumn){
  460. var viewCell = new Element("td", {
  461. "styles": this.css.viewTitleCellNode,
  462. "text": column.displayName
  463. }).inject(this.viewTitleLine);
  464. var size = MWF.getTextSize(column.displayName, this.css.viewTitleCellNode);
  465. viewCell.setStyle("min-width", ""+size.x+"px");
  466. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  467. }else{
  468. this.hideColumns.push(column.column);
  469. }
  470. if (column.allowOpen) this.openColumns.push(column.column);
  471. }.bind(this));
  472. if( this.options.hasAction ){
  473. var viewCell = new Element("td", {
  474. "styles": this.css.viewTitleCellNode,
  475. "text": "操作"
  476. }).inject(this.viewTitleLine);
  477. viewCell.setStyle("width","40px");
  478. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  479. }
  480. this.lookup(data);
  481. }else{
  482. this.viewJson.selectList.each(function(column){
  483. if (column.hideColumn) this.hideColumns.push(column.column);
  484. if (!column.allowOpen) this.openColumns.push(column.column);
  485. }.bind(this));
  486. this.lookup(data);
  487. }
  488. },
  489. loadLayout: function(){
  490. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  491. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.searchContainer || this.node );
  492. this.viewAreaNode = new Element("div.viewAreaNode", {"styles": this.css.viewAreaNode}).inject(this.node);
  493. },
  494. //loadData: function(){
  495. // if (this.gridJson.length){
  496. // this.gridJson.each(function(line, i){
  497. // this.items.push(new MWF.xApplication.cms.Module.QueryViewer.Item(this, line, null, i));
  498. // }.bind(this));
  499. // }
  500. //},
  501. loadData: function(){
  502. if (this.gridJson.length){
  503. if( !this.options.paging ){
  504. this.gridJson.each(function(line, i){
  505. this.items.push(new MWF.xApplication.cms.Module.QueryViewer.Item(this, line, null, i));
  506. }.bind(this));
  507. }else{
  508. this.loadPaging();
  509. }
  510. }
  511. },
  512. loadPaging : function(){
  513. this.isItemsLoading = false;
  514. this.pageNumber = 0;
  515. this.isItemsLoaded = false;
  516. this.isSetedScroll = false;
  517. this.setScroll();
  518. this.loadDataByPaging()
  519. },
  520. setScroll : function(){
  521. if( this.options.paging && !this.isSetedScroll ){
  522. this.contentAreaNode.setStyle("overflow","auto");
  523. this.scrollContainerFun = function(){
  524. var scrollSize = this.contentAreaNode.getScrollSize();
  525. var clientSize = this.contentAreaNode.getSize();
  526. var scrollHeight = scrollSize.y - clientSize.y;
  527. //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
  528. if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
  529. if (!this.isItemsLoaded) this.loadDataByPaging();
  530. }
  531. }.bind(this);
  532. this.isSetedScroll = true;
  533. this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
  534. }
  535. },
  536. loadDataByPaging : function(){
  537. if( this.isItemsLoading )return;
  538. if( !this.isItemsLoaded ){
  539. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  540. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  541. this.isItemsLoading = true;
  542. for( var i = from; i<to; i++ ){
  543. this.items.push(new MWF.xApplication.cms.Module.QueryViewer.Item(this, this.gridJson[i], null, i));
  544. }
  545. this.isItemsLoading = false;
  546. this.pageNumber ++;
  547. if( to == this.gridJson.length )this.isItemsLoaded = true;
  548. }
  549. },
  550. loadGroupData: function(){
  551. if (this.selectTitleCell){
  552. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_process_Application/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  553. this.selectTitleCell.setStyle("cursor", "pointer");
  554. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  555. }
  556. if (this.gridJson.length){
  557. this.gridJson.each(function(data){
  558. this.items.push(new MWF.xApplication.cms.Module.QueryViewer.ItemCategory(this, data));
  559. }.bind(this));
  560. if (this.json.isExpand=="yes")this.expandOrCollapseAll();
  561. }
  562. },
  563. setContentHeight: function(){
  564. if( this.node && this.searchAreaNode && this.viewAreaNode ){
  565. var size = this.node.getSize();
  566. var searchSize = this.searchAreaNode.getSize();
  567. var h = size.y-searchSize.y;
  568. this.viewAreaNode.setStyle("height", ""+h+"px");
  569. }
  570. }
  571. });
  572. MWF.xApplication.cms.Module.QueryViewer.Item = new Class({
  573. Extends : MWF.xApplication.query.Query.Viewer.Item,
  574. load: function(){
  575. var _self = this;
  576. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  577. if (this.prev){
  578. this.node.inject(this.prev.node, "after");
  579. }else{
  580. this.node.inject(this.view.viewTable);
  581. }
  582. this.node.addEvents({
  583. mouseover : function(){ this.setStyles(_self.css.viewContentTrNode_over) },
  584. mouseout : function(){ this.setStyles(_self.css.viewContentTrNode) }
  585. });
  586. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  587. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  588. this.selectTd.setStyles({"cursor": "pointer"});
  589. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  590. //}
  591. Object.each(this.data.data, function(cell, k){
  592. if (this.view.hideColumns.indexOf(k)===-1){
  593. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  594. if (k!== this.view.viewJson.group.column){
  595. var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  596. td.set("text", v);
  597. }
  598. if (this.view.openColumns.indexOf(k)!==-1){
  599. this.setOpenWork(td)
  600. }
  601. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  602. }
  603. }.bind(this));
  604. if( this.view.options.hasAction ){
  605. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  606. this.loadActions( td );
  607. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  608. }
  609. this.setEvent();
  610. },
  611. loadActions : function( container ){
  612. this.deleteNode = new Element("div", {"styles": this.css.actionDeleteNode, "title": "删除"}).inject(container);
  613. this.deleteNode.addEvents({
  614. "mouseover": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  615. "mouseout": function(){this.deleteNode.setStyles(this.css.actionDeleteNode);}.bind(this),
  616. "mousedown": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_down);}.bind(this),
  617. "mouseup": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  618. "click": function(e){
  619. this.remove(e);
  620. e.stopPropagation();
  621. }.bind(this)
  622. });
  623. this.editNode = new Element("div", {"styles": this.css.actionEditNode, "title": "编辑"}).inject(container);
  624. this.editNode.addEvents({
  625. "mouseover": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  626. "mouseout": function(){this.editNode.setStyles(this.css.actionEditNode);}.bind(this),
  627. "mousedown": function(){this.editNode.setStyles(this.css.actionEditNode_down);}.bind(this),
  628. "mouseup": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  629. "click": function(e){
  630. this.editCMSDocument();
  631. e.stopPropagation();
  632. }.bind(this)
  633. });
  634. },
  635. setOpenWork: function(td){
  636. td.setStyle("cursor", "pointer");
  637. td.addEvent("click", function(){
  638. this.openCMSDocument()
  639. }.bind(this));
  640. },
  641. openCMSDocument : function( isEdited ){
  642. var appId = "cms.Document"+this.data.bundle;
  643. if (layout.desktop.apps[appId]){
  644. layout.desktop.apps[appId].setCurrent();
  645. }else {
  646. var options = {
  647. "documentId": this.data.bundle,
  648. "readonly" : !isEdited
  649. };
  650. layout.desktop.openApplication(null, "cms.Document", options);
  651. }
  652. },
  653. editCMSDocument : function(){
  654. this.openCMSDocument( true );
  655. },
  656. remove: function(e){
  657. var text = "删除后不能恢复,你确定要删除该文档?";
  658. var _self = this;
  659. this.node.setStyles(this.css.viewContentTrNode_delete);
  660. this.readyRemove = true;
  661. this.view.app.confirm("warn", e, "删除确认", text, 350, 120, function(){
  662. _self.removeCMSDocument(_self, false);
  663. this.close();
  664. }, function(){
  665. _self.node.setStyles(_self.css.viewContentTrNode );
  666. _self.readyRemove = false;
  667. this.close();
  668. });
  669. },
  670. removeCMSDocument: function(){
  671. var id = this.data.bundle;
  672. //this.view.lookupAction.invoke({"name": "deleteDocument","async": true, "parameter": {"id": id },"success": function(json){
  673. // this.readyRemove = false;
  674. // this.node.destroy();
  675. // this.view.app.notice("删除成功", "success");
  676. // MWF.release(this);
  677. //}.bind(this)});
  678. MWF.Actions.get("x_cms_assemble_control").removeDocument(id, function(json){
  679. this.readyRemove = false;
  680. this.node.destroy();
  681. this.view.app.notice("删除成功", "success");
  682. MWF.release(this);
  683. }.bind(this));
  684. }
  685. });
  686. MWF.xApplication.cms.Module.QueryViewer.ItemCategory = new Class({
  687. Extends : MWF.xApplication.query.Query.Viewer.ItemCategory,
  688. load: function(){
  689. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  690. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  691. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  692. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  693. //}
  694. var colsapn = this.view.viewJson.selectList.length;
  695. if( this.view.options.hasAction ){
  696. colsapn ++
  697. }
  698. this.categoryTd = new Element("td", {
  699. "styles": this.css.viewContentCategoryTdNode,
  700. "colspan": colsapn
  701. }).inject(this.node);
  702. this.groupColumn = null;
  703. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  704. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  705. this.groupColumn = this.view.viewJson.selectList[c];
  706. break;
  707. }
  708. }
  709. if (this.groupColumn){
  710. var text = (this.groupColumn.code) ? MWF.Macro.exec(this.groupColumn.code, {"value": this.data.group, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : this.data.group;
  711. }else{
  712. var text = this.data.group;
  713. }
  714. this.categoryTd.set("html", "<span style='font-family: Webdings'><img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/></span> "+text);
  715. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  716. this.setEvent();
  717. },
  718. expand: function(){
  719. this.items.each(function(item){
  720. item.node.setStyle("display", "table-row");
  721. }.bind(this));
  722. this.node.getElement("span").set("html", "<img src='/x_component_process_Application/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  723. if (!this.loadChild){
  724. //window.setTimeout(function(){
  725. this.data.list.each(function(line){
  726. this.items.push(new MWF.xApplication.cms.Module.QueryViewer.Item(this.view, line, this));
  727. }.bind(this));
  728. this.loadChild = true;
  729. //}.bind(this), 10);
  730. }
  731. }
  732. });