Viewer.js 101 KB

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