Viewer.js 113 KB

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