Viewer.js 101 KB

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