Viewer.js 78 KB

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