代码重构:重构BootstrapAdmin脚本,使用更简单

This commit is contained in:
Argo-MacBookPro 2018-09-02 00:50:13 +08:00
parent 622adfc9a7
commit e31dfe5055
14 changed files with 428 additions and 538 deletions

View File

@ -27,7 +27,6 @@
<script src="~/js/common-scripts.js"></script>
<script src="~/js/log.js"></script>
<script src="~/js/toastr.min.js"></script>
<script src="~/js/framework.js"></script>
@RenderSection("Javascript", false)
}
@await Html.PartialAsync("navigator")

View File

@ -1,29 +1,25 @@
$(function () {
var bsa = new BootstrapAdmin({
$('table').lgbTable({
url: Dicts.url,
dataEntity: new DataEntity({
dataBinder: {
map: {
Id: "dictID",
Category: "dictCate",
Name: "dictName",
Code: "dictCode",
Define: "dictDefine"
Id: "#dictID",
Category: "#dictCate",
Name: "#dictName",
Code: "#dictCode",
Define: "#dictDefine"
}
})
});
$('table').smartTable({
url: Dicts.url,
sortName: 'Category',
queryParams: function (params) { return $.extend(params, { category: $('#txt_dict_cate').val(), name: $("#txt_dict_name").val(), define: $("#txt_dict_define").val() }); },
columns: [
{ checkbox: true },
{ title: "编辑", field: "Id", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "字典标签", field: "Category", sortable: true },
{ title: "字典名称", field: "Name", sortable: true },
{ title: "字典代码", field: "Code", sortable: true },
{ title: "字典分类", field: "Define", sortable: true, formatter: function (value, row, index) { return value == "0" ? "系统使用" : "自定义"; } }
]
},
smartTable: {
sortName: 'Category',
queryParams: function (params) { return $.extend(params, { category: $('#txt_dict_cate').val(), name: $("#txt_dict_name").val(), define: $("#txt_dict_define").val() }); },
columns: [
{ title: "字典标签", field: "Category", sortable: true },
{ title: "字典名称", field: "Name", sortable: true },
{ title: "字典代码", field: "Code", sortable: true },
{ title: "字典分类", field: "Define", sortable: true, formatter: function (value) { return value === "0" ? "系统使用" : "自定义"; } }
]
}
});
// autocomplete

View File

@ -6,11 +6,6 @@
var $errorDetail = $('#errorDetail');
var $errorDetailTitle = $('#myDetailModalLabel');
var bsa = new BootstrapAdmin({
url: Exceptions.url,
validateForm: null
});
$('table').smartTable({
url: Exceptions.url,
sortName: 'LogTime',

View File

@ -1,218 +0,0 @@
(function ($) {
BootstrapAdmin = function (options) {
var that = this;
options = options || {};
options.click = $.extend({}, BootstrapAdmin.settings.click, options.click);
this.options = $.extend({}, BootstrapAdmin.settings, options);
this.dataEntity = options.dataEntity;
// handler click event
for (name in this.options.click) {
var ele = this.options.click[name];
var cId = ele;
var event = null;
if ($.isArray(ele)) {
for (index in ele) {
if (ele[index].id === undefined) {
window.console.log('options.click.assign[{0}].{1}.id 未设置控件id', ele[index].id, name);
continue;
}
cId = ele[index]['id'];
event = ele[index]['click'];
handler(cId, event);
}
}
else handler(cId, event);
}
// handler modal window show event
function handler(cid, event) {
var source = $("#" + cId);
source.data('click', name);
if (event !== null) source.data('event', event);
source.on('click', function (e) {
e.preventDefault();
var method = source.data('click');
BootstrapAdmin.prototype[method].call(that, this, source.data('event'));
});
}
};
BootstrapAdmin.VERSION = "1.0";
BootstrapAdmin.Author = "Argo Zhang";
BootstrapAdmin.Email = "argo@163.com";
BootstrapAdmin.settings = {
url: undefined,
bootstrapTable: 'table',
modal: '#dialogNew',
click: {
query: 'btn_query',
create: 'btn_add',
edit: 'btn_edit',
del: 'btn_delete',
save: 'btnSubmit',
assign: []
}
};
BootstrapAdmin.idFormatter = function (value, row, index) {
return "<a class='edit' title='" + value + "' href='javascript:void(0)'>编辑</a>";
};
BootstrapAdmin.prototype = {
constructor: BootstrapAdmin,
idEvents: function () {
var op = {
dataEntity: $.extend({}, this.options.dataEntity),
table: this.options.bootstrapTable,
modal: this.options.modal,
src: this
};
return {
'click .edit': function (e, value, row, index) {
op.dataEntity.load(row);
$(op.table).bootstrapTable('uncheckAll');
$(op.table).bootstrapTable('check', index);
handlerCallback.call(op.src, null, e, { oper: 'edit', data: row });
$(op.modal).modal("show");
}
}
},
query: function (e, callback) {
if (this.options.bootstrapTable.constructor === String) $(this.options.bootstrapTable).bootstrapTable('refresh');
handlerCallback.call(this, callback, e, { oper: 'query' });
},
create: function (e, callback) {
if (this.dataEntity instanceof DataEntity) this.dataEntity.reset();
if (this.options.modal.constructor === String) $(this.options.modal).modal("show");
if (this.options.bootstrapTable.constructor === String) $(this.options.bootstrapTable).bootstrapTable('uncheckAll');
handlerCallback.call(this, callback, e, { oper: 'create' });
},
edit: function (e, callback) {
var options = this.options;
var data = {};
if (options.bootstrapTable.constructor === String) {
var arrselections = $(options.bootstrapTable).bootstrapTable('getSelections');
if (arrselections.length == 0) {
lgbSwal({ title: '请选择要编辑的数据', type: "warning" });
return;
}
else if (arrselections.length > 1) {
lgbSwal({ title: '请选择一个要编辑的数据', type: "warning" });
return;
}
else {
data = arrselections[0];
if (this.dataEntity instanceof DataEntity) this.dataEntity.load(data);
if (options.modal.constructor === String) $(options.modal).modal("show");
}
}
handlerCallback.call(this, callback, e, { oper: 'edit', data: data });
},
del: function (e, callback) {
var that = this;
var options = this.options;
if (options.bootstrapTable.constructor === String) {
var arrselections = $(options.bootstrapTable).bootstrapTable('getSelections');
if (arrselections.length == 0) {
lgbSwal({ title: '请选择要删除的数据', type: "warning" });
return;
}
else {
swal({
title: "您确定要删除吗?",
type: "warning",
showCancelButton: true,
closeOnConfirm: true,
confirmButtonText: "是的,我要删除",
confirmButtonColor: "#d9534f",
cancelButtonText: "取消"
}, function () {
setTimeout(function () {
var iDs = arrselections.map(function (element, index) { return element.Id; });
$.bc({
url: options.url, data: iDs, method: 'DELETE', title: '删除数据',
callback: function (result) {
if ($.isPlainObject(result)) {
lgbSwal({ title: result.msg, type: result.result ? "success" : "error" });
result = result.result;
}
if (result) $(options.bootstrapTable).bootstrapTable('refresh');
handlerCallback.call(that, callback, e, { oper: 'del', success: result });
}
});
}, 100);
});
}
}
},
save: function (e, callback) {
var that = this;
var options = $.extend({ data: {} }, this.options);
if (this.dataEntity instanceof DataEntity) options = $.extend(options, { data: this.dataEntity.get() });
$.bc({
url: options.url, data: options.data, title: "保存数据", modal: options.modal,
callback: function (result) {
if (result) {
var finalData = null;
var index = 0;
if (result) {
if (options.bootstrapTable.constructor === String && options.data.Id.constructor === String) {
// 更新表格
if (options.data.Id > 0) {
var allTableData = $(options.bootstrapTable).bootstrapTable('getData');
for (index = 0; index < allTableData.length; index++) {
finalData = allTableData[index];
if (finalData.Id == options.data.Id) {
break;
}
}
}
else {
$(options.bootstrapTable).bootstrapTable('refresh');
finalData = options.data;
}
}
}
$(options.bootstrapTable).bootstrapTable('refresh');
handlerCallback.call(that, callback, e, { oper: 'save', success: result, index: index, data: finalData });
}
}
});
},
assign: function (e, callback) {
var options = this.options;
var row = {};
if (options.bootstrapTable && options.bootstrapTable.constructor === String) {
var arrselections = $(options.bootstrapTable).bootstrapTable('getSelections');
if (arrselections.length === 0) {
lgbSwal({ title: '请选择要编辑的数据', type: "warning" });
return;
}
else if (arrselections.length > 1) {
lgbSwal({ title: '请选择一个要编辑的数据', type: "warning" });
return;
}
else {
row = arrselections[0];
}
}
var data = options.dataEntity;
if (data instanceof DataEntity) data = data.get();
if ($.isFunction(callback)) callback.call(e, row, $.extend({}, data));
if ($.isFunction(this.options.callback)) this.options.callback.call(e, { oper: 'assign', row: row, data: data });
}
};
var handlerCallback = function (callback, e, data) {
if ($.isFunction(callback)) callback.call(e, data);
if ($.isFunction(this.options.callback)) this.options.callback.call(e, data);
};
})(jQuery);

View File

@ -6,37 +6,32 @@
var $dialogRoleHeader = $('#myRoleModalLabel');
var $dialogRoleForm = $('#roleForm');
var bsa = new BootstrapAdmin({
$('table').lgbTable({
url: Group.url,
dataEntity: new DataEntity({
dataBinder: {
map: {
Id: "groupID",
GroupName: "groupName",
Description: "groupDesc"
}
}),
click: {
assign: [{
id: 'btn_assignRole',
click: function (row) {
Id: "#groupID",
GroupName: "#groupName",
Description: "#groupDesc"
},
events: {
'#btn_assignRole': function (row) {
$.bc({
id: row.Id, url: Role.url, data: { type: "group" }, swal: false,
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
return $.format(htmlTemplate, element.Id, element.RoleName, element.Checked, element.Description);
}).join('')
}).join('');
$dialogRoleHeader.text($.format('{0}-角色授权窗口', row.GroupName));
$dialogRoleForm.html(html).find('[data-toggle="tooltip"]').each(function (index, label) {
if (label.title == "") label.title = "未设置";
if (label.title === "") label.title = "未设置";
}).tooltip();
$dialogRole.modal('show');
}
});
}
}, {
id: 'btn_assignUser',
click: function (row) {
},
'#btn_assignUser': function (row) {
$.bc({
id: row.Id, url: User.url, data: { type: "group" }, swal: false,
callback: function (result) {
@ -46,42 +41,35 @@
}).join('');
$dialogUserHeader.text($.format('{0}-用户授权窗口', row.GroupName));
$dialogUserForm.html(html).find('[data-toggle="tooltip"]').each(function (index, label) {
if (label.title == "") label.title = "未设置";
if (label.title === "") label.title = "未设置";
}).tooltip();
$dialogUser.modal('show');
}
});
}
}, {
id: 'btnSubmitRole',
click: function (row) {
},
'#btnSubmitRole': function (row) {
var groupId = row.Id;
var roleIds = $dialogRole.find('input:checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: groupId, url: Role.url, method: "PUT", data: { type: "group", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' });
}
}, {
id: 'btnSubmitUser',
click: function (row) {
},
'#btnSubmitUser': function (row) {
var groupId = row.Id;
var userIds = $dialogUser.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: groupId, url: User.url, method: "PUT", data: { type: "group", userIds: userIds }, title: User.title, modal: '#dialogUser' });
}
}]
}
},
smartTable: {
sortName: 'GroupName',
queryParams: function (params) { return $.extend(params, { groupName: $("#txt_search_name").val(), description: $("#txt_group_desc").val() }); }, //传递参数(*
columns: [
{ title: "部门名称", field: "GroupName", sortable: true },
{ title: "部门描述", field: "Description", sortable: false }
]
}
});
$('table').smartTable({
url: Group.url, //请求后台的URL*
sortName: 'GroupName',
queryParams: function (params) { return $.extend(params, { groupName: $("#txt_search_name").val(), description: $("#txt_group_desc").val() }); }, //传递参数(*
columns: [{ checkbox: true },
{ title: "编辑", field: "Id", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "部门名称", field: "GroupName", sortable: true },
{ title: "部门描述", field: "Description", sortable: false }
]
});
});

