Viewer.js 78 KB

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