Viewer.js 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929
  1. MWF.xApplication.query = MWF.xApplication.query || {};
  2. MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
  3. MWF.require("MWF.widget.Common", null, false);
  4. MWF.require("o2.widget.Paging", null, false);
  5. MWF.require("MWF.xScript.Macro", null, false);
  6. MWF.xDesktop.requireApp("query.Query", "lp.zh-cn", null, false);
  7. MWF.xApplication.query.Query.Viewer = MWF.QViewer = new Class({
  8. Implements: [Options, Events],
  9. Extends: MWF.widget.Common,
  10. options: {
  11. "style": "default",
  12. "skin" : null,
  13. "resizeNode": true,
  14. "paging" : "scroll",
  15. "perPageCount" : 50,
  16. "isload": "true",
  17. "export": false,
  18. "moduleEvents": ["queryLoad", "postLoad", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
  19. "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow"]
  20. // "actions": {
  21. // "lookup": {"uri": "/jaxrs/view/flag/{view}/query/{application}/execute", "method":"PUT"},
  22. // "getView": {"uri": "/jaxrs/view/flag/{view}/query/{application}"}
  23. //
  24. // },
  25. // "actionRoot": "x_query_assemble_surface"
  26. },
  27. initialize: function(container, json, options, app, parentMacro){
  28. //本类有三种事件,
  29. //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
  30. //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
  31. //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件
  32. this.setOptions(options);
  33. this.path = "/x_component_query_Query/$Viewer/";
  34. this.cssPath = "/x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
  35. this._loadCss();
  36. this.lp = MWF.xApplication.query.Query.LP;
  37. this.app = app;
  38. this.container = $(container);
  39. this.json = json;
  40. this.parentMacro = parentMacro;
  41. debugger;
  42. this.originalJson = Object.clone(json);
  43. this.viewJson = null;
  44. this.filterItems = [];
  45. this.searchStatus = "none"; //none, custom, default
  46. this.items = [];
  47. this.selectedItems = [];
  48. this.hideColumns = [];
  49. this.openColumns = [];
  50. this.gridJson = null;
  51. if (this.options.isload){
  52. this.init(function(){
  53. this.load();
  54. }.bind(this));
  55. }
  56. },
  57. loadView: function(){
  58. if (this.viewJson){
  59. this.reload();
  60. }else{
  61. this.init(function(){
  62. this.load();
  63. }.bind(this));
  64. }
  65. },
  66. init: function(callback){
  67. if (this.json.data){
  68. this.viewJson = JSON.decode(this.json.data);
  69. if (callback) callback();
  70. }else{
  71. this.getView(callback);
  72. }
  73. },
  74. load: function(){
  75. this.loadMacro( function () {
  76. this._loadModuleEvents();
  77. if (this.fireEvent("queryLoad")){
  78. this._loadUserInterface();
  79. //this._loadStyles();
  80. this._loadDomEvents();
  81. }
  82. }.bind(this))
  83. },
  84. _loadUserInterface : function(){
  85. this.loadLayout();
  86. this.createActionbarNode();
  87. this.createSearchNode();
  88. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  89. if (this.options.resizeNode){
  90. this.setContentHeightFun = this.setContentHeight.bind(this);
  91. this.container.addEvent("resize", this.setContentHeightFun);
  92. this.setContentHeightFun();
  93. }
  94. },
  95. loadLayout: function(){
  96. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  97. this.actionbarAreaNode = new Element("div", {"styles": this.css.actionbarAreaNode}).inject(this.node);
  98. //if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
  99. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
  100. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  101. this.viewPageNode = new Element("div", {"styles": this.css.viewPageNode}).inject(this.node);
  102. this.viewPageAreaNode = new Element("div", {"styles": this.css.viewPageAreaNode}).inject(this.viewPageNode);
  103. },
  104. loadMacro: function (callback) {
  105. MWF.require("MWF.xScript.Macro", function () {
  106. this.Macro = new MWF.Macro.ViewContext(this);
  107. if (callback) callback();
  108. }.bind(this));
  109. },
  110. createExportNode: function(){
  111. if (this.options.export){
  112. MWF.require("MWF.widget.Toolbar", function(){
  113. this.toolbar = new MWF.widget.Toolbar(this.actionbarAreaNode, {"style": "simple"}, this); //this.exportAreaNode
  114. var actionNode = new Element("div", {
  115. "id": "",
  116. "MWFnodetype": "MWFToolBarButton",
  117. "MWFButtonImage": this.path+""+this.options.style+"/icon/export.png",
  118. "title": this.lp.exportExcel,
  119. "MWFButtonAction": "exportView",
  120. "MWFButtonText": this.lp.exportExcel
  121. }).inject(this.actionbarAreaNode); //this.exportAreaNode
  122. this.toolbar.load();
  123. }.bind(this));
  124. //this.exportNode = new Element("button", {"text": this.lp.exportExcel}).inject(this.exportAreaNode);
  125. }
  126. },
  127. exportView: function(){
  128. var action = MWF.Actions.get("x_query_assemble_surface");
  129. var filterData = this.json.filter ? this.json.filter.clone() : [];
  130. if (this.filterItems.length){
  131. this.filterItems.each(function(filter){
  132. filterData.push(filter.data);
  133. }.bind(this));
  134. }
  135. action.exportViewWithQuery(this.json.viewName, this.json.application, {"filterList": filterData}, function(json){
  136. var uri = action.action.actions.getViewExcel.uri;
  137. uri = uri.replace("{flag}", json.data.id);
  138. uri = action.action.address+uri;
  139. var a = new Element("a", {"href": uri, "target":"_blank"});
  140. a.click();
  141. a.destroy();
  142. }.bind(this));
  143. },
  144. setContentHeight: function(){
  145. var size = this.node.getSize();
  146. var searchSize = this.searchAreaNode.getComputedSize();
  147. var h = size.y-searchSize.totalHeight;
  148. //if (this.exportAreaNode){
  149. // var exportSize = this.exportAreaNode.getComputedSize();
  150. // h = h-exportSize.totalHeight;
  151. //}
  152. if( this.actionbarAreaNode ){
  153. var exportSize = this.actionbarAreaNode.getComputedSize();
  154. h = h-exportSize.totalHeight;
  155. }
  156. var pageSize = this.viewPageNode.getComputedSize();
  157. h = h-pageSize.totalHeight;
  158. this.viewAreaNode.setStyle("height", ""+h+"px");
  159. },
  160. createLoadding: function(){
  161. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  162. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  163. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  164. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  165. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  166. loadingTextNode.set("text", "loading...");
  167. },
  168. createActionbarNode : function(){
  169. this.actionbarAreaNode.empty();
  170. if( typeOf( this.viewJson.actionbarHidden ) === "boolean" ){
  171. if( this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length )return;
  172. this.actionbar = new MWF.xApplication.query.Query.Viewer.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
  173. this.actionbar.load();
  174. }else{ //兼容以前的ExportNode
  175. this.createExportNode();
  176. }
  177. },
  178. createViewNode: function(data){
  179. this.viewAreaNode.empty();
  180. this.contentAreaNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
  181. this.viewTable = new Element("table", {
  182. "styles": this.css.viewTitleTableNode,
  183. "border": "0px",
  184. "cellPadding": "0",
  185. "cellSpacing": "0"
  186. }).inject(this.contentAreaNode);
  187. this.createLoadding();
  188. if (this.json.isTitle!=="no"){
  189. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  190. //if (this.json.select==="single" || this.json.select==="multi") {
  191. this.selectTitleCell = new Element("td", {
  192. "styles": this.css.viewTitleCellNode
  193. }).inject(this.viewTitleLine);
  194. this.selectTitleCell.setStyle("width", "10px");
  195. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  196. //}
  197. //序号
  198. if (this.viewJson.isSequence==="yes"){
  199. this.sequenceTitleCell = new Element("td", {
  200. "styles": this.css.viewTitleCellNode
  201. }).inject(this.viewTitleLine);
  202. this.sequenceTitleCell.setStyle("width", "10px");
  203. if (this.json.titleStyles) this.sequenceTitleCell.setStyles(this.json.titleStyles);
  204. }
  205. this.entries = {};
  206. this.viewJson.selectList.each(function(column){
  207. this.entries[column.column] = column;
  208. if (!column.hideColumn){
  209. var viewCell = new Element("td", {
  210. "styles": this.css.viewTitleCellNode,
  211. "text": column.displayName
  212. }).inject(this.viewTitleLine);
  213. var size = MWF.getTextSize(column.displayName, this.css.viewTitleCellNode);
  214. viewCell.setStyle("min-width", ""+size.x+"px");
  215. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  216. }else{
  217. this.hideColumns.push(column.column);
  218. }
  219. if (column.allowOpen) this.openColumns.push(column.column);
  220. }.bind(this));
  221. this.lookup(data);
  222. }else{
  223. this.viewJson.selectList.each(function(column){
  224. if (column.hideColumn) this.hideColumns.push(column.column);
  225. if (!column.allowOpen) this.openColumns.push(column.column);
  226. }.bind(this));
  227. this.lookup(data);
  228. }
  229. },
  230. // _loadPageCountNode: function(){
  231. // this.viewPageContentNode.empty();
  232. //
  233. // var size = this.viewPageAreaNode.getSize();
  234. // var w1 = this.viewPageFirstNode.getSize().x*2;
  235. // var w2 = this.viewPageContentNode.getStyle("margin-left").toInt();
  236. // var w = size.x-w1-w2;
  237. //
  238. // var bw = this.css.viewPageButtonNode.width.toInt()+this.css.viewPageButtonNode["margin-right"].toInt();
  239. // var count = (w/bw).toInt()-2;
  240. // if (count>10) count = 10;
  241. // this.showPageCount = Math.min(count, this.pages);
  242. //
  243. // var tmp = this.showPageCount/2;
  244. // var n = tmp.toInt();
  245. // var left = this.currentPage-n;
  246. // if (left<=0) left = 1;
  247. // var right = this.showPageCount + left-1;
  248. // if (right>this.pages) right = this.pages;
  249. // left = right-this.showPageCount+1;
  250. // if (left<=1) left = 1;
  251. //
  252. // this.viewPagePrevNode = new Element("div", {"styles": this.css.viewPagePrevButtonNode}).inject(this.viewPageContentNode);
  253. // this.loadPageButtonEvent(this.viewPagePrevNode, "viewPagePrevButtonNode_over", "viewPagePrevButtonNode_up", "viewPagePrevButtonNode_down", function(){
  254. // if (this.currentPage>1) this.currentPage--;
  255. // this.loadCurrentPageData();
  256. // }.bind(this));
  257. //
  258. // for (i=left; i<=right; i++){
  259. // var node = new Element("div", {"styles": this.css.viewPageButtonNode, "text": i}).inject(this.viewPageContentNode);
  260. // if (i==this.currentPage){
  261. // node.setStyles(this.css.viewPageButtonNode_current);
  262. // }else{
  263. // this.loadPageButtonEvent(node, "viewPageButtonNode_over", "viewPageButtonNode_up", "viewPageButtonNode_down", function(e){
  264. // this.currentPage = e.target.get("text").toInt();
  265. // this.loadCurrentPageData();
  266. // }.bind(this));
  267. // }
  268. // }
  269. // this.viewPageNextNode = new Element("div", {"styles": this.css.viewPageNextButtonNode}).inject(this.viewPageContentNode);
  270. // this.loadPageButtonEvent(this.viewPageNextNode, "viewPageNextButtonNode_over", "viewPageNextButtonNode_up", "viewPageNextButtonNode_down", function(){
  271. // if (this.currentPage<=this.pages-1) this.currentPage++;
  272. // this.loadCurrentPageData();
  273. // }.bind(this));
  274. // },
  275. // loadPageButtonEvent: function(node, over, out, down, click){
  276. // node.addEvents({
  277. // "mouseover": function(){node.setStyles(this.css[over])}.bind(this),
  278. // "mouseout": function(){node.setStyles(this.css[out])}.bind(this),
  279. // "mousedown": function(){node.setStyles(this.css[down])}.bind(this),
  280. // "mouseup": function(){node.setStyles(this.css[out])}.bind(this),
  281. // "click": click
  282. // });
  283. // },
  284. // _loadPageNode: function(){
  285. // this.viewPageAreaNode.empty();
  286. // this.viewPageFirstNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.firstPage}).inject(this.viewPageAreaNode);
  287. // this.viewPageContentNode = new Element("div", {"styles": this.css.viewPageContentNode}).inject(this.viewPageAreaNode);
  288. // this.viewPageLastNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.lastPage}).inject(this.viewPageAreaNode);
  289. // this._loadPageCountNode();
  290. //
  291. // this.loadPageButtonEvent(this.viewPageFirstNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  292. // this.currentPage = 1;
  293. // this.loadCurrentPageData();
  294. // }.bind(this));
  295. // this.loadPageButtonEvent(this.viewPageLastNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  296. // this.currentPage = this.pages;
  297. // this.loadCurrentPageData();
  298. // }.bind(this));
  299. // },
  300. _loadPageNode : function(){
  301. this.viewPageAreaNode.empty();
  302. this.paging = new o2.widget.Paging(this.viewPageAreaNode, {
  303. style : this.options.skin && this.options.skin.pagingBar ? this.options.skin.pagingBar : "default",
  304. countPerPage: this.json.pageSize || this.options.perPageCount,
  305. visiblePages: this.viewJson.visiblePages ? this.viewJson.visiblePages.toInt() : 9,
  306. currentPage: this.currentPage,
  307. itemSize: this.count,
  308. pageSize: this.pages,
  309. hasNextPage: typeOf( this.viewJson.hasPreNextPage ) === "boolean" ? this.viewJson.hasPreNextPage : true,
  310. hasPrevPage: typeOf( this.viewJson.hasPreNextPage ) === "boolean" ? this.viewJson.hasPreNextPage : true,
  311. hasTruningBar: typeOf( this.viewJson.hasTruningBar ) === "boolean" ? this.viewJson.hasTruningBar : true,
  312. hasBatchTuring: typeOf( this.viewJson.hasBatchTuring ) === "boolean" ? this.viewJson.hasBatchTuring : true,
  313. hasFirstPage: typeOf( this.viewJson.hasFirstLastPage ) === "boolean" ? this.viewJson.hasFirstLastPage : true,
  314. hasLastPage: typeOf( this.viewJson.hasFirstLastPage ) === "boolean" ? this.viewJson.hasFirstLastPage : true,
  315. hasJumper: typeOf( this.viewJson.hasPageJumper ) === "boolean" ? this.viewJson.hasPageJumper : true,
  316. hiddenWithDisable: false,
  317. hiddenWithNoItem: true,
  318. text: {
  319. prePage: "",
  320. nextPage: "",
  321. firstPage: this.lp.firstPage,
  322. lastPage: this.lp.lastPage
  323. },
  324. onJumpingPage : function( pageNum, itemNum ){
  325. this.currentPage = pageNum;
  326. this.loadCurrentPageData();
  327. }.bind(this),
  328. onPostLoad : function () {
  329. if(this.setContentHeightFun)this.setContentHeightFun();
  330. }.bind(this)
  331. });
  332. this.paging.load();
  333. },
  334. _initPage: function(){
  335. this.count = this.bundleItems.length;
  336. var i = this.count/this.json.pageSize;
  337. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  338. this.currentPage = 1;
  339. },
  340. lookup: function(data){
  341. this.getLookupAction(function(){
  342. if (this.json.application){
  343. var d = data || {};
  344. d.count = this.json.count;
  345. this.lookupAction.bundleView(this.json.id, d, function(json){
  346. this.bundleItems = json.data.valueList;
  347. this._initPage();
  348. if (this.bundleItems.length){
  349. this.loadCurrentPageData( function () {
  350. this.fireEvent("postLoad"); //用户配置的事件
  351. }.bind(this));
  352. }else{
  353. //this._loadPageNode();
  354. this.viewPageAreaNode.empty();
  355. if (this.loadingAreaNode){
  356. this.loadingAreaNode.destroy();
  357. this.loadingAreaNode = null;
  358. }
  359. this.fireEvent("postLoad"); //用户配置的事件
  360. }
  361. }.bind(this));
  362. }
  363. }.bind(this));
  364. },
  365. loadCurrentPageData: function( callback ){
  366. //是否需要在翻页的时候清空之前的items ?
  367. this.items = [];
  368. var p = this.currentPage;
  369. var d = {};
  370. var valueList = this.bundleItems.slice((p-1)*this.json.pageSize,this.json.pageSize*p);
  371. d.bundleList = valueList;
  372. while (this.viewTable.rows.length>1){
  373. this.viewTable.deleteRow(-1);
  374. }
  375. //this.createLoadding();
  376. this.loadViewRes = this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
  377. this.viewData = json.data;
  378. this.fireEvent("postLoadPageData");
  379. if (this.viewJson.group.column){
  380. this.gridJson = json.data.groupGrid;
  381. this.loadGroupData();
  382. }else{
  383. this.gridJson = json.data.grid;
  384. this.loadData();
  385. }
  386. if (this.gridJson.length) this._loadPageNode();
  387. if (this.loadingAreaNode){
  388. this.loadingAreaNode.destroy();
  389. this.loadingAreaNode = null;
  390. }
  391. this.fireEvent("loadView"); //options 传入的事件
  392. this.fireEvent("postLoadPage");
  393. if(callback)callback();
  394. }.bind(this));
  395. },
  396. loadData: function(){
  397. if (this.gridJson.length){
  398. // if( !this.options.paging ){
  399. this.gridJson.each(function(line, i){
  400. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, line, null, i));
  401. }.bind(this));
  402. // }else{
  403. // this.loadPaging();
  404. // }
  405. }else{
  406. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  407. }
  408. },
  409. loadPaging : function(){
  410. this.isItemsLoading = false;
  411. this.pageNumber = 0;
  412. this.isItemsLoaded = false;
  413. this.isSetedScroll = false;
  414. this.setScroll();
  415. this.loadDataByPaging()
  416. },
  417. setScroll : function(){
  418. if( this.options.paging && !this.isSetedScroll ){
  419. this.contentAreaNode.setStyle("overflow","auto");
  420. this.scrollContainerFun = function(){
  421. var scrollSize = this.contentAreaNode.getScrollSize();
  422. var clientSize = this.contentAreaNode.getSize();
  423. var scrollHeight = scrollSize.y - clientSize.y;
  424. //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
  425. if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
  426. if (!this.isItemsLoaded) this.loadDataByPaging();
  427. }
  428. }.bind(this);
  429. this.isSetedScroll = true;
  430. this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
  431. }
  432. },
  433. loadDataByPaging : function(){
  434. if( this.isItemsLoading )return;
  435. if( !this.isItemsLoaded ){
  436. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  437. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  438. this.isItemsLoading = true;
  439. for( var i = from; i<to; i++ ){
  440. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, this.gridJson[i], null, i));
  441. }
  442. this.isItemsLoading = false;
  443. this.pageNumber ++;
  444. if( to == this.gridJson.length )this.isItemsLoaded = true;
  445. }
  446. },
  447. loadGroupData: function(){
  448. if (this.selectTitleCell){
  449. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  450. this.selectTitleCell.setStyle("cursor", "pointer");
  451. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  452. }
  453. if (this.gridJson.length){
  454. var i = 0;
  455. this.gridJson.each(function(data){
  456. this.items.push(new MWF.xApplication.query.Query.Viewer.ItemCategory(this, data, i));
  457. i += data.list.length;
  458. }.bind(this));
  459. if (this.json.isExpand=="yes") this.expandOrCollapseAll();
  460. }else{
  461. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  462. }
  463. },
  464. expandOrCollapseAll: function(){
  465. var icon = this.selectTitleCell.getElement("span");
  466. if (icon.get("html").indexOf("expand.png")===-1){
  467. this.items.each(function(item){
  468. item.collapse();
  469. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  470. }.bind(this));
  471. }else{
  472. this.items.each(function(item, i){
  473. window.setTimeout(function(){
  474. item.expand();
  475. }.bind(this), 10*i+5);
  476. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
  477. }.bind(this));
  478. }
  479. },
  480. getView: function(callback){
  481. this.getLookupAction(function(){
  482. if (this.json.application){
  483. this.getViewRes = this.lookupAction.getView(this.json.viewName, this.json.application, function(json){
  484. this.viewJson = JSON.decode(json.data.data);
  485. this.json = Object.merge(this.json, json.data);
  486. if (callback) callback();
  487. }.bind(this));
  488. // this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  489. // this.viewJson = JSON.decode(json.data.data);
  490. // this.json = Object.merge(this.json, json.data);
  491. // //var viewData = JSON.decode(json.data.data);
  492. // if (callback) callback();
  493. // }.bind(this)});
  494. }else{
  495. this.getViewRes = this.lookupAction.getViewById(this.json.viewId, function(json){
  496. this.viewJson = JSON.decode(json.data.data);
  497. this.json.application = json.data.query;
  498. this.json = Object.merge(this.json, json.data);
  499. if (callback) callback();
  500. }.bind(this));
  501. }
  502. }.bind(this));
  503. },
  504. getLookupAction: function(callback){
  505. if (!this.lookupAction){
  506. this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
  507. if (callback) callback();
  508. // var _self = this;
  509. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  510. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
  511. // this.lookupAction.getActions = function(actionCallback){
  512. // this.actions = _self.options.actions;
  513. // if (actionCallback) actionCallback();
  514. // };
  515. // if (callback) callback();
  516. // }.bind(this));
  517. }else{
  518. if (callback) callback();
  519. }
  520. },
  521. hide: function(){
  522. this.node.setStyle("display", "none");
  523. },
  524. reload: function(){
  525. this.node.setStyle("display", "block");
  526. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  527. this.filterItems.each(function(filter){
  528. filter.destroy();
  529. }.bind(this));
  530. this.filterItems = [];
  531. if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
  532. this.closeCustomSearch();
  533. this.viewAreaNode.empty();
  534. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  535. },
  536. getFilter: function(){
  537. var filterData = [];
  538. if (this.searchStatus==="custom"){
  539. if (this.filterItems.length){
  540. this.filterItems.each(function(filter){
  541. filterData.push(filter.data);
  542. }.bind(this));
  543. }
  544. }
  545. if (this.searchStatus==="default"){
  546. var key = this.viewSearchInputNode.get("value");
  547. if (key && key!==this.lp.searchKeywork){
  548. this.viewJson.customFilterList.each(function(entry){
  549. if (entry.formatType==="textValue"){
  550. var d = {
  551. "path": entry.path,
  552. "value": key,
  553. "formatType": entry.formatType,
  554. "logic": "or",
  555. "comparison": "like"
  556. };
  557. filterData.push(d);
  558. }
  559. if (entry.formatType==="numberValue"){
  560. var v = key.toFloat();
  561. if (!isNaN(v)){
  562. var d = {
  563. "path": entry.path,
  564. "value": v,
  565. "formatType": entry.formatType,
  566. "logic": "or",
  567. "comparison": "like"
  568. };
  569. filterData.push(d);
  570. }
  571. }
  572. }.bind(this));
  573. }
  574. }
  575. return (filterData.length) ? filterData : null;
  576. },
  577. getData: function(){
  578. if (this.selectedItems.length){
  579. var arr = [];
  580. this.selectedItems.each(function(item){
  581. arr.push(item.data);
  582. });
  583. return arr;
  584. }else{
  585. return [];
  586. }
  587. },
  588. _loadModuleEvents : function(){
  589. Object.each(this.viewJson.events, function(e, key){
  590. if (e.code){
  591. if (this.options.moduleEvents.indexOf(key)!==-1){
  592. this.addEvent(key, function(event, target){
  593. return this.Macro.fire(e.code, target || this, event);
  594. }.bind(this));
  595. }
  596. }
  597. }.bind(this));
  598. },
  599. _loadDomEvents: function(){
  600. Object.each(this.viewJson.events, function(e, key){
  601. if (e.code){
  602. if (this.options.moduleEvents.indexOf(key)===-1){
  603. this.node.addEvent(key, function(event){
  604. return this.Macro.fire(e.code, this, event);
  605. }.bind(this));
  606. }
  607. }
  608. }.bind(this));
  609. },
  610. //搜索相关开始
  611. createSearchNode: function(){
  612. if (this.viewJson.customFilterList && this.viewJson.customFilterList.length){
  613. this.searchStatus = "default";
  614. this.loadFilterSearch();
  615. }else{
  616. this.loadSimpleSearch();
  617. }
  618. },
  619. loadSimpleSearch: function(){
  620. return false;
  621. this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
  622. this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
  623. this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
  624. this.searchSimpleButtonNode.addEvent("click", function(){
  625. this.search();
  626. }.bind(this));
  627. this.searchSimpleInputNode.addEvents({
  628. "focus": function(){
  629. if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
  630. }.bind(this),
  631. "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  632. "keydown": function(e){
  633. if (e.code===13) this.search();
  634. }.bind(this)
  635. });
  636. },
  637. search: function(){
  638. if (this.gridJson){
  639. var key = this.searchSimpleInputNode.get("value");
  640. var rows = this.viewTable.rows;
  641. var first = (this.json.isTitle!=="no") ? 1 : 0;
  642. for (var i = first; i<rows.length; i++){
  643. var tr = rows[i];
  644. if (!key || key==this.lp.searchKeywork){
  645. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  646. }else{
  647. if (tr.get("text").indexOf(key)!==-1){
  648. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  649. }else{
  650. if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
  651. }
  652. }
  653. }
  654. //if (this.viewPageAreaNode) this.viewPageAreaNode.hide();
  655. }
  656. },
  657. loadFilterSearch: function(){
  658. this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
  659. this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
  660. this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
  661. this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
  662. this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
  663. this.viewSearchInputNode.addEvents({
  664. "focus": function(){
  665. if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
  666. }.bind(this),
  667. "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  668. "keydown": function(e){
  669. if (e.code===13) this.searchView();
  670. }.bind(this)
  671. });
  672. this.viewSearchIconNode.addEvents({
  673. "click": function(){this.searchView();}.bind(this)
  674. });
  675. this.viewSearchCustomActionNode.addEvents({
  676. "click": function(){this.loadCustomSearch();}.bind(this)
  677. });
  678. },
  679. searchView: function(){
  680. if (this.viewJson.customFilterList) {
  681. var key = this.viewSearchInputNode.get("value");
  682. if (key && key !== this.lp.searchKeywork) {
  683. var filterData = this.json.filter ? this.json.filter : [];
  684. this.filterItems = [];
  685. this.viewJson.customFilterList.each(function (entry) {
  686. if (entry.formatType === "textValue") {
  687. var d = {
  688. "path": entry.path,
  689. "value": key,
  690. "formatType": entry.formatType,
  691. "logic": "or",
  692. "comparison": "like"
  693. };
  694. filterData.push(d);
  695. this.filterItems.push({"data":d});
  696. }
  697. if (entry.formatType === "numberValue") {
  698. var v = key.toFloat();
  699. if (!isNaN(v)) {
  700. var d = {
  701. "path": entry.path,
  702. "value": v,
  703. "formatType": entry.formatType,
  704. "logic": "or",
  705. "comparison": "like"
  706. };
  707. filterData.push(d);
  708. this.filterItems.push({"data":d});
  709. }
  710. }
  711. }.bind(this));
  712. this.createViewNode({"filterList": filterData});
  713. }else{
  714. this.createViewNode();
  715. }
  716. }
  717. },
  718. searchCustomView: function(){
  719. if (this.filterItems.length){
  720. var filterData = this.json.filter ? this.json.filter.clone() : [];
  721. this.filterItems.each(function(filter){
  722. filterData.push(filter.data);
  723. }.bind(this));
  724. this.createViewNode({"filterList": filterData});
  725. }else{
  726. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  727. }
  728. },
  729. loadCustomSearch: function(){
  730. this.viewSearchIconNode.setStyle("display", "none");
  731. this.viewSearchInputBoxNode.setStyle("display", "none");
  732. this.viewSearchCustomActionNode.setStyle("display", "none");
  733. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  734. var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
  735. this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
  736. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  737. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  738. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
  739. this.searchStatus = "custom";
  740. this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
  741. this.viewSearchInputAreaNode.setStyle("width", "auto");
  742. if (this.viewSearchCustomContentNode){
  743. this.viewSearchCustomCloseActionNode.setStyle("display", "block");
  744. this.viewSearchCustomContentNode.setStyle("display", "block");
  745. }else{
  746. this.loadCustomSearchContent();
  747. }
  748. this.setContentHeightFun();
  749. }.bind(this));
  750. this.searchCustomView();
  751. },
  752. loadCustomSearchContent: function(){
  753. this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
  754. this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
  755. this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
  756. this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
  757. this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
  758. this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
  759. this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
  760. this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
  761. this.loadViewSearchCustomList();
  762. this.viewSearchCustomCloseActionNode.addEvents({
  763. "click": function(){this.closeCustomSearch();}.bind(this)
  764. });
  765. this.viewSearchCustomAddIconNode.addEvents({
  766. "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
  767. });
  768. },
  769. loadViewSearchCustomList: function(){
  770. this.viewSearchCustomPathListNode = new Element("select", {
  771. "styles": this.css.viewFilterSearchCustomPathListNode,
  772. "multiple": true
  773. }).inject(this.viewSearchCustomPathContentNode);
  774. this.viewSearchCustomComparisonListNode = new Element("select", {
  775. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  776. "multiple": true
  777. }).inject(this.viewSearchCustomComparisonContentNode);
  778. this.viewJson.customFilterList.each(function(entry){
  779. var option = new Element("option", {
  780. "style": this.css.viewFilterSearchOptionNode,
  781. "value": entry.path,
  782. "text": entry.title
  783. }).inject(this.viewSearchCustomPathListNode);
  784. option.store("entry", entry);
  785. }.bind(this));
  786. this.viewSearchCustomPathListNode.addEvent("change", function(){
  787. this.loadViewSearchCustomComparisonList();
  788. }.bind(this));
  789. },
  790. loadViewSearchCustomComparisonList: function(){
  791. var idx = this.viewSearchCustomPathListNode.selectedIndex;
  792. var option = this.viewSearchCustomPathListNode.options[idx];
  793. var entry = option.retrieve("entry");
  794. if (entry){
  795. var selectableList = this.getCustomSelectScriptResult(entry);
  796. switch (entry.formatType){
  797. case "numberValue":
  798. this.loadComparisonSelect(this.lp.numberFilter);
  799. if( selectableList.length > 0 ){
  800. this.loadViewSerchCustomSelectByScript(selectableList)
  801. }else{
  802. this.loadViewSearchCustomValueNumberInput();
  803. }
  804. break;
  805. case "dateTimeValue":
  806. this.loadComparisonSelect(this.lp.dateFilter);
  807. if( selectableList.length > 0 ){
  808. this.loadViewSerchCustomSelectByScript(selectableList)
  809. }else {
  810. this.loadViewSearchCustomValueDateTimeInput();
  811. }
  812. break;
  813. case "dateValue":
  814. this.loadComparisonSelect(this.lp.dateFilter);
  815. if( selectableList.length > 0 ){
  816. this.loadViewSerchCustomSelectByScript(selectableList)
  817. }else {
  818. this.loadViewSearchCustomValueDateInput();
  819. }
  820. break;
  821. case "timeValue":
  822. this.loadComparisonSelect(this.lp.dateFilter);
  823. if( selectableList.length > 0 ){
  824. this.loadViewSerchCustomSelectByScript(selectableList)
  825. }else {
  826. this.loadViewSearchCustomValueTimeInput();
  827. }
  828. break;
  829. case "booleanValue":
  830. this.loadComparisonSelect(this.lp.booleanFilter);
  831. if( selectableList.length > 0 ){
  832. this.loadViewSerchCustomSelectByScript(selectableList)
  833. }else {
  834. this.loadViewSearchCustomValueBooleanInput();
  835. }
  836. break;
  837. default:
  838. this.loadComparisonSelect(this.lp.textFilter);
  839. if( selectableList.length > 0 ){
  840. this.loadViewSerchCustomSelectByScript(selectableList)
  841. }else {
  842. this.loadViewSearchCustomValueTextInput();
  843. }
  844. }
  845. }
  846. },
  847. getCustomSelectScriptResult : function( entry ){
  848. var scriptResult = [];
  849. if( entry.valueType === "script" ){
  850. if( entry.valueScript && entry.valueScript.code ){
  851. var result = this.Macro.exec(entry.valueScript.code, this);
  852. var array = typeOf( result ) === "array" ? result : [result];
  853. for( var i=0; i<array.length; i++ ){
  854. if( array[i].indexOf( "|" ) > -1 ){
  855. var arr = array[i].split("|");
  856. scriptResult.push({ "text" : arr[0], "value" : arr[1] })
  857. }else{
  858. scriptResult.push({ "text" : array[i], "value" : array[i] })
  859. }
  860. }
  861. }
  862. }
  863. return scriptResult;
  864. },
  865. loadViewSerchCustomSelectByScript: function( array ){
  866. this.viewSearchCustomValueContentNode.empty();
  867. this.viewSearchCustomValueNode = new Element("select", {
  868. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  869. "multiple": true
  870. }).inject(this.viewSearchCustomValueContentNode);
  871. array.each(function( v ){
  872. var option = new Element("option", {
  873. "style": this.css.viewFilterSearchOptionNode,
  874. "value": v.value,
  875. "text": v.text,
  876. "selected" : array.length === 1
  877. }).inject(this.viewSearchCustomValueNode);
  878. }.bind(this));
  879. },
  880. loadViewSearchCustomValueNumberInput: function(){
  881. this.viewSearchCustomValueContentNode.empty();
  882. this.viewSearchCustomValueNode = new Element("input", {
  883. "styles": this.css.viewFilterSearchCustomValueNode,
  884. "type": "number"
  885. }).inject(this.viewSearchCustomValueContentNode);
  886. },
  887. loadViewSearchCustomValueDateTimeInput: function(){
  888. this.viewSearchCustomValueContentNode.empty();
  889. this.viewSearchCustomValueNode = new Element("input", {
  890. "styles": this.css.viewFilterSearchCustomValueNode,
  891. "type": "text",
  892. "readonly": true
  893. }).inject(this.viewSearchCustomValueContentNode);
  894. MWF.require("MWF.widget.Calendar", function(){
  895. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  896. "style": "xform",
  897. "isTime": true,
  898. "secondEnable" : true,
  899. "target": this.container,
  900. "format": "db"
  901. });
  902. }.bind(this));
  903. },
  904. loadViewSearchCustomValueDateInput: function(){
  905. this.viewSearchCustomValueContentNode.empty();
  906. this.viewSearchCustomValueNode = new Element("input", {
  907. "styles": this.css.viewFilterSearchCustomValueNode,
  908. "type": "text",
  909. "readonly": true
  910. }).inject(this.viewSearchCustomValueContentNode);
  911. MWF.require("MWF.widget.Calendar", function(){
  912. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  913. "style": "xform",
  914. "isTime": false,
  915. "target": this.container,
  916. "format": "%Y-%m-%d"
  917. });
  918. }.bind(this));
  919. },
  920. loadViewSearchCustomValueTimeInput: function(){
  921. this.viewSearchCustomValueContentNode.empty();
  922. this.viewSearchCustomValueNode = new Element("input", {
  923. "styles": this.css.viewFilterSearchCustomValueNode,
  924. "type": "text",
  925. "readonly": true
  926. }).inject(this.viewSearchCustomValueContentNode);
  927. MWF.require("MWF.widget.Calendar", function(){
  928. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  929. "style": "xform",
  930. "timeOnly": true,
  931. "target": this.container,
  932. "format": "%H:%M:%S"
  933. });
  934. }.bind(this));
  935. },
  936. loadViewSearchCustomValueBooleanInput: function(){
  937. this.viewSearchCustomValueContentNode.empty();
  938. this.viewSearchCustomValueNode = new Element("select", {
  939. "styles": this.css.viewFilterSearchCustomValueSelectNode,
  940. "multiple": true
  941. }).inject(this.viewSearchCustomValueContentNode);
  942. new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
  943. new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
  944. },
  945. loadViewSearchCustomValueTextInput: function(){
  946. this.viewSearchCustomValueContentNode.empty();
  947. this.viewSearchCustomValueNode = new Element("textarea", {
  948. "styles": this.css.viewFilterSearchCustomValueNode
  949. }).inject(this.viewSearchCustomValueContentNode);
  950. },
  951. loadComparisonSelect:function(obj){
  952. this.viewSearchCustomComparisonListNode.empty();
  953. Object.each(obj, function(v, k){
  954. var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
  955. }.bind(this));
  956. },
  957. closeCustomSearch: function(){
  958. if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
  959. this.viewSearchCustomCloseActionNode.setStyle("display", "none");
  960. this.viewSearchCustomContentNode.setStyle("display", "none");
  961. var x = this.viewSearchInputAreaNode.getParent().getSize().x;
  962. x1 = x-2-10-90;
  963. this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
  964. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  965. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  966. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  967. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
  968. this.searchStatus = "default";
  969. this.css.viewFilterSearchInputAreaNode.width = "auto";
  970. this.viewSearchInputAreaNode.setStyle("margin-right", "90px");
  971. this.viewSearchIconNode.setStyle("display", "block");
  972. this.viewSearchInputBoxNode.setStyle("display", "block");
  973. this.viewSearchCustomActionNode.setStyle("display", "block");
  974. this.setContentHeightFun();
  975. }.bind(this));
  976. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  977. }
  978. },
  979. viewSearchCustomAddToFilter: function(){
  980. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  981. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  982. if (pathIdx===-1){
  983. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  984. return false;
  985. }
  986. if (comparisonIdx===-1){
  987. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  988. return false;
  989. }
  990. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  991. var entry = pathOption.retrieve("entry");
  992. if (entry){
  993. var pathTitle = entry.title;
  994. var path = entry.path;
  995. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  996. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  997. var value = "";
  998. if( entry.valueType === "script" && entry.valueScript && entry.valueScript.code ){
  999. var idx = this.viewSearchCustomValueNode.selectedIndex;
  1000. if (idx!==-1){
  1001. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  1002. value = entry.formatType === "booleanValue" ? (v==="true") : v;
  1003. }
  1004. }else{
  1005. switch (entry.formatType){
  1006. case "numberValue":
  1007. value = this.viewSearchCustomValueNode.get("value");
  1008. break;
  1009. case "dateTimeValue":
  1010. value = this.viewSearchCustomValueNode.get("value");
  1011. break;
  1012. case "booleanValue":
  1013. var idx = this.viewSearchCustomValueNode.selectedIndex;
  1014. if (idx!==-1){
  1015. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  1016. value = (v==="true");
  1017. }
  1018. break;
  1019. default:
  1020. value = this.viewSearchCustomValueNode.get("value");
  1021. }
  1022. }
  1023. if (value===""){
  1024. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  1025. return false;
  1026. }
  1027. this.filterItems.push(new MWF.xApplication.query.Query.Viewer.Filter(this, {
  1028. "logic": "and",
  1029. "path": path,
  1030. "title": pathTitle,
  1031. "comparison": comparison,
  1032. "comparisonTitle": comparisonTitle,
  1033. "value": value,
  1034. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  1035. }, this.viewSearchCustomFilterContentNode));
  1036. this.searchCustomView();
  1037. }
  1038. },
  1039. searchViewRemoveFilter: function(filter){
  1040. this.filterItems.erase(filter);
  1041. filter.destroy();
  1042. this.searchCustomView()
  1043. },
  1044. //搜索相关结束
  1045. //api 使用 开始
  1046. getParentEnvironment : function(){
  1047. return this.parentMacro ? this.parentMacro.environment : null;
  1048. },
  1049. getViewInfor : function(){
  1050. return this.json;
  1051. },
  1052. getPageInfor : function(){
  1053. return {
  1054. pages : this.pages,
  1055. perPageCount : this.options.perPageCount,
  1056. currentPageNumber : this.currentPage
  1057. };
  1058. },
  1059. getPageData : function () {
  1060. return this.gridJson;
  1061. },
  1062. toPage : function( pageNumber, callback ){
  1063. this.currentPage = pageNumber;
  1064. this.loadCurrentPageData( callback );
  1065. },
  1066. getSelectedData : function(){
  1067. return this.getData();
  1068. },
  1069. selectAll : function(){
  1070. var flag = this.json.select || this.viewJson.select || "none";
  1071. if ( flag==="multi"){
  1072. this.items.each( function (item) {
  1073. if( item.clazzType === "item" ){
  1074. item.selected();
  1075. }else{
  1076. item.expand();
  1077. if( item.items ){
  1078. item.items.each( function (it) {
  1079. it.selected();
  1080. })
  1081. }
  1082. }
  1083. })
  1084. }
  1085. },
  1086. unSelectAll : function(){
  1087. var flag = this.json.select || this.viewJson.select || "none";
  1088. if ( flag==="multi"){
  1089. this.items.each( function (item) {
  1090. if( item.clazzType === "item" ){
  1091. item.unSelected();
  1092. }else{
  1093. if(item.items){
  1094. item.items.each( function (it) {
  1095. it.unSelected();
  1096. })
  1097. }
  1098. }
  1099. })
  1100. }
  1101. },
  1102. setFilter : function( filter ){
  1103. if( !filter )filter = [];
  1104. if( typeOf( filter ) === "object" )filter = [ filter ];
  1105. this.json.filter = filter;
  1106. if( this.viewAreaNode ){
  1107. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  1108. }
  1109. },
  1110. switchView : function( json ){
  1111. debugger;
  1112. // json = {
  1113. // "application": application,
  1114. // "viewName": viewName,
  1115. // "isTitle": "yes",
  1116. // "select": "none",
  1117. // "titleStyles": titleStyles,
  1118. // "itemStyles": itemStyles,
  1119. // "isExpand": "no",
  1120. // "filter": filter
  1121. // }
  1122. this.node.setStyle("display", "block");
  1123. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  1124. this.searchMorph = null;
  1125. this.viewSearchCustomContentNode = null;
  1126. var newJson = Object.merge( Object.clone(this.originalJson), json );
  1127. this.container.empty();
  1128. this.initialize( this.container, newJson, Object.clone(this.options), this.app, this.parentMacro);
  1129. },
  1130. confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
  1131. this.app.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style)
  1132. },
  1133. alert: function (type, title, text, width, height) {
  1134. this.app.alert(type, "center", title, text, width, height);
  1135. },
  1136. notice: function (content, type, target, where, offset, option) {
  1137. this.app.notice(content, type, target, where, offset, option)
  1138. }
  1139. //api 使用 结束
  1140. });
  1141. MWF.xApplication.query.Query.Viewer.Item = new Class({
  1142. initialize: function(view, data, prev, i){
  1143. this.view = view;
  1144. this.data = data;
  1145. this.css = this.view.css;
  1146. this.isSelected = false;
  1147. this.prev = prev;
  1148. this.idx = i;
  1149. this.clazzType = "item";
  1150. this.load();
  1151. },
  1152. load: function(){
  1153. this.view.fireEvent("queryLoadItemRow", [null, this]);
  1154. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  1155. if (this.prev){
  1156. this.node.inject(this.prev.node, "after");
  1157. }else{
  1158. this.node.inject(this.view.viewTable);
  1159. }
  1160. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1161. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1162. this.selectTd.setStyles({"cursor": "pointer"});
  1163. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1164. //}
  1165. //序号
  1166. if (this.view.viewJson.isSequence==="yes"){
  1167. this.sequenceTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1168. this.sequenceTd.setStyle("width", "10px");
  1169. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  1170. this.sequenceTd.set("text", s);
  1171. }
  1172. Object.each(this.view.entries, function(c, k){
  1173. var cell = this.data.data[k];
  1174. if (cell === undefined) cell = "";
  1175. //if (cell){
  1176. if (this.view.hideColumns.indexOf(k)===-1){
  1177. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1178. if (k!== this.view.viewJson.group.column){
  1179. //var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  1180. var v = cell;
  1181. if (c.isHtml){
  1182. td.set("html", v);
  1183. }else{
  1184. td.set("text", v);
  1185. }
  1186. }
  1187. if (this.view.openColumns.indexOf(k)!==-1){
  1188. this.setOpenWork(td, c)
  1189. }
  1190. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1191. }
  1192. //}
  1193. }.bind(this));
  1194. // Object.each(this.data.data, function(cell, k){
  1195. // if (this.view.hideColumns.indexOf(k)===-1){
  1196. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1197. // if (k!== this.view.viewJson.group.column){
  1198. // var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  1199. // td.set("text", v);
  1200. // }
  1201. // if (this.view.openColumns.indexOf(k)!==-1){
  1202. // this.setOpenWork(td)
  1203. // }
  1204. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1205. // }
  1206. // }.bind(this));
  1207. this.setEvent();
  1208. this.view.fireEvent("postLoadItemRow", [null, this]);
  1209. },
  1210. setOpenWork: function(td, column){
  1211. td.setStyle("cursor", "pointer");
  1212. if( column.clickCode ){
  1213. // if( !this.view.Macro ){
  1214. // MWF.require("MWF.xScript.Macro", function () {
  1215. // this.view.businessData = {};
  1216. // this.view.Macro = new MWF.Macro.PageContext(this.view);
  1217. // }.bind(this), false);
  1218. // }
  1219. td.addEvent("click", function( ev ){
  1220. var result = this.view.Macro.fire(column.clickCode, this, ev);
  1221. ev.stopPropagation();
  1222. return result;
  1223. }.bind(this));
  1224. }else{
  1225. if (this.view.json.type==="cms"){
  1226. td.addEvent("click", function(ev){
  1227. this.openCms(ev)
  1228. ev.stopPropagation();
  1229. }.bind(this));
  1230. }else{
  1231. td.addEvent("click", function(ev){
  1232. this.openWorkAndCompleted(ev)
  1233. ev.stopPropagation();
  1234. }.bind(this));
  1235. }
  1236. }
  1237. },
  1238. openCms: function(e){
  1239. var options = {"documentId": this.data.bundle};
  1240. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1241. layout.desktop.openApplication(e, "cms.Document", options);
  1242. },
  1243. openWorkAndCompleted: function(e){
  1244. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
  1245. var workCompletedCount = json.data.workCompletedList.length;
  1246. var workCount = json.data.workList.length;
  1247. var count = workCount+workCompletedCount;
  1248. if (count===1){
  1249. if (workCompletedCount) {
  1250. this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  1251. }else{
  1252. this.openWork(json.data.workList[0].id, e);
  1253. }
  1254. }else if (count>1){
  1255. var worksAreaNode = this.createWorksArea();
  1256. json.data.workCompletedList.each(function(work){
  1257. this.createWorkCompletedNode(work, worksAreaNode);
  1258. }.bind(this));
  1259. json.data.workList.each(function(work){
  1260. this.createWorkNode(work, worksAreaNode);
  1261. }.bind(this));
  1262. this.showWorksArea(worksAreaNode, e);
  1263. }else{
  1264. }
  1265. }.bind(this));
  1266. },
  1267. createWorkNode: function(work, worksAreaNode){
  1268. var worksAreaContentNode = worksAreaNode.getLast();
  1269. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1270. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1271. actionNode.store("workId", work.id);
  1272. actionNode.addEvent("click", function(e){
  1273. this.openWork(e.target.retrieve("workId"), e);
  1274. this.mask.hide();
  1275. worksAreaNode.destroy();
  1276. }.bind(this));
  1277. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1278. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1279. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1280. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1281. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  1282. var taskUsers = [];
  1283. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  1284. json.data.each(function(task){
  1285. taskUsers.push(MWF.name.cn(task.person));
  1286. }.bind(this));
  1287. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  1288. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  1289. }.bind(this));
  1290. },
  1291. createWorkCompletedNode: function(work, worksAreaNode){
  1292. var worksAreaContentNode = worksAreaNode.getLast();
  1293. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1294. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1295. actionNode.store("workId", work.id);
  1296. actionNode.addEvent("click", function(e){
  1297. this.mask.hide();
  1298. var id = e.target.retrieve("workId");
  1299. worksAreaNode.destroy();
  1300. this.openWorkCompleted(id, e);
  1301. }.bind(this));
  1302. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1303. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1304. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1305. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1306. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  1307. },
  1308. createWorksArea: function(){
  1309. var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
  1310. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  1311. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  1312. worksAreaTitleCloseNode.addEvent("click", function(e){
  1313. this.mask.hide();
  1314. e.target.getParent().getParent().destroy();
  1315. }.bind(this));
  1316. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  1317. return worksAreaNode;
  1318. },
  1319. showWorksArea: function(node, e){
  1320. MWF.require("MWF.widget.Mask", null, false);
  1321. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  1322. this.mask.loadNode(this.view.container);
  1323. node.inject(this.view.node);
  1324. this.setWorksAreaPosition(node, e.target);
  1325. },
  1326. setWorksAreaPosition: function(node, td){
  1327. var p = td.getPosition(this.view.container);
  1328. var containerS = this.view.container.getSize();
  1329. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  1330. var s = node.getSize();
  1331. var offX = p.x+s.x-containerS.x;
  1332. offX = (offX>0) ? offX+20 : 0;
  1333. var offY = p.y+s.y-containerS.y;
  1334. offY = (offY>0) ? offY+5 : 0;
  1335. node.position({
  1336. "relativeTo": td,
  1337. "position": "lefttop",
  1338. "edge": "lefttop",
  1339. "offset": {
  1340. "x": 0-offX,
  1341. "y": 0-offY
  1342. }
  1343. });
  1344. },
  1345. openWork: function(id, e){
  1346. var options = {"workId": id};
  1347. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1348. layout.desktop.openApplication(e, "process.Work", options);
  1349. },
  1350. openWorkCompleted: function(id, e){
  1351. var options = {"workCompletedId": id};
  1352. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1353. layout.desktop.openApplication(e, "process.Work", options);
  1354. },
  1355. setEvent: function(){
  1356. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1357. if ( flag ==="single" || flag==="multi"){
  1358. this.node.addEvents({
  1359. "mouseover": function(){
  1360. if (!this.isSelected){
  1361. var iconName = "checkbox";
  1362. if (flag==="single") iconName = "radiobox";
  1363. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  1364. }
  1365. }.bind(this),
  1366. "mouseout": function(){
  1367. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  1368. }.bind(this),
  1369. "click": function(){this.select();}.bind(this)
  1370. });
  1371. }
  1372. },
  1373. select: function(){
  1374. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1375. if (this.isSelected){
  1376. if (flag==="single"){
  1377. this.unSelectedSingle();
  1378. }else{
  1379. this.unSelected();
  1380. }
  1381. }else{
  1382. if (flag==="single"){
  1383. this.selectedSingle();
  1384. }else{
  1385. this.selected();
  1386. }
  1387. }
  1388. this.view.fireEvent("select"); //options 传入的事件
  1389. },
  1390. selected: function(){
  1391. this.view.selectedItems.push(this);
  1392. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  1393. this.node.setStyles(this.css.viewContentTrNode_selected);
  1394. this.isSelected = true;
  1395. this.view.fireEvent("selectRow", [this]);
  1396. },
  1397. unSelected: function(){
  1398. this.view.selectedItems.erase(this);
  1399. this.selectTd.setStyles({"background": "transparent"});
  1400. this.node.setStyles(this.css.viewContentTrNode);
  1401. this.isSelected = false;
  1402. this.view.fireEvent("unselectRow", [this]);
  1403. },
  1404. selectedSingle: function(){
  1405. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  1406. this.view.selectedItems = [this];
  1407. this.view.currentSelectedItem = this;
  1408. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
  1409. this.node.setStyles(this.css.viewContentTrNode_selected);
  1410. this.isSelected = true;
  1411. this.view.fireEvent("selectRow", [this]);
  1412. },
  1413. unSelectedSingle: function(){
  1414. this.view.selectedItems = [];
  1415. this.view.currentSelectedItem = null;
  1416. this.selectTd.setStyles({"background": "transparent"});
  1417. this.node.setStyles(this.css.viewContentTrNode);
  1418. this.isSelected = false;
  1419. this.view.fireEvent("unselectRow", [this]);
  1420. }
  1421. });
  1422. MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
  1423. initialize: function(view, data, i){
  1424. this.view = view;
  1425. this.data = data;
  1426. this.css = this.view.css;
  1427. this.items = [];
  1428. this.loadChild = false;
  1429. this.idx = i;
  1430. this.clazzType = "category";
  1431. this.load();
  1432. },
  1433. load: function(){
  1434. this.view.fireEvent("queryLoadCategoryRow", [null, this]);
  1435. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  1436. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1437. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  1438. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1439. //}
  1440. this.categoryTd = new Element("td", {
  1441. "styles": this.css.viewContentCategoryTdNode,
  1442. "colspan": this.view.viewJson.selectList.length+1
  1443. }).inject(this.node);
  1444. this.groupColumn = null;
  1445. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  1446. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  1447. this.groupColumn = this.view.viewJson.selectList[c];
  1448. break;
  1449. }
  1450. }
  1451. if (this.groupColumn){
  1452. //var text = (this.groupColumn.code) ? MWF.Macro.exec(this.groupColumn.code, {"value": this.data.group, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : this.data.group;
  1453. var text = this.data.group;
  1454. }else{
  1455. var text = this.data.group;
  1456. }
  1457. this.categoryTd.set("html", "<span style='font-family: Webdings'><img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/></span> "+text);
  1458. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  1459. this.setEvent();
  1460. this.view.fireEvent("postLoadCategoryRow", [null, this]);
  1461. },
  1462. setEvent: function(){
  1463. //if (this.selectTd){
  1464. this.node.addEvents({
  1465. "click": function(){this.expandOrCollapse();}.bind(this)
  1466. });
  1467. //}
  1468. },
  1469. expandOrCollapse: function(){
  1470. var t = this.node.getElement("span").get("html");
  1471. if (t.indexOf("expand.png")===-1){
  1472. this.collapse();
  1473. }else{
  1474. this.expand();
  1475. }
  1476. },
  1477. collapse: function(){
  1478. this.items.each(function(item){
  1479. item.node.setStyle("display", "none");
  1480. }.bind(this));
  1481. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  1482. },
  1483. expand: function(){
  1484. this.items.each(function(item){
  1485. item.node.setStyle("display", "table-row");
  1486. }.bind(this));
  1487. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  1488. if (!this.loadChild){
  1489. //window.setTimeout(function(){
  1490. this.data.list.each(function(line, i){
  1491. var s = this.idx+i;
  1492. this.lastItem = new MWF.xApplication.query.Query.Viewer.Item(this.view, line, (this.lastItem || this), s);
  1493. this.items.push(this.lastItem);
  1494. }.bind(this));
  1495. this.loadChild = true;
  1496. //}.bind(this), 10);
  1497. }
  1498. }
  1499. });
  1500. MWF.xApplication.query.Query.Viewer.Filter = new Class({
  1501. initialize: function(viewer, data, node){
  1502. this.viewer = viewer;
  1503. this.data = data;
  1504. this.css = this.viewer.css;
  1505. this.content = node;
  1506. this.load();
  1507. },
  1508. load: function(){
  1509. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  1510. if (this.viewer.filterItems.length){
  1511. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  1512. this.logicSelectNode = new Element("div", {
  1513. "styles": this.css.viewSearchFilterSelectNode,
  1514. "text": this.viewer.lp.and,
  1515. "value": "and"
  1516. }).inject(this.logicNode);
  1517. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  1518. this.logicNode.addEvents({
  1519. "click": function(){
  1520. var v = this.logicSelectNode.get("value");
  1521. if (v==="and"){
  1522. this.logicSelectButtonNode.setStyle("float", "left");
  1523. this.logicSelectNode.setStyle("float", "right");
  1524. this.logicSelectNode.set({
  1525. "text": this.viewer.lp.or,
  1526. "value": "or"
  1527. });
  1528. this.data.logic = "or";
  1529. }else{
  1530. this.logicSelectButtonNode.setStyle("float", "right");
  1531. this.logicSelectNode.setStyle("float", "left");
  1532. this.logicSelectNode.set({
  1533. "text": this.viewer.lp.and,
  1534. "value": "and"
  1535. });
  1536. this.data.logic = "and";
  1537. }
  1538. this.viewer.searchCustomView();
  1539. }.bind(this)
  1540. });
  1541. }
  1542. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  1543. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  1544. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  1545. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  1546. this.node.addEvents({
  1547. "mouseover": function(){
  1548. this.node.setStyles(this.css.viewSearchFilterNode_over);
  1549. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  1550. }.bind(this),
  1551. "mouseout": function(){
  1552. this.node.setStyles(this.css.viewSearchFilterNode);
  1553. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  1554. }.bind(this)
  1555. });
  1556. this.deleteNode.addEvent("click", function(){
  1557. this.viewer.searchViewRemoveFilter(this);
  1558. }.bind(this));
  1559. },
  1560. destroy: function(){
  1561. this.node.destroy();
  1562. MWF.release(this);
  1563. }
  1564. });
  1565. MWF.xApplication.query.Query.Viewer.Actionbar = new Class({
  1566. Implements: [Events],
  1567. options: {
  1568. "style" : "default",
  1569. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
  1570. },
  1571. initialize: function(node, json, form, options){
  1572. this.node = $(node);
  1573. this.node.store("module", this);
  1574. this.json = json;
  1575. this.form = form;
  1576. this.view = form;
  1577. },
  1578. hide: function(){
  1579. var dsp = this.node.getStyle("display");
  1580. if (dsp!=="none") this.node.store("mwf_display", dsp);
  1581. this.node.setStyle("display", "none");
  1582. },
  1583. show: function(){
  1584. var dsp = this.node.retrieve("mwf_display", dsp);
  1585. this.node.setStyle("display", dsp);
  1586. },
  1587. load: function(){
  1588. this._loadModuleEvents();
  1589. if (this.fireEvent("queryLoad")){
  1590. //this._queryLoaded();
  1591. this._loadUserInterface();
  1592. this._loadStyles();
  1593. this._loadDomEvents();
  1594. //this._loadEvents();
  1595. //this._afterLoaded();
  1596. this.fireEvent("postLoad");
  1597. this.fireEvent("load");
  1598. }
  1599. },
  1600. _loadStyles: function(){
  1601. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1602. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  1603. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1604. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1605. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  1606. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1607. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1608. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1609. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1610. }
  1611. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1612. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1613. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1614. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1615. }
  1616. if (value.indexOf("/x_cms_assemble_control")!==-1){
  1617. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1618. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  1619. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1620. }
  1621. }
  1622. this.node.setStyle(key, value);
  1623. }.bind(this));
  1624. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  1625. // var host = MWF.Actions.getHost(root);
  1626. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  1627. // }
  1628. //if (this.json.styles) this.node.setStyles(this.json.styles);
  1629. },
  1630. _loadModuleEvents : function(){
  1631. Object.each(this.json.events, function(e, key){
  1632. if (e.code){
  1633. if (this.options.moduleEvents.indexOf(key)!==-1){
  1634. this.addEvent(key, function(event){
  1635. return this.form.Macro.fire(e.code, this, event);
  1636. }.bind(this));
  1637. }
  1638. }
  1639. }.bind(this));
  1640. },
  1641. _loadDomEvents: function(){
  1642. Object.each(this.json.events, function(e, key){
  1643. if (e.code){
  1644. if (this.options.moduleEvents.indexOf(key)===-1){
  1645. this.node.addEvent(key, function(event){
  1646. return this.form.Macro.fire(e.code, this, event);
  1647. }.bind(this));
  1648. }
  1649. }
  1650. }.bind(this));
  1651. },
  1652. _loadEvents: function(){
  1653. Object.each(this.json.events, function(e, key){
  1654. if (e.code){
  1655. if (this.options.moduleEvents.indexOf(key)!==-1){
  1656. this.addEvent(key, function(event){
  1657. return this.form.Macro.fire(e.code, this, event);
  1658. }.bind(this));
  1659. }else{
  1660. this.node.addEvent(key, function(event){
  1661. return this.form.Macro.fire(e.code, this, event);
  1662. }.bind(this));
  1663. }
  1664. }
  1665. }.bind(this));
  1666. },
  1667. addModuleEvent: function(key, fun){
  1668. if (this.options.moduleEvents.indexOf(key)!==-1){
  1669. this.addEvent(key, function(event){
  1670. return (fun) ? fun(this, event) : null;
  1671. }.bind(this));
  1672. }else{
  1673. this.node.addEvent(key, function(event){
  1674. return (fun) ? fun(this, event) : null;
  1675. }.bind(this));
  1676. }
  1677. },
  1678. _loadUserInterface: function(){
  1679. // if (this.form.json.mode == "Mobile"){
  1680. // this.node.empty();
  1681. // }else if (COMMON.Browser.Platform.isMobile){
  1682. // this.node.empty();
  1683. // }else{
  1684. this.toolbarNode = this.node.getFirst("div");
  1685. if( !this.toolbarNode ){
  1686. this.toolbarNode = new Element("div").inject( this.node );
  1687. }
  1688. this.toolbarNode.empty();
  1689. MWF.require("MWF.widget.Toolbar", function(){
  1690. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  1691. "style": this.json.style,
  1692. "onPostLoad" : function(){
  1693. this.fireEvent("afterLoad");
  1694. }.bind(this)
  1695. }, this);
  1696. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  1697. //alert(this.readonly)
  1698. if (this.json.hideSystemTools){
  1699. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1700. this.toolbarWidget.load();
  1701. }else{
  1702. if (this.json.defaultTools){
  1703. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  1704. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1705. this.toolbarWidget.load();
  1706. }else{
  1707. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  1708. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  1709. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1710. this.toolbarWidget.load();
  1711. }.bind(this), null);
  1712. }
  1713. }
  1714. }.bind(this));
  1715. // }
  1716. },
  1717. setCustomToolbars: function(tools, node){
  1718. var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1719. var iconPath = "";
  1720. if( this.json.customIconStyle ){
  1721. iconPath = this.json.customIconStyle+"/";
  1722. }
  1723. tools.each(function(tool){
  1724. var flag = true;
  1725. if (this.readonly){
  1726. flag = tool.readShow;
  1727. }else{
  1728. flag = tool.editShow;
  1729. }
  1730. if (flag){
  1731. flag = true;
  1732. // if (tool.control){
  1733. // flag = this.form.businessData.control[tool.control]
  1734. // }
  1735. if (tool.condition){
  1736. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1737. flag = !hideFlag;
  1738. }
  1739. if (flag){
  1740. var actionNode = new Element("div", {
  1741. "id": tool.id,
  1742. "MWFnodetype": tool.type,
  1743. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  1744. "title": tool.title,
  1745. "MWFButtonAction": "runCustomAction",
  1746. "MWFButtonText": tool.text
  1747. }).inject(node);
  1748. if( this.json.customIconOverStyle ){
  1749. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  1750. }
  1751. if( tool.properties ){
  1752. actionNode.set(tool.properties);
  1753. }
  1754. if (tool.actionScript){
  1755. actionNode.store("script", tool.actionScript);
  1756. }
  1757. if (tool.sub){
  1758. var subNode = node.getLast();
  1759. this.setCustomToolbars(tool.sub, subNode);
  1760. }
  1761. }
  1762. }
  1763. }.bind(this));
  1764. },
  1765. setToolbarItem: function(tool, node, readonly, noCondition){
  1766. //var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1767. var path = "/x_component_query_ViewDesigner/$View/";
  1768. var flag = true;
  1769. // if (tool.control){
  1770. // flag = this.form.businessData.control[tool.control]
  1771. // }
  1772. if (!noCondition) if (tool.condition){
  1773. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1774. flag = flag && (!hideFlag);
  1775. }
  1776. if (readonly) if (!tool.read) flag = false;
  1777. if (flag){
  1778. var actionNode = new Element("div", {
  1779. "id": tool.id,
  1780. "MWFnodetype": tool.type,
  1781. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  1782. //"MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  1783. "MWFButtonImage": path+this.options.style+"/actionbar/"+tool.img,
  1784. "title": tool.title,
  1785. "MWFButtonAction": tool.action,
  1786. "MWFButtonText": tool.text
  1787. }).inject(node);
  1788. if( this.json.iconOverStyle ){
  1789. actionNode.set("MWFButtonImageOver" , path+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
  1790. //actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  1791. }
  1792. if( tool.properties ){
  1793. actionNode.set(tool.properties);
  1794. }
  1795. if (tool.sub){
  1796. var subNode = node.getLast();
  1797. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  1798. }
  1799. }
  1800. },
  1801. setToolbars: function(tools, node, readonly, noCondition){
  1802. tools.each(function(tool){
  1803. this.setToolbarItem(tool, node, readonly, noCondition);
  1804. }.bind(this));
  1805. },
  1806. runCustomAction: function(bt){
  1807. var script = bt.node.retrieve("script");
  1808. this.form.Macro.exec(script, this);
  1809. },
  1810. exportView : function(){
  1811. this.form.exportView();
  1812. },
  1813. deleteWork: function(){
  1814. this.form.deleteWork();
  1815. }
  1816. });