Viewer.js 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332
  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. "resizeNode": true,
  14. "paging" : "scroll",
  15. "perPageCount" : 50,
  16. "isload": "true",
  17. "export": false,
  18. "moduleEvents": ["queryLoad", "postLoad", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
  19. "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow"]
  20. // "actions": {
  21. // "lookup": {"uri": "/jaxrs/view/flag/{view}/query/{application}/execute", "method":"PUT"},
  22. // "getView": {"uri": "/jaxrs/view/flag/{view}/query/{application}"}
  23. //
  24. // },
  25. // "actionRoot": "x_query_assemble_surface"
  26. },
  27. initialize: function(container, json, options, app, parentMacro){
  28. //本类有三种事件,
  29. //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
  30. //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
  31. //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件
  32. this.setOptions(options);
  33. this.path = "../x_component_query_Query/$Viewer/";
  34. this.cssPath = "../x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
  35. this._loadCss();
  36. this.lp = MWF.xApplication.query.Query.LP;
  37. this.app = app;
  38. this.container = $(container);
  39. this.json = json;
  40. this.parentMacro = parentMacro;
  41. this.originalJson = Object.clone(json);
  42. this.viewJson = null;
  43. this.filterItems = [];
  44. this.searchStatus = "none"; //none, custom, default
  45. this.items = [];
  46. this.selectedItems = [];
  47. this.hideColumns = [];
  48. this.openColumns = [];
  49. this.gridJson = null;
  50. if (this.options.isload){
  51. this.init(function(){
  52. this.load();
  53. }.bind(this));
  54. }
  55. },
  56. loadView: function(){
  57. if (this.viewJson){
  58. this.reload();
  59. }else{
  60. this.init(function(){
  61. this.load();
  62. }.bind(this));
  63. }
  64. },
  65. init: function(callback){
  66. if (this.json.data){
  67. this.viewJson = JSON.decode(this.json.data);
  68. if (callback) callback();
  69. }else{
  70. this.getView(callback);
  71. }
  72. },
  73. load: function(){
  74. this.loadMacro( function () {
  75. this._loadModuleEvents();
  76. if (this.fireEvent("queryLoad")){
  77. this._loadUserInterface();
  78. //this._loadStyles();
  79. this._loadDomEvents();
  80. }
  81. }.bind(this))
  82. },
  83. _loadUserInterface : function(){
  84. this.loadLayout();
  85. this.createActionbarNode();
  86. this.createSearchNode();
  87. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  88. if (this.options.resizeNode){
  89. this.setContentHeightFun = this.setContentHeight.bind(this);
  90. this.container.addEvent("resize", this.setContentHeightFun);
  91. this.setContentHeightFun();
  92. }
  93. },
  94. loadLayout: function(){
  95. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  96. this.actionbarAreaNode = new Element("div.actionbarAreaNode", {"styles": this.css.actionbarAreaNode}).inject(this.node);
  97. //if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
  98. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
  99. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  100. // this.viewPageNode = new Element("div", {"styles": this.css.viewPageNode}).inject(this.node);
  101. this.viewPageAreaNode = new Element("div", {"styles": this.css.viewPageAreaNode}).inject(this.node);
  102. },
  103. loadMacro: function (callback) {
  104. MWF.require("MWF.xScript.Macro", function () {
  105. this.Macro = new MWF.Macro.ViewContext(this);
  106. if (callback) callback();
  107. }.bind(this));
  108. },
  109. createExportNode: function(){
  110. if (this.options.export){
  111. MWF.require("MWF.widget.Toolbar", function(){
  112. this.toolbar = new MWF.widget.Toolbar(this.actionbarAreaNode, {"style": "simple"}, this); //this.exportAreaNode
  113. var actionNode = new Element("div", {
  114. "id": "",
  115. "MWFnodetype": "MWFToolBarButton",
  116. "MWFButtonImage": this.path+""+this.options.style+"/icon/export.png",
  117. "title": this.lp.exportExcel,
  118. "MWFButtonAction": "exportView",
  119. "MWFButtonText": this.lp.exportExcel
  120. }).inject(this.actionbarAreaNode); //this.exportAreaNode
  121. this.toolbar.load();
  122. }.bind(this));
  123. //this.exportNode = new Element("button", {"text": this.lp.exportExcel}).inject(this.exportAreaNode);
  124. }
  125. },
  126. exportView: function(){
  127. var action = MWF.Actions.get("x_query_assemble_surface");
  128. var filterData = this.json.filter ? this.json.filter.clone() : [];
  129. if (this.filterItems.length){
  130. this.filterItems.each(function(filter){
  131. filterData.push(filter.data);
  132. }.bind(this));
  133. }
  134. action.exportViewWithQuery(this.json.viewName, this.json.application, {"filterList": filterData}, function(json){
  135. var uri = action.action.actions.getViewExcel.uri;
  136. uri = uri.replace("{flag}", json.data.id);
  137. uri = action.action.address+uri;
  138. var a = new Element("a", {"href": uri, "target":"_blank"});
  139. a.click();
  140. a.destroy();
  141. }.bind(this));
  142. },
  143. setContentHeight: function(){
  144. var size = this.node.getSize();
  145. var searchSize = this.searchAreaNode.getComputedSize();
  146. var h = size.y-searchSize.totalHeight;
  147. //if (this.exportAreaNode){
  148. // var exportSize = this.exportAreaNode.getComputedSize();
  149. // h = h-exportSize.totalHeight;
  150. //}
  151. if( this.actionbarAreaNode ){
  152. var exportSize = this.actionbarAreaNode.getComputedSize();
  153. h = h-exportSize.totalHeight;
  154. }
  155. var pageSize = this.viewPageAreaNode.getComputedSize();
  156. h = h-pageSize.totalHeight;
  157. this.viewAreaNode.setStyle("height", ""+h+"px");
  158. },
  159. createLoadding: function(){
  160. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  161. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  162. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  163. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  164. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  165. loadingTextNode.set("text", "loading...");
  166. },
  167. createActionbarNode : function(){
  168. this.actionbarAreaNode.empty();
  169. if( typeOf(this.json.showActionbar) === "boolean" && this.json.showActionbar !== true )return;
  170. if( typeOf( this.viewJson.actionbarHidden ) === "boolean" ){
  171. if( this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length )return;
  172. this.actionbar = new MWF.xApplication.query.Query.Viewer.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
  173. this.actionbar.load();
  174. }else{ //兼容以前的ExportNode
  175. this.createExportNode();
  176. }
  177. },
  178. createViewNode: function(data, callback){
  179. this.viewAreaNode.empty();
  180. this.selectedItems = [];
  181. var viewStyles = this.viewJson.viewStyles;
  182. this.contentAreaNode = new Element("div", {"styles":
  183. (viewStyles && viewStyles["container"]) ? viewStyles["container"] : this.css.contentAreaNode
  184. }).inject(this.viewAreaNode);
  185. this.viewTable = new Element("table", {
  186. "styles": this.css.viewTitleTableNode,
  187. "border": "0px",
  188. "cellPadding": "0",
  189. "cellSpacing": "0"
  190. }).inject(this.contentAreaNode);
  191. if( viewStyles ){
  192. if( viewStyles["tableProperties"] )this.viewTable.set(viewStyles["tableProperties"]);
  193. if( viewStyles["table"] )this.viewTable.setStyles(viewStyles["table"]);
  194. }
  195. this.createLoadding();
  196. var viewTitleCellNode = (viewStyles && viewStyles["titleTd"]) ? viewStyles["titleTd"] : this.css.viewTitleCellNode;
  197. if (this.json.isTitle!=="no"){
  198. this.viewTitleLine = new Element("tr", {
  199. "styles": (viewStyles && viewStyles["titleTr"]) ? viewStyles["titleTr"] : this.css.viewTitleLineNode
  200. }).inject(this.viewTable);
  201. //if (this.json.select==="single" || this.json.select==="multi") {
  202. this.selectTitleCell = new Element("td.selectTitleCell", {
  203. "styles": viewTitleCellNode
  204. }).inject(this.viewTitleLine);
  205. this.selectTitleCell.setStyle("width", "10px");
  206. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  207. //}
  208. if( this.isSelectTdHidden() ){
  209. this.selectTitleCell.hide();
  210. }
  211. //序号
  212. if (this.viewJson.isSequence==="yes"){
  213. this.sequenceTitleCell = new Element("td", {
  214. "styles": viewTitleCellNode
  215. }).inject(this.viewTitleLine);
  216. this.sequenceTitleCell.setStyle("width", "10px");
  217. if (this.json.titleStyles) this.sequenceTitleCell.setStyles(this.json.titleStyles);
  218. }
  219. this.entries = {};
  220. this.viewJson.selectList.each(function(column){
  221. this.entries[column.column] = column;
  222. if (!column.hideColumn){
  223. var viewCell = new Element("td", {
  224. "styles": viewTitleCellNode,
  225. "text": column.displayName
  226. }).inject(this.viewTitleLine);
  227. var size = MWF.getTextSize(column.displayName, viewTitleCellNode);
  228. viewCell.setStyle("min-width", ""+size.x+"px");
  229. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  230. if( typeOf(column.titleStyles) === "object" )viewCell.setStyles(column.titleStyles);
  231. if( typeOf(column.titleProperties) === "object" )viewCell.setProperties(column.titleProperties);
  232. if( column.events && column.events.loadTitle && column.events.loadTitle.code ){
  233. var code = column.events.loadTitle.code;
  234. this.Macro.fire( code, {"node" : viewCell, "json" : column, "data" : column.displayName, "view" : this});
  235. }
  236. }else{
  237. this.hideColumns.push(column.column);
  238. }
  239. if (column.allowOpen) this.openColumns.push(column.column);
  240. }.bind(this));
  241. this.lookup(data, callback);
  242. }else{
  243. this.viewJson.selectList.each(function(column){
  244. if (column.hideColumn) this.hideColumns.push(column.column);
  245. if (!column.allowOpen) this.openColumns.push(column.column);
  246. }.bind(this));
  247. this.lookup(data, callback);
  248. }
  249. },
  250. isSelectTdHidden :function(){
  251. if( !this.viewJson.firstTdHidden ){
  252. return false;
  253. }
  254. if( this.json.select === "single" || this.json.select === "multi" || this.json.defaultSelectedScript || this.viewJson.defaultSelectedScript ){
  255. return false;
  256. }
  257. if( this.viewJson.select === "single" || this.viewJson.select === "multi" ){
  258. return false;
  259. }
  260. if( this.options.select === "single" || this.options.select === "multi" ){
  261. return false;
  262. }
  263. if( this.viewJson.group && this.viewJson.group.column ){
  264. return false;
  265. }
  266. return true;
  267. },
  268. // _loadPageCountNode: function(){
  269. // this.viewPageContentNode.empty();
  270. //
  271. // var size = this.viewPageAreaNode.getSize();
  272. // var w1 = this.viewPageFirstNode.getSize().x*2;
  273. // var w2 = this.viewPageContentNode.getStyle("margin-left").toInt();
  274. // var w = size.x-w1-w2;
  275. //
  276. // var bw = this.css.viewPageButtonNode.width.toInt()+this.css.viewPageButtonNode["margin-right"].toInt();
  277. // var count = (w/bw).toInt()-2;
  278. // if (count>10) count = 10;
  279. // this.showPageCount = Math.min(count, this.pages);
  280. //
  281. // var tmp = this.showPageCount/2;
  282. // var n = tmp.toInt();
  283. // var left = this.currentPage-n;
  284. // if (left<=0) left = 1;
  285. // var right = this.showPageCount + left-1;
  286. // if (right>this.pages) right = this.pages;
  287. // left = right-this.showPageCount+1;
  288. // if (left<=1) left = 1;
  289. //
  290. // this.viewPagePrevNode = new Element("div", {"styles": this.css.viewPagePrevButtonNode}).inject(this.viewPageContentNode);
  291. // this.loadPageButtonEvent(this.viewPagePrevNode, "viewPagePrevButtonNode_over", "viewPagePrevButtonNode_up", "viewPagePrevButtonNode_down", function(){
  292. // if (this.currentPage>1) this.currentPage--;
  293. // this.loadCurrentPageData();
  294. // }.bind(this));
  295. //
  296. // for (i=left; i<=right; i++){
  297. // var node = new Element("div", {"styles": this.css.viewPageButtonNode, "text": i}).inject(this.viewPageContentNode);
  298. // if (i==this.currentPage){
  299. // node.setStyles(this.css.viewPageButtonNode_current);
  300. // }else{
  301. // this.loadPageButtonEvent(node, "viewPageButtonNode_over", "viewPageButtonNode_up", "viewPageButtonNode_down", function(e){
  302. // this.currentPage = e.target.get("text").toInt();
  303. // this.loadCurrentPageData();
  304. // }.bind(this));
  305. // }
  306. // }
  307. // this.viewPageNextNode = new Element("div", {"styles": this.css.viewPageNextButtonNode}).inject(this.viewPageContentNode);
  308. // this.loadPageButtonEvent(this.viewPageNextNode, "viewPageNextButtonNode_over", "viewPageNextButtonNode_up", "viewPageNextButtonNode_down", function(){
  309. // if (this.currentPage<=this.pages-1) this.currentPage++;
  310. // this.loadCurrentPageData();
  311. // }.bind(this));
  312. // },
  313. // loadPageButtonEvent: function(node, over, out, down, click){
  314. // node.addEvents({
  315. // "mouseover": function(){node.setStyles(this.css[over])}.bind(this),
  316. // "mouseout": function(){node.setStyles(this.css[out])}.bind(this),
  317. // "mousedown": function(){node.setStyles(this.css[down])}.bind(this),
  318. // "mouseup": function(){node.setStyles(this.css[out])}.bind(this),
  319. // "click": click
  320. // });
  321. // },
  322. // _loadPageNode: function(){
  323. // this.viewPageAreaNode.empty();
  324. // this.viewPageFirstNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.firstPage}).inject(this.viewPageAreaNode);
  325. // this.viewPageContentNode = new Element("div", {"styles": this.css.viewPageContentNode}).inject(this.viewPageAreaNode);
  326. // this.viewPageLastNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.lastPage}).inject(this.viewPageAreaNode);
  327. // this._loadPageCountNode();
  328. //
  329. // this.loadPageButtonEvent(this.viewPageFirstNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  330. // this.currentPage = 1;
  331. // this.loadCurrentPageData();
  332. // }.bind(this));
  333. // this.loadPageButtonEvent(this.viewPageLastNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  334. // this.currentPage = this.pages;
  335. // this.loadCurrentPageData();
  336. // }.bind(this));
  337. // },
  338. _loadPageNode : function(){
  339. this.viewPageAreaNode.empty();
  340. if( !this.paging ){
  341. var json;
  342. if( !this.viewJson.pagingList || !this.viewJson.pagingList.length ){
  343. json = {
  344. "firstPageText": this.lp.firstPage,
  345. "lastPageText": this.lp.lastPage
  346. };
  347. }else{
  348. json = this.viewJson.pagingList[0];
  349. }
  350. this.paging = new MWF.xApplication.query.Query.Viewer.Paging(this.viewPageAreaNode, json, this, {});
  351. this.paging.load();
  352. }else{
  353. this.paging.reload();
  354. }
  355. },
  356. _initPage: function(){
  357. this.count = this.bundleItems.length;
  358. var i = this.count/this.json.pageSize;
  359. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  360. this.currentPage = this.options.defaultPage || 1;
  361. this.options.defaultPage = null;
  362. },
  363. lookup: function(data, callback){
  364. this.getLookupAction(function(){
  365. if (this.json.application){
  366. var d = data || {};
  367. d.count = this.json.count;
  368. this.lookupAction.bundleView(this.json.id, d, function(json){
  369. this.bundleItems = json.data.valueList;
  370. this._initPage();
  371. if (this.bundleItems.length){
  372. if( this.noDataTextNode )this.noDataTextNode.destroy();
  373. this.loadCurrentPageData( function () {
  374. this.fireEvent("postLoad"); //用户配置的事件
  375. if(callback)callback(this);
  376. }.bind(this));
  377. }else{
  378. //this._loadPageNode();
  379. this.viewPageAreaNode.empty();
  380. if( this.viewJson.noDataText ){
  381. var noDataTextNodeStyle = this.css.noDataTextNode;
  382. if( this.viewJson.viewStyles && this.viewJson.viewStyles["noDataTextNode"] ){
  383. noDataTextNodeStyle = this.viewJson.viewStyles["noDataTextNode"];
  384. }
  385. this.noDataTextNode = new Element( "div", {
  386. "styles": noDataTextNodeStyle,
  387. "text" : this.viewJson.noDataText
  388. }).inject( this.contentAreaNode );
  389. }
  390. if (this.loadingAreaNode){
  391. this.loadingAreaNode.destroy();
  392. this.loadingAreaNode = null;
  393. }
  394. this.fireEvent("postLoad"); //用户配置的事件
  395. if(callback)callback(this);
  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, callback ){
  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}, callback);
  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. //默认选中
  1299. var defaultSelectedScript = this.view.json.defaultSelectedScript || this.view.viewJson.defaultSelectedScript;
  1300. if( !this.isSelected && defaultSelectedScript ){
  1301. // var flag = this.view.json.select || this.view.viewJson.select || "none";
  1302. // if ( flag ==="single" || flag==="multi"){
  1303. //
  1304. // }
  1305. var flag = this.view.Macro.exec( defaultSelectedScript,
  1306. {"node" : this.node, "data" : this.data, "view": this.view, "row" : this});
  1307. if( flag ){
  1308. if( flag === "multi" || flag === "single" ){
  1309. this.select( flag );
  1310. }else if( flag.toString() === "true" ){
  1311. var f = this.view.json.select || this.view.viewJson.select || "none";
  1312. if ( f ==="single" || f==="multi"){
  1313. this.select();
  1314. }
  1315. }
  1316. }
  1317. }
  1318. // Object.each(this.data.data, function(cell, k){
  1319. // if (this.view.hideColumns.indexOf(k)===-1){
  1320. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1321. // if (k!== this.view.viewJson.group.column){
  1322. // 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;
  1323. // td.set("text", v);
  1324. // }
  1325. // if (this.view.openColumns.indexOf(k)!==-1){
  1326. // this.setOpenWork(td)
  1327. // }
  1328. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1329. // }
  1330. // }.bind(this));
  1331. this.setEvent();
  1332. this.view.fireEvent("postLoadItemRow", [null, this]);
  1333. },
  1334. setOpenWork: function(td, column){
  1335. td.setStyle("cursor", "pointer");
  1336. if( column.clickCode ){
  1337. // if( !this.view.Macro ){
  1338. // MWF.require("MWF.xScript.Macro", function () {
  1339. // this.view.businessData = {};
  1340. // this.view.Macro = new MWF.Macro.PageContext(this.view);
  1341. // }.bind(this), false);
  1342. // }
  1343. td.addEvent("click", function( ev ){
  1344. var result = this.view.Macro.fire(column.clickCode, this, ev);
  1345. ev.stopPropagation();
  1346. return result;
  1347. }.bind(this));
  1348. }else{
  1349. if (this.view.json.type==="cms"){
  1350. td.addEvent("click", function(ev){
  1351. this.openCms(ev)
  1352. ev.stopPropagation();
  1353. }.bind(this));
  1354. }else{
  1355. td.addEvent("click", function(ev){
  1356. this.openWorkAndCompleted(ev)
  1357. ev.stopPropagation();
  1358. }.bind(this));
  1359. }
  1360. }
  1361. },
  1362. openCms: function(e){
  1363. var options = {"documentId": this.data.bundle};
  1364. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1365. layout.desktop.openApplication(e, "cms.Document", options);
  1366. },
  1367. openWorkAndCompleted: function(e){
  1368. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
  1369. var workCompletedCount = json.data.workCompletedList.length;
  1370. var workCount = json.data.workList.length;
  1371. var count = workCount+workCompletedCount;
  1372. if (count===1){
  1373. if (workCompletedCount) {
  1374. this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  1375. }else{
  1376. this.openWork(json.data.workList[0].id, e);
  1377. }
  1378. }else if (count>1){
  1379. var worksAreaNode = this.createWorksArea();
  1380. json.data.workCompletedList.each(function(work){
  1381. this.createWorkCompletedNode(work, worksAreaNode);
  1382. }.bind(this));
  1383. json.data.workList.each(function(work){
  1384. this.createWorkNode(work, worksAreaNode);
  1385. }.bind(this));
  1386. this.showWorksArea(worksAreaNode, e);
  1387. }else{
  1388. }
  1389. }.bind(this));
  1390. },
  1391. createWorkNode: function(work, worksAreaNode){
  1392. var worksAreaContentNode = worksAreaNode.getLast();
  1393. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1394. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1395. actionNode.store("workId", work.id);
  1396. actionNode.addEvent("click", function(e){
  1397. this.openWork(e.target.retrieve("workId"), e);
  1398. this.mask.hide();
  1399. worksAreaNode.destroy();
  1400. }.bind(this));
  1401. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1402. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1403. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1404. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1405. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  1406. var taskUsers = [];
  1407. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  1408. json.data.each(function(task){
  1409. taskUsers.push(MWF.name.cn(task.person));
  1410. }.bind(this));
  1411. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  1412. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  1413. }.bind(this));
  1414. },
  1415. createWorkCompletedNode: function(work, worksAreaNode){
  1416. var worksAreaContentNode = worksAreaNode.getLast();
  1417. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1418. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1419. actionNode.store("workId", work.id);
  1420. actionNode.addEvent("click", function(e){
  1421. this.mask.hide();
  1422. var id = e.target.retrieve("workId");
  1423. worksAreaNode.destroy();
  1424. this.openWorkCompleted(id, e);
  1425. }.bind(this));
  1426. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1427. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1428. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1429. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1430. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  1431. },
  1432. createWorksArea: function(){
  1433. var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
  1434. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  1435. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  1436. worksAreaTitleCloseNode.addEvent("click", function(e){
  1437. this.mask.hide();
  1438. e.target.getParent().getParent().destroy();
  1439. }.bind(this));
  1440. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  1441. return worksAreaNode;
  1442. },
  1443. showWorksArea: function(node, e){
  1444. MWF.require("MWF.widget.Mask", null, false);
  1445. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  1446. this.mask.loadNode(this.view.container);
  1447. node.inject(this.view.node);
  1448. this.setWorksAreaPosition(node, e.target);
  1449. },
  1450. setWorksAreaPosition: function(node, td){
  1451. var p = td.getPosition(this.view.container);
  1452. var containerS = this.view.container.getSize();
  1453. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  1454. var s = node.getSize();
  1455. var offX = p.x+s.x-containerS.x;
  1456. offX = (offX>0) ? offX+20 : 0;
  1457. var offY = p.y+s.y-containerS.y;
  1458. offY = (offY>0) ? offY+5 : 0;
  1459. node.position({
  1460. "relativeTo": td,
  1461. "position": "lefttop",
  1462. "edge": "lefttop",
  1463. "offset": {
  1464. "x": 0-offX,
  1465. "y": 0-offY
  1466. }
  1467. });
  1468. },
  1469. openWork: function(id, e){
  1470. var options = {"workId": id};
  1471. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1472. layout.desktop.openApplication(e, "process.Work", options);
  1473. },
  1474. openWorkCompleted: function(id, e){
  1475. var options = {"workCompletedId": id};
  1476. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1477. layout.desktop.openApplication(e, "process.Work", options);
  1478. },
  1479. setEvent: function(){
  1480. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1481. if ( flag ==="single" || flag==="multi"){
  1482. this.node.addEvents({
  1483. "mouseover": function(){
  1484. if (!this.isSelected){
  1485. var viewStyles = this.view.viewJson.viewStyles;
  1486. if( viewStyles ){
  1487. if( flag === "single" ){
  1488. this.selectTd.setStyles( viewStyles["radioNode"] );
  1489. }else{
  1490. this.selectTd.setStyles( viewStyles["checkboxNode"] );
  1491. }
  1492. }else{
  1493. var iconName = "checkbox";
  1494. if (flag==="single") iconName = "radiobox";
  1495. this.selectTd.setStyles({"background": "url("+"../x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  1496. }
  1497. }
  1498. }.bind(this),
  1499. "mouseout": function(){
  1500. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  1501. }.bind(this),
  1502. "click": function(){this.select();}.bind(this)
  1503. });
  1504. }
  1505. },
  1506. select: function( force ){
  1507. var flag = force || this.view.json.select || this.view.viewJson.select || "none";
  1508. if (this.isSelected){
  1509. if (flag==="single"){
  1510. this.unSelectedSingle();
  1511. }else{
  1512. this.unSelected();
  1513. }
  1514. }else{
  1515. if (flag==="single"){
  1516. this.selectedSingle();
  1517. }else{
  1518. this.selected();
  1519. }
  1520. }
  1521. this.view.fireEvent("select"); //options 传入的事件
  1522. },
  1523. selected: function(){
  1524. this.view.selectedItems.push(this);
  1525. var viewStyles = this.view.viewJson.viewStyles;
  1526. if( viewStyles ){
  1527. this.selectTd.setStyles( viewStyles["checkedCheckboxNode"] );
  1528. this.node.setStyles( viewStyles["contentSelectedTr"] );
  1529. }else{
  1530. this.selectTd.setStyles({"background": "url("+"../x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  1531. this.node.setStyles(this.css.viewContentTrNode_selected);
  1532. }
  1533. this.isSelected = true;
  1534. this.view.fireEvent("selectRow", [this]);
  1535. },
  1536. unSelected: function(){
  1537. this.view.selectedItems.erase(this);
  1538. this.selectTd.setStyles({"background": "transparent"});
  1539. var viewStyles = this.view.viewJson.viewStyles;
  1540. if( viewStyles ){
  1541. this.node.setStyles( viewStyles["contentTr"] );
  1542. }else{
  1543. this.node.setStyles(this.css.viewContentTrNode);
  1544. }
  1545. this.isSelected = false;
  1546. this.view.fireEvent("unselectRow", [this]);
  1547. },
  1548. selectedSingle: function(){
  1549. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  1550. this.view.selectedItems = [this];
  1551. this.view.currentSelectedItem = this;
  1552. var viewStyles = this.view.viewJson.viewStyles;
  1553. if( viewStyles ){
  1554. this.selectTd.setStyles( viewStyles["checkedRadioNode"] );
  1555. this.node.setStyles( viewStyles["contentSelectedTr"] );
  1556. }else {
  1557. this.selectTd.setStyles({"background": "url(" + "../x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
  1558. this.node.setStyles(this.css.viewContentTrNode_selected);
  1559. }
  1560. this.isSelected = true;
  1561. this.view.fireEvent("selectRow", [this]);
  1562. },
  1563. unSelectedSingle: function(){
  1564. this.view.selectedItems = [];
  1565. this.view.currentSelectedItem = null;
  1566. this.selectTd.setStyles({"background": "transparent"});
  1567. var viewStyles = this.view.viewJson.viewStyles;
  1568. if( viewStyles ){
  1569. this.node.setStyles( viewStyles["contentTr"] );
  1570. }else{
  1571. this.node.setStyles(this.css.viewContentTrNode);
  1572. }
  1573. this.isSelected = false;
  1574. this.view.fireEvent("unselectRow", [this]);
  1575. }
  1576. });
  1577. MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
  1578. initialize: function(view, data, i){
  1579. this.view = view;
  1580. this.data = data;
  1581. this.css = this.view.css;
  1582. this.items = [];
  1583. this.loadChild = false;
  1584. this.idx = i;
  1585. this.clazzType = "category";
  1586. this.load();
  1587. },
  1588. load: function(){
  1589. this.view.fireEvent("queryLoadCategoryRow", [null, this]);
  1590. var viewStyles = this.view.viewJson.viewStyles;
  1591. var viewContentCategoryTdNode = ( viewStyles && viewStyles["contentGroupTd"] ) ? viewStyles["contentGroupTd"] : this.css.viewContentCategoryTdNode;
  1592. this.node = new Element("tr", {
  1593. "styles": (viewStyles && viewStyles["contentTr"]) ? viewStyles["contentTr"] : this.css.viewContentTrNode
  1594. }).inject(this.view.viewTable);
  1595. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1596. this.selectTd = new Element("td", {"styles": viewContentCategoryTdNode}).inject(this.node);
  1597. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1598. // if( this.view.isSelectTdHidden() ){
  1599. // this.selectTd.hide();
  1600. // }
  1601. //}
  1602. this.categoryTd = new Element("td", {
  1603. "styles": viewContentCategoryTdNode,
  1604. "colspan": this.view.viewJson.selectList.length+1
  1605. }).inject(this.node);
  1606. this.groupColumn = null;
  1607. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  1608. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  1609. this.groupColumn = this.view.viewJson.selectList[c];
  1610. break;
  1611. }
  1612. }
  1613. if (this.groupColumn){
  1614. //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;
  1615. var text = this.data.group;
  1616. }else{
  1617. var text = this.data.group;
  1618. }
  1619. if( viewStyles && viewStyles["groupCollapseNode"] ){
  1620. this.expandNode = new Element("span", {
  1621. styles : viewStyles["groupCollapseNode"]
  1622. }).inject( this.categoryTd );
  1623. new Element("span", { text : text }).inject( this.categoryTd );
  1624. // this.categoryTd.set("text", text );
  1625. }else{
  1626. 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);
  1627. }
  1628. this.expanded = false;
  1629. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  1630. debugger;
  1631. if( this.groupColumn ){
  1632. if( typeOf(this.groupColumn.contentStyles) === "object" )this.categoryTd.setStyles(this.groupColumn.contentStyles);
  1633. if( typeOf(this.groupColumn.contentProperties) === "object" )this.categoryTd.setProperties(this.groupColumn.contentProperties);
  1634. }
  1635. this.setEvent();
  1636. var column = this.groupColumn;
  1637. var td = this.categoryTd;
  1638. Object.each( column.events || {}, function (e , key) {
  1639. if(e.code){
  1640. if( key === "loadContent" ){
  1641. this.view.Macro.fire( e.code,
  1642. {"node" : td, "json" : column, "data" : this.data.group, "view": this.view, "row" : this});
  1643. }else if( key !== "loadTitle" ){
  1644. td.addEvent(key, function(event){
  1645. return this.view.Macro.fire(
  1646. e.code,
  1647. {"node" : td, "json" : column, "data" : this.data.group, "view": this.view, "row" : this},
  1648. event
  1649. );
  1650. }.bind(this));
  1651. }
  1652. }
  1653. }.bind(this));
  1654. this.view.fireEvent("postLoadCategoryRow", [null, this]);
  1655. },
  1656. setEvent: function(){
  1657. //if (this.selectTd){
  1658. this.node.addEvents({
  1659. "click": function(){this.expandOrCollapse();}.bind(this)
  1660. });
  1661. //}
  1662. },
  1663. expandOrCollapse: function(){
  1664. // var t = this.node.getElement("span").get("html");
  1665. // if (t.indexOf("expand.png")===-1){
  1666. // this.collapse();
  1667. // }else{
  1668. // this.expand();
  1669. // }
  1670. if( this.expanded ){
  1671. this.collapse();
  1672. }else{
  1673. this.expand();
  1674. }
  1675. },
  1676. collapse: function(){
  1677. this.items.each(function(item){
  1678. item.node.setStyle("display", "none");
  1679. }.bind(this));
  1680. if( this.expandNode ){
  1681. this.expandNode.setStyles( this.view.viewJson.viewStyles["groupCollapseNode"] )
  1682. }else{
  1683. this.node.getElement("span").set("html", "<img src='../x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  1684. }
  1685. this.expanded = false;
  1686. },
  1687. expand: function(){
  1688. this.items.each(function(item){
  1689. item.node.setStyle("display", "table-row");
  1690. }.bind(this));
  1691. if( this.expandNode ){
  1692. this.expandNode.setStyles( this.view.viewJson.viewStyles["groupExpandNode"] )
  1693. }else{
  1694. this.node.getElement("span").set("html", "<img src='../x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  1695. }
  1696. this.expanded = true;
  1697. if (!this.loadChild){
  1698. //window.setTimeout(function(){
  1699. this.data.list.each(function(line, i){
  1700. var s = this.idx+i;
  1701. this.lastItem = new MWF.xApplication.query.Query.Viewer.Item(this.view, line, (this.lastItem || this), s);
  1702. this.items.push(this.lastItem);
  1703. }.bind(this));
  1704. this.loadChild = true;
  1705. //}.bind(this), 10);
  1706. }
  1707. }
  1708. });
  1709. MWF.xApplication.query.Query.Viewer.Filter = new Class({
  1710. initialize: function(viewer, data, node){
  1711. this.viewer = viewer;
  1712. this.data = data;
  1713. this.css = this.viewer.css;
  1714. this.content = node;
  1715. this.load();
  1716. },
  1717. load: function(){
  1718. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  1719. if (this.viewer.filterItems.length){
  1720. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  1721. this.logicSelectNode = new Element("div", {
  1722. "styles": this.css.viewSearchFilterSelectNode,
  1723. "text": this.viewer.lp.and,
  1724. "value": "and"
  1725. }).inject(this.logicNode);
  1726. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  1727. this.logicNode.addEvents({
  1728. "click": function(){
  1729. var v = this.logicSelectNode.get("value");
  1730. if (v==="and"){
  1731. this.logicSelectButtonNode.setStyle("float", "left");
  1732. this.logicSelectNode.setStyle("float", "right");
  1733. this.logicSelectNode.set({
  1734. "text": this.viewer.lp.or,
  1735. "value": "or"
  1736. });
  1737. this.data.logic = "or";
  1738. }else{
  1739. this.logicSelectButtonNode.setStyle("float", "right");
  1740. this.logicSelectNode.setStyle("float", "left");
  1741. this.logicSelectNode.set({
  1742. "text": this.viewer.lp.and,
  1743. "value": "and"
  1744. });
  1745. this.data.logic = "and";
  1746. }
  1747. this.viewer.searchCustomView();
  1748. }.bind(this)
  1749. });
  1750. }
  1751. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  1752. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  1753. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  1754. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  1755. this.node.addEvents({
  1756. "mouseover": function(){
  1757. this.node.setStyles(this.css.viewSearchFilterNode_over);
  1758. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  1759. }.bind(this),
  1760. "mouseout": function(){
  1761. this.node.setStyles(this.css.viewSearchFilterNode);
  1762. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  1763. }.bind(this)
  1764. });
  1765. this.deleteNode.addEvent("click", function(){
  1766. this.viewer.searchViewRemoveFilter(this);
  1767. }.bind(this));
  1768. },
  1769. destroy: function(){
  1770. this.node.destroy();
  1771. MWF.release(this);
  1772. }
  1773. });
  1774. MWF.xApplication.query.Query.Viewer.Actionbar = new Class({
  1775. Implements: [Events],
  1776. options: {
  1777. "style" : "default",
  1778. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
  1779. },
  1780. initialize: function(node, json, form, options){
  1781. this.node = $(node);
  1782. this.node.store("module", this);
  1783. this.json = json;
  1784. this.form = form;
  1785. this.view = form;
  1786. },
  1787. hide: function(){
  1788. var dsp = this.node.getStyle("display");
  1789. if (dsp!=="none") this.node.store("mwf_display", dsp);
  1790. this.node.setStyle("display", "none");
  1791. },
  1792. show: function(){
  1793. var dsp = this.node.retrieve("mwf_display", dsp);
  1794. this.node.setStyle("display", dsp);
  1795. },
  1796. load: function(){
  1797. this._loadModuleEvents();
  1798. if (this.fireEvent("queryLoad")){
  1799. //this._queryLoaded();
  1800. this._loadUserInterface();
  1801. this._loadStyles();
  1802. this._loadDomEvents();
  1803. //this._loadEvents();
  1804. //this._afterLoaded();
  1805. this.fireEvent("postLoad");
  1806. this.fireEvent("load");
  1807. }
  1808. },
  1809. _loadStyles: function(){
  1810. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1811. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  1812. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1813. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1814. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  1815. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1816. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1817. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1818. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1819. }
  1820. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1821. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1822. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1823. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1824. }
  1825. if (value.indexOf("/x_cms_assemble_control")!==-1){
  1826. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1827. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  1828. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1829. }
  1830. }
  1831. this.node.setStyle(key, value);
  1832. }.bind(this));
  1833. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  1834. // var host = MWF.Actions.getHost(root);
  1835. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  1836. // }
  1837. //if (this.json.styles) this.node.setStyles(this.json.styles);
  1838. },
  1839. _loadModuleEvents : function(){
  1840. Object.each(this.json.events, function(e, key){
  1841. if (e.code){
  1842. if (this.options.moduleEvents.indexOf(key)!==-1){
  1843. this.addEvent(key, function(event){
  1844. return this.form.Macro.fire(e.code, this, event);
  1845. }.bind(this));
  1846. }
  1847. }
  1848. }.bind(this));
  1849. },
  1850. _loadDomEvents: function(){
  1851. Object.each(this.json.events, function(e, key){
  1852. if (e.code){
  1853. if (this.options.moduleEvents.indexOf(key)===-1){
  1854. this.node.addEvent(key, function(event){
  1855. return this.form.Macro.fire(e.code, this, event);
  1856. }.bind(this));
  1857. }
  1858. }
  1859. }.bind(this));
  1860. },
  1861. _loadEvents: function(){
  1862. Object.each(this.json.events, function(e, key){
  1863. if (e.code){
  1864. if (this.options.moduleEvents.indexOf(key)!==-1){
  1865. this.addEvent(key, function(event){
  1866. return this.form.Macro.fire(e.code, this, event);
  1867. }.bind(this));
  1868. }else{
  1869. this.node.addEvent(key, function(event){
  1870. return this.form.Macro.fire(e.code, this, event);
  1871. }.bind(this));
  1872. }
  1873. }
  1874. }.bind(this));
  1875. },
  1876. addModuleEvent: function(key, fun){
  1877. if (this.options.moduleEvents.indexOf(key)!==-1){
  1878. this.addEvent(key, function(event){
  1879. return (fun) ? fun(this, event) : null;
  1880. }.bind(this));
  1881. }else{
  1882. this.node.addEvent(key, function(event){
  1883. return (fun) ? fun(this, event) : null;
  1884. }.bind(this));
  1885. }
  1886. },
  1887. _loadUserInterface: function(){
  1888. // if (this.form.json.mode == "Mobile"){
  1889. // this.node.empty();
  1890. // }else if (COMMON.Browser.Platform.isMobile){
  1891. // this.node.empty();
  1892. // }else{
  1893. this.toolbarNode = this.node.getFirst("div");
  1894. if( !this.toolbarNode ){
  1895. this.toolbarNode = new Element("div").inject( this.node );
  1896. }
  1897. this.toolbarNode.empty();
  1898. MWF.require("MWF.widget.Toolbar", function(){
  1899. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  1900. "style": this.json.style,
  1901. "onPostLoad" : function(){
  1902. this.fireEvent("afterLoad");
  1903. }.bind(this)
  1904. }, this);
  1905. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  1906. //alert(this.readonly)
  1907. if (this.json.hideSystemTools){
  1908. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1909. this.toolbarWidget.load();
  1910. }else{
  1911. if (this.json.defaultTools){
  1912. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  1913. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1914. this.toolbarWidget.load();
  1915. }else{
  1916. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  1917. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  1918. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1919. this.toolbarWidget.load();
  1920. }.bind(this), null);
  1921. }
  1922. }
  1923. }.bind(this));
  1924. // }
  1925. },
  1926. setCustomToolbars: function(tools, node){
  1927. var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  1928. var iconPath = "";
  1929. if( this.json.customIconStyle ){
  1930. iconPath = this.json.customIconStyle+"/";
  1931. }
  1932. tools.each(function(tool){
  1933. var flag = true;
  1934. if (this.readonly){
  1935. flag = tool.readShow;
  1936. }else{
  1937. flag = tool.editShow;
  1938. }
  1939. if (flag){
  1940. flag = true;
  1941. // if (tool.control){
  1942. // flag = this.form.businessData.control[tool.control]
  1943. // }
  1944. if (tool.condition){
  1945. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1946. flag = !hideFlag;
  1947. }
  1948. if (flag){
  1949. var actionNode = new Element("div", {
  1950. "id": tool.id,
  1951. "MWFnodetype": tool.type,
  1952. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  1953. "title": tool.title,
  1954. "MWFButtonAction": "runCustomAction",
  1955. "MWFButtonText": tool.text
  1956. }).inject(node);
  1957. if( this.json.customIconOverStyle ){
  1958. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  1959. }
  1960. if( tool.properties ){
  1961. actionNode.set(tool.properties);
  1962. }
  1963. if (tool.actionScript){
  1964. actionNode.store("script", tool.actionScript);
  1965. }
  1966. if (tool.sub){
  1967. var subNode = node.getLast();
  1968. this.setCustomToolbars(tool.sub, subNode);
  1969. }
  1970. }
  1971. }
  1972. }.bind(this));
  1973. },
  1974. setToolbarItem: function(tool, node, readonly, noCondition){
  1975. //var path = "../x_component_process_FormDesigner/Module/Actionbar/";
  1976. var path = "../x_component_query_ViewDesigner/$View/";
  1977. var flag = true;
  1978. // if (tool.control){
  1979. // flag = this.form.businessData.control[tool.control]
  1980. // }
  1981. if (!noCondition) if (tool.condition){
  1982. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1983. flag = flag && (!hideFlag);
  1984. }
  1985. if (readonly) if (!tool.read) flag = false;
  1986. if (flag){
  1987. var actionNode = new Element("div", {
  1988. "id": tool.id,
  1989. "MWFnodetype": tool.type,
  1990. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  1991. //"MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  1992. "MWFButtonImage": path+this.options.style+"/actionbar/"+ ( this.json.iconStyle || "default" ) +"/"+tool.img,
  1993. "title": tool.title,
  1994. "MWFButtonAction": tool.action,
  1995. "MWFButtonText": tool.text
  1996. }).inject(node);
  1997. if( this.json.iconOverStyle ){
  1998. actionNode.set("MWFButtonImageOver" , path+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
  1999. //actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  2000. }
  2001. if( tool.properties ){
  2002. actionNode.set(tool.properties);
  2003. }
  2004. if (tool.sub){
  2005. var subNode = node.getLast();
  2006. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  2007. }
  2008. }
  2009. },
  2010. setToolbars: function(tools, node, readonly, noCondition){
  2011. tools.each(function(tool){
  2012. this.setToolbarItem(tool, node, readonly, noCondition);
  2013. }.bind(this));
  2014. },
  2015. runCustomAction: function(bt){
  2016. var script = bt.node.retrieve("script");
  2017. this.form.Macro.exec(script, this);
  2018. },
  2019. exportView : function(){
  2020. this.form.exportView();
  2021. },
  2022. deleteWork: function(){
  2023. this.form.deleteWork();
  2024. }
  2025. });
  2026. MWF.xApplication.query.Query.Viewer.Paging = new Class({
  2027. Implements: [Events],
  2028. options: {
  2029. "style" : "default",
  2030. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad","jump"]
  2031. },
  2032. initialize: function(node, json, form, options){
  2033. this.node = $(node);
  2034. this.node.store("module", this);
  2035. this.json = json;
  2036. this.form = form;
  2037. this.view = form;
  2038. },
  2039. hide: function(){
  2040. var dsp = this.node.getStyle("display");
  2041. if (dsp!=="none") this.node.store("mwf_display", dsp);
  2042. this.node.setStyle("display", "none");
  2043. },
  2044. show: function(){
  2045. var dsp = this.node.retrieve("mwf_display", dsp);
  2046. this.node.setStyle("display", dsp);
  2047. },
  2048. load: function(){
  2049. this._loadModuleEvents();
  2050. if (this.fireEvent("queryLoad")){
  2051. //this._queryLoaded();
  2052. this._loadUserInterface();
  2053. this._loadStyles();
  2054. this._loadDomEvents();
  2055. //this._loadEvents();
  2056. //this._afterLoaded();
  2057. this.fireEvent("postLoad");
  2058. }
  2059. },
  2060. _loadStyles: function(){
  2061. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  2062. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  2063. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  2064. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  2065. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  2066. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  2067. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  2068. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  2069. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  2070. }
  2071. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  2072. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  2073. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  2074. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  2075. }
  2076. if (value.indexOf("/x_cms_assemble_control")!==-1){
  2077. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  2078. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  2079. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  2080. }
  2081. }
  2082. this.node.setStyle(key, value);
  2083. }.bind(this));
  2084. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  2085. // var host = MWF.Actions.getHost(root);
  2086. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  2087. // }
  2088. //if (this.json.styles) this.node.setStyles(this.json.styles);
  2089. },
  2090. _loadModuleEvents : function(){
  2091. Object.each(this.json.events, function(e, key){
  2092. if (e.code){
  2093. if (this.options.moduleEvents.indexOf(key)!==-1){
  2094. this.addEvent(key, function(event){
  2095. return this.form.Macro.fire(e.code, this, event);
  2096. }.bind(this));
  2097. }
  2098. }
  2099. }.bind(this));
  2100. },
  2101. _loadDomEvents: function(){
  2102. Object.each(this.json.events, function(e, key){
  2103. if (e.code){
  2104. if (this.options.moduleEvents.indexOf(key)===-1){
  2105. this.node.addEvent(key, function(event){
  2106. return this.form.Macro.fire(e.code, this, event);
  2107. }.bind(this));
  2108. }
  2109. }
  2110. }.bind(this));
  2111. },
  2112. _loadEvents: function(){
  2113. Object.each(this.json.events, function(e, key){
  2114. if (e.code){
  2115. if (this.options.moduleEvents.indexOf(key)!==-1){
  2116. this.addEvent(key, function(event){
  2117. return this.form.Macro.fire(e.code, this, event);
  2118. }.bind(this));
  2119. }else{
  2120. this.node.addEvent(key, function(event){
  2121. return this.form.Macro.fire(e.code, this, event);
  2122. }.bind(this));
  2123. }
  2124. }
  2125. }.bind(this));
  2126. },
  2127. addModuleEvent: function(key, fun){
  2128. if (this.options.moduleEvents.indexOf(key)!==-1){
  2129. this.addEvent(key, function(event){
  2130. return (fun) ? fun(this, event) : null;
  2131. }.bind(this));
  2132. }else{
  2133. this.node.addEvent(key, function(event){
  2134. return (fun) ? fun(this, event) : null;
  2135. }.bind(this));
  2136. }
  2137. },
  2138. _loadUserInterface: function(){
  2139. // if (this.form.json.mode == "Mobile"){
  2140. // this.node.empty();
  2141. // }else if (COMMON.Browser.Platform.isMobile){
  2142. // this.node.empty();
  2143. // }else{
  2144. this.loadPaging( true )
  2145. },
  2146. reload : function(){
  2147. this.loadPaging( false )
  2148. },
  2149. loadPaging : function( firstLoading ){
  2150. // this.pagingNode = this.node.getFirst("div");
  2151. // if( !this.pagingNode ){
  2152. // this.pagingNode = new Element("div").inject( this.node );
  2153. // }
  2154. // this.pagingNode.empty();
  2155. this.node.empty();
  2156. this.paging = new o2.widget.Paging(this.node, {
  2157. //style : this.options.skin && this.options.skin.pagingBar ? this.options.skin.pagingBar : "default",
  2158. countPerPage: this.view.json.pageSize || this.view.options.perPageCount,
  2159. visiblePages: layout.mobile?5:(this.json.visiblePages ? this.json.visiblePages.toInt() : 9),
  2160. currentPage: this.view.currentPage,
  2161. itemSize: this.view.count,
  2162. pageSize: this.view.pages,
  2163. hasNextPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  2164. hasPrevPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  2165. hasTruningBar: typeOf( this.json.hasTruningBar ) === "boolean" ? this.json.hasTruningBar : true,
  2166. hasBatchTuring: typeOf( this.json.hasBatchTuring ) === "boolean" ? this.json.hasBatchTuring : true,
  2167. hasFirstPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : (layout.mobile?false:true),
  2168. hasLastPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : (layout.mobile?false:true),
  2169. hasJumper: typeOf( this.json.hasPageJumper ) === "boolean" ? this.json.hasPageJumper : (layout.mobile?false:true),
  2170. hiddenWithDisable: false,
  2171. hiddenWithNoItem: true,
  2172. text: {
  2173. prePage: this.json.prePageText,
  2174. nextPage: this.json.nextPageText,
  2175. firstPage: this.json.firstPageText,
  2176. lastPage: this.json.lastPageText
  2177. },
  2178. onJumpingPage : function( pageNum, itemNum ){
  2179. this.view.currentPage = pageNum;
  2180. this.fireEvent("jump");
  2181. this.view.loadCurrentPageData( null, false );
  2182. }.bind(this),
  2183. onPostLoad : function () {
  2184. if( firstLoading ){
  2185. if(this.view.setContentHeightFun)this.view.setContentHeightFun();
  2186. this.fireEvent("load");
  2187. }
  2188. this.fireEvent("afterLoad");
  2189. }.bind(this)
  2190. }, this.json.pagingStyles || {});
  2191. this.paging.load();
  2192. }
  2193. });