123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- Ext.QuickTips.init();
- Ext.define('erp.controller.ma.Power', {
- extend : 'Ext.app.Controller',
- requires: ['erp.util.FormUtil','erp.view.core.grid.HeaderFilter','erp.view.core.plugin.CopyPasteMenu'],
- views : [ 'ma.Power', 'core.button.Distribute', 'core.grid.GroupPower', 'core.trigger.DbfindTrigger',
- 'core.trigger.EmpTrigger', 'core.button.Sync', 'core.trigger.MultiDbfindTrigger','core.trigger.SearchField'],
- init : function() {
- var me = this;
- me.FormUtil = Ext.create('erp.util.FormUtil');
- this.control({
- 'treepanel[id=powertree]' : {
- afterrender : function(tree) {
- me.loadTree(tree);
- },
- itemmousedown : function(selModel, record) {
- var tree = selModel.ownerCt;
- me.loadTree(tree, record);
- },
- scrollershow: function(scroller) {
- if (scroller && scroller.scrollEl) {
- scroller.clearManagedListeners();
- scroller.mon(scroller.scrollEl, 'scroll', scroller.onElScroll, scroller);
- }
- }
- },
- 'button[id=personal_set]' : {// 个人权限设置
- click : function(btn) {
- var grid = btn.ownerCt.ownerCt;
- if (grid.pp_caller) {
- me.showPersonal(grid);
- }
- }
- },
- 'button[id=special_set]': {// 设置特殊权限
- click: function(btn) {
- var grid = btn.ownerCt.ownerCt;
- if (grid.pp_caller) {
- me.showSpecial(grid);
- }
- }
- },
- 'button[id=power_copy]': {// 复制权限
- click: function(btn) {
- me.showCopyPane();
- }
- },
- 'button[id=power_sync]': {// 同步权限
- click: function(btn) {
- this.showSyncWin();
- }
- },
- 'button[id=power_cover]': {// 同步所有权限
- beforerender:function(btn){
- btn.sync=function() {
- var masters = btn.getCheckData(), me = btn,w = this.win,
- datas = null, cal='PowerCover';
- Ext.MessageBox.confirm('提示', '确认将当前帐套所有岗位权限、个人权限、特殊权限,覆盖到目标帐套?', function(but) {
- if(but=='yes'){
- if (!Ext.isEmpty(masters)) {
- w.setLoading(true);
- Ext.Ajax.request({
- url: basePath + 'hr/employee/vastPostPower.action',
- params: {
- caller: cal,
- to: masters
- },
- callback: function(opt, s, r) {
- w.setLoading(false);
- if(s) {
- var rs = Ext.decode(r.responseText);
- if(rs.data) {
- showMessage('提示', rs.data);
- } else {
- alert('权限覆盖成功!');
- }
- w.hide();
- if(me.autoClearCache) {
- me.clearCache();
- }
- me.fireEvent('aftersync', me, cal, datas, masters);
- }
- }
- });
- }
- }
- });
- };
- } ,
- afterrender: function(btn){
- if(em_type && em_type != 'admin'){
- btn.hide();
- }
- }
- },
- 'multidbfindtrigger[name=em_position]': {
- aftertrigger: function(t, rs) {
- if(rs.length > 0) {
- var m = t.ownerCt;
- Ext.Array.each(rs, function(r, i){
- if(i == 0) {
- t.jo_id = r.get('jo_id');
- t.setValue(r.get('jo_name'));
- } else {
- m.insert(m.items.length - 2, {
- xtype: 'multidbfindtrigger',
- name: 'em_position',
- fieldLabel: '复制到',
- jo_id: r.get('jo_id'),
- value: r.get('jo_name'),
- p: 2,
- editable: false,
- autoDbfind: false,
- clearable: true
- });
- }
- });
- } else {
- f.setValue(null);
- f.jo_id = null;
- }
- }
- }
- });
- },
- loadTree : function(tree, record) {
- var pid = 0, me = this;
- if (record) {
- if (record.get('leaf')) {
- me.loadPower(record);
- return;
- } else {
- if (record.isExpanded() && record.childNodes.length > 0) {
- record.collapse(true, true);// 收拢
- return;
- } else {
- if (record.childNodes.length != 0) {
- record.expand(false, true);// 展开
- return;
- }
- }
- }
- pid = record.get('id');
- }
- tree.setLoading(true);
- Ext.Ajax.request({
- url : basePath + 'ma/lazyTree.action',
- params : {
- parentId : pid,
- condition : 'sn_limit=1'
- },
- callback : function(options, success, response) {
- tree.setLoading(false);
- var res = new Ext.decode(response.responseText);
- if (res.tree) {
- if (record) {
- record.appendChild(res.tree);
- record.expand(false, true);// 展开
- } else {
- tree.store.setRootNode({
- text : 'root',
- id : 'root',
- expanded : true,
- children : res.tree
- });
- }
- } else if (res.exceptionInfo) {
- showError(res.exceptionInfo);
- }
- }
- });
- },
- loadPower : function(record) {
- var caller = record.get('caller'), set = Ext.getCmp('grid');
- set.pp_caller = caller;
- set.down('tbtext').setText('<font color=gray>权限名:</font>' + record.get('text'));
- if (!Ext.isEmpty(caller)) {
- set.getGroupData(this.getUrlType(record.get('url')));
- } else {
- set.store.removeAll();
- }
- },
- getUrlType : function(url) {
- if (contains(url, 'datalist.jsp') || contains(url, 'editDatalist.jsp') || contains(url, 'vastDatalist.jsp')
- || contains(url, 'turnGoodsSend.jsp') || contains(url, 'turnEstimate.jsp')) {
- return 'list';
- } else if (contains(url, 'batchDeal.jsp') || contains(url, 'query.jsp') || contains(url, 'print.jsp')
- || contains(url, 'batchPrint.jsp') || contains(url, 'gridPage.jsp')|| contains(url, 'redirect.action')) {
- return 'deal';
- }
- return null;
- },
- showPersonal : function(grid) {
- var me = this;
- var win = Ext.getCmp('emp-win');
- if (!win) {
- win = Ext.create('Ext.Window', {
- id : 'emp-win',
- width : 800,
- height : 600,
- title : '员工',
- modal : true,
- closeAction:'hide',
- layout: 'anchor',
- items : [ {
- xtype : 'gridpanel',
- anchor: '100% 100%',
- autoScroller:true,
- columnLines : true,
- plugins : [Ext.create(
- 'erp.view.core.grid.HeaderFilter'
- ), Ext.create('erp.view.core.plugin.CopyPasteMenu')],
- selModel : Ext.create(
- 'Ext.selection.CheckboxModel', {
- checkOnly : true,
- headerWidth : 30
- }),
- columns : [ {
- text : 'ID',
- dataIndex : 'em_id',
- hidden : true
- }, {
- text : '编号',
- dataIndex : 'em_code',
- flex : 1,
- filter: {xtype: 'textfield', filterName: 'em_code'}
- }, {
- text : '姓名',
- dataIndex : 'em_name',
- flex : 1,
- filter: {xtype: 'textfield', filterName: 'em_name'}
- }, {
- text : '部门',
- dataIndex : 'em_depart',
- flex : 1,
- filter: {xtype: 'textfield', filterName: 'em_depart'}
- },{
- text : '组织',
- dataIndex : 'em_defaultorname',
- flex : 1,
- filter: {xtype: 'textfield', filterName: 'em_defaultorname'}
- }, {
- text : '职位',
- dataIndex : 'em_position',
- flex : 1,
- filter: {xtype: 'textfield', filterName: 'em_position'}
- } ],
- store:Ext.create('Ext.data.Store',{
- fields : [ {
- name : 'em_id',
- type : 'number'
- }, 'em_code', 'em_name','em_depart','em_defaultorname', 'em_position' ],
- data:[],
- autoLoad: false
- }),
- listeners: {
- afterrender: function() {
- me.getData(this);
- }
- }
- }],
- buttonAlign: 'center',
- buttons: [{
- text: $I18N.common.button.erpConfirmButton,
- iconCls: 'x-btn-confirm',
- handler: function(btn) {
- me.getPersonalPower(grid, btn.ownerCt.ownerCt.down('gridpanel'));
- btn.ownerCt.ownerCt.hide();
- }
- },{
- text: $I18N.common.button.erpCloseButton,
- iconCls: 'x-btn-close',
- handler: function(btn) {
- btn.ownerCt.ownerCt.hide();
- }
- }]
- });
- }
- win.show();
- },
- getData:function(grid){
- var f="nvl(em_class,' ')<>'离职'";
- Ext.Ajax.request({
- url : basePath + 'ma/update/getEmpdbfindData.action',
- method : 'post',
- params : {
- fields:'em_id,em_code,em_name,em_depart,em_defaultorname,em_position',
- condition: f,
- page: -1,
- pagesize: 0
- },
- method : 'post',
- callback : function(opt, s, res){
- var r = new Ext.decode(res.responseText);
- if(r.exceptionInfo){
- showError(r.exceptionInfo);return;
- } else if(r.success && r.data){
- var data = Ext.decode(r.data.replace(/,}/g, '}').replace(/,]/g, ']'));
- grid.getStore().loadData(data);
- }
- }
- });
- },
- getPersonalPower: function(grid, gl) {
- var em = new Array();
- Ext.each(gl.selModel.getSelection(),function(r){
- if(!Ext.isEmpty(r.get('em_id')) && r.get('em_id') > 0) {
- em.push({em_id: r.get('em_id'), em_name: r.get('em_name')});
- }
- });
- grid.getPersonalData(grid.urlType, em);
- },
- showSpecial: function(grid) {
- var me = this, cal = grid.pp_caller;
- function showButton(value,cellmeta){
- var returnStr = "<INPUT align='center' type='button' value='删除' onclick='Delete(""+cal+"");'>";
- return returnStr;
- };
- var win = Ext.getCmp('special-win-' + cal);
- if (!win) {
- win = Ext.create('Ext.Window', {
- id : 'special-win-' + cal,
- width : 500,
- height : 360,
- title : '特殊权限',
- modal : true,
- layout: 'anchor',
- items: [{
- xtype: 'gridpanel',
- id:'special'+cal,
- anchor: '100% 100%',
- columnLines : true,
- columns : [ {
- text : 'ID',
- dataIndex : 'ssp_id',
- hidden : true
- }, {
- text : 'caller',
- dataIndex : 'ssp_caller',
- hidden : true
- }, {
- text : '描述',
- dataIndex : 'ssp_desc',
- flex : 1,
- editor: {
- xtype: 'textfield'
- }
- }, {
- text : '链接',
- dataIndex : 'ssp_action',
- flex : 1,
- editor: {
- xtype: 'textfield'
- }
- },{
- text:'操作',
- dataIndex: 'button',
- flex:0.2,
- renderer:showButton
- }],
- store : new Ext.data.Store({
- fields : [ {
- name : 'ssp_id',
- type : 'number'
- }, 'ssp_caller', 'ssp_desc', 'ssp_action' ],
- data : [ {}, {}, {}, {}, {}, {}, {}, {}, {}, {} ]
- }),
- plugins : [ Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit : 1
- }) ],
- listeners : {
- itemclick : function(selModel, record) {
- var grid = selModel.ownerCt, store = grid.store, idx = store.indexOf(record), len = store
- .getCount();
- if (idx == len - 1) {
- store.add([ {}, {}, {}, {}, {} ]);
- }
- }
- }
- }],
- buttonAlign: 'center',
- buttons: [{
- text: $I18N.common.button.erpSaveButton,
- iconCls: 'x-btn-save',
- handler: function(btn) {
- me.saveSysSpecials(cal, btn.ownerCt.ownerCt.down('gridpanel'));
- btn.ownerCt.ownerCt.hide();
- }
- },{
- text: $I18N.common.button.erpCloseButton,
- iconCls: 'x-btn-close',
- handler: function(btn) {
- btn.ownerCt.ownerCt.hide();
- }
- }]
- });
- }
- win.show();
- this.getSysSpecialPowers(cal, win.down('grid'));
- },
- getSysSpecialPowers: function(cal, grid) {
- Ext.Ajax.request({
- url: basePath + 'ma/power/getSysSpecialPowers.action',
- params: {
- caller: cal
- },
- callback: function(opt, s, r) {
- var rs = Ext.decode(r.responseText);
- if(rs.exceptionInfo) {
- showError(rs.exceptionInfo);
- } else if(rs.data){
- if(rs.data.length==0){
- rs.data=[ {}, {}, {}, {}, {} ];
- }
- grid.store.loadData(rs.data);
- }
- }
- });
- },
- saveSysSpecials: function(cal, grid) {
- var data = new Array();
- grid.store.each(function(item){
- if(item.dirty) {
- if((!Ext.isEmpty(item.get('ssp_desc')) && !Ext.isEmpty(item.get('ssp_action'))) ||
- (item.get('ssp_id') > 0)) {
- item.data.ssp_caller = cal;
- data.push(item.data);
- }
- }
- });
- if(data.length > 0) {
- Ext.Ajax.request({
- url: basePath + 'ma/power/saveSysSpecialPowers.action',
- params: {
- caller: cal,
- data: unescape(Ext.encode(data).replace(/\\/g,"%"))
- },
- callback: function(opt, s, r) {
- var rs = Ext.decode(r.responseText);
- if(rs.exceptionInfo) {
- showError(rs.exceptionInfo);
- } else if(rs.data){
- grid.store.loadData(rs.data);
- }
- }
- });
- }
- },
- showCopyPane: function(grid) {
- var me = this, win = Ext.create('Ext.Window', {
- width : 500,
- height: 300,
- title : '复制权限',
- modal : true,
- layout: 'anchor',
- items: [{
- xtype: 'container',
- anchor: '100% 100%',
- autoScroll: true,
- layout: 'column',
- padding: '10',
- defaults: {
- labelWidth: 60,
- columnWidth: 1,
- margin: '3 10 3 10'
- },
- items: [{
- xtype: 'dbfindtrigger',
- fieldLabel: '从',
- name: 'em_position',
- p: 1,
- editable: false,
- autoDbfind: false,
- clearable: true,
- listeners: {
- aftertrigger: function(f, r) {
- f.jo_id = r.get('jo_id');
- f.setValue(r.get('jo_name'));
- }
- }
- },{
- xtype: 'multidbfindtrigger',
- name: 'em_position',
- fieldLabel: '复制到',
- p: 2,
- editable: false,
- autoDbfind: false,
- clearable: true
- },{
- xtype: 'displayfield',
- columnWidth: .75
- },{
- xtype: 'button',
- text: '添加',
- columnWidth: .25,
- cls: 'x-dd-drop-ok-add',
- iconCls: 'x-dd-drop-icon',
- iconAlign: 'right',
- handler: function(btn) {
- var f = btn.ownerCt;
- f.insert(f.items.length - 2, {
- xtype: 'multidbfindtrigger',
- name: 'em_position',
- fieldLabel: '复制到',
- p: 2,
- editable: false,
- autoDbfind: false,
- clearable: true
- });
- }
- }]
- }],
- buttonAlign: 'center',
- buttons: [{
- text: $I18N.common.button.erpSaveButton,
- cls: 'x-btn-blue',
- handler: function(btn) {
- Ext.MessageBox.show({
- title: $I18N.common.msg.title_prompt,
- msg: '目标岗位的权限将会被指定岗位覆盖,确定复制?',
- buttons: Ext.Msg.YESNO,
- icon: Ext.Msg.WARNING,
- fn: function(b){
- if(b == 'ok' || b == 'yes') {
- var w = btn.ownerCt.ownerCt,
- from = w.down('dbfindtrigger[p=1]'),
- to = w.query('multidbfindtrigger[p=2]'), tos = [];
- Ext.Array.each(to, function(t){
- if(!Ext.isEmpty(t.getValue()))
- tos.push(t.jo_id);
- });
- if(tos.length > 0)
- me.copyPower(from.jo_id, tos.join(','));
- w.hide();
- }
- }
- });
- }
- },{
- text: $I18N.common.button.erpCloseButton,
- cls: 'x-btn-blue',
- handler: function(btn) {
- btn.ownerCt.ownerCt.hide();
- }
- }]
- });
- win.show();
- },
- showSyncWin: function() {
- var me = this, win = Ext.create('Ext.Window', {
- title: '权限同步',
- width: 300,
- height: 300,
- defaults: {
- margin: '3 10 10 5'
- },
- items: [{
- xtype: 'radio',
- name: 'synctype1',
- boxLabel: '按岗位同步',
- checked: true,
- listeners: {
- change: function(f) {
- f.ownerCt.down('radio[name=synctype2]').setValue(!f.value);
- f.ownerCt.down('dbfindtrigger[name=em_code]').setDisabled(f.value);
- f.ownerCt.down('multidbfindtrigger[name=em_position]').setDisabled(!f.value);
-
- }
- }
- },{
- xtype: 'multidbfindtrigger',
- name: 'em_position',
- editable: false,
- fieldLabel: '岗位名称',
- listeners: {
- aftertrigger: function(f, rs) {
- var jo_id = null, name = null;
- var p = f.ownerCt.down('field[name=positions]'),
- j = p.jobs || new Array(), d = p.descs || new Array();
- if(rs && rs.length > 0) {
- Ext.each(rs, function(){
- jo_id = this.get('jo_id');
- name = this.get('jo_name');
- if(!Ext.Array.contains(j, jo_id)) {
- j.push(jo_id);
- d.push(name);
- }
- });
- }
- p.jobs = j;
- p.descs = d;
- p.setValue(d.join('\t'));
- f.setValue(null);
- f.up('window').down('erpSyncButton[itemId=sync]').syncdatas = j.join(',');
- f.up('window').down('erpSyncButton[itemId=sync]').caller ='PositionPower!Post';
- }
- }
- },{
- xtype : 'displayfield',
- name: 'positions',
- width: 280
- },{
- xtype: 'radio',
- name: 'synctype2',
- checked: false,
- boxLabel: '按个人同步',
- listeners: {
- change: function(f) {
- f.ownerCt.down('radio[name=synctype1]').setValue(!f.value);
- f.ownerCt.down('dbfindtrigger[name=em_code]').setDisabled(!f.value);
- f.ownerCt.down('multidbfindtrigger[name=em_position]').setDisabled(f.value);
- }
- }
- },{
- xtype: 'dbfindtrigger',
- name: 'em_code',
- fieldLabel: '员工编号',
- disabled: true,
- listeners: {
- aftertrigger: function(f, r) {
- f.setValue(r.get('em_code'));
- f.up('window').down('erpSyncButton[itemId=sync]').syncdatas = r.get('em_id');
- f.up('window').down('erpSyncButton[itemId=sync]').caller ='PersonalPower!Post';
- }
- }
- }],
- buttonAlign: 'center',
- buttons: [{
- cls: 'x-btn-blue',
- xtype: 'erpSyncButton',
- itemId : 'sync',
- autoClearCache: true,
- syncUrl:'ma/power/syncPower.action'
- }, {
- text: $I18N.common.button.erpCloseButton,
- cls: 'x-btn-blue',
- handler: function(b) {
- b.up('window').hide();
- }
- }]
- });
- win.show();
- },
- getAllJobs : function(b) {
- Ext.Ajax.request({
- url : basePath + 'common/getFieldData.action',
- async: false,
- params: {
- caller: 'Job',
- field: 'wmsys.wm_concat(jo_id)',
- condition: '1=1'
- },
- method : 'post',
- callback : function(opt, s, res){
- var r = new Ext.decode(res.responseText);
- if(r.exceptionInfo){
- showError(r.exceptionInfo);
- } else if(r.success && r.data){
- b.syncdatas = r.data;
- }
- }
- });
- },
- copyPower : function(fid, tid) {
- if(fid != tid) {
- Ext.Ajax.request({
- url: basePath + 'ma/power/copypower.action',
- params: {
- f : fid,
- t : tid
- },
- callback : function(o, s, r) {
- if( s ) {
- var e = r.responseText;
- if(e == 'success') {
- alert('复制成功!');
- } else {
- alert(e);
- }
- }
- }
- });
- }
- }
- });
|