Viewer.js 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854
  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: 6,
  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. this.json.pageSize = 2;
  696. var i = this.count/this.json.pageSize;
  697. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  698. this.currentPage = 1;
  699. },
  700. lookup: function(data){
  701. this.getLookupAction(function(){
  702. if (this.json.application){
  703. var d = data || {};
  704. d.count = this.json.count;
  705. this.lookupAction.bundleView(this.json.id, d, function(json){
  706. this.bundleItems = json.data.valueList;
  707. this._initPage();
  708. if (this.bundleItems.length){
  709. this.loadCurrentPageData( function () {
  710. this.fireEvent("postLoad"); //用户配置的事件
  711. }.bind(this));
  712. }else{
  713. //this._loadPageNode();
  714. this.viewPageAreaNode.empty();
  715. if (this.loadingAreaNode){
  716. this.loadingAreaNode.destroy();
  717. this.loadingAreaNode = null;
  718. }
  719. this.fireEvent("postLoad"); //用户配置的事件
  720. }
  721. }.bind(this));
  722. }
  723. }.bind(this));
  724. },
  725. loadCurrentPageData: function( callback ){
  726. debugger;
  727. //是否需要在翻页的时候清空之前的items ?
  728. this.items = [];
  729. var p = this.currentPage;
  730. var d = {};
  731. var valueList = this.bundleItems.slice((p-1)*this.json.pageSize,this.json.pageSize*p);
  732. d.bundleList = valueList;
  733. while (this.viewTable.rows.length>1){
  734. this.viewTable.deleteRow(-1);
  735. }
  736. //this.createLoadding();
  737. this.loadViewRes = this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
  738. this.viewData = json.data;
  739. this.fireEvent("postLoadPageData");
  740. if (this.viewJson.group.column){
  741. this.gridJson = json.data.groupGrid;
  742. this.loadGroupData();
  743. }else{
  744. this.gridJson = json.data.grid;
  745. this.loadData();
  746. }
  747. if (this.gridJson.length) this._loadPageNode();
  748. if (this.loadingAreaNode){
  749. this.loadingAreaNode.destroy();
  750. this.loadingAreaNode = null;
  751. }
  752. this.fireEvent("loadView"); //options 传入的事件
  753. this.fireEvent("postLoadPage");
  754. if(callback)callback();
  755. }.bind(this));
  756. },
  757. loadData: function(){
  758. if (this.gridJson.length){
  759. // if( !this.options.paging ){
  760. this.gridJson.each(function(line, i){
  761. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, line, null, i));
  762. }.bind(this));
  763. // }else{
  764. // this.loadPaging();
  765. // }
  766. }else{
  767. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  768. }
  769. },
  770. loadPaging : function(){
  771. this.isItemsLoading = false;
  772. this.pageNumber = 0;
  773. this.isItemsLoaded = false;
  774. this.isSetedScroll = false;
  775. this.setScroll();
  776. this.loadDataByPaging()
  777. },
  778. setScroll : function(){
  779. if( this.options.paging && !this.isSetedScroll ){
  780. this.contentAreaNode.setStyle("overflow","auto");
  781. this.scrollContainerFun = function(){
  782. var scrollSize = this.contentAreaNode.getScrollSize();
  783. var clientSize = this.contentAreaNode.getSize();
  784. var scrollHeight = scrollSize.y - clientSize.y;
  785. //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
  786. if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
  787. if (!this.isItemsLoaded) this.loadDataByPaging();
  788. }
  789. }.bind(this);
  790. this.isSetedScroll = true;
  791. this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
  792. }
  793. },
  794. loadDataByPaging : function(){
  795. if( this.isItemsLoading )return;
  796. if( !this.isItemsLoaded ){
  797. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  798. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  799. this.isItemsLoading = true;
  800. for( var i = from; i<to; i++ ){
  801. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, this.gridJson[i], null, i));
  802. }
  803. this.isItemsLoading = false;
  804. this.pageNumber ++;
  805. if( to == this.gridJson.length )this.isItemsLoaded = true;
  806. }
  807. },
  808. loadGroupData: function(){
  809. if (this.selectTitleCell){
  810. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  811. this.selectTitleCell.setStyle("cursor", "pointer");
  812. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  813. }
  814. if (this.gridJson.length){
  815. var i = 0;
  816. this.gridJson.each(function(data){
  817. this.items.push(new MWF.xApplication.query.Query.Viewer.ItemCategory(this, data, i));
  818. i += data.list.length;
  819. }.bind(this));
  820. if (this.json.isExpand=="yes") this.expandOrCollapseAll();
  821. }else{
  822. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  823. }
  824. },
  825. expandOrCollapseAll: function(){
  826. var icon = this.selectTitleCell.getElement("span");
  827. if (icon.get("html").indexOf("expand.png")===-1){
  828. this.items.each(function(item){
  829. item.collapse();
  830. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  831. }.bind(this));
  832. }else{
  833. this.items.each(function(item, i){
  834. window.setTimeout(function(){
  835. item.expand();
  836. }.bind(this), 10*i+5);
  837. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
  838. }.bind(this));
  839. }
  840. },
  841. getView: function(callback){
  842. this.getLookupAction(function(){
  843. if (this.json.application){
  844. this.getViewRes = this.lookupAction.getView(this.json.viewName, this.json.application, function(json){
  845. this.viewJson = JSON.decode(json.data.data);
  846. this.json = Object.merge(this.json, json.data);
  847. if (callback) callback();
  848. }.bind(this));
  849. // this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  850. // this.viewJson = JSON.decode(json.data.data);
  851. // this.json = Object.merge(this.json, json.data);
  852. // //var viewData = JSON.decode(json.data.data);
  853. // if (callback) callback();
  854. // }.bind(this)});
  855. }else{
  856. this.getViewRes = this.lookupAction.getViewById(this.json.viewId, function(json){
  857. this.viewJson = JSON.decode(json.data.data);
  858. this.json.application = json.data.query;
  859. this.json = Object.merge(this.json, json.data);
  860. if (callback) callback();
  861. }.bind(this));
  862. }
  863. }.bind(this));
  864. },
  865. getLookupAction: function(callback){
  866. if (!this.lookupAction){
  867. this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
  868. if (callback) callback();
  869. // var _self = this;
  870. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  871. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
  872. // this.lookupAction.getActions = function(actionCallback){
  873. // this.actions = _self.options.actions;
  874. // if (actionCallback) actionCallback();
  875. // };
  876. // if (callback) callback();
  877. // }.bind(this));
  878. }else{
  879. if (callback) callback();
  880. }
  881. },
  882. hide: function(){
  883. this.node.setStyle("display", "none");
  884. },
  885. reload: function(){
  886. this.node.setStyle("display", "block");
  887. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  888. this.filterItems.each(function(filter){
  889. filter.destroy();
  890. }.bind(this));
  891. this.filterItems = [];
  892. if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
  893. this.closeCustomSearch();
  894. this.viewAreaNode.empty();
  895. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  896. },
  897. getFilter: function(){
  898. var filterData = [];
  899. if (this.searchStatus==="custom"){
  900. if (this.filterItems.length){
  901. this.filterItems.each(function(filter){
  902. filterData.push(filter.data);
  903. }.bind(this));
  904. }
  905. }
  906. if (this.searchStatus==="default"){
  907. var key = this.viewSearchInputNode.get("value");
  908. if (key && key!==this.lp.searchKeywork){
  909. this.viewJson.customFilterList.each(function(entry){
  910. if (entry.formatType==="textValue"){
  911. var d = {
  912. "path": entry.path,
  913. "value": key,
  914. "formatType": entry.formatType,
  915. "logic": "or",
  916. "comparison": "like"
  917. };
  918. filterData.push(d);
  919. }
  920. if (entry.formatType==="numberValue"){
  921. var v = key.toFloat();
  922. if (!isNaN(v)){
  923. var d = {
  924. "path": entry.path,
  925. "value": v,
  926. "formatType": entry.formatType,
  927. "logic": "or",
  928. "comparison": "like"
  929. };
  930. filterData.push(d);
  931. }
  932. }
  933. }.bind(this));
  934. }
  935. }
  936. return (filterData.length) ? filterData : null;
  937. },
  938. getSelectedData : function(){
  939. return this.getData();
  940. },
  941. getData: function(){
  942. if (this.selectedItems.length){
  943. var arr = [];
  944. this.selectedItems.each(function(item){
  945. arr.push(item.data);
  946. });
  947. return arr;
  948. }else{
  949. return [];
  950. }
  951. },
  952. _loadModuleEvents : function(){
  953. debugger;
  954. Object.each(this.viewJson.events, function(e, key){
  955. if (e.code){
  956. if (this.options.moduleEvents.indexOf(key)!==-1){
  957. this.addEvent(key, function(event, target){
  958. debugger;
  959. return this.Macro.fire(e.code, target || this, event);
  960. }.bind(this));
  961. }
  962. }
  963. }.bind(this));
  964. },
  965. _loadDomEvents: function(){
  966. Object.each(this.viewJson.events, function(e, key){
  967. if (e.code){
  968. if (this.options.moduleEvents.indexOf(key)===-1){
  969. this.node.addEvent(key, function(event){
  970. return this.Macro.fire(e.code, this, event);
  971. }.bind(this));
  972. }
  973. }
  974. }.bind(this));
  975. },
  976. //api 使用 开始
  977. getParentEnvironment : function(){
  978. return this.parentMacro ? this.parentMacro.environment : null;
  979. },
  980. getViewInfor : function(){
  981. return this.json;
  982. },
  983. getPageInfor : function(){
  984. return {
  985. pages : this.pages,
  986. perPageCount : this.options.perPageCount,
  987. currentPageNumber : this.currentPage
  988. };
  989. },
  990. getPageData : function () {
  991. return this.gridJson;
  992. },
  993. toPage : function( pageNumber, callback ){
  994. this.currentPage = pageNumber;
  995. this.loadCurrentPageData( callback );
  996. },
  997. selectAll : function(){
  998. var flag = this.json.select || this.viewJson.select || "none";
  999. if ( flag==="multi"){
  1000. this.items.each( function (item) {
  1001. if( item.clazzType === "item" ){
  1002. item.selected();
  1003. }else{
  1004. item.expand();
  1005. if( item.items ){
  1006. item.items.each( function (it) {
  1007. it.selected();
  1008. })
  1009. }
  1010. }
  1011. })
  1012. }
  1013. },
  1014. unSelectAll : function(){
  1015. var flag = this.json.select || this.viewJson.select || "none";
  1016. if ( flag==="multi"){
  1017. this.items.each( function (item) {
  1018. if( item.clazzType === "item" ){
  1019. item.unSelected();
  1020. }else{
  1021. if(item.items){
  1022. item.items.each( function (it) {
  1023. it.unSelected();
  1024. })
  1025. }
  1026. }
  1027. })
  1028. }
  1029. },
  1030. setFilter : function( filter ){
  1031. if( !filter )filter = [];
  1032. if( typeOf( filter ) === "object" )filter = [ filter ];
  1033. this.json.filter = filter;
  1034. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  1035. },
  1036. switchView : function( json ){
  1037. debugger;
  1038. // json = {
  1039. // "application": application,
  1040. // "viewName": viewName,
  1041. // "isTitle": "yes",
  1042. // "select": "none",
  1043. // "titleStyles": titleStyles,
  1044. // "itemStyles": itemStyles,
  1045. // "isExpand": "no",
  1046. // "filter": filter
  1047. // }
  1048. this.node.setStyle("display", "block");
  1049. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  1050. this.searchMorph = null;
  1051. this.viewSearchCustomContentNode = null;
  1052. var newJson = Object.merge( Object.clone(this.originalJson), json );
  1053. this.container.empty();
  1054. this.initialize( this.container, newJson, Object.clone(this.options), this.app, this.parentMacro);
  1055. },
  1056. confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
  1057. this.app.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style)
  1058. },
  1059. alert: function (type, title, text, width, height) {
  1060. this.app.alert(type, "center", title, text, width, height);
  1061. },
  1062. notice: function (content, type, target, where, offset, option) {
  1063. this.app.notice(content, type, target, where, offset, option)
  1064. }
  1065. //api 使用 结束
  1066. });
  1067. MWF.xApplication.query.Query.Viewer.Item = new Class({
  1068. initialize: function(view, data, prev, i){
  1069. this.view = view;
  1070. this.data = data;
  1071. this.css = this.view.css;
  1072. this.isSelected = false;
  1073. this.prev = prev;
  1074. this.idx = i;
  1075. this.clazzType = "item";
  1076. this.load();
  1077. },
  1078. load: function(){
  1079. this.view.fireEvent("queryLoadItemRow", [null, this]);
  1080. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  1081. if (this.prev){
  1082. this.node.inject(this.prev.node, "after");
  1083. }else{
  1084. this.node.inject(this.view.viewTable);
  1085. }
  1086. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1087. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1088. this.selectTd.setStyles({"cursor": "pointer"});
  1089. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1090. //}
  1091. //序号
  1092. if (this.view.viewJson.isSequence==="yes"){
  1093. this.sequenceTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1094. this.sequenceTd.setStyle("width", "10px");
  1095. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  1096. this.sequenceTd.set("text", s);
  1097. }
  1098. Object.each(this.view.entries, function(c, k){
  1099. var cell = this.data.data[k];
  1100. if (cell === undefined) cell = "";
  1101. //if (cell){
  1102. if (this.view.hideColumns.indexOf(k)===-1){
  1103. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1104. if (k!== this.view.viewJson.group.column){
  1105. //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;
  1106. var v = cell;
  1107. if (c.isHtml){
  1108. td.set("html", v);
  1109. }else{
  1110. td.set("text", v);
  1111. }
  1112. }
  1113. if (this.view.openColumns.indexOf(k)!==-1){
  1114. this.setOpenWork(td, c)
  1115. }
  1116. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1117. }
  1118. //}
  1119. }.bind(this));
  1120. // Object.each(this.data.data, function(cell, k){
  1121. // if (this.view.hideColumns.indexOf(k)===-1){
  1122. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1123. // if (k!== this.view.viewJson.group.column){
  1124. // 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;
  1125. // td.set("text", v);
  1126. // }
  1127. // if (this.view.openColumns.indexOf(k)!==-1){
  1128. // this.setOpenWork(td)
  1129. // }
  1130. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1131. // }
  1132. // }.bind(this));
  1133. this.setEvent();
  1134. this.view.fireEvent("postLoadItemRow", [null, this]);
  1135. },
  1136. setOpenWork: function(td, column){
  1137. td.setStyle("cursor", "pointer");
  1138. if( column.clickCode ){
  1139. // if( !this.view.Macro ){
  1140. // MWF.require("MWF.xScript.Macro", function () {
  1141. // this.view.businessData = {};
  1142. // this.view.Macro = new MWF.Macro.PageContext(this.view);
  1143. // }.bind(this), false);
  1144. // }
  1145. td.addEvent("click", function( ev ){
  1146. var result = this.view.Macro.fire(column.clickCode, this, ev);
  1147. ev.stopPropagation();
  1148. return result;
  1149. }.bind(this));
  1150. }else{
  1151. if (this.view.json.type==="cms"){
  1152. td.addEvent("click", function(ev){
  1153. this.openCms(ev)
  1154. ev.stopPropagation();
  1155. }.bind(this));
  1156. }else{
  1157. td.addEvent("click", function(ev){
  1158. this.openWorkAndCompleted(ev)
  1159. ev.stopPropagation();
  1160. }.bind(this));
  1161. }
  1162. }
  1163. },
  1164. openCms: function(e){
  1165. var options = {"documentId": this.data.bundle};
  1166. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1167. layout.desktop.openApplication(e, "cms.Document", options);
  1168. },
  1169. openWorkAndCompleted: function(e){
  1170. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
  1171. var workCompletedCount = json.data.workCompletedList.length;
  1172. var workCount = json.data.workList.length;
  1173. var count = workCount+workCompletedCount;
  1174. if (count===1){
  1175. if (workCompletedCount) {
  1176. this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  1177. }else{
  1178. this.openWork(json.data.workList[0].id, e);
  1179. }
  1180. }else if (count>1){
  1181. var worksAreaNode = this.createWorksArea();
  1182. json.data.workCompletedList.each(function(work){
  1183. this.createWorkCompletedNode(work, worksAreaNode);
  1184. }.bind(this));
  1185. json.data.workList.each(function(work){
  1186. this.createWorkNode(work, worksAreaNode);
  1187. }.bind(this));
  1188. this.showWorksArea(worksAreaNode, e);
  1189. }else{
  1190. }
  1191. }.bind(this));
  1192. },
  1193. createWorkNode: function(work, worksAreaNode){
  1194. var worksAreaContentNode = worksAreaNode.getLast();
  1195. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1196. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1197. actionNode.store("workId", work.id);
  1198. actionNode.addEvent("click", function(e){
  1199. this.openWork(e.target.retrieve("workId"), e);
  1200. this.mask.hide();
  1201. worksAreaNode.destroy();
  1202. }.bind(this));
  1203. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1204. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1205. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1206. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1207. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  1208. var taskUsers = [];
  1209. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  1210. json.data.each(function(task){
  1211. taskUsers.push(MWF.name.cn(task.person));
  1212. }.bind(this));
  1213. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  1214. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  1215. }.bind(this));
  1216. },
  1217. createWorkCompletedNode: function(work, worksAreaNode){
  1218. var worksAreaContentNode = worksAreaNode.getLast();
  1219. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1220. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1221. actionNode.store("workId", work.id);
  1222. actionNode.addEvent("click", function(e){
  1223. this.mask.hide();
  1224. var id = e.target.retrieve("workId");
  1225. worksAreaNode.destroy();
  1226. this.openWorkCompleted(id, e);
  1227. }.bind(this));
  1228. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1229. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1230. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1231. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1232. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  1233. },
  1234. createWorksArea: function(){
  1235. var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
  1236. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  1237. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  1238. worksAreaTitleCloseNode.addEvent("click", function(e){
  1239. this.mask.hide();
  1240. e.target.getParent().getParent().destroy();
  1241. }.bind(this));
  1242. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  1243. return worksAreaNode;
  1244. },
  1245. showWorksArea: function(node, e){
  1246. MWF.require("MWF.widget.Mask", null, false);
  1247. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  1248. this.mask.loadNode(this.view.container);
  1249. node.inject(this.view.node);
  1250. this.setWorksAreaPosition(node, e.target);
  1251. },
  1252. setWorksAreaPosition: function(node, td){
  1253. var p = td.getPosition(this.view.container);
  1254. var containerS = this.view.container.getSize();
  1255. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  1256. var s = node.getSize();
  1257. var offX = p.x+s.x-containerS.x;
  1258. offX = (offX>0) ? offX+20 : 0;
  1259. var offY = p.y+s.y-containerS.y;
  1260. offY = (offY>0) ? offY+5 : 0;
  1261. node.position({
  1262. "relativeTo": td,
  1263. "position": "lefttop",
  1264. "edge": "lefttop",
  1265. "offset": {
  1266. "x": 0-offX,
  1267. "y": 0-offY
  1268. }
  1269. });
  1270. },
  1271. openWork: function(id, e){
  1272. var options = {"workId": id};
  1273. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1274. layout.desktop.openApplication(e, "process.Work", options);
  1275. },
  1276. openWorkCompleted: function(id, e){
  1277. var options = {"workCompletedId": id};
  1278. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1279. layout.desktop.openApplication(e, "process.Work", options);
  1280. },
  1281. setEvent: function(){
  1282. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1283. if ( flag ==="single" || flag==="multi"){
  1284. this.node.addEvents({
  1285. "mouseover": function(){
  1286. if (!this.isSelected){
  1287. var iconName = "checkbox";
  1288. if (flag==="single") iconName = "radiobox";
  1289. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  1290. }
  1291. }.bind(this),
  1292. "mouseout": function(){
  1293. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  1294. }.bind(this),
  1295. "click": function(){this.select();}.bind(this)
  1296. });
  1297. }
  1298. },
  1299. select: function(){
  1300. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1301. if (this.isSelected){
  1302. if (flag==="single"){
  1303. this.unSelectedSingle();
  1304. }else{
  1305. this.unSelected();
  1306. }
  1307. }else{
  1308. if (flag==="single"){
  1309. this.selectedSingle();
  1310. }else{
  1311. this.selected();
  1312. }
  1313. }
  1314. this.view.fireEvent("select"); //options 传入的事件
  1315. },
  1316. selected: function(){
  1317. this.view.selectedItems.push(this);
  1318. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  1319. this.node.setStyles(this.css.viewContentTrNode_selected);
  1320. this.isSelected = true;
  1321. this.view.fireEvent("selectRow", [this]);
  1322. },
  1323. unSelected: function(){
  1324. this.view.selectedItems.erase(this);
  1325. this.selectTd.setStyles({"background": "transparent"});
  1326. this.node.setStyles(this.css.viewContentTrNode);
  1327. this.isSelected = false;
  1328. this.view.fireEvent("unselectRow", [this]);
  1329. },
  1330. selectedSingle: function(){
  1331. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  1332. this.view.selectedItems = [this];
  1333. this.view.currentSelectedItem = this;
  1334. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
  1335. this.node.setStyles(this.css.viewContentTrNode_selected);
  1336. this.isSelected = true;
  1337. this.view.fireEvent("selectRow", [this]);
  1338. },
  1339. unSelectedSingle: function(){
  1340. this.view.selectedItems = [];
  1341. this.view.currentSelectedItem = null;
  1342. this.selectTd.setStyles({"background": "transparent"});
  1343. this.node.setStyles(this.css.viewContentTrNode);
  1344. this.isSelected = false;
  1345. this.view.fireEvent("unselectRow", [this]);
  1346. }
  1347. });
  1348. MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
  1349. initialize: function(view, data, i){
  1350. this.view = view;
  1351. this.data = data;
  1352. this.css = this.view.css;
  1353. this.items = [];
  1354. this.loadChild = false;
  1355. this.idx = i;
  1356. this.clazzType = "category";
  1357. this.load();
  1358. },
  1359. load: function(){
  1360. this.view.fireEvent("queryLoadCategoryRow", [null, this]);
  1361. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  1362. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1363. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  1364. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1365. //}
  1366. this.categoryTd = new Element("td", {
  1367. "styles": this.css.viewContentCategoryTdNode,
  1368. "colspan": this.view.viewJson.selectList.length+1
  1369. }).inject(this.node);
  1370. this.groupColumn = null;
  1371. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  1372. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  1373. this.groupColumn = this.view.viewJson.selectList[c];
  1374. break;
  1375. }
  1376. }
  1377. if (this.groupColumn){
  1378. //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;
  1379. var text = this.data.group;
  1380. }else{
  1381. var text = this.data.group;
  1382. }
  1383. 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);
  1384. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  1385. this.setEvent();
  1386. this.view.fireEvent("postLoadCategoryRow", [null, this]);
  1387. },
  1388. setEvent: function(){
  1389. //if (this.selectTd){
  1390. this.node.addEvents({
  1391. "click": function(){this.expandOrCollapse();}.bind(this)
  1392. });
  1393. //}
  1394. },
  1395. expandOrCollapse: function(){
  1396. var t = this.node.getElement("span").get("html");
  1397. if (t.indexOf("expand.png")===-1){
  1398. this.collapse();
  1399. }else{
  1400. this.expand();
  1401. }
  1402. },
  1403. collapse: function(){
  1404. this.items.each(function(item){
  1405. item.node.setStyle("display", "none");
  1406. }.bind(this));
  1407. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  1408. },
  1409. expand: function(){
  1410. this.items.each(function(item){
  1411. item.node.setStyle("display", "table-row");
  1412. }.bind(this));
  1413. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  1414. if (!this.loadChild){
  1415. //window.setTimeout(function(){
  1416. this.data.list.each(function(line, i){
  1417. var s = this.idx+i;
  1418. this.lastItem = new MWF.xApplication.query.Query.Viewer.Item(this.view, line, (this.lastItem || this), s);
  1419. this.items.push(this.lastItem);
  1420. }.bind(this));
  1421. this.loadChild = true;
  1422. //}.bind(this), 10);
  1423. }
  1424. }
  1425. });
  1426. MWF.xApplication.query.Query.Viewer.Filter = new Class({
  1427. initialize: function(viewer, data, node){
  1428. this.viewer = viewer;
  1429. this.data = data;
  1430. this.css = this.viewer.css;
  1431. this.content = node;
  1432. this.load();
  1433. },
  1434. load: function(){
  1435. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  1436. if (this.viewer.filterItems.length){
  1437. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  1438. this.logicSelectNode = new Element("div", {
  1439. "styles": this.css.viewSearchFilterSelectNode,
  1440. "text": this.viewer.lp.and,
  1441. "value": "and"
  1442. }).inject(this.logicNode);
  1443. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  1444. this.logicNode.addEvents({
  1445. "click": function(){
  1446. var v = this.logicSelectNode.get("value");
  1447. if (v==="and"){
  1448. this.logicSelectButtonNode.setStyle("float", "left");
  1449. this.logicSelectNode.setStyle("float", "right");
  1450. this.logicSelectNode.set({
  1451. "text": this.viewer.lp.or,
  1452. "value": "or"
  1453. });
  1454. this.data.logic = "or";
  1455. }else{
  1456. this.logicSelectButtonNode.setStyle("float", "right");
  1457. this.logicSelectNode.setStyle("float", "left");
  1458. this.logicSelectNode.set({
  1459. "text": this.viewer.lp.and,
  1460. "value": "and"
  1461. });
  1462. this.data.logic = "and";
  1463. }
  1464. this.viewer.searchCustomView();
  1465. }.bind(this)
  1466. });
  1467. }
  1468. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  1469. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  1470. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  1471. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  1472. this.node.addEvents({
  1473. "mouseover": function(){
  1474. this.node.setStyles(this.css.viewSearchFilterNode_over);
  1475. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  1476. }.bind(this),
  1477. "mouseout": function(){
  1478. this.node.setStyles(this.css.viewSearchFilterNode);
  1479. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  1480. }.bind(this)
  1481. });
  1482. this.deleteNode.addEvent("click", function(){
  1483. this.viewer.searchViewRemoveFilter(this);
  1484. }.bind(this));
  1485. },
  1486. destroy: function(){
  1487. this.node.destroy();
  1488. MWF.release(this);
  1489. }
  1490. });
  1491. MWF.xApplication.query.Query.Viewer.Actionbar = new Class({
  1492. Implements: [Events],
  1493. options: {
  1494. "style" : "default",
  1495. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
  1496. },
  1497. initialize: function(node, json, form, options){
  1498. this.node = $(node);
  1499. this.node.store("module", this);
  1500. this.json = json;
  1501. this.form = form;
  1502. this.view = form;
  1503. },
  1504. hide: function(){
  1505. var dsp = this.node.getStyle("display");
  1506. if (dsp!=="none") this.node.store("mwf_display", dsp);
  1507. this.node.setStyle("display", "none");
  1508. },
  1509. show: function(){
  1510. var dsp = this.node.retrieve("mwf_display", dsp);
  1511. this.node.setStyle("display", dsp);
  1512. },
  1513. load: function(){
  1514. this._loadModuleEvents();
  1515. if (this.fireEvent("queryLoad")){
  1516. //this._queryLoaded();
  1517. this._loadUserInterface();
  1518. this._loadStyles();
  1519. this._loadDomEvents();
  1520. //this._loadEvents();
  1521. //this._afterLoaded();
  1522. this.fireEvent("postLoad");
  1523. this.fireEvent("load");
  1524. }
  1525. },
  1526. _loadStyles: function(){
  1527. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1528. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  1529. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1530. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1531. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  1532. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1533. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1534. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1535. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1536. }
  1537. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1538. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1539. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1540. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1541. }
  1542. if (value.indexOf("/x_cms_assemble_control")!==-1){
  1543. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1544. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  1545. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1546. }
  1547. }
  1548. this.node.setStyle(key, value);
  1549. }.bind(this));
  1550. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  1551. // var host = MWF.Actions.getHost(root);
  1552. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  1553. // }
  1554. //if (this.json.styles) this.node.setStyles(this.json.styles);
  1555. },
  1556. _loadModuleEvents : function(){
  1557. Object.each(this.json.events, function(e, key){
  1558. if (e.code){
  1559. if (this.options.moduleEvents.indexOf(key)!==-1){
  1560. this.addEvent(key, function(event){
  1561. return this.form.Macro.fire(e.code, this, event);
  1562. }.bind(this));
  1563. }
  1564. }
  1565. }.bind(this));
  1566. },
  1567. _loadDomEvents: function(){
  1568. Object.each(this.json.events, function(e, key){
  1569. if (e.code){
  1570. if (this.options.moduleEvents.indexOf(key)===-1){
  1571. this.node.addEvent(key, function(event){
  1572. return this.form.Macro.fire(e.code, this, event);
  1573. }.bind(this));
  1574. }
  1575. }
  1576. }.bind(this));
  1577. },
  1578. _loadEvents: function(){
  1579. Object.each(this.json.events, function(e, key){
  1580. if (e.code){
  1581. if (this.options.moduleEvents.indexOf(key)!==-1){
  1582. this.addEvent(key, function(event){
  1583. return this.form.Macro.fire(e.code, this, event);
  1584. }.bind(this));
  1585. }else{
  1586. this.node.addEvent(key, function(event){
  1587. return this.form.Macro.fire(e.code, this, event);
  1588. }.bind(this));
  1589. }
  1590. }
  1591. }.bind(this));
  1592. },
  1593. addModuleEvent: function(key, fun){
  1594. if (this.options.moduleEvents.indexOf(key)!==-1){
  1595. this.addEvent(key, function(event){
  1596. return (fun) ? fun(this, event) : null;
  1597. }.bind(this));
  1598. }else{
  1599. this.node.addEvent(key, function(event){
  1600. return (fun) ? fun(this, event) : null;
  1601. }.bind(this));
  1602. }
  1603. },
  1604. _loadUserInterface: function(){
  1605. // if (this.form.json.mode == "Mobile"){
  1606. // this.node.empty();
  1607. // }else if (COMMON.Browser.Platform.isMobile){
  1608. // this.node.empty();
  1609. // }else{
  1610. this.toolbarNode = this.node.getFirst("div");
  1611. if( !this.toolbarNode ){
  1612. this.toolbarNode = new Element("div").inject( this.node );
  1613. }
  1614. this.toolbarNode.empty();
  1615. MWF.require("MWF.widget.Toolbar", function(){
  1616. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  1617. "style": this.json.style,
  1618. "onPostLoad" : function(){
  1619. this.fireEvent("afterLoad");
  1620. }.bind(this)
  1621. }, this);
  1622. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  1623. //alert(this.readonly)
  1624. if (this.json.hideSystemTools){
  1625. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1626. this.toolbarWidget.load();
  1627. }else{
  1628. if (this.json.defaultTools){
  1629. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  1630. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1631. this.toolbarWidget.load();
  1632. }else{
  1633. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  1634. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  1635. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1636. this.toolbarWidget.load();
  1637. }.bind(this), null);
  1638. }
  1639. }
  1640. }.bind(this));
  1641. // }
  1642. },
  1643. setCustomToolbars: function(tools, node){
  1644. var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1645. var iconPath = "";
  1646. if( this.json.customIconStyle ){
  1647. iconPath = this.json.customIconStyle+"/";
  1648. }
  1649. tools.each(function(tool){
  1650. var flag = true;
  1651. if (this.readonly){
  1652. flag = tool.readShow;
  1653. }else{
  1654. flag = tool.editShow;
  1655. }
  1656. if (flag){
  1657. flag = true;
  1658. // if (tool.control){
  1659. // flag = this.form.businessData.control[tool.control]
  1660. // }
  1661. if (tool.condition){
  1662. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1663. flag = !hideFlag;
  1664. }
  1665. if (flag){
  1666. var actionNode = new Element("div", {
  1667. "id": tool.id,
  1668. "MWFnodetype": tool.type,
  1669. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  1670. "title": tool.title,
  1671. "MWFButtonAction": "runCustomAction",
  1672. "MWFButtonText": tool.text
  1673. }).inject(node);
  1674. if( this.json.customIconOverStyle ){
  1675. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  1676. }
  1677. if( tool.properties ){
  1678. actionNode.set(tool.properties);
  1679. }
  1680. if (tool.actionScript){
  1681. actionNode.store("script", tool.actionScript);
  1682. }
  1683. if (tool.sub){
  1684. var subNode = node.getLast();
  1685. this.setCustomToolbars(tool.sub, subNode);
  1686. }
  1687. }
  1688. }
  1689. }.bind(this));
  1690. },
  1691. setToolbarItem: function(tool, node, readonly, noCondition){
  1692. //var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1693. var path = "/x_component_query_ViewDesigner/$View/";
  1694. var flag = true;
  1695. // if (tool.control){
  1696. // flag = this.form.businessData.control[tool.control]
  1697. // }
  1698. if (!noCondition) if (tool.condition){
  1699. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1700. flag = flag && (!hideFlag);
  1701. }
  1702. if (readonly) if (!tool.read) flag = false;
  1703. if (flag){
  1704. var actionNode = new Element("div", {
  1705. "id": tool.id,
  1706. "MWFnodetype": tool.type,
  1707. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  1708. //"MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  1709. "MWFButtonImage": path+this.options.style+"/actionbar/"+tool.img,
  1710. "title": tool.title,
  1711. "MWFButtonAction": tool.action,
  1712. "MWFButtonText": tool.text
  1713. }).inject(node);
  1714. if( this.json.iconOverStyle ){
  1715. actionNode.set("MWFButtonImageOver" , path+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
  1716. //actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  1717. }
  1718. if( tool.properties ){
  1719. actionNode.set(tool.properties);
  1720. }
  1721. if (tool.sub){
  1722. var subNode = node.getLast();
  1723. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  1724. }
  1725. }
  1726. },
  1727. setToolbars: function(tools, node, readonly, noCondition){
  1728. tools.each(function(tool){
  1729. this.setToolbarItem(tool, node, readonly, noCondition);
  1730. }.bind(this));
  1731. },
  1732. runCustomAction: function(bt){
  1733. var script = bt.node.retrieve("script");
  1734. this.form.Macro.exec(script, this);
  1735. },
  1736. exportView : function(){
  1737. this.form.exportView();
  1738. },
  1739. deleteWork: function(){
  1740. this.form.deleteWork();
  1741. }
  1742. });