Viewer.js 125 KB

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