Viewer.js 102 KB

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