Viewer.js 101 KB

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