Statement.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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. debugger;
  21. this.json = json || {};
  22. this.parentMacro = parentMacro;
  23. this.originalJson = Object.clone(json);
  24. this.viewJson = null;
  25. this.filterItems = [];
  26. this.searchStatus = "none"; //none, custom, default
  27. this.items = [];
  28. this.selectedItems = [];
  29. this.hideColumns = [];
  30. this.openColumns = [];
  31. this.parameter = {};
  32. this.gridJson = null;
  33. if (this.options.isload){
  34. this.init(function(){
  35. this.load();
  36. }.bind(this));
  37. }
  38. },
  39. init: function(callback){
  40. if (this.json.view){
  41. this.viewJson = JSON.decode(this.json.view);
  42. this.statementJson = this.json;
  43. this.statementJson.viewJson = this.viewJson;
  44. if (callback) callback();
  45. }else{
  46. this.getView(callback);
  47. }
  48. },
  49. loadMacro: function (callback) {
  50. MWF.require("MWF.xScript.Macro", function () {
  51. this.Macro = new MWF.Macro.ViewContext(this);
  52. if (callback) callback();
  53. }.bind(this));
  54. },
  55. createActionbarNode : function(){
  56. this.actionbarAreaNode.empty();
  57. if( typeOf(this.json.showActionbar) === "boolean" && this.json.showActionbar !== true )return;
  58. if( typeOf( this.viewJson.actionbarHidden ) === "boolean" ){
  59. if( this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length )return;
  60. this.actionbar = new MWF.xApplication.query.Query.Statement.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
  61. this.actionbar.load();
  62. }
  63. },
  64. _loadPageNode : function(){
  65. this.viewPageAreaNode.empty();
  66. if( !this.paging ){
  67. var json;
  68. if( !this.viewJson.pagingList || !this.viewJson.pagingList.length ){
  69. json = {
  70. "firstPageText": this.lp.firstPage,
  71. "lastPageText": this.lp.lastPage
  72. };
  73. }else{
  74. json = this.viewJson.pagingList[0];
  75. }
  76. this.paging = new MWF.xApplication.query.Query.Statement.Paging(this.viewPageAreaNode, json, this, {});
  77. this.paging.load();
  78. }else{
  79. this.paging.reload();
  80. }
  81. },
  82. // _initPage: function(){
  83. // var i = this.count/this.json.pageSize;
  84. // this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  85. // this.currentPage = this.options.defaultPage || 1;
  86. // this.options.defaultPage = null;
  87. // },
  88. lookup: function(data, callback){
  89. if( this.lookuping )return;
  90. this.lookuping = true;
  91. // this.getLookupAction(function(){
  92. // if (this.json.application){
  93. var d = data || {};
  94. // d.count = this.json.count;
  95. // this.lookupAction.bundleView(this.json.id, d, function(json){
  96. // this.bundleItems = json.data.valueList;
  97. // this._initPage();
  98. debugger;
  99. this.loadParameter( d );
  100. this.loadFilter( d );
  101. this.currentPage = this.options.defaultPage || 1;
  102. this.options.defaultPage = null;
  103. if( this.noDataTextNode )this.noDataTextNode.destroy();
  104. this.loadCurrentPageData( function (json) {
  105. if(this.count){
  106. this.fireEvent("postLoad"); //用户配置的事件
  107. this.lookuping = false;
  108. if(callback)callback(this);
  109. }else{
  110. this.viewPageAreaNode.empty();
  111. if( this.viewJson.noDataText ){
  112. var noDataTextNodeStyle = this.css.noDataTextNode;
  113. if( this.viewJson.viewStyles && this.viewJson.viewStyles["noDataTextNode"] ){
  114. noDataTextNodeStyle = this.viewJson.viewStyles["noDataTextNode"];
  115. }
  116. this.noDataTextNode = new Element( "div", {
  117. "styles": noDataTextNodeStyle,
  118. "text" : this.viewJson.noDataText
  119. }).inject( this.contentAreaNode );
  120. }
  121. // if (this.loadingAreaNode){
  122. // this.loadingAreaNode.destroy();
  123. // this.loadingAreaNode = null;
  124. // }
  125. this.fireEvent("postLoad"); //用户配置的事件
  126. this.lookuping = false;
  127. if(callback)callback(this);
  128. }
  129. }.bind(this), true,"all");
  130. // }.bind(this));
  131. // }
  132. // }.bind(this));
  133. },
  134. loadFilter : function( data ){
  135. debugger;
  136. this.filterList = [];
  137. ( data.filterList || [] ).each( function (d) {
  138. var parameterName = d.path.replace(/\./g, "_");
  139. var value = d.value;
  140. // if( d.code && d.code.code ){
  141. // value = this.Macro.exec( d.code.code, this);
  142. // }
  143. if( d.comparison === "like" || d.comparison === "notLike" ){
  144. if( value.substr(0, 1) !== "%" )value = "%"+value;
  145. if( value.substr(value.length-1,1) !== "%" )value = value+"%";
  146. this.parameter[ parameterName ] = value; //"%"+value+"%";
  147. }else{
  148. if( d.formatType === "dateTimeValue" || d.formatType === "datetimeValue"){
  149. value = "{ts '"+value+"'}"
  150. }else if( d.formatType === "dateValue" ){
  151. value = "{d '"+value+"'}"
  152. }else if( d.formatType === "timeValue" ){
  153. value = "{t '"+value+"'}"
  154. }
  155. this.parameter[ parameterName ] = value;
  156. }
  157. d.value = parameterName;
  158. this.filterList.push( d );
  159. }.bind(this))
  160. },
  161. loadParameter : function(){
  162. this.parameter = {};
  163. debugger;
  164. var parameter = this.json.parameter ? Object.clone(this.json.parameter) : {};
  165. //系统默认的参数
  166. ( this.viewJson.parameterList || [] ).each( function (f) {
  167. var value = f.value;
  168. if( parameter && parameter[ f.parameter ] ){
  169. value = parameter[ f.parameter ];
  170. delete parameter[ f.parameter ];
  171. }
  172. if( typeOf( value ) === "date" ){
  173. value = value.format("db");
  174. }
  175. if( f.valueType === "script" ){
  176. value = this.Macro.exec( f.valueScript ? f.valueScript.code : "", this);
  177. }else{
  178. var user = layout.user;
  179. switch ( f.value ) {
  180. case "@person":
  181. value = user.distinguishedName;
  182. break;
  183. case "@identityList":
  184. value = user.identityList.map( function (d) {
  185. return d.distinguishedName;
  186. });
  187. break;
  188. case "@unitList":
  189. o2.Actions.load("x_organization_assemble_express").UnitAction.listWithPerson({ "personList" : [user.distinguishedName] }, function (json) {
  190. value = json.unitList;
  191. }, null, false);
  192. break;
  193. case "@unitAllList":
  194. o2.Actions.load("x_organization_assemble_express").UnitAction.listWithIdentitySupNested({ "personList" : [user.distinguishedName] }, function (json) {
  195. value = json.unitList;
  196. }, null, false);
  197. break;
  198. case "@year":
  199. value = (new Date().getFullYear()).toString();
  200. break;
  201. case "@season":
  202. var m = new Date().format("%m");
  203. if( ["01","02","03"].contains(m) ){
  204. value = "1"
  205. }else if( ["04","05","06"].contains(m) ){
  206. value = "2"
  207. }else if( ["07","08","09"].contains(m) ){
  208. value = "3"
  209. }else{
  210. value = "4"
  211. }
  212. break;
  213. case "@month":
  214. value = new Date().format("%Y-%m");
  215. break;
  216. case "@time":
  217. value = new Date().format("db");
  218. break;
  219. case "@date":
  220. value = new Date().format("%Y-%m-%d");
  221. break;
  222. default:
  223. }
  224. }
  225. if( f.formatType === "dateTimeValue" || f.formatType === "datetimeValue"){
  226. value = "{ts '"+value+"'}"
  227. }else if( f.formatType === "dateValue" ){
  228. value = "{d '"+value+"'}"
  229. }else if( f.formatType === "timeValue" ){
  230. value = "{t '"+value+"'}"
  231. }
  232. this.parameter[ f.parameter ] = value;
  233. }.bind(this));
  234. //传入的参数
  235. for( var p in parameter ){
  236. var value = parameter[p];
  237. if( typeOf( value ) === "date" ){
  238. value = "{ts '"+value.format("db")+"'}"
  239. }
  240. this.parameter[ p ] = value;
  241. }
  242. },
  243. loadCurrentPageData: function( callback, async, type ){
  244. //是否需要在翻页的时候清空之前的items ?
  245. debugger;
  246. if( this.pageloading )return;
  247. this.pageloading = true;
  248. this.items = [];
  249. var p = this.currentPage;
  250. var d = {
  251. "filterList" : this.filterList,
  252. "parameter" : this.parameter
  253. };
  254. while (this.viewTable.rows.length>1){
  255. this.viewTable.deleteRow(-1);
  256. }
  257. //this.createLoadding();
  258. this.loadViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  259. this.options.statementId || this.options.statementName || this.json.statementId || this.json.statementName,
  260. type || "data", p, this.json.pageSize, d, function(json){
  261. if( type === "all" || type === "count" ){
  262. if( typeOf(json.count) === "number" ){
  263. this.count = json.count;
  264. var i = this.count/this.json.pageSize;
  265. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  266. }
  267. }
  268. this.gridJson = json.data;
  269. this.setSelectedableFlag();
  270. this.fireEvent("postLoadPageData");
  271. // if (this.viewJson.group.column){
  272. // this.gridJson = json.data.groupGrid;
  273. // }else{
  274. // this.gridJson = json.data.grid;
  275. this.loadData();
  276. // }
  277. if (this.gridJson.length) this._loadPageNode();
  278. if (this.loadingAreaNode){
  279. this.loadingAreaNode.destroy();
  280. this.loadingAreaNode = null;
  281. }
  282. this.pageloading = false;
  283. this.fireEvent("loadView"); //options 传入的事件
  284. this.fireEvent("postLoadPage");
  285. if(callback)callback( json );
  286. }.bind(this), null, async === false ? false : true );
  287. },
  288. getView: function(callback){
  289. this.getViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.get(this.json.statementId || this.json.statementName, function(json){
  290. debugger;
  291. var viewData = JSON.decode(json.data.view);
  292. if( !this.json.pageSize )this.json.pageSize = viewData.pageSize || "20";
  293. this.viewJson = viewData.data;
  294. this.json.application = json.data.query;
  295. //this.json = Object.merge(this.json, json.data);
  296. this.statementJson = json.data;
  297. this.statementJson.viewJson = this.viewJson;
  298. if (callback) callback();
  299. }.bind(this));
  300. },
  301. loadData: function(){
  302. if( this.getSelectFlag() === "multi" && this.viewJson.allowSelectAll ) {
  303. if(this.selectTitleCell && this.selectTitleCell.retrieve("selectAllLoaded")){
  304. this.setUnSelectAllStyle();
  305. }else{
  306. this.createSelectAllNode();
  307. }
  308. }else if(this.selectAllNode){
  309. this.clearSelectAllStyle();
  310. }
  311. if (this.gridJson.length){
  312. // if( !this.options.paging ){
  313. this.gridJson.each(function(line, i){
  314. this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, line, null, i));
  315. }.bind(this));
  316. // }else{
  317. // this.loadPaging();
  318. // }
  319. }else{
  320. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  321. }
  322. },
  323. loadDataByPaging : function(){
  324. if( this.isItemsLoading )return;
  325. if( !this.isItemsLoaded ){
  326. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  327. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  328. this.isItemsLoading = true;
  329. for( var i = from; i<to; i++ ){
  330. this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, this.gridJson[i], null, i));
  331. }
  332. this.isItemsLoading = false;
  333. this.pageNumber ++;
  334. if( to == this.gridJson.length )this.isItemsLoaded = true;
  335. }
  336. },
  337. getFilter: function(){
  338. var filterData = [];
  339. if (this.searchStatus==="custom"){
  340. if (this.filterItems.length){
  341. this.filterItems.each(function(filter){
  342. filterData.push(filter.data);
  343. }.bind(this));
  344. }
  345. }
  346. if (this.searchStatus==="default"){
  347. var key = this.viewSearchInputNode.get("value");
  348. if (key && key!==this.lp.searchKeywork){
  349. this.viewJson.customFilterList.each(function(entry){
  350. if (entry.formatType==="textValue"){
  351. var d = {
  352. "path": entry.path,
  353. "value": key,
  354. "formatType": entry.formatType,
  355. "logic": "or",
  356. "comparison": "like"
  357. };
  358. filterData.push(d);
  359. }
  360. if (entry.formatType==="numberValue"){
  361. var v = key.toFloat();
  362. if (!isNaN(v)){
  363. var d = {
  364. "path": entry.path,
  365. "value": v,
  366. "formatType": entry.formatType,
  367. "logic": "or",
  368. "comparison": "like"
  369. };
  370. filterData.push(d);
  371. }
  372. }
  373. }.bind(this));
  374. }
  375. }
  376. return (filterData.length) ? filterData : null;
  377. },
  378. viewSearchCustomAddToFilter: function(){
  379. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  380. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  381. if (pathIdx===-1){
  382. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  383. return false;
  384. }
  385. if (comparisonIdx===-1){
  386. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  387. return false;
  388. }
  389. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  390. var entry = pathOption.retrieve("entry");
  391. if (entry){
  392. var pathTitle = entry.title;
  393. var path = entry.path;
  394. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  395. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  396. var value = "";
  397. if( entry.valueType === "script" && entry.valueScript && entry.valueScript.code ){
  398. var idx = this.viewSearchCustomValueNode.selectedIndex;
  399. if (idx!==-1){
  400. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  401. value = entry.formatType === "booleanValue" ? (v==="true") : v;
  402. }
  403. }else{
  404. switch (entry.formatType){
  405. case "numberValue":
  406. value = this.viewSearchCustomValueNode.get("value");
  407. break;
  408. case "dateTimeValue":
  409. value = this.viewSearchCustomValueNode.get("value");
  410. break;
  411. case "booleanValue":
  412. var idx = this.viewSearchCustomValueNode.selectedIndex;
  413. if (idx!==-1){
  414. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  415. value = (v==="true");
  416. }
  417. break;
  418. default:
  419. value = this.viewSearchCustomValueNode.get("value");
  420. }
  421. }
  422. if (value===""){
  423. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  424. return false;
  425. }
  426. this.filterItems.push(new MWF.xApplication.query.Query.Statement.Filter(this, {
  427. "logic": "and",
  428. "path": path,
  429. "title": pathTitle,
  430. "comparison": comparison,
  431. "comparisonTitle": comparisonTitle,
  432. "value": value,
  433. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  434. }, this.viewSearchCustomFilterContentNode));
  435. this.searchCustomView();
  436. }
  437. },
  438. //搜索相关结束
  439. getStatementInfor : function () {
  440. debugger;
  441. return this.statementJson;
  442. },
  443. getPageInfor : function(){
  444. return {
  445. pages : this.pages,
  446. perPageCount : this.json.pageSize,
  447. currentPageNumber : this.currentPage
  448. };
  449. },
  450. switchStatement : function (json) {
  451. this.switchView(json);
  452. },
  453. setFilter : function( filter, parameter, callback ){
  454. if( this.lookuping || this.pageloading )return;
  455. if( !filter )filter = [];
  456. if( !parameter )parameter = {};
  457. this.json.filter = filter;
  458. this.json.parameter = parameter;
  459. if( this.viewAreaNode ){
  460. this.createViewNode({"filterList": this.json.filter.clone() }, callback);
  461. }
  462. }
  463. });
  464. MWF.xApplication.query.Query.Statement.Item = new Class({
  465. Extends : MWF.xApplication.query.Query.Viewer.Item,
  466. initialize: function(view, data, prev, i, category){
  467. this.view = view;
  468. this.data = data;
  469. this.css = this.view.css;
  470. this.isSelected = false;
  471. this.category = category;
  472. this.prev = prev;
  473. this.idx = i;
  474. this.clazzType = "item";
  475. this.load();
  476. },
  477. load: function(){
  478. this.view.fireEvent("queryLoadItemRow", [null, this]);
  479. var viewStyles = this.view.viewJson.viewStyles;
  480. var viewContentTdNode = ( viewStyles && viewStyles["contentTd"] ) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
  481. this.node = new Element("tr", {
  482. "styles": ( viewStyles && viewStyles["contentTr"] ) ? viewStyles["contentTr"] : this.css.viewContentTrNode
  483. });
  484. if (this.prev){
  485. this.node.inject(this.prev.node, "after");
  486. }else{
  487. this.node.inject(this.view.viewTable);
  488. }
  489. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  490. this.selectTd = new Element("td", { "styles": viewContentTdNode }).inject(this.node);
  491. this.selectTd.setStyles({"cursor": "pointer"});
  492. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  493. //var selectFlag = this.view.json.select || this.view.viewJson.select || "none";
  494. var selectFlag = this.view.getSelectFlag();
  495. if ( this.data.$selectedEnable && ["multi","single"].contains(selectFlag) && this.view.viewJson.selectBoxShow==="always") {
  496. var viewStyles = this.view.viewJson.viewStyles;
  497. if (viewStyles) {
  498. if (selectFlag === "single") {
  499. this.selectTd.setStyles(viewStyles["radioNode"]);
  500. } else {
  501. this.selectTd.setStyles(viewStyles["checkboxNode"]);
  502. }
  503. } else {
  504. var iconName = "checkbox";
  505. if (selectFlag === "single") iconName = "radiobox";
  506. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/" + iconName + ".png) center center no-repeat"});
  507. }
  508. }
  509. if( this.view.isSelectTdHidden() ){
  510. this.selectTd.hide();
  511. }
  512. //}
  513. //序号
  514. if (this.view.viewJson.isSequence==="yes"){
  515. this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  516. this.sequenceTd.setStyle("width", "10px");
  517. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  518. this.sequenceTd.set("text", s);
  519. }
  520. debugger;
  521. Object.each(this.view.entries, function(c, k){
  522. //if (cell){
  523. if (this.view.hideColumns.indexOf(k)===-1){
  524. var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  525. var cell = this.getText( c, k, td ); //this.data[k];
  526. if (cell === undefined || cell === null) cell = "";
  527. // if (k!== this.view.viewJson.group.column){
  528. var v = cell;
  529. if (c.isHtml){
  530. td.set("html", v);
  531. }else{
  532. td.set("text", v);
  533. }
  534. if( typeOf(c.contentProperties) === "object" )td.setProperties(c.contentProperties);
  535. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  536. if( typeOf(c.contentStyles) === "object" )td.setStyles(c.contentStyles);
  537. // }else{
  538. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  539. // }
  540. if (this.view.openColumns.indexOf(k)!==-1){
  541. this.setOpenWork(td, c)
  542. }
  543. // if (k!== this.view.viewJson.group.column){
  544. Object.each( c.events || {}, function (e , key) {
  545. if(e.code){
  546. if( key === "loadContent" ){
  547. this.view.Macro.fire( e.code,
  548. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this});
  549. }else if( key !== "loadTitle" ){
  550. td.addEvent(key, function(event){
  551. return this.view.Macro.fire(
  552. e.code,
  553. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this},
  554. event
  555. );
  556. }.bind(this));
  557. }
  558. }
  559. }.bind(this));
  560. // }
  561. }
  562. //}
  563. }.bind(this));
  564. //默认选中
  565. var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
  566. if( !this.isSelected && defaultSelectedScript ){
  567. // var flag = this.view.json.select || this.view.viewJson.select || "none";
  568. // if ( flag ==="single" || flag==="multi"){
  569. //
  570. // }
  571. var flag = this.view.Macro.exec( defaultSelectedScript,
  572. {"node" : this.node, "data" : this.data, "view": this.view, "row" : this});
  573. if( flag ){
  574. if( flag === "multi" || flag === "single" ){
  575. this.select( flag );
  576. }else if( flag.toString() === "true" ){
  577. var f = this.view.json.select || this.view.viewJson.select || "none";
  578. if ( f ==="single" || f==="multi"){
  579. this.select();
  580. }
  581. }
  582. }
  583. }
  584. this.setEvent();
  585. this.view.fireEvent("postLoadItemRow", [null, this]);
  586. },
  587. getDataByPath : function( obj, path ){
  588. var pathList = path.split(".");
  589. for (var i = 0; i < pathList.length; i++) {
  590. var p = pathList[i];
  591. if ((/(^[1-9]\d*$)/.test(p))) p = p.toInt();
  592. if (obj[p]) {
  593. obj = obj[p];
  594. } else {
  595. obj = "";
  596. break;
  597. }
  598. }
  599. return obj
  600. },
  601. getText : function(c, k, td){
  602. var path = c.path, code = c.code, obj = this.data;
  603. if( !path ){
  604. return ""
  605. }else if( path === "$all" ){
  606. }else{
  607. obj = this.getDataByPath(obj, path);
  608. }
  609. if( code && code.trim())obj = this.view.Macro.exec( code, {"value": obj, "data": this.data, "entry": c, "node" : td, "json" : c, "row" : this});
  610. var toName = function (value) {
  611. if(typeOf(value) === "array"){
  612. Array.each( value, function (v, idx) {
  613. value[idx] = toName(v)
  614. })
  615. }else if( typeOf(value) === "object" ){
  616. Object.each( value, function (v, key) {
  617. value[key] = toName(v);
  618. })
  619. }else if( typeOf( value ) === "string" ){
  620. value = o2.name.cn( value )
  621. }
  622. return value;
  623. };
  624. var d;
  625. if( obj!= undefined && obj!= null ){
  626. if( typeOf(obj) === "array" ) {
  627. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  628. }else if( typeOf(obj) === "object" ){
  629. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  630. }else{
  631. d = c.isName ? o2.name.cn( obj.toString() ) : obj;
  632. }
  633. }
  634. return d;
  635. },
  636. setOpenWork: function(td, column){
  637. td.setStyle("cursor", "pointer");
  638. if( column.clickCode ){
  639. if( !this.view.Macro ){
  640. MWF.require("MWF.xScript.Macro", function () {
  641. this.view.businessData = {};
  642. this.view.Macro = new MWF.Macro.PageContext(this.view);
  643. }.bind(this), false);
  644. }
  645. td.addEvent("click", function( ev ){
  646. var result = this.view.Macro.fire(column.clickCode, this, ev);
  647. ev.stopPropagation();
  648. return result;
  649. }.bind(this));
  650. }else if( this.view.statementJson.entityCategory==="official" && column.idPath ){
  651. var id = this.getDataByPath(this.data, column.idPath );
  652. if( id ){
  653. if (this.view.statementJson.entityClassName==="com.x.cms.core.entity.Document"){
  654. td.addEvent("click", function(ev){
  655. this.openCms(ev, id);
  656. ev.stopPropagation();
  657. }.bind(this));
  658. }else{
  659. td.addEvent("click", function(ev){
  660. this.openWork(ev, id);
  661. ev.stopPropagation();
  662. }.bind(this));
  663. }
  664. }
  665. }
  666. },
  667. openCms: function(e, id){
  668. var options = {"documentId": id};
  669. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  670. layout.desktop.openApplication(e, "cms.Document", options);
  671. },
  672. openWork: function(e, id){
  673. var options = {"workId": id};
  674. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  675. layout.desktop.openApplication(e, "process.Work", options);
  676. }
  677. });
  678. MWF.xApplication.query.Query.Statement.Filter = new Class({
  679. Extends : MWF.xApplication.query.Query.Viewer.Filter
  680. });
  681. MWF.xApplication.query.Query.Statement.Actionbar = new Class({
  682. Extends : MWF.xApplication.query.Query.Viewer.Actionbar
  683. });
  684. MWF.xApplication.query.Query.Statement.Paging = new Class({
  685. Extends : MWF.xApplication.query.Query.Viewer.Paging
  686. });