Statement.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. MWF.xApplication.query = MWF.xApplication.query || {};
  2. MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
  3. MWF.xDesktop.requireApp("query.Query", "Viewer", null, false);
  4. MWF.xApplication.query.Query.Statement = MWF.QStatement = new Class({
  5. Extends: MWF.QViewer,
  6. options: {
  7. },
  8. initialize: function(container, json, options, app, parentMacro){
  9. //本类有三种事件,
  10. //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
  11. //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
  12. //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件
  13. this.setOptions(options);
  14. this.path = "../x_component_query_Query/$Viewer/";
  15. this.cssPath = "../x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.lp = MWF.xApplication.query.Query.LP;
  18. this.app = app;
  19. this.container = $(container);
  20. this.json = json || {};
  21. this.parentMacro = parentMacro;
  22. this.originalJson = Object.clone(json);
  23. this.viewJson = null;
  24. this.filterItems = [];
  25. this.searchStatus = "none"; //none, custom, default
  26. this.items = [];
  27. this.selectedItems = [];
  28. this.hideColumns = [];
  29. this.openColumns = [];
  30. this.parameter = {};
  31. this.gridJson = null;
  32. if (this.options.isload){
  33. this.init(function(){
  34. this.load();
  35. }.bind(this));
  36. }
  37. },
  38. init: function(callback){
  39. if (this.json.view){
  40. this.viewJson = JSON.decode(this.json.view);
  41. if (callback) callback();
  42. }else{
  43. this.getView(callback);
  44. }
  45. },
  46. loadMacro: function (callback) {
  47. MWF.require("MWF.xScript.Macro", function () {
  48. this.Macro = new MWF.Macro.ViewContext(this);
  49. if (callback) callback();
  50. }.bind(this));
  51. },
  52. createActionbarNode : function(){
  53. this.actionbarAreaNode.empty();
  54. if( typeOf(this.json.showActionbar) === "boolean" && this.json.showActionbar !== true )return;
  55. if( typeOf( this.viewJson.actionbarHidden ) === "boolean" ){
  56. if( this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length )return;
  57. this.actionbar = new MWF.xApplication.query.Query.Statement.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
  58. this.actionbar.load();
  59. }
  60. },
  61. _loadPageNode : function(){
  62. this.viewPageAreaNode.empty();
  63. if( !this.paging ){
  64. var json;
  65. if( !this.viewJson.pagingList || !this.viewJson.pagingList.length ){
  66. json = {
  67. "firstPageText": this.lp.firstPage,
  68. "lastPageText": this.lp.lastPage
  69. };
  70. }else{
  71. json = this.viewJson.pagingList[0];
  72. }
  73. this.paging = new MWF.xApplication.query.Query.Statement.Paging(this.viewPageAreaNode, json, this, {});
  74. this.paging.load();
  75. }else{
  76. this.paging.reload();
  77. }
  78. },
  79. // _initPage: function(){
  80. // var i = this.count/this.json.pageSize;
  81. // this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  82. // this.currentPage = this.options.defaultPage || 1;
  83. // this.options.defaultPage = null;
  84. // },
  85. lookup: function(data, callback){
  86. if( this.lookuping )return;
  87. this.lookuping = true;
  88. // this.getLookupAction(function(){
  89. // if (this.json.application){
  90. var d = data || {};
  91. // d.count = this.json.count;
  92. // this.lookupAction.bundleView(this.json.id, d, function(json){
  93. // this.bundleItems = json.data.valueList;
  94. // this._initPage();
  95. debugger;
  96. this.currentPage = this.options.defaultPage || 1;
  97. this.options.defaultPage = null;
  98. if( this.noDataTextNode )this.noDataTextNode.destroy();
  99. this.loadCurrentPageData( function (json) {
  100. if(this.count){
  101. this.fireEvent("postLoad"); //用户配置的事件
  102. this.lookuping = false;
  103. if(callback)callback(this);
  104. }else{
  105. this.viewPageAreaNode.empty();
  106. if( this.viewJson.noDataText ){
  107. var noDataTextNodeStyle = this.css.noDataTextNode;
  108. if( this.viewJson.viewStyles && this.viewJson.viewStyles["noDataTextNode"] ){
  109. noDataTextNodeStyle = this.viewJson.viewStyles["noDataTextNode"];
  110. }
  111. this.noDataTextNode = new Element( "div", {
  112. "styles": noDataTextNodeStyle,
  113. "text" : this.viewJson.noDataText
  114. }).inject( this.contentAreaNode );
  115. }
  116. // if (this.loadingAreaNode){
  117. // this.loadingAreaNode.destroy();
  118. // this.loadingAreaNode = null;
  119. // }
  120. this.fireEvent("postLoad"); //用户配置的事件
  121. this.lookuping = false;
  122. if(callback)callback(this);
  123. }
  124. }.bind(this), true,"all");
  125. // }.bind(this));
  126. // }
  127. // }.bind(this));
  128. },
  129. getParameter : function(){
  130. ( this.viewJson.filterList || [] ).each( function (f) {
  131. var value = f.value;
  132. if( f.valueType === "script" ){
  133. value = this.Macro.exec( f.valueScript ? f.valueScript.code : "", this);
  134. }else if( f.value.indexOf( "@" ) > -1 ){
  135. debugger;
  136. var user = layout.user;
  137. switch ( f.value ) {
  138. case "@person":
  139. value = user.distinguishedName;
  140. break;
  141. case "@identityList":
  142. value = user.identityList.map( function (d) {
  143. return d.distinguishedName;
  144. })
  145. break;
  146. case "@unitList":
  147. o2.Actions.load("x_organization_assemble_express").UnitAction.listWithPerson({ "personList" : [user.distinguishedName] }, function (json) {
  148. value = json.unitList;
  149. }, null, false)
  150. break;
  151. case "@unitAllList":
  152. o2.Actions.load("x_organization_assemble_express").UnitAction.listWithIdentitySupNested({ "personList" : [user.distinguishedName] }, function (json) {
  153. value = json.unitList;
  154. }, null, false)
  155. break;
  156. case "@year":
  157. value = (new Date().getFullYear()).toString();
  158. break;
  159. case "@season":
  160. break;
  161. case "@month":
  162. value = new Date().format("%Y-%m");
  163. break;
  164. case "@time":
  165. value = new Date().format("db");
  166. break;
  167. case "@date":
  168. value = new Date().format("%Y-%m-%");
  169. break;
  170. default:
  171. }
  172. }
  173. this.parameter[ f.parameter ] = value;
  174. }.bind(this))
  175. },
  176. loadCurrentPageData: function( callback, async, type ){
  177. //是否需要在翻页的时候清空之前的items ?
  178. debugger;
  179. if( this.pageloading )return;
  180. this.pageloading = true;
  181. this.items = [];
  182. var p = this.currentPage;
  183. var d = {
  184. "filterList" : [],
  185. "parameter" : this.getParameter()
  186. };
  187. while (this.viewTable.rows.length>1){
  188. this.viewTable.deleteRow(-1);
  189. }
  190. //this.createLoadding();
  191. this.loadViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  192. this.json.statementId || this.json.statementName,
  193. type || "data", p, this.json.pageSize, d, function(json){
  194. if( type === "all" || type === "count" ){
  195. if( typeOf(json.count) === "number" ){
  196. this.count = json.count;
  197. var i = this.count/this.json.pageSize;
  198. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  199. }
  200. }
  201. this.gridJson = json.data;
  202. this.fireEvent("postLoadPageData");
  203. // if (this.viewJson.group.column){
  204. // this.gridJson = json.data.groupGrid;
  205. // }else{
  206. // this.gridJson = json.data.grid;
  207. this.loadData();
  208. // }
  209. if (this.gridJson.length) this._loadPageNode();
  210. if (this.loadingAreaNode){
  211. this.loadingAreaNode.destroy();
  212. this.loadingAreaNode = null;
  213. }
  214. this.pageloading = false;
  215. this.fireEvent("loadView"); //options 传入的事件
  216. this.fireEvent("postLoadPage");
  217. if(callback)callback( json );
  218. }.bind(this), null, async === false ? false : true );
  219. },
  220. getView: function(callback){
  221. this.getViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.get(this.json.statementId || this.json.statementName, function(json){
  222. debugger;
  223. var viewData = JSON.decode(json.data.view);
  224. if( !this.json.pageSize )this.json.pageSize = viewData.pageSize;
  225. this.viewJson = viewData.data;
  226. this.json.application = json.data.query;
  227. //this.json = Object.merge(this.json, json.data);
  228. this.statementJson = json.data;
  229. if (callback) callback();
  230. }.bind(this));
  231. },
  232. loadData: function(){
  233. if (this.gridJson.length){
  234. // if( !this.options.paging ){
  235. this.gridJson.each(function(line, i){
  236. this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, line, null, i));
  237. }.bind(this));
  238. // }else{
  239. // this.loadPaging();
  240. // }
  241. }else{
  242. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  243. }
  244. },
  245. loadDataByPaging : function(){
  246. if( this.isItemsLoading )return;
  247. if( !this.isItemsLoaded ){
  248. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  249. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  250. this.isItemsLoading = true;
  251. for( var i = from; i<to; i++ ){
  252. this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, this.gridJson[i], null, i));
  253. }
  254. this.isItemsLoading = false;
  255. this.pageNumber ++;
  256. if( to == this.gridJson.length )this.isItemsLoaded = true;
  257. }
  258. },
  259. getFilter: function(){
  260. var filterData = [];
  261. if (this.searchStatus==="custom"){
  262. if (this.filterItems.length){
  263. this.filterItems.each(function(filter){
  264. filterData.push(filter.data);
  265. }.bind(this));
  266. }
  267. }
  268. if (this.searchStatus==="default"){
  269. var key = this.viewSearchInputNode.get("value");
  270. if (key && key!==this.lp.searchKeywork){
  271. this.viewJson.customFilterList.each(function(entry){
  272. if (entry.formatType==="textValue"){
  273. var d = {
  274. "path": entry.path,
  275. "value": key,
  276. "formatType": entry.formatType,
  277. "logic": "and",
  278. "comparison": "like"
  279. };
  280. filterData.push(d);
  281. }
  282. if (entry.formatType==="numberValue"){
  283. var v = key.toFloat();
  284. if (!isNaN(v)){
  285. var d = {
  286. "path": entry.path,
  287. "value": v,
  288. "formatType": entry.formatType,
  289. "logic": "and",
  290. "comparison": "like"
  291. };
  292. filterData.push(d);
  293. }
  294. }
  295. }.bind(this));
  296. }
  297. }
  298. return (filterData.length) ? filterData : null;
  299. },
  300. viewSearchCustomAddToFilter: function(){
  301. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  302. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  303. if (pathIdx===-1){
  304. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  305. return false;
  306. }
  307. if (comparisonIdx===-1){
  308. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  309. return false;
  310. }
  311. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  312. var entry = pathOption.retrieve("entry");
  313. if (entry){
  314. var pathTitle = entry.title;
  315. var path = entry.path;
  316. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  317. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  318. var value = "";
  319. if( entry.valueType === "script" && entry.valueScript && entry.valueScript.code ){
  320. var idx = this.viewSearchCustomValueNode.selectedIndex;
  321. if (idx!==-1){
  322. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  323. value = entry.formatType === "booleanValue" ? (v==="true") : v;
  324. }
  325. }else{
  326. switch (entry.formatType){
  327. case "numberValue":
  328. value = this.viewSearchCustomValueNode.get("value");
  329. break;
  330. case "dateTimeValue":
  331. value = this.viewSearchCustomValueNode.get("value");
  332. break;
  333. case "booleanValue":
  334. var idx = this.viewSearchCustomValueNode.selectedIndex;
  335. if (idx!==-1){
  336. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  337. value = (v==="true");
  338. }
  339. break;
  340. default:
  341. value = this.viewSearchCustomValueNode.get("value");
  342. }
  343. }
  344. if (value===""){
  345. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  346. return false;
  347. }
  348. this.filterItems.push(new MWF.xApplication.query.Query.Statement.Filter(this, {
  349. "logic": "and",
  350. "path": path,
  351. "title": pathTitle,
  352. "comparison": comparison,
  353. "comparisonTitle": comparisonTitle,
  354. "value": value,
  355. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  356. }, this.viewSearchCustomFilterContentNode));
  357. this.searchCustomView();
  358. }
  359. },
  360. //搜索相关结束
  361. getStatementInfor : function () {
  362. return this.json;
  363. },
  364. switchStatement : function (json) {
  365. this.switchView(json);
  366. }
  367. });
  368. MWF.xApplication.query.Query.Statement.Item = new Class({
  369. Extends : MWF.xApplication.query.Query.Viewer.Item,
  370. initialize: function(view, data, prev, i){
  371. this.view = view;
  372. this.data = data;
  373. this.css = this.view.css;
  374. this.isSelected = false;
  375. this.prev = prev;
  376. this.idx = i;
  377. this.clazzType = "item";
  378. this.load();
  379. },
  380. load: function(){
  381. this.view.fireEvent("queryLoadItemRow", [null, this]);
  382. var viewStyles = this.view.viewJson.viewStyles;
  383. var viewContentTdNode = ( viewStyles && viewStyles["contentTd"] ) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
  384. this.node = new Element("tr", {
  385. "styles": ( viewStyles && viewStyles["contentTr"] ) ? viewStyles["contentTr"] : this.css.viewContentTrNode
  386. });
  387. if (this.prev){
  388. this.node.inject(this.prev.node, "after");
  389. }else{
  390. this.node.inject(this.view.viewTable);
  391. }
  392. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  393. this.selectTd = new Element("td", { "styles": viewContentTdNode }).inject(this.node);
  394. this.selectTd.setStyles({"cursor": "pointer"});
  395. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  396. if( this.view.isSelectTdHidden() ){
  397. this.selectTd.hide();
  398. }
  399. //}
  400. //序号
  401. if (this.view.viewJson.isSequence==="yes"){
  402. this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  403. this.sequenceTd.setStyle("width", "10px");
  404. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  405. this.sequenceTd.set("text", s);
  406. }
  407. debugger;
  408. Object.each(this.view.entries, function(c, k){
  409. var cell = this.data.data[k];
  410. if (cell === undefined) cell = "";
  411. //if (cell){
  412. if (this.view.hideColumns.indexOf(k)===-1){
  413. var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  414. if (k!== this.view.viewJson.group.column){
  415. //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;
  416. var v = cell;
  417. if (c.isHtml){
  418. td.set("html", v);
  419. }else{
  420. td.set("text", v);
  421. }
  422. if( typeOf(c.contentProperties) === "object" )td.setProperties(c.contentProperties);
  423. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  424. if( typeOf(c.contentStyles) === "object" )td.setStyles(c.contentStyles);
  425. }else{
  426. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  427. }
  428. if (this.view.openColumns.indexOf(k)!==-1){
  429. this.setOpenWork(td, c)
  430. }
  431. if (k!== this.view.viewJson.group.column){
  432. Object.each( c.events || {}, function (e , key) {
  433. if(e.code){
  434. if( key === "loadContent" ){
  435. this.view.Macro.fire( e.code,
  436. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this});
  437. }else if( key !== "loadTitle" ){
  438. td.addEvent(key, function(event){
  439. return this.view.Macro.fire(
  440. e.code,
  441. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this},
  442. event
  443. );
  444. }.bind(this));
  445. }
  446. }
  447. }.bind(this));
  448. }
  449. }
  450. //}
  451. }.bind(this));
  452. //默认选中
  453. var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
  454. if( !this.isSelected && defaultSelectedScript ){
  455. // var flag = this.view.json.select || this.view.viewJson.select || "none";
  456. // if ( flag ==="single" || flag==="multi"){
  457. //
  458. // }
  459. var flag = this.view.Macro.exec( defaultSelectedScript,
  460. {"node" : this.node, "data" : this.data, "view": this.view, "row" : this});
  461. if( flag ){
  462. if( flag === "multi" || flag === "single" ){
  463. this.select( flag );
  464. }else if( flag.toString() === "true" ){
  465. var f = this.view.json.select || this.view.viewJson.select || "none";
  466. if ( f ==="single" || f==="multi"){
  467. this.select();
  468. }
  469. }
  470. }
  471. }
  472. this.setEvent();
  473. this.view.fireEvent("postLoadItemRow", [null, this]);
  474. },
  475. setOpenWork: function(td, column){
  476. td.setStyle("cursor", "pointer");
  477. if( column.clickCode ){
  478. if( !this.view.Macro ){
  479. MWF.require("MWF.xScript.Macro", function () {
  480. this.view.businessData = {};
  481. this.view.Macro = new MWF.Macro.PageContext(this.view);
  482. }.bind(this), false);
  483. }
  484. td.addEvent("click", function( ev ){
  485. var result = this.view.Macro.fire(column.clickCode, this, ev);
  486. ev.stopPropagation();
  487. return result;
  488. }.bind(this));
  489. }else{
  490. // if (this.view.json.type==="cms"){
  491. // td.addEvent("click", function(ev){
  492. // this.openCms(ev)
  493. // ev.stopPropagation();
  494. // }.bind(this));
  495. // }else{
  496. td.addEvent("click", function(ev){
  497. this.openWorkAndCompleted(ev)
  498. ev.stopPropagation();
  499. }.bind(this));
  500. // }
  501. }
  502. }
  503. });
  504. MWF.xApplication.query.Query.Statement.Filter = new Class({
  505. Extends : MWF.xApplication.query.Query.Viewer.Filter
  506. });
  507. MWF.xApplication.query.Query.Statement.Actionbar = new Class({
  508. Extends : MWF.xApplication.query.Query.Viewer.Actionbar
  509. });
  510. MWF.xApplication.query.Query.Statement.Paging = new Class({
  511. Extends : MWF.xApplication.query.Query.Viewer.Paging
  512. });