Statement.js 29 KB

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