Viewer.js 84 KB

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