Viewer.js 75 KB

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