/*******************************导入包开始**************************************/ $import("mx.containers.Accordion"); $import("mx.containers.Panel"); $import("mx.containers.HSplit"); $import("mx.containers.VSplit"); $import("mx.containers.Container"); $import("mx.containers.TabControl"); $import("mx.containers.TabPage"); $import("mx.controls.ToolBar"); $import("mx.datacontainers.FormEntityContainer"); $import("mx.datacontrols.DataForm"); $import("mx.datacontainers.GridEntityContainer"); $import("mx.datacontrols.DataGridSearchBox"); $import("mx.datacontrols.DataGrid"); $import("mx.datacontrols.ComplexGrid"); $import("mx.datacontrols.DataTree"); $import("mx.datacontainers.TreeEntityContainer"); /*******************************布局控件上下分割HSplit开始**************************************/ var HSplit1 = null; var HSplit1Area0 = null; var HSplit1Area1 = null; _initHSplit1(); _initHSplit1Area0(); _initHSplit1Area1(); function _initHSplit1(){ HSplit1 = new mx.containers.HSplit({ id:"HSplit1", rows:"50%,50%" }); me.addControl(HSplit1); } function _initHSplit1Area0(){ HSplit1Area0 = new mx.containers.Container({ id:"HSplit1Area0" }); HSplit1.addControl(HSplit1Area0, 0); } function _initHSplit1Area1(){ HSplit1Area1 = new mx.containers.Container({ id:"HSplit1Area1" }); HSplit1.addControl(HSplit1Area1, 1); } /*******************************布局控件左右分割VSplit开始**************************************/ var VSplit1 = null; var VSplit1Area0 = null; var VSplit1Area1 = null; _initVSplit1(); _initVSplit1Area0(); _initVSplit1Area1(); function _initVSplit1(){ VSplit1 = new mx.containers.VSplit({ id:"VSplit1", cols:"20%,80%" }); me.addControl(VSplit1); } function _initVSplit1Area0(){ VSplit1Area0 = new mx.containers.Container({ id:"VSplit1Area0" }); VSplit1.addControl(VSplit1Area0, 0); } function _initVSplit1Area1(){ VSplit1Area1 = new mx.containers.Container({ id:"VSplit1Area1" }); VSplit1.addControl(VSplit1Area1, 1); } /*******************************布局控件手风琴Accordion开始**************************************/ var Accordion1 = null; var Panel1 = null; var Panel2 = null; _initAccordion1(); _initPanel1(); _initPanel2(); function _initAccordion1(){ Accordion1 = new mx.containers.Accordion({ id:"Accordion1" }); me.addControl(Accordion1); } function _initPanel1(){ Panel1 = new mx.containers.Panel({ id:"Panel1", border:"0", title:"Panel" }); Accordion1.appendPanel(Panel1); } function _initPanel2(){ Panel2 = new mx.containers.Panel({ id:"Panel2", border:"0", title:"Panel" }); Accordion1.appendPanel(Panel2); } /*******************************布局控件选项卡TabControl开始**************************************/ var TabControl = null; var TabPage1 = null; _initTabControl(); _initTabPage1(); function _initTabControl(){ TabControl = new mx.containers.TabControl({ id:"TabControl", width:"100%" }); VSplit1Area1.addControl(TabControl); } function _initTabPage1(){ TabPage1 = new mx.containers.TabPage({ id:"TabPage1", autoInit:true, width:"100%", text:"欢迎", name:"TabPage1" }); TabControl.appendPage(TabPage1); } me.getTabControl = function(){ return TabControl; } /*******************************动态添加选项卡TabControl开始**************************************/ me._tree_onclick=function(e){ //create new tab page when note has no children if(!e.node.hasChildren){ var nodeId = e.node.id; var nodeName = e.node.text; var pages = me.view.getTabControl().pages; if(!isContainPageById(pages, nodeId)){ var nodePage = mx.containers.TabPage({ id:nodeId, alias:nodeId, name:nodeId, width:"100%", closable:true, text:nodeName }); me.view.getTabControl().appendPage(nodePage); } me.view.getTabControl().pages[nodeId].show(); me.view.getTabControl().selectPage(me.view.getTabControl().pages[nodeId]); //add weblet to tab page if(me.view.getTabControl().pages[nodeId].controls.length < 1){ var container = new mx.containers.Container(); var webletContainer = new mx.weblets.WebletContainer({ $e:container.$e, webletID: nodeId }); me.view.getTabControl().pages[nodeId].addControl(container); } } } function isContainPageById(pages, pageId){ var isContain = false; var pages = me.view.getTabControl().pages; if(pages.length > 0){ for(var i = 0; i < pages.length; i++){ if(pages[i].id == pageId){ isContain = true; break; } } } return isContain; } /*******************************数据控件DataForm开始**************************************/ var _form = null; _initDataForm(); function _initDataForm() { var restUrl = "~/rest/deployapp/"; /* 初始化 EntityContainer */ var formEntityContainer = new mx.datacontainers.FormEntityContainer({ baseUrl : appinfo.mappath(restUrl), iscID : "-1", // iscID 是数据元素的统一权限功能编码。默认值为 "-1" ,表示不应用权限设置。 primaryKey: "appId" }); _form = new mx.datacontrols.DataForm({ alias:"appinfoDetailViewDataForm", displayPrimaryKey: false, fields: [ { name: "appId", caption: "应用ID", editorType: "TextEditor", visible:false}, { name: "appName", caption: "应用名称", editorType: "TextEditor"}, { name: "dispIdx", caption: "部署顺序", editorType: "TextEditor"}, { name: "unitId", caption: "部署单元ID", editorType: "TextEditor"} ], entityContainer: formEntityContainer }); me.addControl(_form); } me.getForm = function(){ return _form; } /*******************************数据控件DataGrid开始**************************************/ var _dataGrid = null; _initDataGrid(); function _initDataGrid() { var restUrl = "~/rest/deployapp/"; /* 初始化 EntityContainer */ var gridEntityContainer = new mx.datacontainers.GridEntityContainer({ baseUrl : appinfo.mappath(restUrl), iscID : "-1", // iscID 是数据元素的统一权限功能编码。默认值为 "-1" ,表示不应用权限设置。 primaryKey: "appId" }); /* 初始化 DataGrid */ _dataGrid = new mx.datacontrols.ComplexGrid({ // 构造查询属性。 alias: "appinfoMainViewDataGrid", searchBox: new mx.datacontrols.DataGridSearchBox({ fields: [ ] }), columns:[ { name: "appId", caption: "应用ID" , editorType: "TextEditor" }, { name: "appName", caption: "应用名称" , editorType: "TextEditor" }, { name: "dispIdx", caption: "部署顺序" , editorType: "TextEditor" }, { name: "unitId", caption: "部署单元ID" , editorType: "TextEditor", visible:false } ], // 构造列排序条件,如果有多列,则以逗号分隔。例sorter: "school ASC, class DESC" displayCheckBox: true, displayPrimaryKey:false,//列表是否显示主键 allowEditing: false, //列表默认不可编辑 pageSize : 20, entityContainer: gridEntityContainer, onload: me.controller._dataGrid_onload, onitemclick: me.controller._dataGrid_onitemclick, create: me.controller._btnNew_onclick, remove: me.controller._btnDelete_onclick }); //重置toolBar按钮项 _resetToolBarItems(); VSplit1Area1.addControl(_dataGrid); } /** * 重置按钮项 */ function _resetToolBarItems(){ _dataGrid.toolBar.removeByName("new"); //去除保存按钮 _dataGrid.toolBar.removeByIndex(1); _dataGrid.toolBar.removeByName("save"); /*//插入编辑按钮 _dataGrid.toolBar.insertItem(2,"-",true); _dataGrid.toolBar.insertItem(3,{ name: "edit", text: mx.msg("EDIT"), toolTip: mx.msg("EDIT"), imageKey : "edit", onclick: me.controller._btnEdit_onclick},true);*/ } me.getDataGrid = function(){ return _dataGrid; } /*******************************多表头GroupHeaderGrid开始**************************************/ //////////////view中的代码 var SumDataGrid = null; _initSumDataGrid(); function _initSumDataGrid() { //var restUrl = "~/rest/sgdep/"; /* 初始化 EntityContainer */ var gridEntityContainer = new mx.datacontainers.GridEntityContainer({ type:"local", //baseUrl : provincesum.mappath(restUrl), iscID : "-1", // iscID 是数据元素的统一权限功能编码。默认值为 "-1" ,表示不应用权限设置。 primaryKey: "compId" }); SumDataGrid = new mx.datacontrols.GroupHeaderGrid({ columns: [ { name:"EVAL_NAME", caption:"评价项目名称", }, { name:"EVAL_BASE", caption:"基准分", }, { name:"PAR_PARENT", caption:"华北地区", columns:[ { name:"BJ_SUM_MARK", caption:"北京公司" }, { name:"TJ_SUM_MARK", caption:"天津公司" } ] }, { name:"PAR_PARENT", caption:"华东地区", columns:[ { name:"JS_SUM_MARK", caption:"江苏省公司" }, { name:"ZJ_SUM_MARK", caption:"浙江省公司" } ] } ], pageSize: 20, entityContainer: gridEntityContainer }); //SumDataGrid.load(); me.addControl(SumDataGrid); } me.getSumDataGrid = function(){ return SumDataGrid; } //////////////view controller中的代码 me._onactivate = function(e) { me.load_provinceSum(); }; me.load_provinceSum = function() { var restClient = new mx.rpc.RESTClient(); var p_context = restClient.get( provincesum.mappath("~/rest/provincesum/"), me.load_provinceSum_complete ); }; me.load_provinceSum_complete = function(p_data) { if(p_data && p_data.successful) { me.view.getSumDataGrid().entityContainer.data = p_data.resultValue.items; me.view.getSumDataGrid().load(); } } /*******************************数据控件DataTree开始**************************************/ var _treeView = null; _initTreeView(); function _initTreeView() { _treeView = new mx.datacontrols.DataTree({ baseUrl: leave.mappath("~/rest/examdep/tree"), displayCheckBox: true, // 是否需要在树中显示选中框 onnodeclick: me.controller._tree_onclick, onselectionchanged: me.controller._tree_selectionchanged }); HSplitLeftArea1.addControl(_treeView); _initContextMenu(); } function _initContextMenu() { _treeView.nodeMenu = new mx.controls.ContextMenu({ items: [ { name: "refresh", text: "刷新" } // 菜单项可以嵌套,表示子菜单 ], // 菜单项集合 onitemclick: me.controller._contextMenuItem_click }); } me.getTreeView = function(){ return _treeView; } /*******************************弹出表单开始**************************************/ /////////view中代码 var _detailWin = null; _initDetailWindow(); /** * 初始化表单视图窗口对象 */ function _initDetailWindow(){ _detailWin = appinfo.context.windowManager.create({ reusable: true,//是否复用 width:640, height:480, title:"表单维护" }); } /** * 获取表单视图窗口对象 */ me.getDetailWindow = function(){ return _detailWin; } /////////view controller中代码 var _detailView = null; /** * 获取表单视图对象 */ me._getDetailFromView = function(){ if (_detailView == null) { var mvc = new appinfo.views.DetailViewController(); _detailView = mvc.getView(); _detailView.getForm().entityContainer.off("saved", me._refreshDataGrid); _detailView.getForm().entityContainer.on("saved", me._refreshDataGrid); } return _detailView; } /** * 新增 */ me._btnNew_onclick = function() { // TODO: 此处新增的数据需要将服务端返回的 id 值设置到 GridItem 上。 var _detailView = me._getDetailFromView(); //设置对象id _detailView.objID = null; _showDetailFormView(_detailView,"表单填写"); }; /** * 显示表单视图 * @param p_view : 需要显示的视图对象 * @param p_title : 对话框的标题 */ function _showDetailFormView(p_view,p_title){ var win = me.view.getDetailWindow(); if(typeof p_view != "undefined"){ p_view.load(); //设置显示视图、标题信息 win.setPosition("fixed"); win.setView(p_view); win.setTitle(p_title ? p_title : win.title); } win.showDialog(); } /*******************************JS处理BPM开始**************************************/ requires:["bpm/bpmintegrate"], onload: function(e) { $import("bpmintegrate.utils.BPMClient"); }, /** * 调用js流程发起 */ me._btnStartJS_onclick = function (){ var _dataGrid = me.view.getDataGrid() if (_dataGrid.getCheckedIDs().length == 0) { mx.indicate("info", "请勾选一条待编辑记录。"); return; } // 多选框勾选记录,判断是否选择多条 if (_dataGrid.getCheckedIDs().length > 1) { mx.indicate("info", "选定的记录条数不能超过一条。"); return; } // 判断已勾选记录的流程状态,只允许没有发起流程的状态 var lczt = _dataGrid.getCheckedItems()[0].getValue("lczt"); if (lczt == "0" || lczt == null|| lczt == "" ||lczt == "null") { // 发起流程,参数为勾选记录的ID var bpmclient = new bpmintegrate.utils.BPMClient();//创建js代理对象 var params = "{\"BUSINESSID\" : \"" + _dataGrid.getCheckedIDs()[0] + "\"}";//业务主键 /** * 创建流程实例,可以选择是否立即启动,可带参数 * * <p> * 注意事项: * <ul> * <li>如果第一、二个参数为空,则抛出异常 * <li>如果第一参数对应的流程定义找不到发布版本,则抛异常 * </ul> * * @param processDefName 流程定义名称 * @param processInstName 流程实例名称 * @param processInstDesc 流程实例描述 * @param isStart 是否启动流程实例 * *@param finishFirst 是否完成第一个工作项,取值为true或false * @param relativeData 流程参数,格式为{key1:value1,key2:value2}的JSON串 */ var flag = bpmclient.createProcessInstWithOption("vacation","请假流程管理","",true,false,params); if(flag){ mx.indicate("info", "流程创建成功"); //发起成功后处理业务逻辑 _dataGrid.load(); }else{ mx.indicate("info", "流程创建失败"); } } else { mx.indicate("info", "选定记录的流程已发送,不能再次发送!"); return; } } /** * 调用js流程推送 */ me._btnSendJS_onclick = function(){ me.view.form.save(function(p_data) { if(p_data) { savedObj = p_data.successful; if(!savedObj) { alert("信息保存【失败】,不能发送流程!"); return; } var bpmclient = new bpmintegrate.utils.BPMClient(); /** * 完成工作项 * * @param workItemId 工作项ID */ var flag = bpmclient.finishWorkItem(me.workItemIdD); if(flag){ mx.indicate("info", "流程发送成功"); } } }); } /*******************************form自动填写不渴编辑开始**************************************/ onload: me.controller.setDepId_onload, me.setDepId_onload = function() { me.view.getForm().entityContainer.data.setValue("depId", me.view.depId); me.view.getForm().setFieldReadOnly("depId", true); }; /*******************************前端调用后台开始**************************************/ var client = new mx.rpc.RESTClient(); var startUrl = "~/../exam/rest/examfeedetail/updateStatus"; var businessData = { businessId : checkedID, status : status }; client.get(startUrl, businessData, function(p_flag) {} // End of callback function ); /*******************************weblet container使用**************************************/ var WebletContainer = null; function _initWebletView() { WebletContainer = new mx.weblets.WebletContainer({ $e: HSplitRightArea0.$e, webletID: "emp" }); //WebletContainer.view.getDataGrid().on("itemclick",me.controller._emp_onitemclick); } me.getWebletContainer = function(){ return WebletContainer; } /*******************************导出excel使用开始**************************************/ me._btnExportExcel_onclick = function() { me.view.getDataGrid().exportExcel( { tableName:"exam_fee_detail", columnNames:"fee_Id,emp_Id,fee,sub_Time,end_Time,fee_Status", columnCaptions:"报销流水ID,员工ID,报销金额,提交时间,结束时间,报销进度", fileName:"报销表单" }); }; /*******************************rendCell使用开始**************************************/ { name: "operate", caption: "操作" , isVirtual: true, editorType: "TextEditor" , renderCell:me.controller._btnOpreateColumn_onclick } me._btnOpreateColumn_onclick = function(p_item, $p_cell) { var editLinkEditor = new mx.editors.LinkEditor( { "type" : "imgtext",//指定链接的类型。 "width" : "30",//指定控件宽度。 "imageKey" : "1",//指定图标名称。 "text" : "编辑" }); editLinkEditor.on("click", me._btnSubEdit_onclick); var deleteLinkEditor = new mx.editors.LinkEditor( { "type" : "imgtext",//指定链接的类型。 "width" : "30",//指定控件宽度。 "imageKey" : "1",//指定图标名称。 "text" : "删除" }); deleteLinkEditor.on("click", me._btnSubDelete_onclick); $p_cell.append(editLinkEditor.$e); $p_cell.append(deleteLinkEditor.$e); }; /** * datagrid单元格渲染变色 */ me._btnMasterItem_oncelledited = function(e) { if(e.column.name == "compName"){ e.cell.css("background-color","green"); } }; /*******************************Form field变色开始**************************************/ { name: "leader", caption: "法人", editorType: "TextEditor", onchanged:me.controller._btnSubItem_oncelledited}, me._btnSubItem_oncelledited = function() { //me.view.getForm().getEditor("leader").$e.css("background-color","red"); me.view.getForm().getEditor("leader").$e.find("input").css("background-color","red"); }; /*******************************FilteEditor开始**************************************/ //注意type用form还是grid { name: "operFile", caption: "投标文件", editorType: "FileEditor", type: "form" , uploadMode: "blob" , tableName: "proj_unit_detail" , primaryKey: "ID" , colName: "OPER_FILE" }, /*******************************图表使用开始**************************************/ ////图表前端代码 var lineContainer=null; var chartTitle={}; var chartAxes={}; var dataTable=null; var createLineChart=null; _initLineChartContainer(); _initRemoteChart(); //创建div,用于绘制图表 function _initLineChartContainer(){ lineContainer=new mx.containers.Container({ id:"divLineChartContainer" }); me.addControl(lineContainer); } /** * create pie chart */ function _createLineChart(){ createLineChart = new mx.charts.ChartWrapper({ //设置图表类型 plotType: "CategorizedHorizontal",// 柱状图 globalSettings : { animation:{ enabled:true } }, title: {text: "部门设备数统计"},//创建标题对象 height: "100%", width: "100%", // 设置图表系列显示方式。default_series_type 默认值 Bar,可选值 Bar、RangeBar、Line、RangeArea、RangeSplineArea、 // Spline、Marker、Area、Bubble、Candlestick、OHLC等。 data_plot_setting: { pie_series:{ label_settings:{ enabled:true, position:{ anchor:"Center", padding:20 }, format:"{%Name}-{%YPercentOfSeries}{numDecimals:1}%" } }, tooltip_settings:{ enabled:true, format:"{%Name}Sales: ${%Value}Percent: {%YPercentOfSeries}{numDecimals: 2}%" } }, chart_settings: { chart_background:{ border: {color: "blue", thickness: 2}, corners: {type: "Rounded"}, // type 默认值 Square,可选值 Square、Cut、Rounded、RoundedInner。分别代表方角、切角、圆角。 effects: {drop_shaddow: {enabled: true}} },//设置图表背景。 axes: { y_axis: {title: {text: "设备数"}}, x_axis: {title: {text: "部门"}} } //设置图表纵、横坐标标题。 }, data_plot_background: { fill: {type: "Gradient", opacity: 0.5}, //type 默认值 Solid,可选值 Solid、Gradient、Image,分别代表实线、渐变、图片填充。 effects: {enabled: true, inner_shaddow: {enabled: true, distance: 5, angle: 30}} },//设置图表数据区域背景。 palettes: {item: {color: "red, blue, yellow"}, gradient: {type: "Radial"}}//type 默认值 Linear,可选值 Linear、Radial,分别代表线性填充和辐射填充。 }); createLineChart.setData(dataTable); createLineChart.draw("divLineChartContainer"); } //初始化远程表格属性 function _initRemoteChart(){ /*chartTitle.text="部门设备数统计"; chartAxes.y_axis={title:{text:"设备数"}}; chartAxes.x_axis={title:{text:"部门"}}; dataTable = new mx.datas.DataTable({ rows: [ {cells:[{value:"江苏"},{value:1000}]}, {cells:[{value:"南京"},{value:800}]}, {cells:[{value:"苏州"},{value:600}]}, {cells:[{value:"扬州"},{value:650}]} ] });*/ chartTitle.text="设备数统计"; chartAxes.y_axis={title:{text:"设备数"}}; chartAxes.x_axis={title:{text:"公司"}}; var restClient = new mx.rpc.RESTClient(); var p_context=restClient.getSync( case4.mappath("~/rest/uapbm/chart/") ); p_context = "{rows:[{cells:[{value:'江苏省电力公司'},{value:'2'}]},{cells:[{value:'南京电力公司'},{value:'1'}]},{cells:[{value:'苏州电力公司'},{value:'1'}]}]}"; var jsonObj=eval("("+p_context+")"); dataTable = new mx.datas.DataTable(jsonObj); } ////图表后台代码 @RequestMapping(value="/chart",method=RequestMethod.GET) public @RawResponseBody Object getChartValue() { @SuppressWarnings("unchecked") //根据公司名查询出公司以及公司对应的设备数 List<Object> chartValueList = departBizc.getChartValue(); //封装DataTable格式 StringBuffer dataTable=new StringBuffer(); dataTable.append("{rows:["); for (int i = 0; i < chartValueList.size(); i++) { Object[] obj=(Object[])chartValueList.get(i); if(i==chartValueList.size()-1){ dataTable.append("{cells:[{value:'"+obj[0]+"'},{value:'"+obj[1]+"'}]}"); } else{ dataTable.append("{cells:[{value:'"+obj[0]+"'},{value:'"+obj[1]+"'}]},"); } } dataTable.append("]}"); System.out.println(dataTable.toString()); return dataTable; //do not use toString() }
作者:Angelo Lee
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.