View File

@ -1,9 +1,5 @@
$(function () {
var url = '../api/Logs/';
var bsa = new BootstrapAdmin({
url: url,
validateForm: null
});
var url = 'api/Logs/';
$('table').smartTable({
url: url,

View File

@ -171,7 +171,7 @@
function success(result) {
var interval = 10;
if ($.isFunction(options.callback)) {
options.callback.call(options.$element == null ? options : options.$element, result);
options.callback.call(options.$element === null ? options : options.$element, result);
}
if (options.modal !== null && (result || options.loading)) {
$(options.modal).modal('hide');
@ -182,7 +182,7 @@
lgbSwal({ title: options.title + (result ? "成功" : "失败"), type: result ? 'success' : 'error' });
}
if ($.isFunction(callback)) {
callback.call(options.$element == null ? this : options.$element);
callback.call(options.$element === null ? this : options.$element);
}
}, interval);
}
@ -199,7 +199,7 @@
return prefix;
},
fullScreenStatus: function fullScreenStatus(value) {
if (value != undefined) window.fullscreen = value;
if (value !== undefined) window.fullscreen = value;
return document.fullscreen ||
document.mozFullScreen ||
document.webkitIsFullScreen || window.fullscreen ||
@ -217,7 +217,7 @@
},
formatUrl: function (url) {
if (!url) return url;
if (url.substr(0, 4) == "http") return url;
if (url.substr(0, 4) === "http") return url;
var base = $('#pathBase').attr('href');
return base + url;
}
@ -293,7 +293,7 @@
var $collapse = $root.find('a[data-toggle="collapse"]:visible');
$collapse.each(function () {
var $this = $(this);
if ($this.attr('href') != '#') return;
if ($this.attr('href') !== '#') return;
var $target = $this.parent().next();
var tId = $.getUID('collapse');
$target.attr('id', tId);
@ -325,6 +325,20 @@
var op = $.extend({ header: "header", content: ".main-content" }, options);
return ($(op.header).outerHeight() + $(op.content).outerHeight() + this.outerHeight() > $(window).height()) ? this.removeClass('fixed') : this.addClass('fixed');
},
lgbTable: function (options) {
var bsa = new DataTable($.extend(options.dataBinder, { url: options.url }));
var settings = $.extend({
url: options.url,
checkbox: true,
edit: true,
editTitle: "编辑",
editField: "Id"
}, options.smartTable);
if (settings.edit) settings.columns.unshift({ title: settings.editTitle, field: settings.editField, events: bsa.idEvents(), formatter: DataTable.idFormatter });
if (settings.checkbox) settings.columns.unshift({ checkbox: true });
this.smartTable(settings);
},
smartTable: function (options) {
var settings = $.extend({
method: 'get', //请求方式(*
@ -353,7 +367,7 @@
$('#' + $(this).attr('id').replace('tb_', 'btn_')).trigger("click");
}).insertBefore(this.parents('.bootstrap-table').find('.fixed-table-toolbar > .bs-bars'));
return this;
},
}
});
//extend dropdown method

