Viewer.js 79 KB

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