Viewer.js 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086
  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. if( !this.paging ){
  303. var json;
  304. if( !this.viewJson.pagingList || !this.viewJson.pagingList.length ){
  305. json = {
  306. "firstPageText": this.lp.firstPage,
  307. "lastPageText": this.lp.lastPage
  308. };
  309. }else{
  310. json = this.viewJson.pagingList[0];
  311. }
  312. this.paging = new MWF.xApplication.query.Query.Viewer.Paging(this.viewPageAreaNode, json, this, {});
  313. this.paging.load();
  314. }else{
  315. this.paging.reload();
  316. }
  317. },
  318. _initPage: function(){
  319. this.count = this.bundleItems.length;
  320. var i = this.count/this.json.pageSize;
  321. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  322. this.currentPage = 1;
  323. },
  324. lookup: function(data){
  325. this.getLookupAction(function(){
  326. if (this.json.application){
  327. var d = data || {};
  328. d.count = this.json.count;
  329. this.lookupAction.bundleView(this.json.id, d, function(json){
  330. this.bundleItems = json.data.valueList;
  331. this._initPage();
  332. if (this.bundleItems.length){
  333. this.loadCurrentPageData( function () {
  334. this.fireEvent("postLoad"); //用户配置的事件
  335. }.bind(this));
  336. }else{
  337. //this._loadPageNode();
  338. this.viewPageAreaNode.empty();
  339. if (this.loadingAreaNode){
  340. this.loadingAreaNode.destroy();
  341. this.loadingAreaNode = null;
  342. }
  343. this.fireEvent("postLoad"); //用户配置的事件
  344. }
  345. }.bind(this));
  346. }
  347. }.bind(this));
  348. },
  349. loadCurrentPageData: function( callback ){
  350. //是否需要在翻页的时候清空之前的items ?
  351. this.items = [];
  352. var p = this.currentPage;
  353. var d = {};
  354. var valueList = this.bundleItems.slice((p-1)*this.json.pageSize,this.json.pageSize*p);
  355. d.bundleList = valueList;
  356. while (this.viewTable.rows.length>1){
  357. this.viewTable.deleteRow(-1);
  358. }
  359. //this.createLoadding();
  360. this.loadViewRes = this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
  361. this.viewData = json.data;
  362. this.fireEvent("postLoadPageData");
  363. if (this.viewJson.group.column){
  364. this.gridJson = json.data.groupGrid;
  365. this.loadGroupData();
  366. }else{
  367. this.gridJson = json.data.grid;
  368. this.loadData();
  369. }
  370. if (this.gridJson.length) this._loadPageNode();
  371. if (this.loadingAreaNode){
  372. this.loadingAreaNode.destroy();
  373. this.loadingAreaNode = null;
  374. }
  375. this.fireEvent("loadView"); //options 传入的事件
  376. this.fireEvent("postLoadPage");
  377. if(callback)callback();
  378. }.bind(this));
  379. },
  380. loadData: function(){
  381. if (this.gridJson.length){
  382. // if( !this.options.paging ){
  383. this.gridJson.each(function(line, i){
  384. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, line, null, i));
  385. }.bind(this));
  386. // }else{
  387. // this.loadPaging();
  388. // }
  389. }else{
  390. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  391. }
  392. },
  393. loadPaging : function(){
  394. this.isItemsLoading = false;
  395. this.pageNumber = 0;
  396. this.isItemsLoaded = false;
  397. this.isSetedScroll = false;
  398. this.setScroll();
  399. this.loadDataByPaging()
  400. },
  401. setScroll : function(){
  402. if( this.options.paging && !this.isSetedScroll ){
  403. this.contentAreaNode.setStyle("overflow","auto");
  404. this.scrollContainerFun = function(){
  405. var scrollSize = this.contentAreaNode.getScrollSize();
  406. var clientSize = this.contentAreaNode.getSize();
  407. var scrollHeight = scrollSize.y - clientSize.y;
  408. //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
  409. if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
  410. if (!this.isItemsLoaded) this.loadDataByPaging();
  411. }
  412. }.bind(this);
  413. this.isSetedScroll = true;
  414. this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
  415. }
  416. },
  417. loadDataByPaging : function(){
  418. if( this.isItemsLoading )return;
  419. if( !this.isItemsLoaded ){
  420. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  421. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  422. this.isItemsLoading = true;
  423. for( var i = from; i<to; i++ ){
  424. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, this.gridJson[i], null, i));
  425. }
  426. this.isItemsLoading = false;
  427. this.pageNumber ++;
  428. if( to == this.gridJson.length )this.isItemsLoaded = true;
  429. }
  430. },
  431. loadGroupData: function(){
  432. if (this.selectTitleCell){
  433. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  434. this.selectTitleCell.setStyle("cursor", "pointer");
  435. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  436. }
  437. if (this.gridJson.length){
  438. var i = 0;
  439. this.gridJson.each(function(data){
  440. this.items.push(new MWF.xApplication.query.Query.Viewer.ItemCategory(this, data, i));
  441. i += data.list.length;
  442. }.bind(this));
  443. if (this.json.isExpand=="yes") this.expandOrCollapseAll();
  444. }else{
  445. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  446. }
  447. },
  448. expandOrCollapseAll: function(){
  449. var icon = this.selectTitleCell.getElement("span");
  450. if (icon.get("html").indexOf("expand.png")===-1){
  451. this.items.each(function(item){
  452. item.collapse();
  453. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  454. }.bind(this));
  455. }else{
  456. this.items.each(function(item, i){
  457. window.setTimeout(function(){
  458. item.expand();
  459. }.bind(this), 10*i+5);
  460. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
  461. }.bind(this));
  462. }
  463. },
  464. getView: function(callback){
  465. this.getLookupAction(function(){
  466. if (this.json.application){
  467. this.getViewRes = this.lookupAction.getView(this.json.viewName, this.json.application, function(json){
  468. this.viewJson = JSON.decode(json.data.data);
  469. this.json = Object.merge(this.json, json.data);
  470. if (callback) callback();
  471. }.bind(this));
  472. // this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  473. // this.viewJson = JSON.decode(json.data.data);
  474. // this.json = Object.merge(this.json, json.data);
  475. // //var viewData = JSON.decode(json.data.data);
  476. // if (callback) callback();
  477. // }.bind(this)});
  478. }else{
  479. this.getViewRes = this.lookupAction.getViewById(this.json.viewId, function(json){
  480. this.viewJson = JSON.decode(json.data.data);
  481. this.json.application = json.data.query;
  482. this.json = Object.merge(this.json, json.data);
  483. if (callback) callback();
  484. }.bind(this));
  485. }
  486. }.bind(this));
  487. },
  488. getLookupAction: function(callback){
  489. if (!this.lookupAction){
  490. this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
  491. if (callback) callback();
  492. // var _self = this;
  493. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  494. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
  495. // this.lookupAction.getActions = function(actionCallback){
  496. // this.actions = _self.options.actions;
  497. // if (actionCallback) actionCallback();
  498. // };
  499. // if (callback) callback();
  500. // }.bind(this));
  501. }else{
  502. if (callback) callback();
  503. }
  504. },
  505. hide: function(){
  506. this.node.setStyle("display", "none");
  507. },
  508. reload: function(){
  509. this.node.setStyle("display", "block");
  510. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  511. this.filterItems.each(function(filter){
  512. filter.destroy();
  513. }.bind(this));
  514. this.filterItems = [];
  515. if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
  516. this.closeCustomSearch();
  517. this.viewAreaNode.empty();
  518. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  519. },
  520. getFilter: function(){
  521. var filterData = [];
  522. if (this.searchStatus==="custom"){
  523. if (this.filterItems.length){
  524. this.filterItems.each(function(filter){
  525. filterData.push(filter.data);
  526. }.bind(this));
  527. }
  528. }
  529. if (this.searchStatus==="default"){
  530. var key = this.viewSearchInputNode.get("value");
  531. if (key && key!==this.lp.searchKeywork){
  532. this.viewJson.customFilterList.each(function(entry){
  533. if (entry.formatType==="textValue"){
  534. var d = {
  535. "path": entry.path,
  536. "value": key,
  537. "formatType": entry.formatType,
  538. "logic": "or",
  539. "comparison": "like"
  540. };
  541. filterData.push(d);
  542. }
  543. if (entry.formatType==="numberValue"){
  544. var v = key.toFloat();
  545. if (!isNaN(v)){
  546. var d = {
  547. "path": entry.path,
  548. "value": v,
  549. "formatType": entry.formatType,
  550. "logic": "or",
  551. "comparison": "like"
  552. };
  553. filterData.push(d);
  554. }
  555. }
  556. }.bind(this));
  557. }
  558. }
  559. return (filterData.length) ? filterData : null;
  560. },
  561. getData: function(){
  562. if (this.selectedItems.length){
  563. var arr = [];
  564. this.selectedItems.each(function(item){
  565. arr.push(item.data);
  566. });
  567. return arr;
  568. }else{
  569. return [];
  570. }
  571. },
  572. _loadModuleEvents : function(){
  573. Object.each(this.viewJson.events, function(e, key){
  574. if (e.code){
  575. if (this.options.moduleEvents.indexOf(key)!==-1){
  576. this.addEvent(key, function(event, target){
  577. return this.Macro.fire(e.code, target || this, event);
  578. }.bind(this));
  579. }
  580. }
  581. }.bind(this));
  582. },
  583. _loadDomEvents: function(){
  584. Object.each(this.viewJson.events, function(e, key){
  585. if (e.code){
  586. if (this.options.moduleEvents.indexOf(key)===-1){
  587. this.node.addEvent(key, function(event){
  588. return this.Macro.fire(e.code, this, event);
  589. }.bind(this));
  590. }
  591. }
  592. }.bind(this));
  593. },
  594. //搜索相关开始
  595. createSearchNode: function(){
  596. if (this.viewJson.customFilterList && this.viewJson.customFilterList.length){
  597. this.searchStatus = "default";
  598. this.loadFilterSearch();
  599. }else{
  600. this.loadSimpleSearch();
  601. }
  602. },
  603. loadSimpleSearch: function(){
  604. return false;
  605. this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
  606. this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
  607. this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
  608. this.searchSimpleButtonNode.addEvent("click", function(){
  609. this.search();
  610. }.bind(this));
  611. this.searchSimpleInputNode.addEvents({
  612. "focus": function(){
  613. if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
  614. }.bind(this),
  615. "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  616. "keydown": function(e){
  617. if (e.code===13) this.search();
  618. }.bind(this)
  619. });
  620. },
  621. search: function(){
  622. if (this.gridJson){
  623. var key = this.searchSimpleInputNode.get("value");
  624. var rows = this.viewTable.rows;
  625. var first = (this.json.isTitle!=="no") ? 1 : 0;
  626. for (var i = first; i<rows.length; i++){
  627. var tr = rows[i];
  628. if (!key || key==this.lp.searchKeywork){
  629. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  630. }else{
  631. if (tr.get("text").indexOf(key)!==-1){
  632. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  633. }else{
  634. if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
  635. }
  636. }
  637. }
  638. //if (this.viewPageAreaNode) this.viewPageAreaNode.hide();
  639. }
  640. },
  641. loadFilterSearch: function(){
  642. this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
  643. this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
  644. this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
  645. this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
  646. this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
  647. this.viewSearchInputNode.addEvents({
  648. "focus": function(){
  649. if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
  650. }.bind(this),
  651. "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  652. "keydown": function(e){
  653. if (e.code===13) this.searchView();
  654. }.bind(this)
  655. });
  656. this.viewSearchIconNode.addEvents({
  657. "click": function(){this.searchView();}.bind(this)
  658. });
  659. this.viewSearchCustomActionNode.addEvents({
  660. "click": function(){this.loadCustomSearch();}.bind(this)
  661. });
  662. },
  663. searchView: function(){
  664. if (this.viewJson.customFilterList) {
  665. var key = this.viewSearchInputNode.get("value");
  666. if (key && key !== this.lp.searchKeywork) {
  667. var filterData = this.json.filter ? this.json.filter : [];
  668. this.filterItems = [];
  669. this.viewJson.customFilterList.each(function (entry) {
  670. if (entry.formatType === "textValue") {
  671. var d = {
  672. "path": entry.path,
  673. "value": key,
  674. "formatType": entry.formatType,
  675. "logic": "or",
  676. "comparison": "like"
  677. };
  678. filterData.push(d);
  679. this.filterItems.push({"data":d});
  680. }
  681. if (entry.formatType === "numberValue") {
  682. var v = key.toFloat();
  683. if (!isNaN(v)) {
  684. var d = {
  685. "path": entry.path,
  686. "value": v,
  687. "formatType": entry.formatType,
  688. "logic": "or",
  689. "comparison": "like"
  690. };
  691. filterData.push(d);
  692. this.filterItems.push({"data":d});
  693. }
  694. }
  695. }.bind(this));
  696. this.createViewNode({"filterList": filterData});
  697. }else{
  698. this.createViewNode();
  699. }
  700. }
  701. },
  702. searchCustomView: function(){
  703. if (this.filterItems.length){
  704. var filterData = this.json.filter ? this.json.filter.clone() : [];
  705. this.filterItems.each(function(filter){
  706. filterData.push(filter.data);
  707. }.bind(this));
  708. this.createViewNode({"filterList": filterData});
  709. }else{
  710. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  711. }
  712. },
  713. loadCustomSearch: function(){
  714. this.viewSearchIconNode.setStyle("display", "none");
  715. this.viewSearchInputBoxNode.setStyle("display", "none");
  716. this.viewSearchCustomActionNode.setStyle("display", "none");
  717. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  718. var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
  719. this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
  720. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  721. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  722. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
  723. this.searchStatus = "custom";
  724. this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
  725. this.viewSearchInputAreaNode.setStyle("width", "auto");
  726. if (this.viewSearchCustomContentNode){
  727. this.viewSearchCustomCloseActionNode.setStyle("display", "block");
  728. this.viewSearchCustomContentNode.setStyle("display", "block");
  729. }else{
  730. this.loadCustomSearchContent();
  731. }
  732. this.setContentHeightFun();
  733. }.bind(this));
  734. this.searchCustomView();
  735. },
  736. loadCustomSearchContent: function(){
  737. this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
  738. this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
  739. this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
  740. this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
  741. this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
  742. this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
  743. this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
  744. this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
  745. this.loadViewSearchCustomList();
  746. this.viewSearchCustomCloseActionNode.addEvents({
  747. "click": function(){this.closeCustomSearch();}.bind(this)
  748. });
  749. this.viewSearchCustomAddIconNode.addEvents({
  750. "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
  751. });
  752. },
  753. loadViewSearchCustomList: function(){
  754. this.viewSearchCustomPathListNode = new Element("select", {
  755. "styles": this.css.viewFilterSearchCustomPathListNode,
  756. "multiple": true
  757. }).inject(this.viewSearchCustomPathContentNode);
  758. this.viewSearchCustomComparisonListNode = new Element("select", {
  759. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  760. "multiple": true
  761. }).inject(this.viewSearchCustomComparisonContentNode);
  762. this.viewJson.customFilterList.each(function(entry){
  763. var option = new Element("option", {
  764. "style": this.css.viewFilterSearchOptionNode,
  765. "value": entry.path,
  766. "text": entry.title
  767. }).inject(this.viewSearchCustomPathListNode);
  768. option.store("entry", entry);
  769. }.bind(this));
  770. this.viewSearchCustomPathListNode.addEvent("change", function(){
  771. this.loadViewSearchCustomComparisonList();
  772. }.bind(this));
  773. },
  774. loadViewSearchCustomComparisonList: function(){
  775. var idx = this.viewSearchCustomPathListNode.selectedIndex;
  776. var option = this.viewSearchCustomPathListNode.options[idx];
  777. var entry = option.retrieve("entry");
  778. if (entry){
  779. var selectableList = this.getCustomSelectScriptResult(entry);
  780. switch (entry.formatType){
  781. case "numberValue":
  782. this.loadComparisonSelect(this.lp.numberFilter);
  783. if( selectableList.length > 0 ){
  784. this.loadViewSerchCustomSelectByScript(selectableList)
  785. }else{
  786. this.loadViewSearchCustomValueNumberInput();
  787. }
  788. break;
  789. case "dateTimeValue":
  790. this.loadComparisonSelect(this.lp.dateFilter);
  791. if( selectableList.length > 0 ){
  792. this.loadViewSerchCustomSelectByScript(selectableList)
  793. }else {
  794. this.loadViewSearchCustomValueDateTimeInput();
  795. }
  796. break;
  797. case "dateValue":
  798. this.loadComparisonSelect(this.lp.dateFilter);
  799. if( selectableList.length > 0 ){
  800. this.loadViewSerchCustomSelectByScript(selectableList)
  801. }else {
  802. this.loadViewSearchCustomValueDateInput();
  803. }
  804. break;
  805. case "timeValue":
  806. this.loadComparisonSelect(this.lp.dateFilter);
  807. if( selectableList.length > 0 ){
  808. this.loadViewSerchCustomSelectByScript(selectableList)
  809. }else {
  810. this.loadViewSearchCustomValueTimeInput();
  811. }
  812. break;
  813. case "booleanValue":
  814. this.loadComparisonSelect(this.lp.booleanFilter);
  815. if( selectableList.length > 0 ){
  816. this.loadViewSerchCustomSelectByScript(selectableList)
  817. }else {
  818. this.loadViewSearchCustomValueBooleanInput();
  819. }
  820. break;
  821. default:
  822. this.loadComparisonSelect(this.lp.textFilter);
  823. if( selectableList.length > 0 ){
  824. this.loadViewSerchCustomSelectByScript(selectableList)
  825. }else {
  826. this.loadViewSearchCustomValueTextInput();
  827. }
  828. }
  829. }
  830. },
  831. getCustomSelectScriptResult : function( entry ){
  832. var scriptResult = [];
  833. if( entry.valueType === "script" ){
  834. if( entry.valueScript && entry.valueScript.code ){
  835. var result = this.Macro.exec(entry.valueScript.code, this);
  836. var array = typeOf( result ) === "array" ? result : [result];
  837. for( var i=0; i<array.length; i++ ){
  838. if( array[i].indexOf( "|" ) > -1 ){
  839. var arr = array[i].split("|");
  840. scriptResult.push({ "text" : arr[0], "value" : arr[1] })
  841. }else{
  842. scriptResult.push({ "text" : array[i], "value" : array[i] })
  843. }
  844. }
  845. }
  846. }
  847. return scriptResult;
  848. },
  849. loadViewSerchCustomSelectByScript: function( array ){
  850. this.viewSearchCustomValueContentNode.empty();
  851. this.viewSearchCustomValueNode = new Element("select", {
  852. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  853. "multiple": true
  854. }).inject(this.viewSearchCustomValueContentNode);
  855. array.each(function( v ){
  856. var option = new Element("option", {
  857. "style": this.css.viewFilterSearchOptionNode,
  858. "value": v.value,
  859. "text": v.text,
  860. "selected" : array.length === 1
  861. }).inject(this.viewSearchCustomValueNode);
  862. }.bind(this));
  863. },
  864. loadViewSearchCustomValueNumberInput: function(){
  865. this.viewSearchCustomValueContentNode.empty();
  866. this.viewSearchCustomValueNode = new Element("input", {
  867. "styles": this.css.viewFilterSearchCustomValueNode,
  868. "type": "number"
  869. }).inject(this.viewSearchCustomValueContentNode);
  870. },
  871. loadViewSearchCustomValueDateTimeInput: function(){
  872. this.viewSearchCustomValueContentNode.empty();
  873. this.viewSearchCustomValueNode = new Element("input", {
  874. "styles": this.css.viewFilterSearchCustomValueNode,
  875. "type": "text",
  876. "readonly": true
  877. }).inject(this.viewSearchCustomValueContentNode);
  878. MWF.require("MWF.widget.Calendar", function(){
  879. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  880. "style": "xform",
  881. "isTime": true,
  882. "secondEnable" : true,
  883. "target": this.container,
  884. "format": "db"
  885. });
  886. }.bind(this));
  887. },
  888. loadViewSearchCustomValueDateInput: function(){
  889. this.viewSearchCustomValueContentNode.empty();
  890. this.viewSearchCustomValueNode = new Element("input", {
  891. "styles": this.css.viewFilterSearchCustomValueNode,
  892. "type": "text",
  893. "readonly": true
  894. }).inject(this.viewSearchCustomValueContentNode);
  895. MWF.require("MWF.widget.Calendar", function(){
  896. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  897. "style": "xform",
  898. "isTime": false,
  899. "target": this.container,
  900. "format": "%Y-%m-%d"
  901. });
  902. }.bind(this));
  903. },
  904. loadViewSearchCustomValueTimeInput: 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. "timeOnly": true,
  915. "target": this.container,
  916. "format": "%H:%M:%S"
  917. });
  918. }.bind(this));
  919. },
  920. loadViewSearchCustomValueBooleanInput: function(){
  921. this.viewSearchCustomValueContentNode.empty();
  922. this.viewSearchCustomValueNode = new Element("select", {
  923. "styles": this.css.viewFilterSearchCustomValueSelectNode,
  924. "multiple": true
  925. }).inject(this.viewSearchCustomValueContentNode);
  926. new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
  927. new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
  928. },
  929. loadViewSearchCustomValueTextInput: function(){
  930. this.viewSearchCustomValueContentNode.empty();
  931. this.viewSearchCustomValueNode = new Element("textarea", {
  932. "styles": this.css.viewFilterSearchCustomValueNode
  933. }).inject(this.viewSearchCustomValueContentNode);
  934. },
  935. loadComparisonSelect:function(obj){
  936. this.viewSearchCustomComparisonListNode.empty();
  937. Object.each(obj, function(v, k){
  938. var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
  939. }.bind(this));
  940. },
  941. closeCustomSearch: function(){
  942. if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
  943. this.viewSearchCustomCloseActionNode.setStyle("display", "none");
  944. this.viewSearchCustomContentNode.setStyle("display", "none");
  945. var x = this.viewSearchInputAreaNode.getParent().getSize().x;
  946. x1 = x-2-10-90;
  947. this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
  948. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  949. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  950. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  951. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
  952. this.searchStatus = "default";
  953. this.css.viewFilterSearchInputAreaNode.width = "auto";
  954. this.viewSearchInputAreaNode.setStyle("margin-right", "90px");
  955. this.viewSearchIconNode.setStyle("display", "block");
  956. this.viewSearchInputBoxNode.setStyle("display", "block");
  957. this.viewSearchCustomActionNode.setStyle("display", "block");
  958. this.setContentHeightFun();
  959. }.bind(this));
  960. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  961. }
  962. },
  963. viewSearchCustomAddToFilter: function(){
  964. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  965. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  966. if (pathIdx===-1){
  967. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  968. return false;
  969. }
  970. if (comparisonIdx===-1){
  971. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  972. return false;
  973. }
  974. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  975. var entry = pathOption.retrieve("entry");
  976. if (entry){
  977. var pathTitle = entry.title;
  978. var path = entry.path;
  979. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  980. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  981. var value = "";
  982. if( entry.valueType === "script" && entry.valueScript && entry.valueScript.code ){
  983. var idx = this.viewSearchCustomValueNode.selectedIndex;
  984. if (idx!==-1){
  985. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  986. value = entry.formatType === "booleanValue" ? (v==="true") : v;
  987. }
  988. }else{
  989. switch (entry.formatType){
  990. case "numberValue":
  991. value = this.viewSearchCustomValueNode.get("value");
  992. break;
  993. case "dateTimeValue":
  994. value = this.viewSearchCustomValueNode.get("value");
  995. break;
  996. case "booleanValue":
  997. var idx = this.viewSearchCustomValueNode.selectedIndex;
  998. if (idx!==-1){
  999. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  1000. value = (v==="true");
  1001. }
  1002. break;
  1003. default:
  1004. value = this.viewSearchCustomValueNode.get("value");
  1005. }
  1006. }
  1007. if (value===""){
  1008. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  1009. return false;
  1010. }
  1011. this.filterItems.push(new MWF.xApplication.query.Query.Viewer.Filter(this, {
  1012. "logic": "and",
  1013. "path": path,
  1014. "title": pathTitle,
  1015. "comparison": comparison,
  1016. "comparisonTitle": comparisonTitle,
  1017. "value": value,
  1018. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  1019. }, this.viewSearchCustomFilterContentNode));
  1020. this.searchCustomView();
  1021. }
  1022. },
  1023. searchViewRemoveFilter: function(filter){
  1024. this.filterItems.erase(filter);
  1025. filter.destroy();
  1026. this.searchCustomView()
  1027. },
  1028. //搜索相关结束
  1029. //api 使用 开始
  1030. getParentEnvironment : function(){
  1031. return this.parentMacro ? this.parentMacro.environment : null;
  1032. },
  1033. getViewInfor : function(){
  1034. return this.json;
  1035. },
  1036. getPageInfor : function(){
  1037. return {
  1038. pages : this.pages,
  1039. perPageCount : this.options.perPageCount,
  1040. currentPageNumber : this.currentPage
  1041. };
  1042. },
  1043. getPageData : function () {
  1044. return this.gridJson;
  1045. },
  1046. toPage : function( pageNumber, callback ){
  1047. this.currentPage = pageNumber;
  1048. this.loadCurrentPageData( callback );
  1049. },
  1050. getSelectedData : function(){
  1051. return this.getData();
  1052. },
  1053. selectAll : function(){
  1054. var flag = this.json.select || this.viewJson.select || "none";
  1055. if ( flag==="multi"){
  1056. this.items.each( function (item) {
  1057. if( item.clazzType === "item" ){
  1058. item.selected();
  1059. }else{
  1060. item.expand();
  1061. if( item.items ){
  1062. item.items.each( function (it) {
  1063. it.selected();
  1064. })
  1065. }
  1066. }
  1067. })
  1068. }
  1069. },
  1070. unSelectAll : function(){
  1071. var flag = this.json.select || this.viewJson.select || "none";
  1072. if ( flag==="multi"){
  1073. this.items.each( function (item) {
  1074. if( item.clazzType === "item" ){
  1075. item.unSelected();
  1076. }else{
  1077. if(item.items){
  1078. item.items.each( function (it) {
  1079. it.unSelected();
  1080. })
  1081. }
  1082. }
  1083. })
  1084. }
  1085. },
  1086. setFilter : function( filter ){
  1087. if( !filter )filter = [];
  1088. if( typeOf( filter ) === "object" )filter = [ filter ];
  1089. this.json.filter = filter;
  1090. if( this.viewAreaNode ){
  1091. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  1092. }
  1093. },
  1094. switchView : function( json ){
  1095. debugger;
  1096. // json = {
  1097. // "application": application,
  1098. // "viewName": viewName,
  1099. // "isTitle": "yes",
  1100. // "select": "none",
  1101. // "titleStyles": titleStyles,
  1102. // "itemStyles": itemStyles,
  1103. // "isExpand": "no",
  1104. // "filter": filter
  1105. // }
  1106. this.node.setStyle("display", "block");
  1107. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  1108. this.searchMorph = null;
  1109. this.viewSearchCustomContentNode = null;
  1110. var newJson = Object.merge( Object.clone(this.originalJson), json );
  1111. this.container.empty();
  1112. this.initialize( this.container, newJson, Object.clone(this.options), this.app, this.parentMacro);
  1113. },
  1114. confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
  1115. this.app.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style)
  1116. },
  1117. alert: function (type, title, text, width, height) {
  1118. this.app.alert(type, "center", title, text, width, height);
  1119. },
  1120. notice: function (content, type, target, where, offset, option) {
  1121. this.app.notice(content, type, target, where, offset, option)
  1122. }
  1123. //api 使用 结束
  1124. });
  1125. MWF.xApplication.query.Query.Viewer.Item = new Class({
  1126. initialize: function(view, data, prev, i){
  1127. this.view = view;
  1128. this.data = data;
  1129. this.css = this.view.css;
  1130. this.isSelected = false;
  1131. this.prev = prev;
  1132. this.idx = i;
  1133. this.clazzType = "item";
  1134. this.load();
  1135. },
  1136. load: function(){
  1137. this.view.fireEvent("queryLoadItemRow", [null, this]);
  1138. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  1139. if (this.prev){
  1140. this.node.inject(this.prev.node, "after");
  1141. }else{
  1142. this.node.inject(this.view.viewTable);
  1143. }
  1144. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1145. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1146. this.selectTd.setStyles({"cursor": "pointer"});
  1147. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1148. //}
  1149. //序号
  1150. if (this.view.viewJson.isSequence==="yes"){
  1151. this.sequenceTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1152. this.sequenceTd.setStyle("width", "10px");
  1153. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  1154. this.sequenceTd.set("text", s);
  1155. }
  1156. Object.each(this.view.entries, function(c, k){
  1157. var cell = this.data.data[k];
  1158. if (cell === undefined) cell = "";
  1159. //if (cell){
  1160. if (this.view.hideColumns.indexOf(k)===-1){
  1161. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1162. if (k!== this.view.viewJson.group.column){
  1163. //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;
  1164. var v = cell;
  1165. if (c.isHtml){
  1166. td.set("html", v);
  1167. }else{
  1168. td.set("text", v);
  1169. }
  1170. }
  1171. if (this.view.openColumns.indexOf(k)!==-1){
  1172. this.setOpenWork(td, c)
  1173. }
  1174. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1175. }
  1176. //}
  1177. }.bind(this));
  1178. // Object.each(this.data.data, function(cell, k){
  1179. // if (this.view.hideColumns.indexOf(k)===-1){
  1180. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1181. // if (k!== this.view.viewJson.group.column){
  1182. // 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;
  1183. // td.set("text", v);
  1184. // }
  1185. // if (this.view.openColumns.indexOf(k)!==-1){
  1186. // this.setOpenWork(td)
  1187. // }
  1188. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1189. // }
  1190. // }.bind(this));
  1191. this.setEvent();
  1192. this.view.fireEvent("postLoadItemRow", [null, this]);
  1193. },
  1194. setOpenWork: function(td, column){
  1195. td.setStyle("cursor", "pointer");
  1196. if( column.clickCode ){
  1197. // if( !this.view.Macro ){
  1198. // MWF.require("MWF.xScript.Macro", function () {
  1199. // this.view.businessData = {};
  1200. // this.view.Macro = new MWF.Macro.PageContext(this.view);
  1201. // }.bind(this), false);
  1202. // }
  1203. td.addEvent("click", function( ev ){
  1204. var result = this.view.Macro.fire(column.clickCode, this, ev);
  1205. ev.stopPropagation();
  1206. return result;
  1207. }.bind(this));
  1208. }else{
  1209. if (this.view.json.type==="cms"){
  1210. td.addEvent("click", function(ev){
  1211. this.openCms(ev)
  1212. ev.stopPropagation();
  1213. }.bind(this));
  1214. }else{
  1215. td.addEvent("click", function(ev){
  1216. this.openWorkAndCompleted(ev)
  1217. ev.stopPropagation();
  1218. }.bind(this));
  1219. }
  1220. }
  1221. },
  1222. openCms: function(e){
  1223. var options = {"documentId": this.data.bundle};
  1224. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1225. layout.desktop.openApplication(e, "cms.Document", options);
  1226. },
  1227. openWorkAndCompleted: function(e){
  1228. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
  1229. var workCompletedCount = json.data.workCompletedList.length;
  1230. var workCount = json.data.workList.length;
  1231. var count = workCount+workCompletedCount;
  1232. if (count===1){
  1233. if (workCompletedCount) {
  1234. this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  1235. }else{
  1236. this.openWork(json.data.workList[0].id, e);
  1237. }
  1238. }else if (count>1){
  1239. var worksAreaNode = this.createWorksArea();
  1240. json.data.workCompletedList.each(function(work){
  1241. this.createWorkCompletedNode(work, worksAreaNode);
  1242. }.bind(this));
  1243. json.data.workList.each(function(work){
  1244. this.createWorkNode(work, worksAreaNode);
  1245. }.bind(this));
  1246. this.showWorksArea(worksAreaNode, e);
  1247. }else{
  1248. }
  1249. }.bind(this));
  1250. },
  1251. createWorkNode: function(work, worksAreaNode){
  1252. var worksAreaContentNode = worksAreaNode.getLast();
  1253. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1254. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1255. actionNode.store("workId", work.id);
  1256. actionNode.addEvent("click", function(e){
  1257. this.openWork(e.target.retrieve("workId"), e);
  1258. this.mask.hide();
  1259. worksAreaNode.destroy();
  1260. }.bind(this));
  1261. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1262. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1263. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1264. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1265. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  1266. var taskUsers = [];
  1267. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  1268. json.data.each(function(task){
  1269. taskUsers.push(MWF.name.cn(task.person));
  1270. }.bind(this));
  1271. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  1272. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  1273. }.bind(this));
  1274. },
  1275. createWorkCompletedNode: function(work, worksAreaNode){
  1276. var worksAreaContentNode = worksAreaNode.getLast();
  1277. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1278. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1279. actionNode.store("workId", work.id);
  1280. actionNode.addEvent("click", function(e){
  1281. this.mask.hide();
  1282. var id = e.target.retrieve("workId");
  1283. worksAreaNode.destroy();
  1284. this.openWorkCompleted(id, e);
  1285. }.bind(this));
  1286. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1287. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1288. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1289. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1290. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  1291. },
  1292. createWorksArea: function(){
  1293. var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
  1294. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  1295. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  1296. worksAreaTitleCloseNode.addEvent("click", function(e){
  1297. this.mask.hide();
  1298. e.target.getParent().getParent().destroy();
  1299. }.bind(this));
  1300. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  1301. return worksAreaNode;
  1302. },
  1303. showWorksArea: function(node, e){
  1304. MWF.require("MWF.widget.Mask", null, false);
  1305. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  1306. this.mask.loadNode(this.view.container);
  1307. node.inject(this.view.node);
  1308. this.setWorksAreaPosition(node, e.target);
  1309. },
  1310. setWorksAreaPosition: function(node, td){
  1311. var p = td.getPosition(this.view.container);
  1312. var containerS = this.view.container.getSize();
  1313. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  1314. var s = node.getSize();
  1315. var offX = p.x+s.x-containerS.x;
  1316. offX = (offX>0) ? offX+20 : 0;
  1317. var offY = p.y+s.y-containerS.y;
  1318. offY = (offY>0) ? offY+5 : 0;
  1319. node.position({
  1320. "relativeTo": td,
  1321. "position": "lefttop",
  1322. "edge": "lefttop",
  1323. "offset": {
  1324. "x": 0-offX,
  1325. "y": 0-offY
  1326. }
  1327. });
  1328. },
  1329. openWork: function(id, e){
  1330. var options = {"workId": id};
  1331. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1332. layout.desktop.openApplication(e, "process.Work", options);
  1333. },
  1334. openWorkCompleted: function(id, e){
  1335. var options = {"workCompletedId": id};
  1336. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1337. layout.desktop.openApplication(e, "process.Work", options);
  1338. },
  1339. setEvent: function(){
  1340. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1341. if ( flag ==="single" || flag==="multi"){
  1342. this.node.addEvents({
  1343. "mouseover": function(){
  1344. if (!this.isSelected){
  1345. var iconName = "checkbox";
  1346. if (flag==="single") iconName = "radiobox";
  1347. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  1348. }
  1349. }.bind(this),
  1350. "mouseout": function(){
  1351. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  1352. }.bind(this),
  1353. "click": function(){this.select();}.bind(this)
  1354. });
  1355. }
  1356. },
  1357. select: function(){
  1358. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1359. if (this.isSelected){
  1360. if (flag==="single"){
  1361. this.unSelectedSingle();
  1362. }else{
  1363. this.unSelected();
  1364. }
  1365. }else{
  1366. if (flag==="single"){
  1367. this.selectedSingle();
  1368. }else{
  1369. this.selected();
  1370. }
  1371. }
  1372. this.view.fireEvent("select"); //options 传入的事件
  1373. },
  1374. selected: function(){
  1375. this.view.selectedItems.push(this);
  1376. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  1377. this.node.setStyles(this.css.viewContentTrNode_selected);
  1378. this.isSelected = true;
  1379. this.view.fireEvent("selectRow", [this]);
  1380. },
  1381. unSelected: function(){
  1382. this.view.selectedItems.erase(this);
  1383. this.selectTd.setStyles({"background": "transparent"});
  1384. this.node.setStyles(this.css.viewContentTrNode);
  1385. this.isSelected = false;
  1386. this.view.fireEvent("unselectRow", [this]);
  1387. },
  1388. selectedSingle: function(){
  1389. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  1390. this.view.selectedItems = [this];
  1391. this.view.currentSelectedItem = this;
  1392. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/radiobox_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. unSelectedSingle: function(){
  1398. this.view.selectedItems = [];
  1399. this.view.currentSelectedItem = null;
  1400. this.selectTd.setStyles({"background": "transparent"});
  1401. this.node.setStyles(this.css.viewContentTrNode);
  1402. this.isSelected = false;
  1403. this.view.fireEvent("unselectRow", [this]);
  1404. }
  1405. });
  1406. MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
  1407. initialize: function(view, data, i){
  1408. this.view = view;
  1409. this.data = data;
  1410. this.css = this.view.css;
  1411. this.items = [];
  1412. this.loadChild = false;
  1413. this.idx = i;
  1414. this.clazzType = "category";
  1415. this.load();
  1416. },
  1417. load: function(){
  1418. this.view.fireEvent("queryLoadCategoryRow", [null, this]);
  1419. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  1420. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1421. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  1422. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1423. //}
  1424. this.categoryTd = new Element("td", {
  1425. "styles": this.css.viewContentCategoryTdNode,
  1426. "colspan": this.view.viewJson.selectList.length+1
  1427. }).inject(this.node);
  1428. this.groupColumn = null;
  1429. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  1430. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  1431. this.groupColumn = this.view.viewJson.selectList[c];
  1432. break;
  1433. }
  1434. }
  1435. if (this.groupColumn){
  1436. //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;
  1437. var text = this.data.group;
  1438. }else{
  1439. var text = this.data.group;
  1440. }
  1441. 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);
  1442. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  1443. this.setEvent();
  1444. this.view.fireEvent("postLoadCategoryRow", [null, this]);
  1445. },
  1446. setEvent: function(){
  1447. //if (this.selectTd){
  1448. this.node.addEvents({
  1449. "click": function(){this.expandOrCollapse();}.bind(this)
  1450. });
  1451. //}
  1452. },
  1453. expandOrCollapse: function(){
  1454. var t = this.node.getElement("span").get("html");
  1455. if (t.indexOf("expand.png")===-1){
  1456. this.collapse();
  1457. }else{
  1458. this.expand();
  1459. }
  1460. },
  1461. collapse: function(){
  1462. this.items.each(function(item){
  1463. item.node.setStyle("display", "none");
  1464. }.bind(this));
  1465. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  1466. },
  1467. expand: function(){
  1468. this.items.each(function(item){
  1469. item.node.setStyle("display", "table-row");
  1470. }.bind(this));
  1471. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  1472. if (!this.loadChild){
  1473. //window.setTimeout(function(){
  1474. this.data.list.each(function(line, i){
  1475. var s = this.idx+i;
  1476. this.lastItem = new MWF.xApplication.query.Query.Viewer.Item(this.view, line, (this.lastItem || this), s);
  1477. this.items.push(this.lastItem);
  1478. }.bind(this));
  1479. this.loadChild = true;
  1480. //}.bind(this), 10);
  1481. }
  1482. }
  1483. });
  1484. MWF.xApplication.query.Query.Viewer.Filter = new Class({
  1485. initialize: function(viewer, data, node){
  1486. this.viewer = viewer;
  1487. this.data = data;
  1488. this.css = this.viewer.css;
  1489. this.content = node;
  1490. this.load();
  1491. },
  1492. load: function(){
  1493. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  1494. if (this.viewer.filterItems.length){
  1495. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  1496. this.logicSelectNode = new Element("div", {
  1497. "styles": this.css.viewSearchFilterSelectNode,
  1498. "text": this.viewer.lp.and,
  1499. "value": "and"
  1500. }).inject(this.logicNode);
  1501. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  1502. this.logicNode.addEvents({
  1503. "click": function(){
  1504. var v = this.logicSelectNode.get("value");
  1505. if (v==="and"){
  1506. this.logicSelectButtonNode.setStyle("float", "left");
  1507. this.logicSelectNode.setStyle("float", "right");
  1508. this.logicSelectNode.set({
  1509. "text": this.viewer.lp.or,
  1510. "value": "or"
  1511. });
  1512. this.data.logic = "or";
  1513. }else{
  1514. this.logicSelectButtonNode.setStyle("float", "right");
  1515. this.logicSelectNode.setStyle("float", "left");
  1516. this.logicSelectNode.set({
  1517. "text": this.viewer.lp.and,
  1518. "value": "and"
  1519. });
  1520. this.data.logic = "and";
  1521. }
  1522. this.viewer.searchCustomView();
  1523. }.bind(this)
  1524. });
  1525. }
  1526. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  1527. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  1528. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  1529. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  1530. this.node.addEvents({
  1531. "mouseover": function(){
  1532. this.node.setStyles(this.css.viewSearchFilterNode_over);
  1533. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  1534. }.bind(this),
  1535. "mouseout": function(){
  1536. this.node.setStyles(this.css.viewSearchFilterNode);
  1537. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  1538. }.bind(this)
  1539. });
  1540. this.deleteNode.addEvent("click", function(){
  1541. this.viewer.searchViewRemoveFilter(this);
  1542. }.bind(this));
  1543. },
  1544. destroy: function(){
  1545. this.node.destroy();
  1546. MWF.release(this);
  1547. }
  1548. });
  1549. MWF.xApplication.query.Query.Viewer.Actionbar = new Class({
  1550. Implements: [Events],
  1551. options: {
  1552. "style" : "default",
  1553. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
  1554. },
  1555. initialize: function(node, json, form, options){
  1556. this.node = $(node);
  1557. this.node.store("module", this);
  1558. this.json = json;
  1559. this.form = form;
  1560. this.view = form;
  1561. },
  1562. hide: function(){
  1563. var dsp = this.node.getStyle("display");
  1564. if (dsp!=="none") this.node.store("mwf_display", dsp);
  1565. this.node.setStyle("display", "none");
  1566. },
  1567. show: function(){
  1568. var dsp = this.node.retrieve("mwf_display", dsp);
  1569. this.node.setStyle("display", dsp);
  1570. },
  1571. load: function(){
  1572. this._loadModuleEvents();
  1573. if (this.fireEvent("queryLoad")){
  1574. //this._queryLoaded();
  1575. this._loadUserInterface();
  1576. this._loadStyles();
  1577. this._loadDomEvents();
  1578. //this._loadEvents();
  1579. //this._afterLoaded();
  1580. this.fireEvent("postLoad");
  1581. this.fireEvent("load");
  1582. }
  1583. },
  1584. _loadStyles: function(){
  1585. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1586. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  1587. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1588. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1589. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  1590. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1591. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1592. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1593. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1594. }
  1595. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1596. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1597. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1598. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1599. }
  1600. if (value.indexOf("/x_cms_assemble_control")!==-1){
  1601. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1602. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  1603. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1604. }
  1605. }
  1606. this.node.setStyle(key, value);
  1607. }.bind(this));
  1608. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  1609. // var host = MWF.Actions.getHost(root);
  1610. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  1611. // }
  1612. //if (this.json.styles) this.node.setStyles(this.json.styles);
  1613. },
  1614. _loadModuleEvents : function(){
  1615. Object.each(this.json.events, function(e, key){
  1616. if (e.code){
  1617. if (this.options.moduleEvents.indexOf(key)!==-1){
  1618. this.addEvent(key, function(event){
  1619. return this.form.Macro.fire(e.code, this, event);
  1620. }.bind(this));
  1621. }
  1622. }
  1623. }.bind(this));
  1624. },
  1625. _loadDomEvents: function(){
  1626. Object.each(this.json.events, function(e, key){
  1627. if (e.code){
  1628. if (this.options.moduleEvents.indexOf(key)===-1){
  1629. this.node.addEvent(key, function(event){
  1630. return this.form.Macro.fire(e.code, this, event);
  1631. }.bind(this));
  1632. }
  1633. }
  1634. }.bind(this));
  1635. },
  1636. _loadEvents: function(){
  1637. Object.each(this.json.events, function(e, key){
  1638. if (e.code){
  1639. if (this.options.moduleEvents.indexOf(key)!==-1){
  1640. this.addEvent(key, function(event){
  1641. return this.form.Macro.fire(e.code, this, event);
  1642. }.bind(this));
  1643. }else{
  1644. this.node.addEvent(key, function(event){
  1645. return this.form.Macro.fire(e.code, this, event);
  1646. }.bind(this));
  1647. }
  1648. }
  1649. }.bind(this));
  1650. },
  1651. addModuleEvent: function(key, fun){
  1652. if (this.options.moduleEvents.indexOf(key)!==-1){
  1653. this.addEvent(key, function(event){
  1654. return (fun) ? fun(this, event) : null;
  1655. }.bind(this));
  1656. }else{
  1657. this.node.addEvent(key, function(event){
  1658. return (fun) ? fun(this, event) : null;
  1659. }.bind(this));
  1660. }
  1661. },
  1662. _loadUserInterface: function(){
  1663. // if (this.form.json.mode == "Mobile"){
  1664. // this.node.empty();
  1665. // }else if (COMMON.Browser.Platform.isMobile){
  1666. // this.node.empty();
  1667. // }else{
  1668. this.toolbarNode = this.node.getFirst("div");
  1669. if( !this.toolbarNode ){
  1670. this.toolbarNode = new Element("div").inject( this.node );
  1671. }
  1672. this.toolbarNode.empty();
  1673. MWF.require("MWF.widget.Toolbar", function(){
  1674. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  1675. "style": this.json.style,
  1676. "onPostLoad" : function(){
  1677. this.fireEvent("afterLoad");
  1678. }.bind(this)
  1679. }, this);
  1680. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  1681. //alert(this.readonly)
  1682. if (this.json.hideSystemTools){
  1683. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1684. this.toolbarWidget.load();
  1685. }else{
  1686. if (this.json.defaultTools){
  1687. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  1688. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1689. this.toolbarWidget.load();
  1690. }else{
  1691. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  1692. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  1693. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1694. this.toolbarWidget.load();
  1695. }.bind(this), null);
  1696. }
  1697. }
  1698. }.bind(this));
  1699. // }
  1700. },
  1701. setCustomToolbars: function(tools, node){
  1702. var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1703. var iconPath = "";
  1704. if( this.json.customIconStyle ){
  1705. iconPath = this.json.customIconStyle+"/";
  1706. }
  1707. tools.each(function(tool){
  1708. var flag = true;
  1709. if (this.readonly){
  1710. flag = tool.readShow;
  1711. }else{
  1712. flag = tool.editShow;
  1713. }
  1714. if (flag){
  1715. flag = true;
  1716. // if (tool.control){
  1717. // flag = this.form.businessData.control[tool.control]
  1718. // }
  1719. if (tool.condition){
  1720. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1721. flag = !hideFlag;
  1722. }
  1723. if (flag){
  1724. var actionNode = new Element("div", {
  1725. "id": tool.id,
  1726. "MWFnodetype": tool.type,
  1727. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  1728. "title": tool.title,
  1729. "MWFButtonAction": "runCustomAction",
  1730. "MWFButtonText": tool.text
  1731. }).inject(node);
  1732. if( this.json.customIconOverStyle ){
  1733. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  1734. }
  1735. if( tool.properties ){
  1736. actionNode.set(tool.properties);
  1737. }
  1738. if (tool.actionScript){
  1739. actionNode.store("script", tool.actionScript);
  1740. }
  1741. if (tool.sub){
  1742. var subNode = node.getLast();
  1743. this.setCustomToolbars(tool.sub, subNode);
  1744. }
  1745. }
  1746. }
  1747. }.bind(this));
  1748. },
  1749. setToolbarItem: function(tool, node, readonly, noCondition){
  1750. //var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1751. var path = "/x_component_query_ViewDesigner/$View/";
  1752. var flag = true;
  1753. // if (tool.control){
  1754. // flag = this.form.businessData.control[tool.control]
  1755. // }
  1756. if (!noCondition) if (tool.condition){
  1757. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1758. flag = flag && (!hideFlag);
  1759. }
  1760. if (readonly) if (!tool.read) flag = false;
  1761. if (flag){
  1762. var actionNode = new Element("div", {
  1763. "id": tool.id,
  1764. "MWFnodetype": tool.type,
  1765. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  1766. //"MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  1767. "MWFButtonImage": path+this.options.style+"/actionbar/"+tool.img,
  1768. "title": tool.title,
  1769. "MWFButtonAction": tool.action,
  1770. "MWFButtonText": tool.text
  1771. }).inject(node);
  1772. if( this.json.iconOverStyle ){
  1773. actionNode.set("MWFButtonImageOver" , path+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
  1774. //actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  1775. }
  1776. if( tool.properties ){
  1777. actionNode.set(tool.properties);
  1778. }
  1779. if (tool.sub){
  1780. var subNode = node.getLast();
  1781. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  1782. }
  1783. }
  1784. },
  1785. setToolbars: function(tools, node, readonly, noCondition){
  1786. tools.each(function(tool){
  1787. this.setToolbarItem(tool, node, readonly, noCondition);
  1788. }.bind(this));
  1789. },
  1790. runCustomAction: function(bt){
  1791. var script = bt.node.retrieve("script");
  1792. this.form.Macro.exec(script, this);
  1793. },
  1794. exportView : function(){
  1795. this.form.exportView();
  1796. },
  1797. deleteWork: function(){
  1798. this.form.deleteWork();
  1799. }
  1800. });
  1801. MWF.xApplication.query.Query.Viewer.Paging = new Class({
  1802. Implements: [Events],
  1803. options: {
  1804. "style" : "default",
  1805. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad","jump"]
  1806. },
  1807. initialize: function(node, json, form, options){
  1808. this.node = $(node);
  1809. this.node.store("module", this);
  1810. this.json = json;
  1811. this.form = form;
  1812. this.view = form;
  1813. },
  1814. hide: function(){
  1815. var dsp = this.node.getStyle("display");
  1816. if (dsp!=="none") this.node.store("mwf_display", dsp);
  1817. this.node.setStyle("display", "none");
  1818. },
  1819. show: function(){
  1820. var dsp = this.node.retrieve("mwf_display", dsp);
  1821. this.node.setStyle("display", dsp);
  1822. },
  1823. load: function(){
  1824. this._loadModuleEvents();
  1825. if (this.fireEvent("queryLoad")){
  1826. //this._queryLoaded();
  1827. this._loadUserInterface();
  1828. this._loadStyles();
  1829. this._loadDomEvents();
  1830. //this._loadEvents();
  1831. //this._afterLoaded();
  1832. this.fireEvent("postLoad");
  1833. }
  1834. },
  1835. _loadStyles: function(){
  1836. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1837. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  1838. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1839. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1840. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  1841. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1842. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1843. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1844. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1845. }
  1846. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1847. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1848. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1849. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1850. }
  1851. if (value.indexOf("/x_cms_assemble_control")!==-1){
  1852. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1853. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  1854. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1855. }
  1856. }
  1857. this.node.setStyle(key, value);
  1858. }.bind(this));
  1859. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  1860. // var host = MWF.Actions.getHost(root);
  1861. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  1862. // }
  1863. //if (this.json.styles) this.node.setStyles(this.json.styles);
  1864. },
  1865. _loadModuleEvents : function(){
  1866. Object.each(this.json.events, function(e, key){
  1867. if (e.code){
  1868. if (this.options.moduleEvents.indexOf(key)!==-1){
  1869. this.addEvent(key, function(event){
  1870. return this.form.Macro.fire(e.code, this, event);
  1871. }.bind(this));
  1872. }
  1873. }
  1874. }.bind(this));
  1875. },
  1876. _loadDomEvents: function(){
  1877. Object.each(this.json.events, function(e, key){
  1878. if (e.code){
  1879. if (this.options.moduleEvents.indexOf(key)===-1){
  1880. this.node.addEvent(key, function(event){
  1881. return this.form.Macro.fire(e.code, this, event);
  1882. }.bind(this));
  1883. }
  1884. }
  1885. }.bind(this));
  1886. },
  1887. _loadEvents: function(){
  1888. Object.each(this.json.events, function(e, key){
  1889. if (e.code){
  1890. if (this.options.moduleEvents.indexOf(key)!==-1){
  1891. this.addEvent(key, function(event){
  1892. return this.form.Macro.fire(e.code, this, event);
  1893. }.bind(this));
  1894. }else{
  1895. this.node.addEvent(key, function(event){
  1896. return this.form.Macro.fire(e.code, this, event);
  1897. }.bind(this));
  1898. }
  1899. }
  1900. }.bind(this));
  1901. },
  1902. addModuleEvent: function(key, fun){
  1903. if (this.options.moduleEvents.indexOf(key)!==-1){
  1904. this.addEvent(key, function(event){
  1905. return (fun) ? fun(this, event) : null;
  1906. }.bind(this));
  1907. }else{
  1908. this.node.addEvent(key, function(event){
  1909. return (fun) ? fun(this, event) : null;
  1910. }.bind(this));
  1911. }
  1912. },
  1913. _loadUserInterface: function(){
  1914. // if (this.form.json.mode == "Mobile"){
  1915. // this.node.empty();
  1916. // }else if (COMMON.Browser.Platform.isMobile){
  1917. // this.node.empty();
  1918. // }else{
  1919. this.loadPaging( true )
  1920. },
  1921. reload : function(){
  1922. this.loadPaging( false )
  1923. },
  1924. loadPaging : function( firstLoading ){
  1925. this.pagingNode = this.node.getFirst("div");
  1926. if( !this.pagingNode ){
  1927. this.pagingNode = new Element("div").inject( this.node );
  1928. }
  1929. this.pagingNode.empty();
  1930. this.paging = new o2.widget.Paging(this.pagingNode, {
  1931. //style : this.options.skin && this.options.skin.pagingBar ? this.options.skin.pagingBar : "default",
  1932. countPerPage: this.view.json.pageSize || this.view.options.perPageCount,
  1933. visiblePages: this.json.visiblePages ? this.json.visiblePages.toInt() : 9,
  1934. currentPage: this.view.currentPage,
  1935. itemSize: this.view.count,
  1936. pageSize: this.view.pages,
  1937. hasNextPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  1938. hasPrevPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  1939. hasTruningBar: typeOf( this.json.hasTruningBar ) === "boolean" ? this.json.hasTruningBar : true,
  1940. hasBatchTuring: typeOf( this.json.hasBatchTuring ) === "boolean" ? this.json.hasBatchTuring : true,
  1941. hasFirstPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : true,
  1942. hasLastPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : true,
  1943. hasJumper: typeOf( this.json.hasPageJumper ) === "boolean" ? this.json.hasPageJumper : true,
  1944. hiddenWithDisable: false,
  1945. hiddenWithNoItem: true,
  1946. text: {
  1947. prePage: this.json.prePageText,
  1948. nextPage: this.json.nextPageText,
  1949. firstPage: this.json.firstPageText,
  1950. lastPage: this.json.lastPageText
  1951. },
  1952. onJumpingPage : function( pageNum, itemNum ){
  1953. this.view.currentPage = pageNum;
  1954. this.fireEvent("jump");
  1955. this.view.loadCurrentPageData();
  1956. }.bind(this),
  1957. onPostLoad : function () {
  1958. if( firstLoading ){
  1959. if(this.view.setContentHeightFun)this.view.setContentHeightFun();
  1960. this.fireEvent("load");
  1961. }
  1962. this.fireEvent("afterLoad");
  1963. }.bind(this)
  1964. }, this.json.pagingStyles || {});
  1965. this.paging.load();
  1966. }
  1967. });