Statement.js 28 KB

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