Statement.js 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  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. /** @classdesc Statement 数据中心的查询视图。本章节的脚本上下文请看<b>{@link module:queryStatement|queryStatement}。</b>
  5. * @class
  6. * @o2cn 查询视图
  7. * @extends MWF.xApplication.query.Query.Viewer
  8. * @o2category QueryStatement
  9. * @o2range {QueryStatement}
  10. * @hideconstructor
  11. * @example
  12. * //在查询视图的事件中获取该类
  13. * var view = this.target;
  14. * @example
  15. * //在查询视图的条目中,操作条组件中,分页事件中获取该类
  16. * var view = this.target.view;
  17. * @example
  18. * //调用api进行提示
  19. * this.queryStatement.notice("this is my information", "info");
  20. * */
  21. MWF.xApplication.query.Query.Statement = MWF.QStatement = new Class(
  22. /** @lends MWF.xApplication.query.Query.Statement# */
  23. {
  24. Extends: MWF.QViewer,
  25. options: {
  26. "lazy": false,
  27. /**
  28. * @ignore
  29. * @event MWF.xApplication.query.Query.Statement#queryLoadCategoryRow
  30. */
  31. /**
  32. * @ignore
  33. * @event MWF.xApplication.query.Query.Statement#postLoadCategoryRow
  34. */
  35. /**
  36. * 导出查询Excel的事件,这个时候导出数据已经准备好,this.target可获得查询视图对象。this.event如下:
  37. * <pre><code class='language-js'>{
  38. * data : data, //对象数组,导出的数据,第一个数组为标题。修改后导出的excel内容也会修改。
  39. * colWidthArray : colWidthArr, //数组,每列的宽度
  40. * title : excelName //字符串,导出的文件名
  41. * }</code></pre>
  42. * @event MWF.xApplication.query.Query.Statement#export
  43. */
  44. /**
  45. * 导出查询Excel,产生每行后执行的事件,this.target可获得查询视图对象,可以通过this.event获取下列内容
  46. * <pre><code class='language-js'>{
  47. * data : data, //对象,当前行导出的数据。修改后导出的excel内容也会修改。
  48. * index : 1, //数字,导出的行号,从1开始
  49. * source : source //对象,从后台获取的源数据
  50. * }</code></pre>
  51. * @event MWF.xApplication.query.Query.Statement#exportRow
  52. */
  53. "moduleEvents": ["queryLoad", "postLoad", "beforeLoadPageData", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
  54. "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow", "export", "exportRow"]
  55. },
  56. initialize: function (container, json, options, app, parentMacro) {
  57. //本类有三种事件,
  58. //一种是通过 options 传进来的事件,包括 loadView、openDocument、select、unselect
  59. //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
  60. //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件
  61. this.setOptions(options);
  62. this.path = "../x_component_query_Query/$Viewer/";
  63. this.cssPath = "../x_component_query_Query/$Viewer/" + this.options.style + "/css.wcss";
  64. this._loadCss();
  65. this.lp = MWF.xApplication.query.Query.LP;
  66. this.app = app;
  67. this.container = $(container);
  68. this.json = json || {};
  69. this.parentMacro = parentMacro;
  70. this.originalJson = Object.clone(json);
  71. this.viewJson = null;
  72. this.filterItems = [];
  73. this.searchStatus = "none"; //none, custom, default
  74. this.items = [];
  75. this.selectedItems = [];
  76. this.hideColumns = [];
  77. this.openColumns = [];
  78. this.parameter = {};
  79. this.gridJson = null;
  80. if (this.options.isload) {
  81. this.init(function () {
  82. this.load();
  83. }.bind(this));
  84. }
  85. },
  86. init: function (callback) {
  87. if (this.json.view && this.json.format) {
  88. this.viewJson = JSON.decode(this.json.view);
  89. this.statementJson = this.json;
  90. this.statementJson.viewJson = this.viewJson;
  91. if (callback) callback();
  92. } else {
  93. this.getView(callback);
  94. }
  95. },
  96. loadMacro: function (callback) {
  97. MWF.require("MWF.xScript.Macro", function () {
  98. this.Macro = new MWF.Macro.ViewContext(this);
  99. if (callback) callback();
  100. }.bind(this));
  101. },
  102. createActionbarNode: function () {
  103. this.actionbarAreaNode.empty();
  104. if (typeOf(this.json.showActionbar) === "boolean" && this.json.showActionbar !== true) return;
  105. if (typeOf(this.viewJson.actionbarHidden) === "boolean") {
  106. if (this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length) return;
  107. this.actionbar = new MWF.xApplication.query.Query.Statement.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
  108. this.actionbar.load();
  109. }
  110. },
  111. _loadPageNode: function () {
  112. this.viewPageAreaNode.empty();
  113. if( this.viewJson.pagingbarHidden === true ){
  114. return;
  115. }
  116. if (!this.paging) {
  117. var json;
  118. if (!this.viewJson.pagingList || !this.viewJson.pagingList.length) {
  119. json = {
  120. "firstPageText": this.lp.firstPage,
  121. "lastPageText": this.lp.lastPage
  122. };
  123. } else {
  124. json = this.viewJson.pagingList[0];
  125. // var jsonStr = JSON.stringify(json);
  126. // jsonStr = o2.bindJson(jsonStr, {"lp": MWF.xApplication.query.Query.LP.form});
  127. // json = JSON.parse(jsonStr);
  128. }
  129. this.paging = new MWF.xApplication.query.Query.Statement.Paging(this.viewPageAreaNode, json, this, {});
  130. this.paging.load();
  131. } else {
  132. this.paging.reload();
  133. }
  134. },
  135. // _initPage: function(){
  136. // var i = this.count/this.json.pageSize;
  137. // this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  138. // this.currentPage = this.options.defaultPage || 1;
  139. // this.options.defaultPage = null;
  140. // },
  141. lookup: function (data, callback) {
  142. if (this.lookuping) return;
  143. this.lookuping = true;
  144. // this.getLookupAction(function(){
  145. // if (this.json.application){
  146. var d = Object.clone( data || {} );
  147. // d.count = this.json.count;
  148. // this.lookupAction.bundleView(this.json.id, d, function(json){
  149. // this.bundleItems = json.data.valueList;
  150. // this._initPage();
  151. debugger;
  152. this.loadParameter(d);
  153. this.loadFilter(d);
  154. this.currentPage = this.options.defaultPage || 1;
  155. this.options.defaultPage = null;
  156. if (this.noDataTextNode) this.noDataTextNode.destroy();
  157. this.loadCurrentPageData(function (json) {
  158. if (this.count || (json.data && json.data.length )) {
  159. this.fireEvent("postLoad"); //用户配置的事件
  160. this.lookuping = false;
  161. if (callback) callback(this);
  162. } else {
  163. this.viewPageAreaNode.empty();
  164. if (this.viewJson.noDataText) {
  165. var noDataTextNodeStyle = this.css.noDataTextNode;
  166. if (this.viewJson.viewStyles && this.viewJson.viewStyles["noDataTextNode"]) {
  167. noDataTextNodeStyle = this.viewJson.viewStyles["noDataTextNode"];
  168. }
  169. this.noDataTextNode = new Element("div", {
  170. "styles": noDataTextNodeStyle,
  171. "text": this.viewJson.noDataText
  172. }).inject(this.contentAreaNode);
  173. }
  174. // if (this.loadingAreaNode){
  175. // this.loadingAreaNode.destroy();
  176. // this.loadingAreaNode = null;
  177. // }
  178. this.fireEvent("postLoad"); //用户配置的事件
  179. this.lookuping = false;
  180. if (callback) callback(this);
  181. }
  182. }.bind(this), true, "all");
  183. // }.bind(this));
  184. // }
  185. // }.bind(this));
  186. },
  187. loadFilter: function (data) {
  188. debugger;
  189. this.filterList = [];
  190. (data.filterList || []).each(function (d) {
  191. var pName = d.path.replace(/\./g, "_");
  192. var parameterName = pName;
  193. var suffix = 1;
  194. while( this.parameter[parameterName] ){
  195. parameterName = pName + "_" + suffix;
  196. suffix++;
  197. }
  198. var value = d.value;
  199. // if( d.code && d.code.code ){
  200. // value = this.Macro.exec( d.code.code, this);
  201. // }
  202. if (d.comparison === "like" || d.comparison === "notLike") {
  203. if (value.substr(0, 1) !== "%") value = "%" + value;
  204. if (value.substr(value.length - 1, 1) !== "%") value = value + "%";
  205. this.parameter[parameterName] = value; //"%"+value+"%";
  206. } else {
  207. if( ["sql", "sqlScript"].contains(this.statementJson.format) ){
  208. if (d.formatType === "numberValue"){
  209. value = parseFloat(value);
  210. }
  211. }else{
  212. if (d.formatType === "dateTimeValue" || d.formatType === "datetimeValue") {
  213. value = "{ts '" + value + "'}"
  214. } else if (d.formatType === "dateValue") {
  215. value = "{d '" + value + "'}"
  216. } else if (d.formatType === "timeValue") {
  217. value = "{t '" + value + "'}"
  218. } else if (d.formatType === "numberValue"){
  219. value = parseFloat(value);
  220. }
  221. }
  222. this.parameter[parameterName] = value;
  223. }
  224. d.value = parameterName;
  225. if( !d.logic )d.logic = "and";
  226. this.filterList.push(d);
  227. }.bind(this))
  228. },
  229. loadParameter: function () {
  230. this.parameter = {};
  231. debugger;
  232. var parameter = this.json.parameter ? Object.clone(this.json.parameter) : {};
  233. //系统默认的参数
  234. (this.viewJson.parameterList || []).each(function (f) {
  235. var value = f.value;
  236. if (parameter && parameter[f.parameter]) {
  237. value = parameter[f.parameter];
  238. delete parameter[f.parameter];
  239. }
  240. if (f.valueType === "script") {
  241. value = this.Macro.exec(f.valueScript ? f.valueScript.code : "", this);
  242. }
  243. value = this.parseParameterValue( f, value );
  244. this.parameter[f.parameter] = value;
  245. }.bind(this));
  246. //传入的参数
  247. for (var p in parameter) {
  248. var value = parameter[p];
  249. var configs = (this.json.parameterList || []).filter( function(d){ return d.parameter === p; } );
  250. if( configs.length > 0 ){
  251. value = this.parseParameterValue(configs[0], value);
  252. }else{
  253. if (typeOf(value) === "date") {
  254. if( ["sql", "sqlScript"].contains(this.statementJson.format) ){
  255. value = value.format("db");
  256. }else{
  257. value = "{ts '" + value.format("db") + "'}"
  258. }
  259. }
  260. }
  261. this.parameter[p] = value;
  262. }
  263. },
  264. parseParameterValue: function( f, value ){
  265. // var user = layout.user;
  266. if (typeOf(value) === "date") {
  267. value = value.format("db");
  268. }
  269. switch (value) {
  270. case "@person":
  271. // value = user.distinguishedName;
  272. value = "";
  273. break;
  274. case "@identityList":
  275. // value = user.identityList.map(function (d) {
  276. // return d.distinguishedName;
  277. // });
  278. value = "";
  279. break;
  280. case "@unitList":
  281. // o2.Actions.load("x_organization_assemble_express").UnitAction.listWithPerson({"personList": [user.distinguishedName]}, function (json) {
  282. // value = json.unitList;
  283. // }, null, false);
  284. value = "";
  285. break;
  286. case "@unitAllList":
  287. // o2.Actions.load("x_organization_assemble_express").UnitAction.listWithIdentitySupNested({"personList": [user.distinguishedName]}, function (json) {
  288. // value = json.unitList;
  289. // }, null, false);
  290. value = "";
  291. break;
  292. case "@year":
  293. value = (new Date().getFullYear()).toString();
  294. break;
  295. case "@season":
  296. var m = new Date().format("%m");
  297. if (["01", "02", "03"].contains(m)) {
  298. value = "1"
  299. } else if (["04", "05", "06"].contains(m)) {
  300. value = "2"
  301. } else if (["07", "08", "09"].contains(m)) {
  302. value = "3"
  303. } else {
  304. value = "4"
  305. }
  306. break;
  307. case "@month":
  308. value = new Date().format("%Y-%m");
  309. break;
  310. case "@time":
  311. value = new Date().format("db");
  312. break;
  313. case "@date":
  314. value = new Date().format("%Y-%m-%d");
  315. break;
  316. default:
  317. }
  318. if( !["sql", "sqlScript"].contains(this.statementJson.format) ) {
  319. if( typeOf(value) === "string" && value.substr(0, 1) !== "{" ){
  320. if (f.formatType === "dateTimeValue" || f.formatType === "datetimeValue") {
  321. value = "{ts '" + value + "'}"
  322. } else if (f.formatType === "dateValue") {
  323. value = "{d '" + value + "'}"
  324. } else if (f.formatType === "timeValue") {
  325. value = "{t '" + value + "'}"
  326. }
  327. }
  328. }
  329. return value;
  330. },
  331. loadCurrentPageData: function (callback, async, type) {
  332. //是否需要在翻页的时候清空之前的items ?
  333. if (this.pageloading) return;
  334. this.pageloading = true;
  335. if( this.io ){
  336. this.items.each(function(item){
  337. this.io.unobserve(item.node);
  338. }.bind(this))
  339. }
  340. this.items = [];
  341. var p = this.currentPage;
  342. var d = {
  343. "filterList": this.filterList,
  344. "parameter": this.parameter
  345. };
  346. while (this.viewTable.rows.length > 1) {
  347. this.viewTable.deleteRow(-1);
  348. }
  349. if( this.viewTable.rows.length>0 && !this.viewTable.rows[0].hasClass("viewTitleLine") ){
  350. this.viewTable.deleteRow(0);
  351. }
  352. this.contentAreaNode.scrollTo(0, 0);
  353. //this.createLoadding();
  354. this.fireEvent("beforeLoadPageData", [d])
  355. this.loadViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  356. this.options.statementId || this.options.statementName || this.options.statementAlias ||
  357. this.json.statementId || this.json.statementName || this.json.statementAlias,
  358. type || "data", p, this.json.pageSize, d, function (json) {
  359. if (type === "all" || type === "count") {
  360. if (typeOf(json.count) === "number") {
  361. this.count = json.count;
  362. var i = this.count / this.json.pageSize;
  363. this.pages = (i.toInt() < i) ? i.toInt() + 1 : i;
  364. }
  365. }
  366. this.gridJson = json.data;
  367. this.setSelectedableFlag();
  368. this.fireEvent("postLoadPageData");
  369. // if (this.viewJson.group.column){
  370. // this.gridJson = json.data.groupGrid;
  371. // }else{
  372. // this.gridJson = json.data.grid;
  373. this.loadData();
  374. // }
  375. if (this.gridJson.length) this._loadPageNode();
  376. if (this.loadingAreaNode) {
  377. this.loadingAreaNode.destroy();
  378. this.loadingAreaNode = null;
  379. }
  380. this.pageloading = false;
  381. this.fireEvent("loadView"); //options 传入的事件
  382. this.fireEvent("postLoadPage");
  383. if (callback) callback(json);
  384. }.bind(this), null, async === false ? false : true);
  385. },
  386. getView: function (callback) {
  387. this.getViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.get(
  388. this.json.statementId || this.json.statementName || this.json.statementAlias,
  389. function (json) {
  390. var viewData = JSON.decode(json.data.view);
  391. if (!this.json.pageSize) this.json.pageSize = viewData.pageSize || "20";
  392. this.viewJson = viewData.data;
  393. this.json.application = json.data.query;
  394. //this.json = Object.merge(this.json, json.data);
  395. this.statementJson = json.data;
  396. this.statementJson.viewJson = this.viewJson;
  397. if (callback) callback();
  398. }.bind(this)
  399. );
  400. },
  401. loadData: function () {
  402. if (this.getSelectFlag() === "multi" && this.viewJson.allowSelectAll) {
  403. if (this.selectTitleCell && this.selectTitleCell.retrieve("selectAllLoaded")) {
  404. this.setUnSelectAllStyle();
  405. } else {
  406. this.createSelectAllNode();
  407. }
  408. } else if (this.selectAllNode) {
  409. this.clearSelectAllStyle();
  410. }
  411. if (this.gridJson.length) {
  412. // if( !this.options.paging ){
  413. this.totalMap = {};
  414. this.gridJson.each(function (line, i) {
  415. this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, line, null, i, null, this.options.lazy));
  416. }.bind(this));
  417. // }else{
  418. // this.loadPaging();
  419. // }
  420. } else {
  421. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  422. }
  423. },
  424. loadDataByPaging: function () {
  425. if (this.isItemsLoading) return;
  426. if (!this.isItemsLoaded) {
  427. var from = Math.min(this.pageNumber * this.options.perPageCount, this.gridJson.length);
  428. var to = Math.min((this.pageNumber + 1) * this.options.perPageCount + 1, this.gridJson.length);
  429. this.isItemsLoading = true;
  430. this.totalMap = {};
  431. for (var i = from; i < to; i++) {
  432. this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, this.gridJson[i], null, i, null, this.options.lazy));
  433. }
  434. this.isItemsLoading = false;
  435. this.pageNumber++;
  436. if (to == this.gridJson.length) this.isItemsLoaded = true;
  437. }
  438. },
  439. getFilter: function () {
  440. var filterData = [];
  441. if (this.searchStatus === "custom") {
  442. if (this.filterItems.length) {
  443. this.filterItems.each(function (filter) {
  444. if( !filter.data.logic )filter.data.logic = "and";
  445. filterData.push(filter.data);
  446. }.bind(this));
  447. }
  448. }
  449. if (this.searchStatus === "default") {
  450. var key = this.viewSearchInputNode.get("value");
  451. if (key && key !== this.lp.searchKeywork) {
  452. this.viewJson.customFilterList.each(function (entry) {
  453. if (entry.formatType === "textValue") {
  454. var d = {
  455. "path": entry.path,
  456. "value": key,
  457. "formatType": entry.formatType,
  458. "logic": "or",
  459. "comparison": "like"
  460. };
  461. filterData.push(d);
  462. }
  463. if (entry.formatType === "numberValue") {
  464. var v = key.toFloat();
  465. if (!isNaN(v)) {
  466. var d = {
  467. "path": entry.path,
  468. "value": v,
  469. "formatType": entry.formatType,
  470. "logic": "or",
  471. "comparison": "like"
  472. };
  473. filterData.push(d);
  474. }
  475. }
  476. }.bind(this));
  477. }
  478. }
  479. return (filterData.length) ? filterData : null;
  480. },
  481. viewSearchCustomAddToFilter: function () {
  482. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  483. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  484. if (pathIdx === -1) {
  485. MWF.xDesktop.notice("error", {
  486. "x": "left",
  487. "y": "top"
  488. }, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  489. return false;
  490. }
  491. if (comparisonIdx === -1) {
  492. MWF.xDesktop.notice("error", {
  493. "x": "left",
  494. "y": "top"
  495. }, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  496. return false;
  497. }
  498. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  499. var entry = pathOption.retrieve("entry");
  500. if (entry) {
  501. var pathTitle = entry.title;
  502. var path = entry.path;
  503. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  504. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  505. var value = "";
  506. if (entry.valueType === "script" && entry.valueScript && entry.valueScript.code) {
  507. var idx = this.viewSearchCustomValueNode.selectedIndex;
  508. if (idx !== -1) {
  509. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  510. value = entry.formatType === "booleanValue" ? (v === "true") : v;
  511. }
  512. } else {
  513. switch (entry.formatType) {
  514. case "numberValue":
  515. value = this.viewSearchCustomValueNode.get("value");
  516. break;
  517. case "dateTimeValue":
  518. value = this.viewSearchCustomValueNode.get("value");
  519. break;
  520. case "booleanValue":
  521. var idx = this.viewSearchCustomValueNode.selectedIndex;
  522. if (idx !== -1) {
  523. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  524. value = (v === "true");
  525. }
  526. break;
  527. default:
  528. value = this.viewSearchCustomValueNode.get("value");
  529. }
  530. }
  531. if (value === "") {
  532. MWF.xDesktop.notice("error", {
  533. "x": "left",
  534. "y": "top"
  535. }, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  536. return false;
  537. }
  538. this.filterItems.push(new MWF.xApplication.query.Query.Statement.Filter(this, {
  539. "logic": "and",
  540. "path": path,
  541. "title": pathTitle,
  542. "comparison": comparison,
  543. "comparisonTitle": comparisonTitle,
  544. "value": value,
  545. "formatType": (entry.formatType == "datetimeValue") ? "dateTimeValue" : entry.formatType
  546. }, this.viewSearchCustomFilterContentNode));
  547. this.searchCustomView();
  548. }
  549. },
  550. searchView: function(){
  551. debugger;
  552. if (this.viewJson.customFilterList) {
  553. var key = this.viewSearchInputNode.get("value");
  554. if (key && key !== this.lp.searchKeywork) {
  555. var filterData = [];
  556. this.filterItems = [];
  557. this.viewJson.customFilterList.each(function (entry) {
  558. if (entry.formatType === "textValue") {
  559. var d = {
  560. "path": entry.path,
  561. "value": key,
  562. "formatType": entry.formatType,
  563. "logic": "or",
  564. "comparison": "like"
  565. };
  566. filterData.push(d);
  567. this.filterItems.push({"data":d});
  568. }
  569. if (entry.formatType === "numberValue") {
  570. var v = key.toFloat();
  571. if (!isNaN(v)) {
  572. var d = {
  573. "path": entry.path,
  574. "value": v,
  575. "formatType": entry.formatType,
  576. "logic": "or",
  577. "comparison": "equals"
  578. };
  579. filterData.push(d);
  580. this.filterItems.push({"data":d});
  581. }
  582. }
  583. }.bind(this));
  584. if( this.json.filter ){
  585. this.json.filter.clone().each(function(f){
  586. filterData.push(f);
  587. })
  588. }
  589. this.createViewNode({"filterList": filterData});
  590. }else{
  591. this.filterItems = [];
  592. var filterData = this.json.filter ? this.json.filter.clone() : [];
  593. this.createViewNode( {"filterList": filterData} );
  594. }
  595. }
  596. },
  597. //搜索相关结束
  598. /**
  599. * @method MWF.xApplication.query.Query.Statement#getParentEnvironment
  600. * @summary 如果当前视图是嵌入在表单或者页面中,使用该方法获取表单或页面的上下文。
  601. * @see {@link module:queryStatement.getParentEnvironment|详情查看 this.queryStatement.getParentEnvironment}
  602. * @return {Object}
  603. * @example
  604. * this.target.getParentEnvironment();
  605. */
  606. /**
  607. * @method MWF.xApplication.query.Query.Statement#getPageData
  608. * @summary 获取当前页的数据。
  609. * @see {@link module:queryStatement.getPageData|详情查看 this.queryStatement.getPageData}
  610. * @return {Object}
  611. * @example
  612. * this.target.getPageData();
  613. */
  614. /**
  615. * @method MWF.xApplication.query.Query.Statement#toPage
  616. * @summary 跳转到指定的页面。
  617. * @see {@link module:queryStatement.toPage|详情查看 this.queryStatement.toPage}
  618. * @param {Number} pageNumber 需要跳转的页码
  619. * @param {Function} callback 跳转的页面数据加载完成以后的回调方法。
  620. * @example
  621. * // 跳转到第2页并且获取该页的数据。
  622. * this.target.toPage( 2, function(){
  623. * var data = this.target.getPageData();
  624. * }.bind(this) )
  625. */
  626. /**
  627. * @method MWF.xApplication.query.Query.Statement#getSelectedData
  628. * @summary获取选中的条目的数据。
  629. * @see {@link module:queryStatement.getSelectedData|详情查看 this.queryStatement.getSelectedData}
  630. * @static
  631. * @return {Object[]} 选中的条目的数据。
  632. * @o2syntax
  633. * var data = this.target.getSelectedData();
  634. */
  635. /**
  636. * @method MWF.xApplication.query.Query.Statement#switchView
  637. * @ignore
  638. */
  639. /**
  640. * @method MWF.xApplication.query.Query.Statement#getViewInfor
  641. * @ignore
  642. */
  643. /**
  644. * @summary 获取视查询图的配置信息。
  645. * @see {@link module:queryStatement.getStatementInfor|详情查看 this.queryStatement.getStatementInfor}
  646. * @return {Object}
  647. * @example
  648. * this.target.getStatementInfor();
  649. */
  650. getStatementInfor: function () {
  651. return this.statementJson;
  652. },
  653. /**
  654. * @summary 获取视图当前页的基本信息。
  655. * @see {@link module:queryStatement.getPageInfor|详情查看 this.queryStatement.getPageInfor}
  656. * @return {Object}
  657. * @example
  658. * this.target.getPageInfor();
  659. */
  660. getPageInfor: function () {
  661. return {
  662. pages: this.pages,
  663. perPageCount: this.json.pageSize,
  664. currentPageNumber: this.currentPage
  665. };
  666. },
  667. /**
  668. * @summary 把当前视图切换成另外一个视图。
  669. * @see {@link module:queryStatement.switchStatement|详情查看 this.queryStatement.switchStatement}
  670. * @param {Object} json 需要跳转的参数配置
  671. */
  672. switchStatement: function (json) {
  673. this.switchView(json);
  674. },
  675. /**
  676. * @summary 设置查询视图的过滤条件,该方法不能修改视图中默认的过滤条件(在开发视图的时候添加的过滤条件),而是在这上面新增。
  677. * @see {@link module:queryStatement.setStatementFilter|详情查看 this.queryStatement.setStatementFilter}
  678. * @param {(ViewFilter[]|ViewFilter|Null)} [filter] 过滤条件
  679. * @param {StatementParameter} [parameter] 过滤条件。
  680. * @param {Function} callback 过滤完成并重新加载数据后的回调方法。
  681. */
  682. setFilter: function (filter, parameter, callback) {
  683. if (this.lookuping || this.pageloading) return;
  684. if (!filter) filter = [];
  685. if (!parameter) parameter = {};
  686. this.json.filter = filter;
  687. this.json.parameter = parameter;
  688. if (this.viewAreaNode) {
  689. this.createViewNode({"filterList": this.json.filter.clone()}, callback);
  690. }
  691. },
  692. getExportTotalCount: function(){
  693. return this.count || 100000;
  694. },
  695. // getExportMaxCount: function(){
  696. // return 2000;
  697. // },
  698. exportView: function(){
  699. var _self = this;
  700. var total = this.getExportTotalCount();
  701. var lp = this.lp.viewExport;
  702. var node = this.exportExcelDlgNode = new Element("div");
  703. var html = "<div style=\"line-height: 30px; height: 30px; color: #333333; overflow: hidden;margin-top:20px;\">" + lp.fileName + ":" +
  704. " <input class='filename' value='' style='margin-left: 14px;width: 350px;'><span>"+
  705. "</div>";
  706. html += "<div style=\"line-height: 30px; height: 30px; color: #333333; overflow: hidden;margin-top:20px;\">" + lp.exportRange + ":" +
  707. " <input class='start' value='" + ( this.exportExcelStart || 1) + "'><span>"+ lp.to +"</span>" +
  708. " <input class='end' value='"+ ( this.exportExcelEnd || total ) +"' ><span>"+lp.item+"</span>" +
  709. "</div>";
  710. html += "<div style=\"clear:both; max-height: 300px; margin-bottom:10px; margin-top:10px; overflow-y:auto;\">"+( lp.description.replace("{count}", total ))+"</div>";
  711. node.set("html", html);
  712. var check = function () {
  713. if(this.value.length == 1){
  714. this.value = this.value.replace(/[^1-9]/g,'');
  715. }else{
  716. this.value = this.value.replace(/\D/g,'');
  717. }
  718. if( this.value.toInt() > total ){
  719. this.value = total;
  720. }
  721. }
  722. node.getElement(".start").addEvent( "keyup", function(){ check.call(this) } );
  723. node.getElement(".end").addEvent( "keyup", function(){ check.call(this) } );
  724. var dlg = o2.DL.open({
  725. "title": this.lp.exportExcel,
  726. "style": "user",
  727. "isResize": false,
  728. "content": node,
  729. "width": 600,
  730. "height" : 260,
  731. "buttonList": [
  732. {
  733. "type": "ok",
  734. "text": MWF.LP.process.button.ok,
  735. "action": function (d, e) {
  736. var start = node.getElement(".start").get("value");
  737. var end = node.getElement(".end").get("value");
  738. var filename = node.getElement(".filename").get("value");
  739. if( !start || !end ){
  740. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, lp.inputIntegerNotice, node, {"x": 0, "y": 85});
  741. return false;
  742. }
  743. start = Math.max(start.toInt(), 1);
  744. end = end.toInt();
  745. if( end < start ){
  746. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, lp.startLargetThanEndNotice, node, {"x": 0, "y": 85});
  747. return false;
  748. }
  749. debugger;
  750. this.exportExcelStart = start;
  751. this.exportExcelEnd = end;
  752. this._exportView(start, end, filename);
  753. dlg.close();
  754. }.bind(this)
  755. },
  756. {
  757. "type": "cancel",
  758. "text": MWF.LP.process.button.cancel,
  759. "action": function () { dlg.close(); }
  760. }
  761. ]
  762. });
  763. },
  764. // exportView: function(){
  765. // var excelName = this.statementJson.name;
  766. //
  767. // var p = this.currentPage;
  768. // var d = {
  769. // "filterList": this.filterList,
  770. // "parameter": this.parameter
  771. // };
  772. //
  773. // this.createLoadding();
  774. //
  775. // debugger;
  776. //
  777. // var exportArray = [];
  778. //
  779. // var titleArray = [];
  780. // var colWidthArr = [];
  781. // var dateIndexArray = [];
  782. // var numberIndexArray = [];
  783. // var idx = 0;
  784. // Object.each(this.entries, function (c, k) {
  785. // if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
  786. // titleArray.push(c.displayName);
  787. // colWidthArr.push(c.exportWidth || 200);
  788. // if( c.isTime )dateIndexArray.push(idx);
  789. // if( c.isNumber )numberIndexArray.push(idx);
  790. // idx++;
  791. // }
  792. // }.bind(this));
  793. // exportArray.push(titleArray);
  794. //
  795. // o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  796. // this.options.statementId || this.options.statementName || this.options.statementAlias ||
  797. // this.json.statementId || this.json.statementName || this.json.statementAlias,
  798. // "data", 1, 100000, d, function (json) {
  799. //
  800. // json.data.each(function (d, i) {
  801. // var dataArray = [];
  802. // Object.each(this.entries, function (c, k) {
  803. // if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
  804. // var text = this.getExportText(c, k, d);
  805. // // if( c.isNumber && typeOf(text) === "string" && (parseFloat(text).toString() !== "NaN") ){
  806. // // text = parseFloat(text);
  807. // // }
  808. // dataArray.push( text );
  809. // }
  810. // }.bind(this));
  811. // //exportRow事件
  812. // var argu = {"index":i, "source": d, "data":dataArray};
  813. // this.fireEvent("exportRow", [argu]);
  814. // exportArray.push( argu.data || dataArray );
  815. // }.bind(this));
  816. //
  817. // //export事件
  818. // var arg = {
  819. // data : exportArray,
  820. // colWidthArray : colWidthArr,
  821. // title : excelName
  822. // };
  823. // this.fireEvent("export", [arg]);
  824. //
  825. // if (this.loadingAreaNode) {
  826. // this.loadingAreaNode.destroy();
  827. // this.loadingAreaNode = null;
  828. // }
  829. //
  830. // new MWF.xApplication.query.Query.Statement.ExcelUtils().exportToExcel(
  831. // arg.data || exportArray,
  832. // arg.title || excelName,
  833. // arg.colWidthArray || colWidthArr,
  834. // dateIndexArray, //日期格式列下标
  835. // numberIndexArray //数字格式列下标
  836. // );
  837. //
  838. // }.bind(this));
  839. // },
  840. _exportView: function(start, end, filename){
  841. var excelName = filename || this.statementJson.name;
  842. var p = this.currentPage;
  843. var d = {
  844. "filterList": this.filterList,
  845. "parameter": this.parameter
  846. };
  847. this.createLoadding();
  848. var exportArray = [];
  849. var titleArray = [];
  850. var colWidthArr = [];
  851. var dateIndexArray = [];
  852. var numberIndexArray = [];
  853. var totalArray = [];
  854. var idx = 0;
  855. if (this.viewJson.isSequence === "yes") {
  856. titleArray.push( this.lp.sequence );
  857. colWidthArr.push(100);
  858. totalArray.push('');
  859. idx = idx + 1;
  860. }
  861. Object.each(this.entries, function (c, k) {
  862. if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
  863. titleArray.push(c.displayName);
  864. colWidthArr.push(c.exportWidth || 200);
  865. if( c.isTime )dateIndexArray.push(idx);
  866. if( c.isNumber )numberIndexArray.push(idx);
  867. totalArray.push( ['number', 'count'].contains(c.total) ? new Decimal(0) : '' );
  868. idx++;
  869. }
  870. }.bind(this));
  871. exportArray.push(titleArray);
  872. this.loadExportData(start, end, d, function (dataList) {
  873. var rowIndex = 0;
  874. dataList.each(function (data, j) {
  875. data.each(function (d, i) {
  876. rowIndex = rowIndex + 1;
  877. var columnIndex = 0;
  878. var dataArray = [];
  879. if (this.viewJson.isSequence === "yes") {
  880. dataArray.push( rowIndex );
  881. columnIndex++;
  882. }
  883. Object.each(this.entries, function (c, k) {
  884. if (this.hideColumns.indexOf(k) === -1 && c.exportEnable !== false) {
  885. var text = this.getExportText(c, k, d);
  886. dataArray.push( text );
  887. switch (c.total){
  888. case 'number':
  889. if( parseFloat(text).toString() !== "NaN" ) { //可以转成数字
  890. totalArray[columnIndex] = totalArray[columnIndex].plus(text.toString());
  891. }
  892. break;
  893. case 'count':
  894. totalArray[columnIndex] = totalArray[columnIndex].plus(1);
  895. break;
  896. }
  897. columnIndex++;
  898. }
  899. }.bind(this));
  900. //exportRow事件
  901. var argu = {"index":rowIndex, "source": d, "data":dataArray};
  902. this.fireEvent("exportRow", [argu]);
  903. exportArray.push( argu.data || dataArray );
  904. }.bind(this));
  905. }.bind(this));
  906. var hasTotal = false;
  907. totalArray = totalArray.map(function (d){
  908. if( d ){
  909. hasTotal = true;
  910. return d.toString();
  911. }else{
  912. return '';
  913. }
  914. });
  915. if( hasTotal ){
  916. totalArray[0] = this.lp.total + " " + totalArray[0];
  917. exportArray.push( totalArray );
  918. }
  919. var headTextScript = this.viewJson.exportHeadText;
  920. var headText = headTextScript ? this.Macro.exec(headTextScript, this) : '';
  921. var headStyleScript = this.viewJson.exportHeadStyle;
  922. var headStyle = headStyleScript ? this.Macro.exec(headStyleScript, this) : null;
  923. var titleStyleScript = this.viewJson.exportColumnTitleStyle;
  924. var titleStyle = titleStyleScript ? this.Macro.exec(titleStyleScript, this) : null;
  925. var contentStyleScript = this.viewJson.exportColumnContentStyle;
  926. var contentStyle = contentStyleScript ? this.Macro.exec(contentStyleScript, this) : null;
  927. //export事件
  928. var arg = {
  929. headText: headText,
  930. headStyle: headStyle,
  931. titleStyle: titleStyle,
  932. contentStyle: contentStyle,
  933. data : exportArray,
  934. colWidthArray : colWidthArr,
  935. title : excelName
  936. };
  937. this.fireEvent("export", [arg]);
  938. if (this.loadingAreaNode) {
  939. this.loadingAreaNode.destroy();
  940. this.loadingAreaNode = null;
  941. }
  942. var options = {};
  943. if( arg.headText )options.headText = arg.headText;
  944. if( arg.headStyle )options.headStyle = arg.headStyle;
  945. if( arg.titleStyle )options.columnTitleStyle = arg.titleStyle;
  946. if( arg.contentStyle )options.columnContentStyle = arg.contentStyle;
  947. new MWF.xApplication.query.Query.Statement.ExcelUtils(
  948. options
  949. ).exportToExcel(
  950. arg.data || exportArray,
  951. arg.title || excelName,
  952. arg.colWidthArray || colWidthArr,
  953. dateIndexArray, //日期格式列下标
  954. numberIndexArray //数字格式列下标
  955. );
  956. }.bind(this))
  957. },
  958. loadExportData: function(start, end, body, callback){
  959. start = start - 1;
  960. var differ = end - start;
  961. var count;
  962. if( differ < 10000 ){
  963. count = differ;
  964. }else{
  965. count = 10000;
  966. }
  967. var page = Math.floor( start / count ) + 1;
  968. var startIndex = start % count;
  969. var endIndex = end % count;
  970. var loaded = (page - 1)*count;
  971. var list = [];
  972. do{
  973. var promise = o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  974. this.options.statementId || this.options.statementName || this.options.statementAlias ||
  975. this.json.statementId || this.json.statementName || this.json.statementAlias,
  976. "data", page, count, body);
  977. list.push(promise);
  978. loaded = loaded + count;
  979. page = page + 1;
  980. }while( end > loaded );
  981. var result = [];
  982. Promise.all( list ).then(function (arr) {
  983. arr.each(function (json, i) {
  984. var data = json.data;
  985. var length = json.data.length;
  986. if( i === 0 && i === list.length - 1 ){
  987. data.splice( 0, startIndex );
  988. if( length > endIndex && endIndex > 0 ){
  989. data.splice( endIndex - startIndex , length - endIndex );
  990. }
  991. }else if( i === 0 ){
  992. data.splice( 0, startIndex );
  993. }else if( i=== list.length - 1 ){
  994. if( length > endIndex && endIndex > 0 )data.splice( endIndex, length - endIndex );
  995. }
  996. result.push(data);
  997. });
  998. if( callback )callback(result);
  999. });
  1000. },
  1001. getDataByPath: function (obj, path) {
  1002. var pathList = path.split(".");
  1003. for (var i = 0; i < pathList.length; i++) {
  1004. var p = pathList[i];
  1005. if ((/(^[1-9]\d*$)/.test(p))) p = p.toInt();
  1006. if (obj[p]) {
  1007. obj = obj[p];
  1008. } else if(obj[p] === undefined || obj[p] === null) {
  1009. obj = "";
  1010. break;
  1011. } else {
  1012. obj = obj[p];
  1013. break;
  1014. }
  1015. }
  1016. return obj
  1017. },
  1018. getExportText: function (c, k, data) {
  1019. var path = c.path, code = c.code, obj = data;
  1020. if (!path) {
  1021. } else if (path === "$all") {
  1022. } else {
  1023. obj = this.getDataByPath(obj, path);
  1024. }
  1025. try{
  1026. if (code && code.trim()) obj = this.Macro.exec(code, {
  1027. "value": obj,
  1028. "data": data,
  1029. "entry": c,
  1030. "json": c
  1031. });
  1032. }catch (e) {}
  1033. if( !obj )return "";
  1034. var toName = function (value) {
  1035. if (typeOf(value) === "array") {
  1036. Array.each(value, function (v, idx) {
  1037. value[idx] = toName(v)
  1038. })
  1039. } else if (typeOf(value) === "object") {
  1040. Object.each(value, function (v, key) {
  1041. value[key] = toName(v);
  1042. })
  1043. } else if (typeOf(value) === "string") {
  1044. value = o2.name.cn(value)
  1045. }
  1046. return value;
  1047. };
  1048. var d;
  1049. if (obj != undefined && obj != null) {
  1050. if (typeOf(obj) === "array") {
  1051. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  1052. } else if (typeOf(obj) === "object") {
  1053. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  1054. } else {
  1055. d = c.isName ? o2.name.cn(obj.toString()) : obj;
  1056. }
  1057. }
  1058. return d;
  1059. }
  1060. });
  1061. /** @classdesc StatementItem 数据中心的查询视图的条目。本章节的脚本上下文请看<b>{@link module:queryStatement|queryStatement}。</b>
  1062. * @class
  1063. * @extends MWF.xApplication.query.Query.Viewer.Item
  1064. * @o2cn 查询视图的条目(行)
  1065. * @o2category QueryStatement
  1066. * @o2range {QueryStatement}
  1067. * @hideconstructor
  1068. * @example
  1069. * //在查询视图中获取行
  1070. * var item = this.target.items[0];
  1071. */
  1072. MWF.xApplication.query.Query.Statement.Item = new Class(
  1073. /** @lends MWF.xApplication.query.Query.Statement.Item# */
  1074. {
  1075. Extends: MWF.xApplication.query.Query.Viewer.Item,
  1076. initialize: function (view, data, prev, i, category, lazy) {
  1077. this.view = view;
  1078. this.data = data;
  1079. this.dataString = JSON.stringify(data);
  1080. this.css = this.view.css;
  1081. this.isSelected = false;
  1082. /**
  1083. * @ignore
  1084. */
  1085. this.category = category;
  1086. this.prev = prev;
  1087. this.idx = i;
  1088. this.clazzType = "item";
  1089. this.lazy = lazy;
  1090. this.odd = this.view.items.length % 2 === 1;
  1091. this.load();
  1092. },
  1093. _load: function () {
  1094. this.loading = true;
  1095. if(!this.node)this.view.fireEvent("queryLoadItemRow", [null, this]);
  1096. var viewStyles = this.view.viewJson.viewStyles;
  1097. var viewContentTdNode = (viewStyles && viewStyles["contentTd"]) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
  1098. if( this.odd ){
  1099. viewContentTdNode = ( viewStyles && viewStyles["zebraContentTd"] && Object.keys(viewStyles["zebraContentTd"].length > 0)) ? viewStyles["zebraContentTd"] : viewContentTdNode;
  1100. }
  1101. if(!this.node)this.loadNode();
  1102. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1103. this.selectTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  1104. this.selectTd.setStyles({"cursor": "pointer"});
  1105. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1106. //var selectFlag = this.view.json.select || this.view.viewJson.select || "none";
  1107. var selectFlag = this.view.getSelectFlag();
  1108. if (this.data.$selectedEnable && ["multi", "single"].contains(selectFlag) && this.view.viewJson.selectBoxShow === "always") {
  1109. var viewStyles = this.view.viewJson.viewStyles;
  1110. if (viewStyles) {
  1111. if (selectFlag === "single") {
  1112. this.selectTd.setStyles(viewStyles["radioNode"]);
  1113. } else {
  1114. this.selectTd.setStyles(viewStyles["checkboxNode"]);
  1115. }
  1116. } else {
  1117. var iconName = "checkbox";
  1118. if (selectFlag === "single") iconName = "radiobox";
  1119. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/" + iconName + ".png) center center no-repeat"});
  1120. }
  1121. }
  1122. if (this.view.isSelectTdHidden()) {
  1123. this.selectTd.hide();
  1124. }
  1125. //}
  1126. //序号
  1127. var sequence = 1 + this.view.json.pageSize * (this.view.currentPage - 1) + this.idx;
  1128. this.data["$sequence"] = sequence;
  1129. if (this.view.viewJson.isSequence === "yes") {
  1130. this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  1131. this.sequenceTd.setStyles({
  1132. "width": "30px",
  1133. "text-align": "center"
  1134. });
  1135. if (this.view.json.itemStyles) this.sequenceTd.setStyles(this.view.json.itemStyles);
  1136. this.sequenceTd.set("text", sequence);
  1137. }
  1138. Object.each(this.view.entries, function (c, k) {
  1139. //if (cell){
  1140. if (this.view.hideColumns.indexOf(k) === -1) {
  1141. var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  1142. var cell = this.getText(c, k, td); //this.data[k];
  1143. if (cell === undefined || cell === null) cell = "";
  1144. var v = cell;
  1145. if (c.isHtml) {
  1146. td.set("html", v);
  1147. } else {
  1148. td.set("text", v);
  1149. }
  1150. // if (k!== this.view.viewJson.group.column){
  1151. var total;
  1152. switch (c.total){
  1153. case 'number':
  1154. if( parseFloat(v).toString() !== "NaN" ){ //可以转成数字
  1155. total = this.view.totalMap[ c.column ];
  1156. this.view.totalMap[ c.column ] = total ? total.plus(v.toString()) : new Decimal(v.toString());
  1157. }
  1158. break;
  1159. case 'count':
  1160. total = this.view.totalMap[ c.column ];
  1161. this.view.totalMap[ c.column ] = total ? total.plus(v) : new Decimal(v);
  1162. break;
  1163. }
  1164. if (typeOf(c.contentProperties) === "object") td.setProperties(c.contentProperties);
  1165. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1166. if (typeOf(c.contentStyles) === "object") td.setStyles(c.contentStyles);
  1167. // }else{
  1168. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1169. // }
  1170. if (this.view.openColumns.indexOf(k) !== -1) {
  1171. this.setOpenWork(td, c)
  1172. }
  1173. // if (k!== this.view.viewJson.group.column){
  1174. Object.each(c.events || {}, function (e, key) {
  1175. if (e.code) {
  1176. if (key === "loadContent") {
  1177. this.view.Macro.fire(e.code,
  1178. {"node": td, "json": c, "data": v, "view": this.view, "row": this});
  1179. } else if (key !== "loadTitle") {
  1180. td.addEvent(key, function (event) {
  1181. return this.view.Macro.fire(
  1182. e.code,
  1183. {"node": td, "json": c, "data": v, "view": this.view, "row": this},
  1184. event
  1185. );
  1186. }.bind(this));
  1187. }
  1188. }
  1189. }.bind(this));
  1190. // }
  1191. }
  1192. //}
  1193. }.bind(this));
  1194. if(this.placeholderTd){
  1195. this.placeholderTd.destroy();
  1196. this.placeholderTd = null;
  1197. }
  1198. //默认选中
  1199. var selectedFlag;
  1200. var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
  1201. if (!this.isSelected && defaultSelectedScript) {
  1202. // var flag = this.view.json.select || this.view.viewJson.select || "none";
  1203. // if ( flag ==="single" || flag==="multi"){
  1204. //
  1205. // }
  1206. selectedFlag = this.view.Macro.exec(defaultSelectedScript,
  1207. {"node": this.node, "data": this.data, "view": this.view, "row": this});
  1208. }
  1209. //判断是不是在selectedItems中,用户手工选择
  1210. if (!this.isSelected && this.view.selectedItems.length) {
  1211. for (var i = 0; i < this.view.selectedItems.length; i++) {
  1212. if (this.view.selectedItems[i].dataString === this.dataString) {
  1213. selectedFlag = "true";
  1214. break;
  1215. }
  1216. }
  1217. }
  1218. if (selectedFlag) {
  1219. if (selectedFlag === "multi" || selectedFlag === "single") {
  1220. this.select(selectedFlag);
  1221. } else if (selectedFlag.toString() === "true") {
  1222. var f = this.view.json.select || this.view.viewJson.select || "none";
  1223. if (f === "single" || f === "multi") {
  1224. this.select();
  1225. }
  1226. }
  1227. }
  1228. this.setEvent();
  1229. this.view.fireEvent("postLoadItemRow", [null, this]);
  1230. this.loading = false;
  1231. this.loaded = true;
  1232. },
  1233. selected: function( from ){
  1234. for(var i=0; i<this.view.selectedItems.length; i++){
  1235. var item = this.view.selectedItems[i];
  1236. if( item.dataString === this.dataString ){
  1237. this.view.selectedItems.erase(item);
  1238. break;
  1239. }
  1240. }
  1241. this.view.selectedItems.push(this);
  1242. var viewStyles = this.view.viewJson.viewStyles;
  1243. if( viewStyles ){
  1244. this.selectTd.setStyles( viewStyles["checkedCheckboxNode"] );
  1245. this.node.setStyles( viewStyles["contentSelectedTr"] );
  1246. }else{
  1247. this.selectTd.setStyles({"background": "url("+"../x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  1248. this.node.setStyles(this.css.viewContentTrNode_selected);
  1249. }
  1250. this.isSelected = true;
  1251. if( from !== "view" && from !=="category" && this.view.viewJson.allowSelectAll ){
  1252. this.view.checkSelectAllStatus();
  1253. if( this.category )this.category.checkSelectAllStatus();
  1254. }
  1255. this.view.fireEvent("selectRow", [this]);
  1256. this.view.fireEvent("select", [{
  1257. "selected": true,
  1258. "item": this,
  1259. "data": this.data
  1260. }]); //options 传入的事件
  1261. },
  1262. unSelected: function( from ){
  1263. for(var i=0; i<this.view.selectedItems.length; i++){
  1264. var item = this.view.selectedItems[i];
  1265. if( item.dataString === this.dataString ){
  1266. this.view.selectedItems.erase(item);
  1267. break;
  1268. }
  1269. }
  1270. var viewStyles = this.view.viewJson.viewStyles;
  1271. if( this.view.viewJson.selectBoxShow !=="always" ){
  1272. this.selectTd.setStyles({"background": "transparent"});
  1273. }else{
  1274. if (viewStyles) {
  1275. this.selectTd.setStyles(viewStyles["checkboxNode"]);
  1276. }else{
  1277. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/checkbox.png) center center no-repeat"});
  1278. }
  1279. }
  1280. if( viewStyles ){
  1281. this.node.setStyles( viewStyles["contentTr"] );
  1282. }else{
  1283. this.node.setStyles(this.css.viewContentTrNode);
  1284. }
  1285. this.isSelected = false;
  1286. if( from !== "view" && from !=="category" && this.view.viewJson.allowSelectAll ){
  1287. this.view.checkSelectAllStatus();
  1288. if( this.category )this.category.checkSelectAllStatus();
  1289. }
  1290. this.view.fireEvent("unselectRow", [this]);
  1291. this.view.fireEvent("unselect", [{
  1292. "selected": false,
  1293. "item": this,
  1294. "data": this.data
  1295. }]); //options 传入的事件
  1296. },
  1297. getDataByPath: function (obj, path) {
  1298. var pathList = path.split(".");
  1299. for (var i = 0; i < pathList.length; i++) {
  1300. var p = pathList[i];
  1301. if ((/(^[1-9]\d*$)/.test(p))) p = p.toInt();
  1302. if (obj[p]) {
  1303. obj = obj[p];
  1304. } else if(obj[p] === undefined || obj[p] === null) {
  1305. obj = "";
  1306. break;
  1307. } else {
  1308. obj = obj[p];
  1309. break;
  1310. }
  1311. }
  1312. return obj
  1313. },
  1314. getText: function (c, k, td) {
  1315. var path = c.path, code = c.code, obj = this.data;
  1316. if (!path) {
  1317. var co = code && code.trim();
  1318. if( !co )return "";
  1319. obj = "";
  1320. } else if (path === "$all") {
  1321. } else {
  1322. obj = this.getDataByPath(obj, path);
  1323. }
  1324. if (code && code.trim()) obj = this.view.Macro.exec(code, {
  1325. "value": obj,
  1326. "data": this.data,
  1327. "entry": c,
  1328. "node": td,
  1329. "json": c,
  1330. "row": this
  1331. });
  1332. var toName = function (value) {
  1333. if (typeOf(value) === "array") {
  1334. Array.each(value, function (v, idx) {
  1335. value[idx] = toName(v)
  1336. })
  1337. } else if (typeOf(value) === "object") {
  1338. Object.each(value, function (v, key) {
  1339. value[key] = toName(v);
  1340. })
  1341. } else if (typeOf(value) === "string") {
  1342. value = o2.name.cn(value)
  1343. }
  1344. return value;
  1345. };
  1346. var d;
  1347. if (obj != undefined && obj != null) {
  1348. if (typeOf(obj) === "array") {
  1349. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  1350. } else if (typeOf(obj) === "object") {
  1351. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  1352. } else {
  1353. d = c.isName ? o2.name.cn(obj.toString()) : obj;
  1354. }
  1355. }
  1356. return d;
  1357. },
  1358. setOpenWork: function (td, column) {
  1359. td.setStyle("cursor", "pointer");
  1360. if (column.clickCode) {
  1361. if (!this.view.Macro) {
  1362. MWF.require("MWF.xScript.Macro", function () {
  1363. this.view.businessData = {};
  1364. this.view.Macro = new MWF.Macro.ViewContext(this.view);
  1365. }.bind(this), false);
  1366. }
  1367. td.addEvent("click", function (ev) {
  1368. var result = this.view.Macro.fire(column.clickCode, this, ev);
  1369. ev.stopPropagation();
  1370. return result;
  1371. }.bind(this));
  1372. } else if (this.view.statementJson.entityCategory === "official" && column.idPath) {
  1373. var id = this.getDataByPath(this.data, column.idPath);
  1374. if (id) {
  1375. if (this.view.statementJson.entityClassName === "com.x.cms.core.entity.Document") {
  1376. td.addEvent("click", function (ev) {
  1377. this.openCms(ev, id);
  1378. ev.stopPropagation();
  1379. }.bind(this));
  1380. } else {
  1381. td.addEvent("click", function (ev) {
  1382. this.openWork(ev, id);
  1383. ev.stopPropagation();
  1384. }.bind(this));
  1385. }
  1386. }
  1387. }
  1388. },
  1389. openCms: function (e, id) {
  1390. var options = {"documentId": id};
  1391. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1392. layout.desktop.openApplication(e, "cms.Document", options);
  1393. },
  1394. openWork: function (e, id) {
  1395. var options = {"workId": id};
  1396. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1397. layout.desktop.openApplication(e, "process.Work", options);
  1398. }
  1399. });
  1400. MWF.xApplication.query.Query.Statement.Filter = new Class({
  1401. Extends: MWF.xApplication.query.Query.Viewer.Filter
  1402. });
  1403. /** @class Actionbar 查询视图操作条组件。
  1404. * @o2cn 查询视图操作条
  1405. * @example
  1406. * //可以在查询视图中获取该组件
  1407. * var actionbar = this.target.actionbar; //在视图中获取操作条
  1408. * //方法2
  1409. * var actionbar = this.target; //在操作条和操作本身的事件脚本中获取
  1410. * @extends MWF.xApplication.query.Query.Viewer.Actionbar
  1411. * @o2category QueryStatement
  1412. * @o2range {QueryStatement}
  1413. * @hideconstructor
  1414. */
  1415. MWF.xApplication.query.Query.Statement.Actionbar = new Class({
  1416. Extends: MWF.xApplication.query.Query.Viewer.Actionbar
  1417. });
  1418. /** @class Actionbar 查询视图分页组件。
  1419. * @o2cn 视查询图分页组件
  1420. * @example
  1421. * //可以在查询视图中获取该组件
  1422. * var actionbar = this.target.paging; //在视图中获取操作条
  1423. * //方法2
  1424. * var actionbar = this.target; //在分页组件本身的事件脚本中获取
  1425. * @extends MWF.xApplication.query.Query.Viewer.Paging
  1426. * @o2category QueryStatement
  1427. * @o2range {QueryStatement}
  1428. * @hideconstructor
  1429. */
  1430. MWF.xApplication.query.Query.Statement.Paging = new Class({
  1431. Extends: MWF.xApplication.query.Query.Viewer.Paging
  1432. });
  1433. MWF.xDesktop.requireApp("Template", "utils.ExcelUtils", null, false);
  1434. MWF.xApplication.query.Query.Statement.ExcelUtils = new Class({
  1435. Extends: MWF.xApplication.Template.utils.ExcelUtils
  1436. });