修改框架脚本的BUG,未指定页面控件时报错不准确,重构脚本,简化前台js

This commit is contained in:
Argo-Lenovo 2016-10-28 21:26:13 +08:00
parent 3e32dfc1e5
commit 39490253de
4 changed files with 19 additions and 36 deletions

View File

@ -17,7 +17,7 @@
if ($.isArray(ele)) { if ($.isArray(ele)) {
for (index in ele) { for (index in ele) {
if (ele[index].id === undefined) { if (ele[index].id === undefined) {
window.console.log('options.click.assign[{0}].{1}.id 未设置控件id', index, name); window.console.log('options.click.assign[{0}].{1}.id 未设置控件id', ele[index].id, name);
continue; continue;
} }
cId = ele[index]['id']; cId = ele[index]['id'];
@ -227,9 +227,15 @@
return $.format('<div class="checkbox col-lg-3 col-xs-4"><label title="{3}"><input type="checkbox" value="{0}" {2}>{1}</label></div>', element.ID, element.RoleName, element.Checked, element.Description); return $.format('<div class="checkbox col-lg-3 col-xs-4"><label title="{3}"><input type="checkbox" value="{0}" {2}>{1}</label></div>', element.ID, element.RoleName, element.Checked, element.Description);
}).join(''); }).join('');
data.callback(html); data.callback(html);
return;
} }
} }
else { data.callback(false); } else if ($.isPlainObject(data.callback) && data.callback.modal !== undefined) {
$("#" + data.callback.modal).modal('hide');
}
if (result) { swal("成功", "授权角色", "success"); }
else { swal("失败", "授权角色", "error"); }
data.callback(result);
}, },
error: function (XMLHttpRequest, textStatus, errorThrown) { error: function (XMLHttpRequest, textStatus, errorThrown) {
if ($.isFunction(data.callback)) data.callback(false); if ($.isFunction(data.callback)) data.callback(false);
@ -264,14 +270,18 @@
if ($.isFunction(data.callback)) { if ($.isFunction(data.callback)) {
if ($.isArray(result)) { if ($.isArray(result)) {
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
return $.format('<div class="checkbox col-lg-3 col-xs-4"><input type="checkbox" value="{0}" {2}>{1}</div>', element.ID, element.DisplayName, element.Checked); return $.format('<div class="checkbox col-lg-3 col-xs-4"><label><input type="checkbox" value="{0}" {2}>{1}</label></div>', element.ID, element.DisplayName, element.Checked);
}).join(''); }).join('');
data.callback(html); data.callback(html);
return;
} }
else
data.callback(result);
} }
else { data.callback(false); } else if ($.isPlainObject(data.callback) && data.callback.modal !== undefined) {
$("#" + data.callback.modal).modal('hide');
}
if (result) { swal("成功", "授权用户", "success"); }
else { swal("失败", "授权用户", "error"); }
data.callback(result);
}, },
error: function (XMLHttpRequest, textStatus, errorThrown) { error: function (XMLHttpRequest, textStatus, errorThrown) {
if ($.isFunction(data.callback)) data.callback(false); if ($.isFunction(data.callback)) data.callback(false);

View File

@ -29,14 +29,7 @@
var roleIds = $('#dialogRole :checked').map(function (index, element) { var roleIds = $('#dialogRole :checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray().join(',');
Role.saveRolesByMenuId(menuId, roleIds, function (result) { Role.saveRolesByMenuId(menuId, roleIds, { modal: 'dialogRole' });
if (result) {
$('#dialogRole').modal("hide");
swal("成功", "修改角色", "success");
} else {
swal("失败", "修改角色", "error");
}
});
} }
}] }]
} }

View File

@ -30,22 +30,9 @@
var userIds = $('#dialogUser :checked').map(function (index, element) { var userIds = $('#dialogUser :checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray().join(',');
User.saveUsersByRoleId(roleId, userIds, function (result) { User.saveUsersByRoleId(roleId, userIds, { modal: 'dialogUser' });
if (result) {
$('#dialogUser').modal('hide');
swal("成功", "修改用户", "success");
}
else {
swal("失败", "修改用户", "error");
}
});
} }
}] }]
},
success: function (src, data) {
if (src === 'save' && data.ID === $('#roleId').val()) {
//$('.username').text(data.DisplayName);
}
} }
}); });

View File

@ -31,14 +31,7 @@
var roleIds = $('#dialogRole :checked').map(function (index, element) { var roleIds = $('#dialogRole :checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray().join(',');
Role.saveRolesByUserId(userId, roleIds, function (result) { Role.saveRolesByUserId(userId, roleIds, { modal: 'dialogRole' });
if (result) {
$('#dialogRole').modal("hide");
swal("成功", "修改角色", "success");
} else {
swal("失败", "修改角色", "error");
}
});
} }
}] }]
}, },