Viewer.js 132 KB

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