Viewer.js 100 KB

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