Viewer.js 120 KB

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