Viewer.js 80 KB

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