View File

@ -1,54 +1,226 @@
(function ($) {
DataEntity = function (options) {
this.options = $.extend({ map: {} }, options);
this.options = options;
};
DataEntity.VERSION = "1.0";
DataEntity.Author = "Argo Zhang";
DataEntity.Email = "argo@163.com";
DataEntity.prototype = {
load: function (value) {
for (name in this.options.map) {
var ctl = $("#" + this.options.map[name]);
if (ctl.attr('data-toggle') == "dropdown") {
for (name in this.options) {
var ctl = $(this.options[name]);
if (ctl.attr('data-toggle') === "dropdown") {
ctl.val(value[name]).dropdown('val');
}
else if (ctl.attr('data-toggle') == 'toggle') {
else if (ctl.attr('data-toggle') === 'toggle') {
ctl.bootstrapToggle(value[name] ? 'on' : 'off');
}
else ctl.val(value[name]);
}
},
reset: function () {
for (name in this.options.map) {
var ctl = $("#" + this.options.map[name]);
for (name in this.options) {
var ctl = $(this.options[name]);
var dv = ctl.attr("data-default-val");
if (dv === undefined) dv = "";
if (ctl.attr('data-toggle') == "dropdown") {
if (ctl.attr('data-toggle') === "dropdown") {
ctl.val(dv).dropdown('val');
}
else if (ctl.attr('data-toggle') == 'toggle') {
ctl.bootstrapToggle(dv == "true" ? 'on' : 'off');
else if (ctl.attr('data-toggle') === 'toggle') {
ctl.bootstrapToggle(dv === "true" ? 'on' : 'off');
}
else ctl.val(dv);
}
},
get: function () {
var target = {};
for (name in this.options.map) {
var ctl = $("#" + this.options.map[name]);
for (name in this.options) {
var ctl = $(this.options[name]);
var dv = ctl.attr('data-default-val');
if (ctl.attr('data-toggle') == 'toggle') {
if (ctl.attr('data-toggle') === 'toggle') {
target[name] = ctl.prop('checked');
continue;
}
else if (dv != undefined && ctl.val() == "") target[name] = dv;
else if (dv !== undefined && ctl.val() === "") target[name] = dv;
else target[name] = ctl.val();
if (target[name] == "true" || target[name] == "True") target[name] = true;
if (target[name] == "false" || target[name] == "False") target[name] = false;
if (target[name] === "true" || target[name] === "True") target[name] = true;
if (target[name] === "false" || target[name] === "False") target[name] = false;
}
return target;
}
};
DataTable = function (options) {
var that = this;
this.options = $.extend(true, {}, DataTable.settings, options);
this.dataEntity = new DataEntity(options.map);
// handler click event
for (var name in this.options.click) {
$(name).on('click', { handler: this.options.click[name] }, function (e) {
e.preventDefault();
e.data.handler.call(that, this);
});
}
// handler extra click event
for (var cId in this.options.events) {
$(cId).on('click', { handler: this.options.events[cId] }, function (e) {
var options = that.options;
var row = {};
if (options.bootstrapTable && options.bootstrapTable.constructor === String) {
var arrselections = $(options.bootstrapTable).bootstrapTable('getSelections');
if (arrselections.length === 0) {
lgbSwal({ title: '请选择要编辑的数据', type: "warning" });
return;
}
else if (arrselections.length > 1) {
lgbSwal({ title: '请选择一个要编辑的数据', type: "warning" });
return;
}
else {
row = arrselections[0];
}
}
e.data.handler.call(this, row);
});
}
};
DataTable.settings = {
url: undefined,
bootstrapTable: 'table',
modal: '#dialogNew',
click: {
'#btn_query': function (element) {
if (this.options.bootstrapTable.constructor === String) $(this.options.bootstrapTable).bootstrapTable('refresh');
handlerCallback.call(this, null, element, { oper: 'query' });
},
'#btn_add': function (element) {
this.dataEntity.reset();
if (this.options.modal.constructor === String) $(this.options.modal).modal("show");
if (this.options.bootstrapTable.constructor === String) $(this.options.bootstrapTable).bootstrapTable('uncheckAll');
handlerCallback.call(this, null, element, { oper: 'create' });
},
'#btn_edit': function (element) {
var options = this.options;
var data = {};
if (options.bootstrapTable.constructor === String) {
var arrselections = $(options.bootstrapTable).bootstrapTable('getSelections');
if (arrselections.length === 0) {
lgbSwal({ title: '请选择要编辑的数据', type: "warning" });
return;
}
else if (arrselections.length > 1) {
lgbSwal({ title: '请选择一个要编辑的数据', type: "warning" });
return;
}
else {
data = arrselections[0];
this.dataEntity.load(data);
if (options.modal.constructor === String) $(options.modal).modal("show");
}
}
handlerCallback.call(this, null, element, { oper: 'edit', data: data });
},
'#btn_delete': function (element) {
var that = this;
var options = this.options;
if (options.bootstrapTable.constructor === String) {
var arrselections = $(options.bootstrapTable).bootstrapTable('getSelections');
if (arrselections.length === 0) {
lgbSwal({ title: '请选择要删除的数据', type: "warning" });
return;
}
else {
swal({
title: "您确定要删除吗?",
type: "warning",
showCancelButton: true,
closeOnConfirm: true,
confirmButtonText: "是的,我要删除",
confirmButtonColor: "#d9534f",
cancelButtonText: "取消"
}, function () {
setTimeout(function () {
var iDs = arrselections.map(function (element, index) { return element.Id; });
$.bc({
url: options.url, data: iDs, method: 'DELETE', title: '删除数据',
callback: function (result) {
if ($.isPlainObject(result)) {
lgbSwal({ title: result.msg, type: result.result ? "success" : "error" });
result = result.result;
}
if (result) $(options.bootstrapTable).bootstrapTable('refresh');
handlerCallback.call(that, null, element, { oper: 'del', success: result });
}
});
}, 100);
});
}
}
},
'#btnSubmit': function (element) {
var that = this;
var options = $.extend(true, {}, this.options, { data: this.dataEntity.get() });
$.bc({
url: options.url, data: options.data, title: "保存数据", modal: options.modal,
callback: function (result) {
if (result) {
var finalData = null;
var index = 0;
if (result) {
if (options.bootstrapTable.constructor === String && options.data.Id.constructor === String) {
// 更新表格
if (options.data.Id > 0) {
var allTableData = $(options.bootstrapTable).bootstrapTable('getData');
for (index = 0; index < allTableData.length; index++) {
finalData = allTableData[index];
if (finalData.Id === options.data.Id) {
break;
}
}
}
else {
$(options.bootstrapTable).bootstrapTable('refresh');
finalData = options.data;
}
}
}
$(options.bootstrapTable).bootstrapTable('refresh');
handlerCallback.call(that, null, element, { oper: 'save', success: result, index: index, data: finalData });
}
}
});
}
}
};
DataTable.idFormatter = function (value, row, index) {
return "<a class='edit' title='" + value + "' href='javascript:void(0)'>编辑</a>";
};
DataTable.prototype = {
constructor: DataTable,
idEvents: function () {
var op = {
dataEntity: this.dataEntity,
table: this.options.bootstrapTable,
modal: this.options.modal,
src: this
};
return {
'click .edit': function (e, value, row, index) {
op.dataEntity.load(row);
$(op.table).bootstrapTable('uncheckAll');
$(op.table).bootstrapTable('check', index);
handlerCallback.call(op.src, null, e, { oper: 'edit', data: row });
$(op.modal).modal("show");
}
};
}
};
function handlerCallback(callback, element, data) {
if ($.isFunction(callback)) callback.call(e, data);
if ($.isFunction(this.options.callback)) this.options.callback.call(element, data);
}
}(jQuery));

View File

@ -19,120 +19,111 @@
var initNestMenu = function () {
$nestMenuInput = $nestMenu.find('div.dd3-content');
$nestMenuInput.children('.checkbox').hide();
}
};
var state = [];
var bsa = new BootstrapAdmin({
$('table').lgbTable({
url: Menu.url,
dataEntity: new DataEntity({
dataBinder: {
map: {
Id: "menuID",
ParentId: "parentId",
ParentName: "parentName",
Name: "name",
Order: "order",
Icon: "icon",
Url: "url",
Category: "category",
Target: "target",
IsResource: "isRes",
ApplicationCode: "app"
}
}),
click: {
assign: [{
id: 'btn_assignRole',
click: function (row) {
Id: "#menuID",
ParentId: "#parentId",
ParentName: "#parentName",
Name: "#name",
Order: "#order",
Icon: "#icon",
Url: "#url",
Category: "#category",
Target: "#target",
IsResource: "#isRes",
ApplicationCode: "#app"
},
events: {
'#btn_assignRole': function (row) {
$.bc({
id: row.Id, url: Role.url, data: { type: "menu" }, swal: false,
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
return $.format(htmlTemplate, element.Id, element.RoleName, element.Checked, element.Description);
}).join('')
}).join('');
$dialogRoleHeader.text($.format('{0}-角色授权窗口', row.Name));
$dialogRoleForm.html(html).find('[data-toggle="tooltip"]').each(function (index, label) {
if (label.title == "") label.title = "未设置";
if (label.title === "") label.title = "未设置";
}).tooltip();
$dialogRole.modal('show');
}
});
}
}, {
id: 'btnSubmitRole',
click: function (row) {
},
'#btnSubmitRole': function (row) {
var menuId = row.Id;
var roleIds = $dialogRole.find('input:checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: menuId, url: Role.url, method: "PUT", data: { type: "menu", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' });
}
}]
},
callback: function (result) {
if (!result.success) return;
if ((result.oper === "save") || result.oper === "del") {
$nestMenu.nestMenu(initNestMenu);
}
}
},
callback: function (result) {
if (!result.success) return;
if ((result.oper == "save") || result.oper == "del") {
$nestMenu.nestMenu(initNestMenu);
}
smartTable: {
sortName: 'Order',
queryParams: function (params) { return $.extend(params, { parentName: $('#txt_parent_menus_name').val(), name: $("#txt_menus_name").val(), category: $('#sel_menus_category').val(), isresource: $('#sel_menus_res').val() }); }, //传递参数(*
columns: [
{ title: "父级菜单", field: "ParentName", sortable: true },
{ title: "菜单名称", field: "Name", sortable: true },
{ title: "菜单序号", field: "Order", sortable: true },
{
title: "菜单图标", field: "Icon", sortable: false, align: 'center', formatter: function (value, row, index) {
if (value) {
return $.format('<i class="text-info {0}"></i>', value);
}
return "";
}
},
{ title: "菜单路径", field: "Url", sortable: false },
{ title: "菜单类别", field: "CategoryName", sortable: true },
{
title: "目标", field: "Target", sortable: true, formatter: function (value, row, index) {
var ret = value;
switch (value) {
case "_self":
ret = "本窗口";
break;
case "_blank":
ret = "新窗口";
break;
case "_parent":
ret = "父级窗口";
break;
case "_top":
ret = "顶级窗口";
break;
default:
break;
}
return ret;
}
},
{
title: "菜单类型", field: "IsResource", sortable: true, formatter: function (value, row, index) {
return value === 0 ? "菜单" : "资源";
}
},
{
title: "所属应用", field: "ApplicationCode", sortable: true, formatter: function (value, row, index) {
return $('#app').next().find('[data-val="' + value + '"]:first').text();
}
}
]
}
});
$('table').smartTable({
url: Menu.url, //请求后台的URL*
sortName: 'Order',
queryParams: function (params) { return $.extend(params, { parentName: $('#txt_parent_menus_name').val(), name: $("#txt_menus_name").val(), category: $('#sel_menus_category').val(), isresource: $('#sel_menus_res').val() }); }, //传递参数(*
columns: [
{ checkbox: true },
{ title: "编辑", field: "Id", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "父级菜单", field: "ParentName", sortable: true },
{ title: "菜单名称", field: "Name", sortable: true },
{ title: "菜单序号", field: "Order", sortable: true },
{
title: "菜单图标", field: "Icon", sortable: false, align: 'center', formatter: function (value, row, index) {
if (value) {
return $.format('<i class="text-info {0}"></i>', value);
}
return "";
}
},
{ title: "菜单路径", field: "Url", sortable: false },
{ title: "菜单类别", field: "CategoryName", sortable: true },
{
title: "目标", field: "Target", sortable: true, formatter: function (value, row, index) {
var ret = value;
switch (value) {
case "_self":
ret = "本窗口";
break;
case "_blank":
ret = "新窗口";
break;
case "_parent":
ret = "父级窗口";
break;
case "_top":
ret = "顶级窗口";
break;
default:
break;
}
return ret;
}
},
{
title: "菜单类型", field: "IsResource", sortable: true, formatter: function (value, row, index) {
return value == 0 ? "菜单" : "资源";
}
},
{
title: "所属应用", field: "ApplicationCode", sortable: true, formatter: function (value, row, index) {
return $('#app').next().find('[data-val="' + value + '"]:first').text();
}
}
]
});
// validate
$('#dataForm').on('click', '[data-method]', function () {
var $this = $(this);
@ -174,11 +165,11 @@
$nestMenu.find('li[data-category="' + $category.val() + '"]').show();
// handler new menu
var did = $('#menuID').val();
if (did == "") did = 0;
if (did == 0) {
if (did === "") did = 0;
if (did === 0) {
var menuName = $('#name').val();
var menuCate = $category.val();
if (menuName == "") menuName = "新建菜单-未命名";
if (menuName === "") menuName = "新建菜单-未命名";
$nestMenu.find('ol.dd-list:first').append($.format('<li class="dd-item dd3-item" data-id="0" data-order="10" data-category="{1}"><div class="dd-handle dd3-handle"></div><div class="dd3-content"><label><span>{0}</span></label></div></li>', menuName, menuCate));
}
$nestMenu.find('li[data-id="' + did + '"] > div.dd3-content span').addClass('active');
@ -221,7 +212,7 @@
var mid = $('#menuID').val();
for (index in data) {
var $data = $(data[index]);
if ($data.attr('data-id') == mid || $data.attr('data-id') == 0) {
if ($data.attr('data-id') === mid || $data.attr('data-id') === 0) {
if (index > 0) index--;
$('#order').val($(data[index]).attr('data-order'));
break;
@ -236,7 +227,7 @@
// Dialog shown event
$dialog.on('show.bs.modal', function () {
var icon = $inputIcon.val();
if (icon == "") icon = "fa fa-dashboard";
if (icon === "") icon = "fa fa-dashboard";
$btnPickIcon.find('i').attr('class', icon);
});

View File

@ -21,7 +21,7 @@
var id = $this.attr('data-id');
var result = $this.attr('data-result');
$.bc({
id: id, url: User.url, method: "PUT", data: { type: "user", userIds: result }, title: result == "1" ? "授权用户" : "拒绝用户",
id: id, url: User.url, method: "PUT", data: { type: "user", userIds: result }, title: result === "1" ? "授权用户" : "拒绝用户",
callback: function (result) {
$table.bootstrapTable('refresh');
$.pullNotification($('.header .nav').reloadWidget());

View File

@ -19,27 +19,21 @@
dropZoneTitle: "请选择头像"
}).on('fileuploaded', function (event, data, previewId, index) {
var url = data.response.initialPreview[0];
if (!!url) $headerIcon.attr('src', url);
if (!!url === true) $headerIcon.attr('src', url);
});
var bsa = new BootstrapAdmin({
url: Profiles.url,
bootstrapTable: null,
dataEntity: new DataEntity({
map: {
Password: "currentPassword",
NewPassword: "newPassword",
DisplayName: "displayName",
UserName: "userName",
Css: "css"
}
})
var dataBinder = new DataEntity({
Password: "#currentPassword",
NewPassword: "#newPassword",
DisplayName: "#displayName",
UserName: "#userName",
Css: "#css"
});
$('button[data-method]').on('click', function (e) {
var $this = $(this);
if ($this.parent().attr("data-admin") === "True") return false;
var data = bsa.dataEntity.get();
var data = dataBinder.get();
switch ($this.attr('data-method')) {
case 'password':
data.UserStatus = 2;

View File

@ -12,19 +12,16 @@
var $nestMenu = $('#nestable_menu');
var $nestMenuInput = $nestMenu.find('div.dd3-content');
var bsa = new BootstrapAdmin({
$('table').lgbTable({
url: Role.url,
dataEntity: new DataEntity({
dataBinder: {
map: {
Id: "roleID",
RoleName: "roleName",
Description: "roleDesc"
}
}),
click: {
assign: [{
id: 'btn_assignUser',
click: function (row) {
Id: "#roleID",
RoleName: "#roleName",
Description: "#roleDesc"
},
events: {
'#btn_assignUser': function (row) {
$.bc({
id: row.Id, url: User.url, data: { type: "role" }, swal: false,
callback: function (result) {
@ -34,15 +31,13 @@
}).join('');
$dialogUserHeader.text($.format('{0}-用户授权窗口', row.RoleName));
$dialogUserForm.html(html).find('[data-toggle="tooltip"]').each(function (index, label) {
if (label.title == "") label.title = "未设置";
if (label.title === "") label.title = "未设置";
}).tooltip();
$dialogUser.modal('show');
}
});
}
}, {
id: 'btn_assignGroup',
click: function (row) {
},
'#btn_assignGroup': function (row) {
$.bc({
id: row.Id, url: Group.url, data: { type: "role" }, swal: false,
callback: function (result) {
@ -52,15 +47,13 @@
}).join('');
$dialogGroupHeader.text($.format('{0}-部门授权窗口', row.RoleName));
$dialogGroupForm.html(html).find('[data-toggle="tooltip"]').each(function (index, label) {
if (label.title == "") label.title = "未设置";
if (label.title === "") label.title = "未设置";
}).tooltip();
$dialogGroup.modal('show');
}
});
}
}, {
id: 'btn_assignMenu',
click: function (row) {
},
'#btn_assignMenu': function (row) {
$.bc({
id: row.Id, url: Menu.url, data: { type: "role" }, swal: false,
callback: function (result) {
@ -77,28 +70,22 @@
$dialogMenu.modal('show');
}
});
}
}, {
id: 'btnSubmitUser',
click: function (row) {
},
'#btnSubmitUser': function (row) {
var roleId = row.Id;
var userIds = $dialogUser.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: roleId, url: User.url, method: "PUT", data: { type: "role", userIds: userIds }, modal: '#dialogUser', title: User.title });
}
}, {
id: 'btnSubmitGroup',
click: function (row) {
},
'#btnSubmitGroup': function (row) {
var roleId = row.Id;
var groupIds = $dialogGroup.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: roleId, url: Group.url, method: "PUT", data: { type: "role", groupIds: groupIds }, modal: '#dialogGroup', title: Group.title });
}
}, {
id: 'btnSubmitMenu',
click: function (row) {
},
'#btnSubmitMenu': function (row) {
var roleId = row.Id;
var type = $btnSubmitMenu.data('type');
switch (type) {
@ -112,22 +99,18 @@
}
$.bc({ id: roleId, url: Menu.url, method: "PUT", data: { type: "role", menuIds: menuIds }, modal: '#dialogMenu', title: Menu.title });
}
}]
}
},
smartTable: {
sortName: 'RoleName',
queryParams: function (params) { return $.extend(params, { roleName: $("#txt_search_name").val(), description: $("#txt_role_desc").val() }); }, //传递参数(*
columns: [
{ title: "角色名称", field: "RoleName", sortable: true },
{ title: "角色描述", field: "Description", sortable: false }
]
}
});
$('table').smartTable({
url: Role.url, //请求后台的URL*
sortName: 'RoleName',
queryParams: function (params) { return $.extend(params, { roleName: $("#txt_search_name").val(), description: $("#txt_role_desc").val() }); }, //传递参数(*
columns: [
{ checkbox: true },
{ title: "编辑", field: "Id", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "角色名称", field: "RoleName", sortable: true },
{ title: "角色描述", field: "Description", sortable: false }
]
});
$nestMenu.nestMenu(function () {
$nestMenuInput = $nestMenu.find('div.dd3-content');
$nestMenuInput.on('click', ':checkbox', function () {

View File

@ -1,24 +1,17 @@
$(function () {
$('a[data-admin="False"]').hide();
var bsa = new BootstrapAdmin({
url: Settings.url,
bootstrapTable: null,
validateForm: null,
modal: null,
dataEntity: new DataEntity({
map: {
Title: "sysName",
Footer: "sysFoot"
}
})
var dataBinder = new DataEntity({
Title: "#sysName",
Footer: "#sysFoot"
});
$('button[data-method]').on('click', function (e) {
var $this = $(this);
var data = {};
switch ($this.attr('data-method')) {
case 'footer':
var data = bsa.dataEntity.get();
data = dataBinder.get();
$.bc({
url: Settings.url, data: { name: '网站页脚', code: data.Footer, category: Settings.title }, title: Settings.title,
callback: function (result) {
@ -27,7 +20,7 @@
});
break;
case 'title':
var data = bsa.dataEntity.get();
data = dataBinder.get();
$.bc({
url: Settings.url, data: { name: '网站标题', code: data.Title, category: Settings.title }, title: Settings.title,
callback: function (result) {
@ -100,7 +93,7 @@
},
swal: false
});
}
};
$('a[data-method]').on('click', function (e) {
e.preventDefault();
e.stopPropagation();

View File

@ -6,39 +6,34 @@
var $dialogGroupHeader = $('#myGroupModalLabel');
var $dialogGroupForm = $('#groupForm');
var bsa = new BootstrapAdmin({
$('table').lgbTable({
url: User.url,
dataEntity: new DataEntity({
dataBinder: {
map: {
Id: "userID",
UserName: "userName",
Password: "password",
DisplayName: "displayName",
NewPassword: "confirm"
}
}),
click: {
assign: [{
id: 'btn_assignRole',
click: function (row) {
Id: "#userID",
UserName: "#userName",
Password: "#password",
DisplayName: "#displayName",
NewPassword: "#confirm"
},
events: {
'#btn_assignRole': function (row) {
$.bc({
id: row.Id, url: Role.url, data: { type: "user" }, swal: false,
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
return $.format(htmlTemplate, element.Id, element.RoleName, element.Checked, element.Description);
}).join('')
}).join('');
$dialogRoleHeader.text($.format('{0}-角色授权窗口', row.DisplayName));
$dialogRoleForm.html(html).find('[data-toggle="tooltip"]').each(function (index, label) {
if (label.title == "") label.title = "未设置";
if (label.title === "") label.title = "未设置";
}).tooltip();
$dialogRole.modal('show');
}
});
}
}, {
id: 'btn_assignGroup',
click: function (row) {
},
'#btn_assignGroup': function (row) {
$.bc({
id: row.Id, url: Group.url, data: { type: "user" }, swal: false,
callback: function (result) {
@ -48,59 +43,51 @@
}).join('');
$dialogGroupHeader.text($.format('{0}-部门授权窗口', row.DisplayName));
$dialogGroupForm.html(html).find('[data-toggle="tooltip"]').each(function (index, label) {
if (label.title == "") label.title = "未设置";
if (label.title === "") label.title = "未设置";
}).tooltip();
$dialogGroup.modal('show');
}
});
}
}, {
id: 'btnSubmitRole',
click: function (row) {
},
'#btnSubmitRole': function (row) {
var userId = row.Id;
var roleIds = $dialogRole.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: userId, url: Role.url, method: 'PUT', data: { type: "user", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' });
}
}, {
id: 'btnSubmitGroup',
click: function (row) {
},
'#btnSubmitGroup': function (row) {
var userId = row.Id;
var groupIds = $dialogGroup.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
$.bc({ id: userId, url: Group.url, method: 'PUT', data: { type: "user", groupIds: groupIds }, title: Group.title, modal: '#dialogGroup' });
}
}]
},
callback: function (data) {
if (data && data.success && data.oper === 'save' && data.data.UserName === $('#userDisplayName').attr('data-userName')) {
$('#userDisplayName').text(data.data.DisplayName);
}
if (data && data.oper === 'create') {
$('#userName').prop('readonly', false).removeClass("ignore");
}
else if (data && data.oper === 'edit') {
$('#userName').prop('readonly', true).addClass("ignore");
}
}
},
callback: function (data) {
if (data && data.success && data.oper === 'save' && data.data.UserName == $('#userDisplayName').attr('data-userName')) {
$('#userDisplayName').text(data.data.DisplayName);
}
if (data && data.oper === 'create') {
$('#userName').prop('readonly', false).removeClass("ignore");
}
else if (data && data.oper === 'edit') {
$('#userName').prop('readonly', true).addClass("ignore");
}
smartTable: {
sortName: 'DisplayName',
sortOrder: "asc",
queryParams: function (params) { return $.extend(params, { name: $("#txt_search_name").val(), displayName: $('#txt_display_name').val() }); }, //传递参数(*
columns: [
{ title: "登陆名称", field: "UserName", sortable: true },
{ title: "显示名称", field: "DisplayName", sortable: true },
{ title: "注册时间", field: "RegisterTime", sortable: true },
{ title: "授权时间", field: "ApprovedTime", sortable: true },
{ title: "授权人", field: "ApprovedBy", sortable: true },
{ title: "说明", field: "Description", sortable: false }
]
}
});
$('table').smartTable({
url: User.url, //请求后台的URL*
sortName: 'DisplayName',
sortOrder: "asc",
queryParams: function (params) { return $.extend(params, { name: $("#txt_search_name").val(), displayName: $('#txt_display_name').val() }); }, //传递参数(*
columns: [
{ checkbox: true },
{ title: "编辑", field: "Id", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "登陆名称", field: "UserName", sortable: true },
{ title: "显示名称", field: "DisplayName", sortable: true },
{ title: "注册时间", field: "RegisterTime", sortable: true },
{ title: "授权时间", field: "ApprovedTime", sortable: true },
{ title: "授权人", field: "ApprovedBy", sortable: true },
{ title: "说明", field: "Description", sortable: false }
]
});
});