Statement.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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{
  174. //var user = layout.user;
  175. switch ( f.value ) {
  176. case "@person":
  177. case "person":
  178. //value = user.distinguishedName;
  179. break;
  180. case "@identityList":
  181. case "identityList":
  182. //value = user.identityList.map( function (d) {
  183. // return d.distinguishedName;
  184. //});
  185. break;
  186. case "@unitList":
  187. case "unitList":
  188. //o2.Actions.load("x_organization_assemble_express").UnitAction.listWithPerson({ "personList" : [user.distinguishedName] }, function (json) {
  189. // value = json.unitList;
  190. //}, null, false);
  191. break;
  192. case "@unitAllList":
  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. if( data.parameter ){
  236. for( var p in data.parameter ){
  237. var value = data.parameter[p];
  238. if( typeOf( value ) === "date" ){
  239. value = "{ts '"+value+"'}"
  240. }
  241. this.parameter[ p ] = value;
  242. }
  243. }
  244. },
  245. loadCurrentPageData: function( callback, async, type ){
  246. //是否需要在翻页的时候清空之前的items ?
  247. debugger;
  248. if( this.pageloading )return;
  249. this.pageloading = true;
  250. this.items = [];
  251. var p = this.currentPage;
  252. var d = {
  253. "filterList" : this.filterList,
  254. "parameter" : this.parameter
  255. };
  256. while (this.viewTable.rows.length>1){
  257. this.viewTable.deleteRow(-1);
  258. }
  259. //this.createLoadding();
  260. this.loadViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  261. this.options.statementId || this.options.statementName || this.json.statementId || this.json.statementName,
  262. type || "data", p, this.json.pageSize, d, function(json){
  263. if( type === "all" || type === "count" ){
  264. if( typeOf(json.count) === "number" ){
  265. this.count = json.count;
  266. var i = this.count/this.json.pageSize;
  267. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  268. }
  269. }
  270. this.gridJson = json.data;
  271. this.setSelectedableFlag();
  272. this.fireEvent("postLoadPageData");
  273. // if (this.viewJson.group.column){
  274. // this.gridJson = json.data.groupGrid;
  275. // }else{
  276. // this.gridJson = json.data.grid;
  277. this.loadData();
  278. // }
  279. if (this.gridJson.length) this._loadPageNode();
  280. if (this.loadingAreaNode){
  281. this.loadingAreaNode.destroy();
  282. this.loadingAreaNode = null;
  283. }
  284. this.pageloading = false;
  285. this.fireEvent("loadView"); //options 传入的事件
  286. this.fireEvent("postLoadPage");
  287. if(callback)callback( json );
  288. }.bind(this), null, async === false ? false : true );
  289. },
  290. getView: function(callback){
  291. this.getViewRes = o2.Actions.load("x_query_assemble_surface").StatementAction.get(this.json.statementId || this.json.statementName, function(json){
  292. debugger;
  293. var viewData = JSON.decode(json.data.view);
  294. if( !this.json.pageSize )this.json.pageSize = viewData.pageSize || "20";
  295. this.viewJson = viewData.data;
  296. this.json.application = json.data.query;
  297. //this.json = Object.merge(this.json, json.data);
  298. this.statementJson = json.data;
  299. if (callback) callback();
  300. }.bind(this));
  301. },
  302. loadData: function(){
  303. if( this.getSelectFlag() === "multi" && this.viewJson.allowSelectAll ) {
  304. if(this.selectTitleCell && this.selectTitleCell.retrieve("selectAllLoaded")){
  305. this.setUnSelectAllStyle();
  306. }else{
  307. this.createSelectAllNode();
  308. }
  309. }else if(this.selectAllNode){
  310. this.clearSelectAllStyle();
  311. }
  312. if (this.gridJson.length){
  313. // if( !this.options.paging ){
  314. this.gridJson.each(function(line, i){
  315. this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, line, null, i));
  316. }.bind(this));
  317. // }else{
  318. // this.loadPaging();
  319. // }
  320. }else{
  321. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  322. }
  323. },
  324. loadDataByPaging : function(){
  325. if( this.isItemsLoading )return;
  326. if( !this.isItemsLoaded ){
  327. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  328. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  329. this.isItemsLoading = true;
  330. for( var i = from; i<to; i++ ){
  331. this.items.push(new MWF.xApplication.query.Query.Statement.Item(this, this.gridJson[i], null, i));
  332. }
  333. this.isItemsLoading = false;
  334. this.pageNumber ++;
  335. if( to == this.gridJson.length )this.isItemsLoaded = true;
  336. }
  337. },
  338. getFilter: function(){
  339. var filterData = [];
  340. if (this.searchStatus==="custom"){
  341. if (this.filterItems.length){
  342. this.filterItems.each(function(filter){
  343. filterData.push(filter.data);
  344. }.bind(this));
  345. }
  346. }
  347. if (this.searchStatus==="default"){
  348. var key = this.viewSearchInputNode.get("value");
  349. if (key && key!==this.lp.searchKeywork){
  350. this.viewJson.customFilterList.each(function(entry){
  351. if (entry.formatType==="textValue"){
  352. var d = {
  353. "path": entry.path,
  354. "value": key,
  355. "formatType": entry.formatType,
  356. "logic": "or",
  357. "comparison": "like"
  358. };
  359. filterData.push(d);
  360. }
  361. if (entry.formatType==="numberValue"){
  362. var v = key.toFloat();
  363. if (!isNaN(v)){
  364. var d = {
  365. "path": entry.path,
  366. "value": v,
  367. "formatType": entry.formatType,
  368. "logic": "or",
  369. "comparison": "like"
  370. };
  371. filterData.push(d);
  372. }
  373. }
  374. }.bind(this));
  375. }
  376. }
  377. return (filterData.length) ? filterData : null;
  378. },
  379. viewSearchCustomAddToFilter: function(){
  380. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  381. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  382. if (pathIdx===-1){
  383. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  384. return false;
  385. }
  386. if (comparisonIdx===-1){
  387. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  388. return false;
  389. }
  390. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  391. var entry = pathOption.retrieve("entry");
  392. if (entry){
  393. var pathTitle = entry.title;
  394. var path = entry.path;
  395. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  396. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  397. var value = "";
  398. if( entry.valueType === "script" && entry.valueScript && entry.valueScript.code ){
  399. var idx = this.viewSearchCustomValueNode.selectedIndex;
  400. if (idx!==-1){
  401. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  402. value = entry.formatType === "booleanValue" ? (v==="true") : v;
  403. }
  404. }else{
  405. switch (entry.formatType){
  406. case "numberValue":
  407. value = this.viewSearchCustomValueNode.get("value");
  408. break;
  409. case "dateTimeValue":
  410. value = this.viewSearchCustomValueNode.get("value");
  411. break;
  412. case "booleanValue":
  413. var idx = this.viewSearchCustomValueNode.selectedIndex;
  414. if (idx!==-1){
  415. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  416. value = (v==="true");
  417. }
  418. break;
  419. default:
  420. value = this.viewSearchCustomValueNode.get("value");
  421. }
  422. }
  423. if (value===""){
  424. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  425. return false;
  426. }
  427. this.filterItems.push(new MWF.xApplication.query.Query.Statement.Filter(this, {
  428. "logic": "and",
  429. "path": path,
  430. "title": pathTitle,
  431. "comparison": comparison,
  432. "comparisonTitle": comparisonTitle,
  433. "value": value,
  434. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  435. }, this.viewSearchCustomFilterContentNode));
  436. this.searchCustomView();
  437. }
  438. },
  439. //搜索相关结束
  440. getStatementInfor : function () {
  441. return this.json;
  442. },
  443. switchStatement : function (json) {
  444. this.switchView(json);
  445. },
  446. setFilter : function( filter, callback ){
  447. if( this.lookuping || this.pageloading )return;
  448. if( !filter )filter = {"filterList": [], "paramter" : {} };
  449. if( typeOf( filter ) === "object" )return;
  450. this.json.filter = filter.filterList || [];
  451. this.json.paramter = filter.paramter || {};
  452. if( this.viewAreaNode ){
  453. this.createViewNode({"filterList": this.json.filter.clone(), "paramter" : Object.clone(this.json.paramter) }, callback);
  454. }
  455. }
  456. });
  457. MWF.xApplication.query.Query.Statement.Item = new Class({
  458. Extends : MWF.xApplication.query.Query.Viewer.Item,
  459. initialize: function(view, data, prev, i, category){
  460. this.view = view;
  461. this.data = data;
  462. this.css = this.view.css;
  463. this.isSelected = false;
  464. this.category = category;
  465. this.prev = prev;
  466. this.idx = i;
  467. this.clazzType = "item";
  468. this.load();
  469. },
  470. load: function(){
  471. this.view.fireEvent("queryLoadItemRow", [null, this]);
  472. var viewStyles = this.view.viewJson.viewStyles;
  473. var viewContentTdNode = ( viewStyles && viewStyles["contentTd"] ) ? viewStyles["contentTd"] : this.css.viewContentTdNode;
  474. this.node = new Element("tr", {
  475. "styles": ( viewStyles && viewStyles["contentTr"] ) ? viewStyles["contentTr"] : this.css.viewContentTrNode
  476. });
  477. if (this.prev){
  478. this.node.inject(this.prev.node, "after");
  479. }else{
  480. this.node.inject(this.view.viewTable);
  481. }
  482. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  483. this.selectTd = new Element("td", { "styles": viewContentTdNode }).inject(this.node);
  484. this.selectTd.setStyles({"cursor": "pointer"});
  485. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  486. //var selectFlag = this.view.json.select || this.view.viewJson.select || "none";
  487. var selectFlag = this.view.getSelectFlag();
  488. if ( this.data.$selectedEnable && ["multi","single"].contains(selectFlag) && this.view.viewJson.selectBoxShow==="always") {
  489. var viewStyles = this.view.viewJson.viewStyles;
  490. if (viewStyles) {
  491. if (selectFlag === "single") {
  492. this.selectTd.setStyles(viewStyles["radioNode"]);
  493. } else {
  494. this.selectTd.setStyles(viewStyles["checkboxNode"]);
  495. }
  496. } else {
  497. var iconName = "checkbox";
  498. if (selectFlag === "single") iconName = "radiobox";
  499. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/" + iconName + ".png) center center no-repeat"});
  500. }
  501. }
  502. if( this.view.isSelectTdHidden() ){
  503. this.selectTd.hide();
  504. }
  505. //}
  506. //序号
  507. if (this.view.viewJson.isSequence==="yes"){
  508. this.sequenceTd = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  509. this.sequenceTd.setStyle("width", "10px");
  510. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  511. this.sequenceTd.set("text", s);
  512. }
  513. debugger;
  514. Object.each(this.view.entries, function(c, k){
  515. //if (cell){
  516. if (this.view.hideColumns.indexOf(k)===-1){
  517. var td = new Element("td", {"styles": viewContentTdNode}).inject(this.node);
  518. var cell = this.getText( c, k, td ); //this.data[k];
  519. if (cell === undefined || cell === null) cell = "";
  520. // if (k!== this.view.viewJson.group.column){
  521. var v = cell;
  522. if (c.isHtml){
  523. td.set("html", v);
  524. }else{
  525. td.set("text", v);
  526. }
  527. if( typeOf(c.contentProperties) === "object" )td.setProperties(c.contentProperties);
  528. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  529. if( typeOf(c.contentStyles) === "object" )td.setStyles(c.contentStyles);
  530. // }else{
  531. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  532. // }
  533. if (this.view.openColumns.indexOf(k)!==-1){
  534. this.setOpenWork(td, c)
  535. }
  536. // if (k!== this.view.viewJson.group.column){
  537. Object.each( c.events || {}, function (e , key) {
  538. if(e.code){
  539. if( key === "loadContent" ){
  540. this.view.Macro.fire( e.code,
  541. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this});
  542. }else if( key !== "loadTitle" ){
  543. td.addEvent(key, function(event){
  544. return this.view.Macro.fire(
  545. e.code,
  546. {"node" : td, "json" : c, "data" : v, "view": this.view, "row" : this},
  547. event
  548. );
  549. }.bind(this));
  550. }
  551. }
  552. }.bind(this));
  553. // }
  554. }
  555. //}
  556. }.bind(this));
  557. //默认选中
  558. var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
  559. if( !this.isSelected && defaultSelectedScript ){
  560. // var flag = this.view.json.select || this.view.viewJson.select || "none";
  561. // if ( flag ==="single" || flag==="multi"){
  562. //
  563. // }
  564. var flag = this.view.Macro.exec( defaultSelectedScript,
  565. {"node" : this.node, "data" : this.data, "view": this.view, "row" : this});
  566. if( flag ){
  567. if( flag === "multi" || flag === "single" ){
  568. this.select( flag );
  569. }else if( flag.toString() === "true" ){
  570. var f = this.view.json.select || this.view.viewJson.select || "none";
  571. if ( f ==="single" || f==="multi"){
  572. this.select();
  573. }
  574. }
  575. }
  576. }
  577. this.setEvent();
  578. this.view.fireEvent("postLoadItemRow", [null, this]);
  579. },
  580. getDataByPath : function( obj, path ){
  581. var pathList = path.split(".");
  582. for (var i = 0; i < pathList.length; i++) {
  583. var p = pathList[i];
  584. if ((/(^[1-9]\d*$)/.test(p))) p = p.toInt();
  585. if (obj[p]) {
  586. obj = obj[p];
  587. } else {
  588. obj = "";
  589. break;
  590. }
  591. }
  592. return obj
  593. },
  594. getText : function(c, k, td){
  595. var path = c.path, code = c.code, obj = this.data;
  596. if( !path ){
  597. return ""
  598. }else if( path === "$all" ){
  599. }else{
  600. obj = this.getDataByPath(obj, path);
  601. }
  602. if( code && code.trim())obj = this.view.Macro.exec( code, {"value": obj, "data": this.data, "entry": c, "node" : td, "json" : c, "row" : this});
  603. var toName = function (value) {
  604. if(typeOf(value) === "array"){
  605. Array.each( value, function (v, idx) {
  606. value[idx] = toName(v)
  607. })
  608. }else if( typeOf(value) === "object" ){
  609. Object.each( value, function (v, key) {
  610. value[key] = toName(v);
  611. })
  612. }else if( typeOf( value ) === "string" ){
  613. value = o2.name.cn( value )
  614. }
  615. return value;
  616. };
  617. var d;
  618. if( obj!= undefined && obj!= null ){
  619. if( typeOf(obj) === "array" ) {
  620. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  621. }else if( typeOf(obj) === "object" ){
  622. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  623. }else{
  624. d = c.isName ? o2.name.cn( obj.toString() ) : obj;
  625. }
  626. }
  627. return d;
  628. },
  629. setOpenWork: function(td, column){
  630. td.setStyle("cursor", "pointer");
  631. if( column.clickCode ){
  632. if( !this.view.Macro ){
  633. MWF.require("MWF.xScript.Macro", function () {
  634. this.view.businessData = {};
  635. this.view.Macro = new MWF.Macro.PageContext(this.view);
  636. }.bind(this), false);
  637. }
  638. td.addEvent("click", function( ev ){
  639. var result = this.view.Macro.fire(column.clickCode, this, ev);
  640. ev.stopPropagation();
  641. return result;
  642. }.bind(this));
  643. }else if( this.view.statementJson.entityCategory==="official" && column.idPath ){
  644. var id = this.getDataByPath(this.data, column.idPath );
  645. if( id ){
  646. if (this.view.statementJson.entityClassName==="com.x.cms.core.entity.Document"){
  647. td.addEvent("click", function(ev){
  648. this.openCms(ev, id);
  649. ev.stopPropagation();
  650. }.bind(this));
  651. }else{
  652. td.addEvent("click", function(ev){
  653. this.openWork(ev, id);
  654. ev.stopPropagation();
  655. }.bind(this));
  656. }
  657. }
  658. }
  659. },
  660. openCms: function(e, id){
  661. var options = {"documentId": id};
  662. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  663. layout.desktop.openApplication(e, "cms.Document", options);
  664. },
  665. openWork: function(e, id){
  666. var options = {"workId": id};
  667. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  668. layout.desktop.openApplication(e, "process.Work", options);
  669. }
  670. });
  671. MWF.xApplication.query.Query.Statement.Filter = new Class({
  672. Extends : MWF.xApplication.query.Query.Viewer.Filter
  673. });
  674. MWF.xApplication.query.Query.Statement.Actionbar = new Class({
  675. Extends : MWF.xApplication.query.Query.Viewer.Actionbar
  676. });
  677. MWF.xApplication.query.Query.Statement.Paging = new Class({
  678. Extends : MWF.xApplication.query.Query.Viewer.Paging
  679. });