Viewer.js 100 KB

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