Viewer.js 102 KB

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