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. "resizeNode": true,
  13. "paging" : "scroll",
  14. "perPageCount" : 50,
  15. "isload": "true",
  16. "export": false,
  17. "moduleEvents": ["queryLoad", "postLoad", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
  18. "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow"]
  19. // "actions": {
  20. // "lookup": {"uri": "/jaxrs/view/flag/{view}/query/{application}/execute", "method":"PUT"},
  21. // "getView": {"uri": "/jaxrs/view/flag/{view}/query/{application}"}
  22. //
  23. // },
  24. // "actionRoot": "x_query_assemble_surface"
  25. },
  26. initialize: function(container, json, options, app, parentMacro){
  27. //本类有三种事件,
  28. //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
  29. //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
  30. //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件
  31. this.setOptions(options);
  32. this.path = "/x_component_query_Query/$Viewer/";
  33. this.cssPath = "/x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
  34. this._loadCss();
  35. this.lp = MWF.xApplication.query.Query.LP;
  36. this.app = app;
  37. this.container = $(container);
  38. this.json = json;
  39. this.parentMacro = parentMacro;
  40. debugger;
  41. this.originalJson = Object.clone(json);
  42. this.viewJson = null;
  43. this.filterItems = [];
  44. this.searchStatus = "none"; //none, custom, default
  45. this.items = [];
  46. this.selectedItems = [];
  47. this.hideColumns = [];
  48. this.openColumns = [];
  49. this.gridJson = null;
  50. if (this.options.isload){
  51. this.init(function(){
  52. this.load();
  53. }.bind(this));
  54. }
  55. },
  56. loadView: function(){
  57. if (this.viewJson){
  58. this.reload();
  59. }else{
  60. this.init(function(){
  61. this.load();
  62. }.bind(this));
  63. }
  64. },
  65. init: function(callback){
  66. if (this.json.data){
  67. this.viewJson = JSON.decode(this.json.data);
  68. if (callback) callback();
  69. }else{
  70. this.getView(callback);
  71. }
  72. },
  73. load: function(){
  74. this.loadMacro( function () {
  75. this._loadModuleEvents();
  76. if (this.fireEvent("queryLoad")){
  77. this._loadUserInterface();
  78. //this._loadStyles();
  79. this._loadDomEvents();
  80. }
  81. }.bind(this))
  82. },
  83. _loadUserInterface : function(){
  84. this.loadLayout();
  85. this.createActionbarNode();
  86. this.createSearchNode();
  87. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  88. if (this.options.resizeNode){
  89. this.setContentHeightFun = this.setContentHeight.bind(this);
  90. this.container.addEvent("resize", this.setContentHeightFun);
  91. this.setContentHeightFun();
  92. }
  93. },
  94. loadLayout: function(){
  95. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  96. this.actionbarAreaNode = new Element("div", {"styles": this.css.actionbarAreaNode}).inject(this.node);
  97. //if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
  98. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
  99. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  100. this.viewPageNode = new Element("div", {"styles": this.css.viewPageNode}).inject(this.node);
  101. this.viewPageAreaNode = new Element("div", {"styles": this.css.viewPageAreaNode}).inject(this.viewPageNode);
  102. },
  103. loadMacro: function (callback) {
  104. MWF.require("MWF.xScript.Macro", function () {
  105. this.Macro = new MWF.Macro.ViewContext(this);
  106. if (callback) callback();
  107. }.bind(this));
  108. },
  109. createExportNode: function(){
  110. if (this.options.export){
  111. MWF.require("MWF.widget.Toolbar", function(){
  112. this.toolbar = new MWF.widget.Toolbar(this.actionbarAreaNode, {"style": "simple"}, this); //this.exportAreaNode
  113. var actionNode = new Element("div", {
  114. "id": "",
  115. "MWFnodetype": "MWFToolBarButton",
  116. "MWFButtonImage": this.path+""+this.options.style+"/icon/export.png",
  117. "title": this.lp.exportExcel,
  118. "MWFButtonAction": "exportView",
  119. "MWFButtonText": this.lp.exportExcel
  120. }).inject(this.actionbarAreaNode); //this.exportAreaNode
  121. this.toolbar.load();
  122. }.bind(this));
  123. //this.exportNode = new Element("button", {"text": this.lp.exportExcel}).inject(this.exportAreaNode);
  124. }
  125. },
  126. exportView: function(){
  127. var action = MWF.Actions.get("x_query_assemble_surface");
  128. var filterData = this.json.filter ? this.json.filter.clone() : [];
  129. if (this.filterItems.length){
  130. this.filterItems.each(function(filter){
  131. filterData.push(filter.data);
  132. }.bind(this));
  133. }
  134. action.exportViewWithQuery(this.json.viewName, this.json.application, {"filterList": filterData}, function(json){
  135. var uri = action.action.actions.getViewExcel.uri;
  136. uri = uri.replace("{flag}", json.data.id);
  137. uri = action.action.address+uri;
  138. var a = new Element("a", {"href": uri, "target":"_blank"});
  139. a.click();
  140. a.destroy();
  141. }.bind(this));
  142. },
  143. setContentHeight: function(){
  144. var size = this.node.getSize();
  145. var searchSize = this.searchAreaNode.getComputedSize();
  146. var h = size.y-searchSize.totalHeight;
  147. //if (this.exportAreaNode){
  148. // var exportSize = this.exportAreaNode.getComputedSize();
  149. // h = h-exportSize.totalHeight;
  150. //}
  151. if( this.actionbarAreaNode ){
  152. var exportSize = this.actionbarAreaNode.getComputedSize();
  153. h = h-exportSize.totalHeight;
  154. }
  155. var pageSize = this.viewPageNode.getComputedSize();
  156. h = h-pageSize.totalHeight;
  157. this.viewAreaNode.setStyle("height", ""+h+"px");
  158. },
  159. createLoadding: function(){
  160. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  161. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  162. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  163. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  164. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  165. loadingTextNode.set("text", "loading...");
  166. },
  167. createActionbarNode : function(){
  168. this.actionbarAreaNode.empty();
  169. if( typeOf( this.viewJson.actionbarHidden ) === "boolean" ){
  170. if( this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length )return;
  171. this.actionbar = new MWF.xApplication.query.Query.Viewer.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
  172. this.actionbar.load();
  173. }else{ //兼容以前的ExportNode
  174. this.createExportNode();
  175. }
  176. },
  177. createViewNode: function(data){
  178. this.viewAreaNode.empty();
  179. this.contentAreaNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
  180. this.viewTable = new Element("table", {
  181. "styles": this.css.viewTitleTableNode,
  182. "border": "0px",
  183. "cellPadding": "0",
  184. "cellSpacing": "0"
  185. }).inject(this.contentAreaNode);
  186. this.createLoadding();
  187. if (this.json.isTitle!=="no"){
  188. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  189. //if (this.json.select==="single" || this.json.select==="multi") {
  190. this.selectTitleCell = new Element("td", {
  191. "styles": this.css.viewTitleCellNode
  192. }).inject(this.viewTitleLine);
  193. this.selectTitleCell.setStyle("width", "10px");
  194. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  195. //}
  196. //序号
  197. if (this.viewJson.isSequence==="yes"){
  198. this.sequenceTitleCell = new Element("td", {
  199. "styles": this.css.viewTitleCellNode
  200. }).inject(this.viewTitleLine);
  201. this.sequenceTitleCell.setStyle("width", "10px");
  202. if (this.json.titleStyles) this.sequenceTitleCell.setStyles(this.json.titleStyles);
  203. }
  204. this.entries = {};
  205. this.viewJson.selectList.each(function(column){
  206. this.entries[column.column] = column;
  207. if (!column.hideColumn){
  208. var viewCell = new Element("td", {
  209. "styles": this.css.viewTitleCellNode,
  210. "text": column.displayName
  211. }).inject(this.viewTitleLine);
  212. var size = MWF.getTextSize(column.displayName, this.css.viewTitleCellNode);
  213. viewCell.setStyle("min-width", ""+size.x+"px");
  214. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  215. }else{
  216. this.hideColumns.push(column.column);
  217. }
  218. if (column.allowOpen) this.openColumns.push(column.column);
  219. }.bind(this));
  220. this.lookup(data);
  221. }else{
  222. this.viewJson.selectList.each(function(column){
  223. if (column.hideColumn) this.hideColumns.push(column.column);
  224. if (!column.allowOpen) this.openColumns.push(column.column);
  225. }.bind(this));
  226. this.lookup(data);
  227. }
  228. },
  229. // _loadPageCountNode: function(){
  230. // this.viewPageContentNode.empty();
  231. //
  232. // var size = this.viewPageAreaNode.getSize();
  233. // var w1 = this.viewPageFirstNode.getSize().x*2;
  234. // var w2 = this.viewPageContentNode.getStyle("margin-left").toInt();
  235. // var w = size.x-w1-w2;
  236. //
  237. // var bw = this.css.viewPageButtonNode.width.toInt()+this.css.viewPageButtonNode["margin-right"].toInt();
  238. // var count = (w/bw).toInt()-2;
  239. // if (count>10) count = 10;
  240. // this.showPageCount = Math.min(count, this.pages);
  241. //
  242. // var tmp = this.showPageCount/2;
  243. // var n = tmp.toInt();
  244. // var left = this.currentPage-n;
  245. // if (left<=0) left = 1;
  246. // var right = this.showPageCount + left-1;
  247. // if (right>this.pages) right = this.pages;
  248. // left = right-this.showPageCount+1;
  249. // if (left<=1) left = 1;
  250. //
  251. // this.viewPagePrevNode = new Element("div", {"styles": this.css.viewPagePrevButtonNode}).inject(this.viewPageContentNode);
  252. // this.loadPageButtonEvent(this.viewPagePrevNode, "viewPagePrevButtonNode_over", "viewPagePrevButtonNode_up", "viewPagePrevButtonNode_down", function(){
  253. // if (this.currentPage>1) this.currentPage--;
  254. // this.loadCurrentPageData();
  255. // }.bind(this));
  256. //
  257. // for (i=left; i<=right; i++){
  258. // var node = new Element("div", {"styles": this.css.viewPageButtonNode, "text": i}).inject(this.viewPageContentNode);
  259. // if (i==this.currentPage){
  260. // node.setStyles(this.css.viewPageButtonNode_current);
  261. // }else{
  262. // this.loadPageButtonEvent(node, "viewPageButtonNode_over", "viewPageButtonNode_up", "viewPageButtonNode_down", function(e){
  263. // this.currentPage = e.target.get("text").toInt();
  264. // this.loadCurrentPageData();
  265. // }.bind(this));
  266. // }
  267. // }
  268. // this.viewPageNextNode = new Element("div", {"styles": this.css.viewPageNextButtonNode}).inject(this.viewPageContentNode);
  269. // this.loadPageButtonEvent(this.viewPageNextNode, "viewPageNextButtonNode_over", "viewPageNextButtonNode_up", "viewPageNextButtonNode_down", function(){
  270. // if (this.currentPage<=this.pages-1) this.currentPage++;
  271. // this.loadCurrentPageData();
  272. // }.bind(this));
  273. // },
  274. // loadPageButtonEvent: function(node, over, out, down, click){
  275. // node.addEvents({
  276. // "mouseover": function(){node.setStyles(this.css[over])}.bind(this),
  277. // "mouseout": function(){node.setStyles(this.css[out])}.bind(this),
  278. // "mousedown": function(){node.setStyles(this.css[down])}.bind(this),
  279. // "mouseup": function(){node.setStyles(this.css[out])}.bind(this),
  280. // "click": click
  281. // });
  282. // },
  283. // _loadPageNode: function(){
  284. // this.viewPageAreaNode.empty();
  285. // this.viewPageFirstNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.firstPage}).inject(this.viewPageAreaNode);
  286. // this.viewPageContentNode = new Element("div", {"styles": this.css.viewPageContentNode}).inject(this.viewPageAreaNode);
  287. // this.viewPageLastNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.lastPage}).inject(this.viewPageAreaNode);
  288. // this._loadPageCountNode();
  289. //
  290. // this.loadPageButtonEvent(this.viewPageFirstNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  291. // this.currentPage = 1;
  292. // this.loadCurrentPageData();
  293. // }.bind(this));
  294. // this.loadPageButtonEvent(this.viewPageLastNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  295. // this.currentPage = this.pages;
  296. // this.loadCurrentPageData();
  297. // }.bind(this));
  298. // },
  299. _loadPageNode : function(){
  300. debugger;
  301. this.viewPageAreaNode.empty();
  302. this.paging = new o2.widget.Paging(this.viewPageAreaNode, {
  303. countPerPage: this.json.pageSize || this.options.perPageCount,
  304. visiblePages: this.viewJson.visiblePages ? this.viewJson.visiblePages.toInt() : 9,
  305. currentPage: this.currentPage,
  306. itemSize: this.count,
  307. pageSize: this.pages,
  308. hasNextPage: typeOf( this.viewJson.hasPreNextPage ) === "boolean" ? this.viewJson.hasPreNextPage : true,
  309. hasPrevPage: typeOf( this.viewJson.hasPreNextPage ) === "boolean" ? this.viewJson.hasPreNextPage : true,
  310. hasTruningBar: typeOf( this.viewJson.hasTruningBar ) === "boolean" ? this.viewJson.hasTruningBar : true,
  311. hasBatchTuring: typeOf( this.viewJson.hasBatchTuring ) === "boolean" ? this.viewJson.hasBatchTuring : true,
  312. hasFirstPage: typeOf( this.viewJson.hasFirstLastPage ) === "boolean" ? this.viewJson.hasFirstLastPage : true,
  313. hasLastPage: typeOf( this.viewJson.hasFirstLastPage ) === "boolean" ? this.viewJson.hasFirstLastPage : true,
  314. hasJumper: typeOf( this.viewJson.hasPageJumper ) === "boolean" ? this.viewJson.hasPageJumper : true,
  315. hiddenWithDisable: false,
  316. hiddenWithNoItem: true,
  317. text: {
  318. prePage: "",
  319. nextPage: "",
  320. firstPage: this.lp.firstPage,
  321. lastPage: this.lp.lastPage
  322. },
  323. onJumpingPage : function( pageNum, itemNum ){
  324. this.currentPage = pageNum;
  325. this.loadCurrentPageData();
  326. }.bind(this),
  327. onPostLoad : function () {
  328. this.setContentHeightFun();
  329. }.bind(this)
  330. });
  331. this.paging.load();
  332. },
  333. _initPage: function(){
  334. this.count = this.bundleItems.length;
  335. var i = this.count/this.json.pageSize;
  336. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  337. this.currentPage = 1;
  338. },
  339. lookup: function(data){
  340. this.getLookupAction(function(){
  341. if (this.json.application){
  342. var d = data || {};
  343. d.count = this.json.count;
  344. this.lookupAction.bundleView(this.json.id, d, function(json){
  345. this.bundleItems = json.data.valueList;
  346. this._initPage();
  347. if (this.bundleItems.length){
  348. this.loadCurrentPageData( function () {
  349. this.fireEvent("postLoad"); //用户配置的事件
  350. }.bind(this));
  351. }else{
  352. //this._loadPageNode();
  353. this.viewPageAreaNode.empty();
  354. if (this.loadingAreaNode){
  355. this.loadingAreaNode.destroy();
  356. this.loadingAreaNode = null;
  357. }
  358. this.fireEvent("postLoad"); //用户配置的事件
  359. }
  360. }.bind(this));
  361. }
  362. }.bind(this));
  363. },
  364. loadCurrentPageData: function( callback ){
  365. debugger;
  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. debugger;
  590. Object.each(this.viewJson.events, function(e, key){
  591. if (e.code){
  592. if (this.options.moduleEvents.indexOf(key)!==-1){
  593. this.addEvent(key, function(event, target){
  594. debugger;
  595. return this.Macro.fire(e.code, target || this, event);
  596. }.bind(this));
  597. }
  598. }
  599. }.bind(this));
  600. },
  601. _loadDomEvents: function(){
  602. Object.each(this.viewJson.events, function(e, key){
  603. if (e.code){
  604. if (this.options.moduleEvents.indexOf(key)===-1){
  605. this.node.addEvent(key, function(event){
  606. return this.Macro.fire(e.code, this, event);
  607. }.bind(this));
  608. }
  609. }
  610. }.bind(this));
  611. },
  612. //搜索相关开始
  613. createSearchNode: function(){
  614. if (this.viewJson.customFilterList && this.viewJson.customFilterList.length){
  615. this.searchStatus = "default";
  616. this.loadFilterSearch();
  617. }else{
  618. this.loadSimpleSearch();
  619. }
  620. },
  621. loadSimpleSearch: function(){
  622. return false;
  623. this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
  624. this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
  625. this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
  626. this.searchSimpleButtonNode.addEvent("click", function(){
  627. this.search();
  628. }.bind(this));
  629. this.searchSimpleInputNode.addEvents({
  630. "focus": function(){
  631. if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
  632. }.bind(this),
  633. "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  634. "keydown": function(e){
  635. if (e.code===13) this.search();
  636. }.bind(this)
  637. });
  638. },
  639. search: function(){
  640. if (this.gridJson){
  641. var key = this.searchSimpleInputNode.get("value");
  642. var rows = this.viewTable.rows;
  643. var first = (this.json.isTitle!=="no") ? 1 : 0;
  644. for (var i = first; i<rows.length; i++){
  645. var tr = rows[i];
  646. if (!key || key==this.lp.searchKeywork){
  647. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  648. }else{
  649. if (tr.get("text").indexOf(key)!==-1){
  650. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  651. }else{
  652. if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
  653. }
  654. }
  655. }
  656. //if (this.viewPageAreaNode) this.viewPageAreaNode.hide();
  657. }
  658. },
  659. loadFilterSearch: function(){
  660. this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
  661. this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
  662. this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
  663. this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
  664. this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
  665. this.viewSearchInputNode.addEvents({
  666. "focus": function(){
  667. if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
  668. }.bind(this),
  669. "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  670. "keydown": function(e){
  671. if (e.code===13) this.searchView();
  672. }.bind(this)
  673. });
  674. this.viewSearchIconNode.addEvents({
  675. "click": function(){this.searchView();}.bind(this)
  676. });
  677. this.viewSearchCustomActionNode.addEvents({
  678. "click": function(){this.loadCustomSearch();}.bind(this)
  679. });
  680. },
  681. searchView: function(){
  682. if (this.viewJson.customFilterList) {
  683. var key = this.viewSearchInputNode.get("value");
  684. if (key && key !== this.lp.searchKeywork) {
  685. var filterData = this.json.filter ? this.json.filter : [];
  686. this.filterItems = [];
  687. this.viewJson.customFilterList.each(function (entry) {
  688. if (entry.formatType === "textValue") {
  689. var d = {
  690. "path": entry.path,
  691. "value": key,
  692. "formatType": entry.formatType,
  693. "logic": "or",
  694. "comparison": "like"
  695. };
  696. filterData.push(d);
  697. this.filterItems.push({"data":d});
  698. }
  699. if (entry.formatType === "numberValue") {
  700. var v = key.toFloat();
  701. if (!isNaN(v)) {
  702. var d = {
  703. "path": entry.path,
  704. "value": v,
  705. "formatType": entry.formatType,
  706. "logic": "or",
  707. "comparison": "like"
  708. };
  709. filterData.push(d);
  710. this.filterItems.push({"data":d});
  711. }
  712. }
  713. }.bind(this));
  714. this.createViewNode({"filterList": filterData});
  715. }else{
  716. this.createViewNode();
  717. }
  718. }
  719. },
  720. searchCustomView: function(){
  721. if (this.filterItems.length){
  722. var filterData = this.json.filter ? this.json.filter.clone() : [];
  723. this.filterItems.each(function(filter){
  724. filterData.push(filter.data);
  725. }.bind(this));
  726. this.createViewNode({"filterList": filterData});
  727. }else{
  728. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  729. }
  730. },
  731. loadCustomSearch: function(){
  732. this.viewSearchIconNode.setStyle("display", "none");
  733. this.viewSearchInputBoxNode.setStyle("display", "none");
  734. this.viewSearchCustomActionNode.setStyle("display", "none");
  735. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  736. var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
  737. this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
  738. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  739. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  740. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
  741. this.searchStatus = "custom";
  742. this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
  743. this.viewSearchInputAreaNode.setStyle("width", "auto");
  744. if (this.viewSearchCustomContentNode){
  745. this.viewSearchCustomCloseActionNode.setStyle("display", "block");
  746. this.viewSearchCustomContentNode.setStyle("display", "block");
  747. }else{
  748. this.loadCustomSearchContent();
  749. }
  750. this.setContentHeightFun();
  751. }.bind(this));
  752. this.searchCustomView();
  753. },
  754. loadCustomSearchContent: function(){
  755. this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
  756. this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
  757. this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
  758. this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
  759. this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
  760. this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
  761. this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
  762. this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
  763. this.loadViewSearchCustomList();
  764. this.viewSearchCustomCloseActionNode.addEvents({
  765. "click": function(){this.closeCustomSearch();}.bind(this)
  766. });
  767. this.viewSearchCustomAddIconNode.addEvents({
  768. "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
  769. });
  770. },
  771. loadViewSearchCustomList: function(){
  772. this.viewSearchCustomPathListNode = new Element("select", {
  773. "styles": this.css.viewFilterSearchCustomPathListNode,
  774. "multiple": true
  775. }).inject(this.viewSearchCustomPathContentNode);
  776. this.viewSearchCustomComparisonListNode = new Element("select", {
  777. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  778. "multiple": true
  779. }).inject(this.viewSearchCustomComparisonContentNode);
  780. this.viewJson.customFilterList.each(function(entry){
  781. var option = new Element("option", {
  782. "style": this.css.viewFilterSearchOptionNode,
  783. "value": entry.path,
  784. "text": entry.title
  785. }).inject(this.viewSearchCustomPathListNode);
  786. option.store("entry", entry);
  787. }.bind(this));
  788. this.viewSearchCustomPathListNode.addEvent("change", function(){
  789. this.loadViewSearchCustomComparisonList();
  790. }.bind(this));
  791. },
  792. loadViewSearchCustomComparisonList: function(){
  793. var idx = this.viewSearchCustomPathListNode.selectedIndex;
  794. var option = this.viewSearchCustomPathListNode.options[idx];
  795. var entry = option.retrieve("entry");
  796. if (entry){
  797. var selectableList = this.getCustomSelectScriptResult(entry);
  798. switch (entry.formatType){
  799. case "numberValue":
  800. this.loadComparisonSelect(this.lp.numberFilter);
  801. if( selectableList.length > 0 ){
  802. this.loadViewSerchCustomSelectByScript(selectableList)
  803. }else{
  804. this.loadViewSearchCustomValueNumberInput();
  805. }
  806. break;
  807. case "dateTimeValue":
  808. this.loadComparisonSelect(this.lp.dateFilter);
  809. if( selectableList.length > 0 ){
  810. this.loadViewSerchCustomSelectByScript(selectableList)
  811. }else {
  812. this.loadViewSearchCustomValueDateTimeInput();
  813. }
  814. break;
  815. case "dateValue":
  816. this.loadComparisonSelect(this.lp.dateFilter);
  817. if( selectableList.length > 0 ){
  818. this.loadViewSerchCustomSelectByScript(selectableList)
  819. }else {
  820. this.loadViewSearchCustomValueDateInput();
  821. }
  822. break;
  823. case "timeValue":
  824. this.loadComparisonSelect(this.lp.dateFilter);
  825. if( selectableList.length > 0 ){
  826. this.loadViewSerchCustomSelectByScript(selectableList)
  827. }else {
  828. this.loadViewSearchCustomValueTimeInput();
  829. }
  830. break;
  831. case "booleanValue":
  832. this.loadComparisonSelect(this.lp.booleanFilter);
  833. if( selectableList.length > 0 ){
  834. this.loadViewSerchCustomSelectByScript(selectableList)
  835. }else {
  836. this.loadViewSearchCustomValueBooleanInput();
  837. }
  838. break;
  839. default:
  840. this.loadComparisonSelect(this.lp.textFilter);
  841. if( selectableList.length > 0 ){
  842. this.loadViewSerchCustomSelectByScript(selectableList)
  843. }else {
  844. this.loadViewSearchCustomValueTextInput();
  845. }
  846. }
  847. }
  848. },
  849. getCustomSelectScriptResult : function( entry ){
  850. var scriptResult = [];
  851. if( entry.valueType === "script" ){
  852. if( entry.valueScript && entry.valueScript.code ){
  853. var result = this.Macro.exec(entry.valueScript.code, this);
  854. var array = typeOf( result ) === "array" ? result : [result];
  855. for( var i=0; i<array.length; i++ ){
  856. if( array[i].indexOf( "|" ) > -1 ){
  857. var arr = array[i].split("|");
  858. scriptResult.push({ "text" : arr[0], "value" : arr[1] })
  859. }else{
  860. scriptResult.push({ "text" : array[i], "value" : array[i] })
  861. }
  862. }
  863. }
  864. }
  865. return scriptResult;
  866. },
  867. loadViewSerchCustomSelectByScript: function( array ){
  868. this.viewSearchCustomValueContentNode.empty();
  869. this.viewSearchCustomValueNode = new Element("select", {
  870. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  871. "multiple": true
  872. }).inject(this.viewSearchCustomValueContentNode);
  873. array.each(function( v ){
  874. var option = new Element("option", {
  875. "style": this.css.viewFilterSearchOptionNode,
  876. "value": v.value,
  877. "text": v.text,
  878. "selected" : array.length === 1
  879. }).inject(this.viewSearchCustomValueNode);
  880. }.bind(this));
  881. },
  882. loadViewSearchCustomValueNumberInput: function(){
  883. this.viewSearchCustomValueContentNode.empty();
  884. this.viewSearchCustomValueNode = new Element("input", {
  885. "styles": this.css.viewFilterSearchCustomValueNode,
  886. "type": "number"
  887. }).inject(this.viewSearchCustomValueContentNode);
  888. },
  889. loadViewSearchCustomValueDateTimeInput: function(){
  890. this.viewSearchCustomValueContentNode.empty();
  891. this.viewSearchCustomValueNode = new Element("input", {
  892. "styles": this.css.viewFilterSearchCustomValueNode,
  893. "type": "text",
  894. "readonly": true
  895. }).inject(this.viewSearchCustomValueContentNode);
  896. MWF.require("MWF.widget.Calendar", function(){
  897. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  898. "style": "xform",
  899. "isTime": true,
  900. "secondEnable" : true,
  901. "target": this.container,
  902. "format": "db"
  903. });
  904. }.bind(this));
  905. },
  906. loadViewSearchCustomValueDateInput: function(){
  907. this.viewSearchCustomValueContentNode.empty();
  908. this.viewSearchCustomValueNode = new Element("input", {
  909. "styles": this.css.viewFilterSearchCustomValueNode,
  910. "type": "text",
  911. "readonly": true
  912. }).inject(this.viewSearchCustomValueContentNode);
  913. MWF.require("MWF.widget.Calendar", function(){
  914. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  915. "style": "xform",
  916. "isTime": false,
  917. "target": this.container,
  918. "format": "%Y-%m-%d"
  919. });
  920. }.bind(this));
  921. },
  922. loadViewSearchCustomValueTimeInput: function(){
  923. this.viewSearchCustomValueContentNode.empty();
  924. this.viewSearchCustomValueNode = new Element("input", {
  925. "styles": this.css.viewFilterSearchCustomValueNode,
  926. "type": "text",
  927. "readonly": true
  928. }).inject(this.viewSearchCustomValueContentNode);
  929. MWF.require("MWF.widget.Calendar", function(){
  930. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  931. "style": "xform",
  932. "timeOnly": true,
  933. "target": this.container,
  934. "format": "%H:%M:%S"
  935. });
  936. }.bind(this));
  937. },
  938. loadViewSearchCustomValueBooleanInput: function(){
  939. this.viewSearchCustomValueContentNode.empty();
  940. this.viewSearchCustomValueNode = new Element("select", {
  941. "styles": this.css.viewFilterSearchCustomValueSelectNode,
  942. "multiple": true
  943. }).inject(this.viewSearchCustomValueContentNode);
  944. new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
  945. new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
  946. },
  947. loadViewSearchCustomValueTextInput: function(){
  948. this.viewSearchCustomValueContentNode.empty();
  949. this.viewSearchCustomValueNode = new Element("textarea", {
  950. "styles": this.css.viewFilterSearchCustomValueNode
  951. }).inject(this.viewSearchCustomValueContentNode);
  952. },
  953. loadComparisonSelect:function(obj){
  954. this.viewSearchCustomComparisonListNode.empty();
  955. Object.each(obj, function(v, k){
  956. var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
  957. }.bind(this));
  958. },
  959. closeCustomSearch: function(){
  960. if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
  961. this.viewSearchCustomCloseActionNode.setStyle("display", "none");
  962. this.viewSearchCustomContentNode.setStyle("display", "none");
  963. var x = this.viewSearchInputAreaNode.getParent().getSize().x;
  964. x1 = x-2-10-90;
  965. this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
  966. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  967. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  968. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  969. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
  970. this.searchStatus = "default";
  971. this.css.viewFilterSearchInputAreaNode.width = "auto";
  972. this.viewSearchInputAreaNode.setStyle("margin-right", "90px");
  973. this.viewSearchIconNode.setStyle("display", "block");
  974. this.viewSearchInputBoxNode.setStyle("display", "block");
  975. this.viewSearchCustomActionNode.setStyle("display", "block");
  976. this.setContentHeightFun();
  977. }.bind(this));
  978. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  979. }
  980. },
  981. viewSearchCustomAddToFilter: function(){
  982. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  983. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  984. if (pathIdx===-1){
  985. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  986. return false;
  987. }
  988. if (comparisonIdx===-1){
  989. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  990. return false;
  991. }
  992. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  993. var entry = pathOption.retrieve("entry");
  994. if (entry){
  995. var pathTitle = entry.title;
  996. var path = entry.path;
  997. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  998. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  999. var value = "";
  1000. if( entry.valueType === "script" && entry.valueScript && entry.valueScript.code ){
  1001. var idx = this.viewSearchCustomValueNode.selectedIndex;
  1002. if (idx!==-1){
  1003. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  1004. value = entry.formatType === "booleanValue" ? (v==="true") : v;
  1005. }
  1006. }else{
  1007. switch (entry.formatType){
  1008. case "numberValue":
  1009. value = this.viewSearchCustomValueNode.get("value");
  1010. break;
  1011. case "dateTimeValue":
  1012. value = this.viewSearchCustomValueNode.get("value");
  1013. break;
  1014. case "booleanValue":
  1015. var idx = this.viewSearchCustomValueNode.selectedIndex;
  1016. if (idx!==-1){
  1017. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  1018. value = (v==="true");
  1019. }
  1020. break;
  1021. default:
  1022. value = this.viewSearchCustomValueNode.get("value");
  1023. }
  1024. }
  1025. if (value===""){
  1026. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  1027. return false;
  1028. }
  1029. this.filterItems.push(new MWF.xApplication.query.Query.Viewer.Filter(this, {
  1030. "logic": "and",
  1031. "path": path,
  1032. "title": pathTitle,
  1033. "comparison": comparison,
  1034. "comparisonTitle": comparisonTitle,
  1035. "value": value,
  1036. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  1037. }, this.viewSearchCustomFilterContentNode));
  1038. this.searchCustomView();
  1039. }
  1040. },
  1041. searchViewRemoveFilter: function(filter){
  1042. this.filterItems.erase(filter);
  1043. filter.destroy();
  1044. this.searchCustomView()
  1045. },
  1046. //搜索相关结束
  1047. //api 使用 开始
  1048. getParentEnvironment : function(){
  1049. return this.parentMacro ? this.parentMacro.environment : null;
  1050. },
  1051. getViewInfor : function(){
  1052. return this.json;
  1053. },
  1054. getPageInfor : function(){
  1055. return {
  1056. pages : this.pages,
  1057. perPageCount : this.options.perPageCount,
  1058. currentPageNumber : this.currentPage
  1059. };
  1060. },
  1061. getPageData : function () {
  1062. return this.gridJson;
  1063. },
  1064. toPage : function( pageNumber, callback ){
  1065. this.currentPage = pageNumber;
  1066. this.loadCurrentPageData( callback );
  1067. },
  1068. getSelectedData : function(){
  1069. return this.getData();
  1070. },
  1071. selectAll : function(){
  1072. var flag = this.json.select || this.viewJson.select || "none";
  1073. if ( flag==="multi"){
  1074. this.items.each( function (item) {
  1075. if( item.clazzType === "item" ){
  1076. item.selected();
  1077. }else{
  1078. item.expand();
  1079. if( item.items ){
  1080. item.items.each( function (it) {
  1081. it.selected();
  1082. })
  1083. }
  1084. }
  1085. })
  1086. }
  1087. },
  1088. unSelectAll : function(){
  1089. var flag = this.json.select || this.viewJson.select || "none";
  1090. if ( flag==="multi"){
  1091. this.items.each( function (item) {
  1092. if( item.clazzType === "item" ){
  1093. item.unSelected();
  1094. }else{
  1095. if(item.items){
  1096. item.items.each( function (it) {
  1097. it.unSelected();
  1098. })
  1099. }
  1100. }
  1101. })
  1102. }
  1103. },
  1104. setFilter : function( filter ){
  1105. if( !filter )filter = [];
  1106. if( typeOf( filter ) === "object" )filter = [ filter ];
  1107. this.json.filter = filter;
  1108. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  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. });