📄 user.js
字号:
return;
}
//设置所属部门的ID
if (form_instance_create.isValid()) {
form_instance_create.submit({
waitMsg:'数据提交中.....',
reset: false,
failure: function(form_instance_create, action) {
var info =
Ext.MessageBox.alert('错误信息', action.result.errorInfo);
},
success: function(form_instance_create, action) {
Ext.MessageBox.alert('成功', action.result.info);
aAddInstanceDlg.hide();
ds.load({params:{start:0, limit:myPageSize}});
}
});
}else{
Ext.MessageBox.alert('提示', '输入的数据有误,请重新输入!');
}
});
var layout = aAddInstanceDlg.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('a-addInstance-inner', {title: '添加用户'}));
layout.endUpdate();
aAddInstanceDlg.show();
};
}
//End-----------------------------------------------
//----------------------Begin----------------修改表单动作(提交)
function doSave(){
var aAddInstanceDlg;
if (!aAddInstanceDlg) {
var m = grid.getSelections();
if(m.length!=1){
Ext.MessageBox.alert('Error', '只允许选择单行纪录进行修改!');
return;
}
id_show.setValue(m[0].get("id"));
name_show.setValue(m[0].get("username"));
email_show.setValue(m[0].get("email"));
descn_show.setValue(m[0].get("descn"));
deptId_show.setValue(selectNode.id);
dept_show.setValue(selectNode.text);
password_show.setValue("");
cPassword_show.setValue("");
aAddInstanceDlg = createNewDialog("a-updateInstance-dlg");
aAddInstanceDlg.addButton('重置', resetForm, aAddInstanceDlg);
aAddInstanceDlg.addButton('保存', function() {
if(password_show.getValue()==""){
Ext.MessageBox.alert('提示', '请输入密码!');
}
if (password_show.getValue()!=cPassword_show.getValue()) {
password_show.markInvalid("2次输入的密码不正确!");
password_show.focus();
return;
}
if(selectNode.leaf!=true){
Ext.MessageBox.alert('提示', '用户不能创建在该部门下!');
return;
}
// 向服务器提交数据
if (form_instance_update.isValid()) {
form_instance_update.submit({
waitMsg:'数据提交中.....',
reset: false,
failure: function(form_instance_update, action) {
alert(action.result);
var info =
Ext.MessageBox.alert('Error Message', action.result.errorInfo);
},
success: function(form_instance_update, action) {
Ext.MessageBox.alert('Confirm', action.result.info);
aAddInstanceDlg.hide();
ds.load({params:{start:0, limit:myPageSize}});
}
});
}else{
Ext.MessageBox.alert('提示', '输入的数据有误,请重新输入!');
}
});
var layout = aAddInstanceDlg.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('a-updateInstance-inner', {title: '用户更新'}));
layout.endUpdate();
aAddInstanceDlg.show();
};
}
function doAuth(){
var m = grid.getSelections();
if(m.length<=0){
Ext.MessageBox.alert('提示', '请选择需要授权的用户!');
return;
}
dsRole.load({params:{start:0, limit:myPageSize,id:m[0].get('id')}});
var aAddInstanceDlg = createNewDialog("userAuthRole-dlg");
var layout = aAddInstanceDlg.getLayout();
layout.beginUpdate();
layout.add('center', new Ext.ContentPanel('userAuthRole-inner', {title: '用户授权'}));
layout.endUpdate();
aAddInstanceDlg.show();
}
//删除按钮方法
function doDel(){
var m = grid.getSelections();
if(m.length > 0) {
Ext.MessageBox.confirm('提示', '确定要删除吗?' , doDel2);
} else {
Ext.MessageBox.alert('提示', '请选择要删除的数据行!');
}
}
//删除回调方法
function doDel2(btn) {
if(btn=='yes'){
var m = grid.getSelections();
var userid =new Array();
for(var i = 0, len = m.length; i < len; i++){
m[i].get("id");
userid[i]=m[i].get("id");
ds.remove(m[i]);
}
Ext.Ajax.request({
url:'remove.htm?id='+userid,
success:function(){
Ext.MessageBox.alert('提示', '删除成功!');
ds.load({params:{start:0, limit:myPageSize}});
},
failure:function(){Ext.MessageBox.alert('提示', '删除失败!');}
});
}else{
return;
}
}
// 提供验证功能
Ext.form.Field.prototype.msgTarget = 'side';
Ext.form.Field.prototype.height = 20;
Ext.form.Field.prototype.fieldClass = 'text-field-default';
Ext.form.Field.prototype.focusClass = 'text-field-focus';
Ext.form.Field.prototype.invalidClass = 'text-field-invalid';
// 添加表单
var name_tf = new Ext.form.TextField({
fieldLabel: '用户名',
name: 'username',
allowBlank:false
});
var password_tf = new Ext.form.TextField({
fieldLabel: '密码',
name: 'password',
inputType: 'password',
allowBlank:false
});
var cPassword_tf = new Ext.form.TextField({
fieldLabel: '密码确认',
name: 'cPassword',
inputType: 'password',
allowBlank:false
});
var deptId_tf = new Ext.form.TextField({
name: 'deptId',
inputType:'hidden',
labelStyle:'display: none'
});
var descn_tf = new Ext.form.TextField({
fieldLabel: '描述',
name: 'descn',
allowBlank:true
});
var email_tf = new Ext.form.TextField({
fieldLabel: '电子邮件',
name: 'email',
allowBlank:true
});
var form_instance_create = new Ext.form.Form({
labelAlign: 'right',
url:'insert.htm'
});
form_instance_create.column({width: 430, labelWidth:120, style:'margin-left:8px;margin-top:8px'});
form_instance_create.fieldset({
id:'adduser', legend:'添加用户----请填写数据:'},
name_tf,
password_tf,
cPassword_tf,
descn_tf,
email_tf,
deptId_tf
);
form_instance_create.applyIfToFields({width:255});
form_instance_create.render('a-addInstance-form');
form_instance_create.end();
resetForm = function() {
name_tf.setValue('');
email_tf.setValue('');
descn_tf.setValue('');
deptId_tf.setValue('');
password_tf.setValue('');
cPassword_tf.setValue('');
};
// 更新表单
var id_show = new Ext.form.TextField({
// labelStyle: 'display: none',
inputType: 'hidden',
name: 'id',
readOnly: true,
allowBlank:false,
labelStyle:'display: none'
});
var name_show = new Ext.form.TextField({
fieldLabel: '用户名',
name: 'username',
allowBlank:false
});
var password_show = new Ext.form.TextField({
fieldLabel: '密码',
name: 'password',
inputType: 'password',
allowBlank:false
});
var cPassword_show = new Ext.form.TextField({
fieldLabel: '密码确认',
name: 'cPassword',
inputType: 'password',
allowBlank:false
});
var descn_show = new Ext.form.TextField({
fieldLabel: '描述',
name: 'descn',
allowBlank:true
});
var email_show = new Ext.form.TextField({
fieldLabel: '电子邮件',
name: 'email',
allowBlank:true
});
var dept_show = new Ext.form.TextField({
fieldLabel: '所属部门',
name: 'orgText',
allowBlank:false
});
var deptId_show = new Ext.form.TextField({
inputType: 'hidden',
name: 'deptId',
readOnly: true,
allowBlank:false,
labelStyle:'display: none'
});
var form_instance_update = new Ext.form.Form({
labelAlign: 'right',
url:'update.htm'
});
form_instance_update.column({width: 430, labelWidth:120, style:'margin-left:8px;margin-top:8px'});
form_instance_update.fieldset({
id:'updateuser', legend:'更新用户----请填写数据:'},
name_show,
password_show,
cPassword_show,
descn_show,
email_show,
dept_show,
deptId_show,
id_show
);
form_instance_update.applyIfToFields({width:255});
form_instance_update.render('a-updateInstance-form');
form_instance_update.end();
//-------------------------表格右键菜单BEGAIN
var gridCtxMenu = new Ext.menu.Menu({
id:'gridCtx',
items: [{
id:'addDept',
handler:gridAddDept,
cls:'collapse-all',
text:'添加部门'
},{
id:'addUser',
handler:gridAddUser,
cls:'collapse-all',
text:'添加用户'
},'-',{
id:'remove',
cls:'remove-mi',
text: '移除'
}]
});
function gridPrepareCtx(grid, rowIndex,cellIndex,e){
ctxMenu.items.get('remove')[node.attributes.allowDelete ? 'enable' : 'disable']();
gridCtxMenu.showAt(e.getXY());
}
function gridAddDept(node){
gridCtxMenu.hide();
setTimeout(function(){
node.eachChild(function(n){
//n.collapse(false, false);
});
}, 10);
}
function gridAddUser(node){
gridCtxMenu.hide();
setTimeout(function(){
node.eachChild(function(n){
// n.expand(false, false);
});
}, 10);
}
//-------------------------表格右键菜单END
//=============================================================
//================创建用户树============================
var userTreeloader = new Ext.tree.TreeLoader({
dataUrl:'#user.do?method=rendererUserTree'
});
var Tree = Ext.tree;
var tree = new Tree.TreePanel('source-files', {
animate:true,
loader: new Tree.TreeLoader({
dataUrl:'../dept/getAllTree.htm'
}),
enableDD:true,
containerScroll: true,
dropConfig: {appendOnly:true}
});
tree.on('move',function(tree,thisnode,oldParent,newParent,index){
//操作
});
// 树的根节点
var root = new Tree.AsyncTreeNode({
text: '临远研发中心',
draggable:false,
id:'1',
cls:'folder',
leaf:false
});
tree.setRootNode(root);
//tree.on("expand",reloadds);
tree.on('contextmenu', prepareCtx);
tree.on('click',function(node,e){
selectNode = node;
});
tree.on('click',reloadds);
// 渲染树
tree.render();
root.expand();
function reloadds(node,e){
deptId=node.id;
deptId_show.setValue(selectNode.id);
dept_show.setValue(selectNode.text);
ds.load({params:{start:0, limit:myPageSize,deptId:node.id}});
}
//---------------树右键菜单BEGAIN
var ctxMenu = new Ext.menu.Menu({
id:'copyCtx',
items: [{
id:'expand',
handler:expandAll,
cls:'expand-all',
text:'展开'
},{
id:'collapse',
handler:collapseAll,
cls:'collapse-all',
text:'收拢'
},{
id:'addDept',
handler:collapseAll,
cls:'collapse-all',
text:'添加部门'
},{
id:'addUser',
handler:collapseAll,
cls:'collapse-all',
text:'添加用户'
},'-',{
id:'remove',
cls:'remove-mi',
text: '删除'
}]
});
function prepareCtx(node, e){
node.select();
// ctxMenu.items.get('remove')[node.attributes.allowDelete ? 'enable' : 'disable']();
ctxMenu.items.get('addUser')[node.isLeaf ? 'enable' : 'disable']();
ctxMenu.items.get('addDept')[node.isLeaf ? 'disable' : 'enable']();
ctxMenu.showAt(e.getXY());
}
function collapseAll(node){
ctxMenu.hide();
setTimeout(function(){
node.eachChild(function(n){
n.collapse(false, false);
});
}, 10);
}
function expandAll(node){
ctxMenu.hide();
setTimeout(function(){
node.eachChild(function(n){
n.expand(false, false);
});
}, 10);
}
//---------------树右键菜单END
ds.on('beforeload', function() {
ds.baseParams = {
deptId: deptId
};
});
dsRole.on('beforeload', function() {
dsRole.baseParams = {
userId:grid.getSelections()[0].id
};
});
});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -