Viewer.js 79 KB

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