Statement.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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(){
  159. this.parameter = {};
  160. var parameter = this.json.parameter ? Object.clone(this.json.parameter) : {};
  161. //系统默认的参数
  162. ( this.viewJson.parameterList || [] ).each( function (f) {
  163. var value = f.value;
  164. if( parameter && parameter[ f.parameter ] ){
  165. value = parameter[ f.parameter ];
  166. delete parameter[ f.parameter ];
  167. }
  168. debugger;
  169. if( typeOf( value ) === "date" ){
  170. value = value.format("db");
  171. }
  172. if( f.valueType === "script" ){
  173. value = this.Macro.exec( f.valueScript ? f.valueScript.code : "", this);
  174. }else{
  175. //var user = layout.user;
  176. switch ( f.value ) {
  177. case "@person":
  178. case "person":
  179. //value = user.distinguishedName;
  180. break;
  181. case "@identityList":
  182. case "identityList":
  183. //value = user.identityList.map( function (d) {
  184. // return d.distinguishedName;
  185. //});
  186. break;
  187. case "@unitList":
  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. case "unitAllList":
  195. //o2.Actions.load("x_organization_assemble_express").UnitAction.listWithIdentitySupNested({ "personList" : [user.distinguishedName] }, function (json) {
  196. // value = json.unitList;
  197. //}, null, false);
  198. break;
  199. case "@year":
  200. value = (new Date().getFullYear()).toString();
  201. break;
  202. case "@season":
  203. var m = new Date().format("%m");
  204. if( ["01","02","03"].contains(m) ){
  205. value = "1"
  206. }else if( ["04","05","06"].contains(m) ){
  207. value = "2"
  208. }else if( ["07","08","09"].contains(m) ){
  209. value = "3"
  210. }else{
  211. value = "4"
  212. }
  213. break;
  214. case "@month":
  215. value = new Date().format("%Y-%m");
  216. break;
  217. case "@time":
  218. value = new Date().format("db");
  219. break;
  220. case "@date":
  221. value = new Date().format("%Y-%m-%d");
  222. break;
  223. default:
  224. }
  225. }
  226. if( f.formatType === "dateTimeValue" || f.formatType === "datetimeValue"){
  227. value = "{ts '"+value+"'}"
  228. }else if( f.formatType === "dateValue" ){
  229. value = "{d '"+value+"'}"
  230. }else if( f.formatType === "timeValue" ){
  231. value = "{t '"+value+"'}"
  232. }
  233. this.parameter[ f.parameter ] = value;
  234. }.bind(this));
  235. //传入的参数
  236. for( var p in parameter ){
  237. var value = parameter[p];
  238. if( typeOf( value ) === "date" ){
  239. value = "{ts '"+value+"'}"
  240. }
  241. parameter[ p ] = value;
  242. }
  243. },
  244. loadCurrentPageData: function( callback, async, type ){
  245. //是否需要在翻页的时候清空之前的items ?
  246. debugger;
  247. if( this.pageloading )return;
  248. this.pageloading = true;
  249. this.items = [];
  250. var p = this.currentPage;
  251. var d = {
  252. "filterList" : this.filterList,
  253. "parameter" : this.parameter
  254. };
  255. while (this.viewTable.rows.length>1){
  256. this.viewTable.deleteRow(-1);
  257. }
  258. //this.createLoadding();
  259. this.loadViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  260. this.options.statementId || this.options.statementName || this.json.statementId || this.json.statementName,
  261. type || "data", p, this.json.pageSize, d, function(json){
  262. if( type === "all" || type === "count" ){
  263. if( typeOf(json.count) === "number" ){
  264. this.count = json.count;
  265. var i = this.count/this.json.pageSize;
  266. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  267. }
  268. }
  269. this.gridJson = json.data;
  270. this.setSelectedableFlag();
  271. this.fireEvent("postLoadPageData");
  272. // if (this.viewJson.group.column){
  273. // this.gridJson = json.data.groupGrid;
  274. // }else{
  275. // this.gridJson = json.data.grid;
  276. this.loadData();
  277. // }
  278. if (this.gridJson.length) this._loadPageNode();
  279. if (this.loadingAreaNode){
  280. this.loadingAreaNode.destroy();
  281. this.loadingAreaNode = null;
  282. }
  283. this.pageloading = false;
  284. this.fireEvent("loadView"); //options 传入的事件
  285. this.fireEvent("postLoadPage");
  286. if(callback)callback( json );
  287. }.bind(this), null, async === false ? false : true );
  288. },
  289. getView: function(callback){
  290. this.getViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.get(this.json.statementId || this.json.statementName, function(json){
  291. debugger;
  292. var viewData = JSON.decode(json.data.view);
  293. if( !this.json.pageSize )this.json.pageSize = viewData.pageSize || "20";
  294. this.viewJson = viewData.data;
  295. this.json.application = json.data.query;
  296. //this.json = Object.merge(this.json, json.data);
  297. this.statementJson = json.data;
  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. return this.json;
  441. },
  442. switchStatement : function (json) {
  443. this.switchView(json);
  444. },
  445. setFilter : function( filter, parameter, callback ){
  446. if( this.lookuping || this.pageloading )return;
  447. if( !filter )filter = [];
  448. if( !parameter )parameter = {};
  449. this.json.filter = filter;
  450. this.json.parameter = parameter;
  451. if( this.viewAreaNode ){
  452. this.createViewNode({"filterList": this.json.filter.clone() }, callback);
  453. }
  454. }
  455. });
  456. MWF.xApplication.query.Query.Statement.Item = new Class({
  457. Extends : MWF.xApplication.query.Query.Viewer.Item,
  458. initialize: function(view, data, prev, i, category){
  459. this.view = view;
  460. this.data = data;
  461. this.css = this.view.css;
  462. this.isSelected = false;
  463. this.category = category;
  464. this.prev = prev;
  465. this.idx = i;
  466. this.clazzType = "item";
  467. this.load();
  468. },
  469. load: function(){
  470. this.view.fireEvent("queryLoadItemRow", [null, this]);
  471. var viewStyles = this.view.viewJson.viewStyles;
  472. var viewContentTdNode = ( viewStyles && viewStyles["contentTd"] ) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
  473. this.node = new Element("tr", {
  474. "styles": ( viewStyles && viewStyles["contentTr"] ) ? viewStyles["contentTr"] : this.css.viewContentTrNode
  475. });
  476. if (this.prev){
  477. this.node.inject(this.prev.node, "after");
  478. }else{
  479. this.node.inject(this.view.viewTable);
  480. }
  481. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  482. this.selectTd = new Element("td", { "styles": viewContentTdNode }).inject(this.node);
  483. this.selectTd.setStyles({"cursor": "pointer"});
  484. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  485. //var selectFlag = this.view.json.select || this.view.viewJson.select || "none";
  486. var selectFlag = this.view.getSelectFlag();
  487. if ( this.data.$selectedEnable && ["multi","single"].contains(selectFlag) && this.view.viewJson.selectBoxShow==="always") {
  488. var viewStyles = this.view.viewJson.viewStyles;
  489. if (viewStyles) {
  490. if (selectFlag === "single") {
  491. this.selectTd.setStyles(viewStyles["radioNode"]);
  492. } else {
  493. this.selectTd.setStyles(viewStyles["checkboxNode"]);
  494. }
  495. } else {
  496. var iconName = "checkbox";
  497. if (selectFlag === "single") iconName = "radiobox";
  498. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/" + iconName + ".png) center center no-repeat"});
  499. }
  500. }
  501. if( this.view.isSelectTdHidden() ){
  502. this.selectTd.hide();
  503. }
  504. //}
  505. //序号
  506. if (this.view.viewJson.isSequence==="yes"){
  507. this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  508. this.sequenceTd.setStyle("width", "10px");
  509. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  510. this.sequenceTd.set("text", s);
  511. }
  512. debugger;
  513. Object.each(this.view.entries, function(c, k){
  514. //if (cell){
  515. if (this.view.hideColumns.indexOf(k)===-1){
  516. var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  517. var cell = this.getText( c, k, td ); //this.data[k];
  518. if (cell === undefined || cell === null) cell = "";
  519. // if (k!== this.view.viewJson.group.column){
  520. var v = cell;
  521. if (c.isHtml){
  522. td.set("html", v);
  523. }else{
  524. td.set("text", v);
  525. }
  526. if( typeOf(c.contentProperties) === "object" )td.setProperties(c.contentProperties);
  527. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  528. if( typeOf(c.contentStyles) === "object" )td.setStyles(c.contentStyles);
  529. // }else{
  530. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  531. // }
  532. if (this.view.openColumns.indexOf(k)!==-1){
  533. this.setOpenWork(td, c)
  534. }
  535. // if (k!== this.view.viewJson.group.column){
  536. Object.each( c.events || {}, function (e , key) {
  537. if(e.code){
  538. if( key === "loadContent" ){
  539. this.view.Macro.fire( e.code,
  540. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this});
  541. }else if( key !== "loadTitle" ){
  542. td.addEvent(key, function(event){
  543. return this.view.Macro.fire(
  544. e.code,
  545. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this},
  546. event
  547. );
  548. }.bind(this));
  549. }
  550. }
  551. }.bind(this));
  552. // }
  553. }
  554. //}
  555. }.bind(this));
  556. //默认选中
  557. var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
  558. if( !this.isSelected && defaultSelectedScript ){
  559. // var flag = this.view.json.select || this.view.viewJson.select || "none";
  560. // if ( flag ==="single" || flag==="multi"){
  561. //
  562. // }
  563. var flag = this.view.Macro.exec( defaultSelectedScript,
  564. {"node" : this.node, "data" : this.data, "view": this.view, "row" : this});
  565. if( flag ){
  566. if( flag === "multi" || flag === "single" ){
  567. this.select( flag );
  568. }else if( flag.toString() === "true" ){
  569. var f = this.view.json.select || this.view.viewJson.select || "none";
  570. if ( f ==="single" || f==="multi"){
  571. this.select();
  572. }
  573. }
  574. }
  575. }
  576. this.setEvent();
  577. this.view.fireEvent("postLoadItemRow", [null, this]);
  578. },
  579. getDataByPath : function( obj, path ){
  580. var pathList = path.split(".");
  581. for (var i = 0; i < pathList.length; i++) {
  582. var p = pathList[i];
  583. if ((/(^[1-9]\d*$)/.test(p))) p = p.toInt();
  584. if (obj[p]) {
  585. obj = obj[p];
  586. } else {
  587. obj = "";
  588. break;
  589. }
  590. }
  591. return obj
  592. },
  593. getText : function(c, k, td){
  594. var path = c.path, code = c.code, obj = this.data;
  595. if( !path ){
  596. return ""
  597. }else if( path === "$all" ){
  598. }else{
  599. obj = this.getDataByPath(obj, path);
  600. }
  601. if( code && code.trim())obj = this.view.Macro.exec( code, {"value": obj, "data": this.data, "entry": c, "node" : td, "json" : c, "row" : this});
  602. var toName = function (value) {
  603. if(typeOf(value) === "array"){
  604. Array.each( value, function (v, idx) {
  605. value[idx] = toName(v)
  606. })
  607. }else if( typeOf(value) === "object" ){
  608. Object.each( value, function (v, key) {
  609. value[key] = toName(v);
  610. })
  611. }else if( typeOf( value ) === "string" ){
  612. value = o2.name.cn( value )
  613. }
  614. return value;
  615. };
  616. var d;
  617. if( obj!= undefined && obj!= null ){
  618. if( typeOf(obj) === "array" ) {
  619. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  620. }else if( typeOf(obj) === "object" ){
  621. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  622. }else{
  623. d = c.isName ? o2.name.cn( obj.toString() ) : obj;
  624. }
  625. }
  626. return d;
  627. },
  628. setOpenWork: function(td, column){
  629. td.setStyle("cursor", "pointer");
  630. if( column.clickCode ){
  631. if( !this.view.Macro ){
  632. MWF.require("MWF.xScript.Macro", function () {
  633. this.view.businessData = {};
  634. this.view.Macro = new MWF.Macro.PageContext(this.view);
  635. }.bind(this), false);
  636. }
  637. td.addEvent("click", function( ev ){
  638. var result = this.view.Macro.fire(column.clickCode, this, ev);
  639. ev.stopPropagation();
  640. return result;
  641. }.bind(this));
  642. }else if( this.view.statementJson.entityCategory==="official" && column.idPath ){
  643. var id = this.getDataByPath(this.data, column.idPath );
  644. if( id ){
  645. if (this.view.statementJson.entityClassName==="com.x.cms.core.entity.Document"){
  646. td.addEvent("click", function(ev){
  647. this.openCms(ev, id);
  648. ev.stopPropagation();
  649. }.bind(this));
  650. }else{
  651. td.addEvent("click", function(ev){
  652. this.openWork(ev, id);
  653. ev.stopPropagation();
  654. }.bind(this));
  655. }
  656. }
  657. }
  658. },
  659. openCms: function(e, id){
  660. var options = {"documentId": id};
  661. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  662. layout.desktop.openApplication(e, "cms.Document", options);
  663. },
  664. openWork: function(e, id){
  665. var options = {"workId": id};
  666. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  667. layout.desktop.openApplication(e, "process.Work", options);
  668. }
  669. });
  670. MWF.xApplication.query.Query.Statement.Filter = new Class({
  671. Extends : MWF.xApplication.query.Query.Viewer.Filter
  672. });
  673. MWF.xApplication.query.Query.Statement.Actionbar = new Class({
  674. Extends : MWF.xApplication.query.Query.Viewer.Actionbar
  675. });
  676. MWF.xApplication.query.Query.Statement.Paging = new Class({
  677. Extends : MWF.xApplication.query.Query.Viewer.Paging
  678. });