2016-10-22 20:55:07 +08:00
|
|
|
|
(function ($) {
|
2016-11-15 14:31:53 +08:00
|
|
|
|
var handlerCallback = function (callback, e, data) {
|
|
|
|
|
if ($.isFunction(callback)) callback.call(e, data);
|
|
|
|
|
if ($.isFunction(this.options.callback)) this.options.callback.call(e, data);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-22 20:55:07 +08:00
|
|
|
|
BootstrapAdmin = function (options) {
|
|
|
|
|
var that = this;
|
2016-11-05 15:26:42 +08:00
|
|
|
|
options = options || {};
|
|
|
|
|
options.click = $.extend({}, BootstrapAdmin.settings.click, options.click);
|
2016-10-22 20:55:07 +08:00
|
|
|
|
this.options = $.extend({}, BootstrapAdmin.settings, options);
|
|
|
|
|
|
|
|
|
|
this.dataEntity = options.dataEntity;
|
|
|
|
|
if (!(this.dataEntity instanceof DataEntity) && window.console) {
|
|
|
|
|
window.console.log('初始化参数中没有DataEntity实例');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handler click event
|
|
|
|
|
for (name in this.options.click) {
|
2016-10-25 18:47:33 +08:00
|
|
|
|
var ele = this.options.click[name];
|
|
|
|
|
var cId = ele;
|
|
|
|
|
var event = null;
|
|
|
|
|
if ($.isArray(ele)) {
|
|
|
|
|
for (index in ele) {
|
|
|
|
|
if (ele[index].id === undefined) {
|
2016-10-28 21:26:13 +08:00
|
|
|
|
window.console.log('options.click.assign[{0}].{1}.id 未设置控件id', ele[index].id, name);
|
2016-10-25 18:47:33 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
cId = ele[index]['id'];
|
|
|
|
|
event = ele[index]['click'];
|
|
|
|
|
handler(cId, event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else handler(cId, event);
|
2016-10-22 20:55:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handler modal window show event
|
2016-11-10 00:47:23 +08:00
|
|
|
|
if (this.options.modal && this.options.modal.constructor === String) {
|
2016-10-22 20:55:07 +08:00
|
|
|
|
$('#' + this.options.modal).on('show.bs.modal', function (e) {
|
|
|
|
|
if (that.options.validateForm.constructor === String) {
|
2016-11-15 11:39:59 +08:00
|
|
|
|
var v = $('#' + that.options.validateForm);
|
|
|
|
|
var vf = v.validate();
|
|
|
|
|
vf.currentElements.each(function () { $(this).popover('destroy'); })
|
|
|
|
|
vf.resetForm();
|
|
|
|
|
v.find('div.form-group').removeClass("has-error has-success");
|
2016-10-22 20:55:07 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-10-25 18:47:33 +08:00
|
|
|
|
|
|
|
|
|
function handler(cid, event) {
|
|
|
|
|
var source = $("#" + cId);
|
|
|
|
|
source.data('click', name);
|
|
|
|
|
if (event !== null) source.data('event', event);
|
|
|
|
|
source.click(function () {
|
2016-11-15 14:31:53 +08:00
|
|
|
|
var method = source.data('click');
|
|
|
|
|
BootstrapAdmin.prototype[method].call(that, this, source.data('event'));
|
2016-10-25 18:47:33 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2016-10-22 20:55:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BootstrapAdmin.VERSION = "1.0";
|
|
|
|
|
BootstrapAdmin.Author = "Argo Zhang";
|
|
|
|
|
BootstrapAdmin.Email = "argo@163.com";
|
|
|
|
|
|
|
|
|
|
BootstrapAdmin.settings = {
|
|
|
|
|
url: undefined,
|
|
|
|
|
bootstrapTable: 'table',
|
|
|
|
|
validateForm: 'dataForm',
|
|
|
|
|
modal: 'dialogNew',
|
2016-10-24 20:53:05 +08:00
|
|
|
|
click: {
|
|
|
|
|
query: 'btn_query',
|
|
|
|
|
create: 'btn_add',
|
|
|
|
|
edit: 'btn_edit',
|
|
|
|
|
del: 'btn_delete',
|
2016-10-25 18:47:33 +08:00
|
|
|
|
save: 'btnSubmit',
|
|
|
|
|
assign: []
|
2016-10-24 20:53:05 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2016-10-22 20:55:07 +08:00
|
|
|
|
|
|
|
|
|
BootstrapAdmin.idFormatter = function (value, row, index) {
|
|
|
|
|
return "<a class='edit' href='javascript:void(0)'>" + value + "</a>";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BootstrapAdmin.prototype = {
|
|
|
|
|
constructor: BootstrapAdmin,
|
2016-10-24 19:12:22 +08:00
|
|
|
|
idEvents: function () {
|
|
|
|
|
var op = {
|
2016-10-25 18:47:33 +08:00
|
|
|
|
dataEntity: $.extend({}, this.options.dataEntity),
|
2016-10-24 19:12:22 +08:00
|
|
|
|
table: this.options.bootstrapTable,
|
|
|
|
|
modal: this.options.modal
|
|
|
|
|
};
|
|
|
|
|
return {
|
|
|
|
|
'click .edit': function (e, value, row, index) {
|
|
|
|
|
op.dataEntity.load(row);
|
2016-10-25 18:47:33 +08:00
|
|
|
|
$(op.table).bootstrapTable('uncheckAll');
|
|
|
|
|
$(op.table).bootstrapTable('check', index);
|
2016-10-24 19:12:22 +08:00
|
|
|
|
$('#' + op.modal).modal("show");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2016-10-22 20:55:07 +08:00
|
|
|
|
|
2016-11-15 14:31:53 +08:00
|
|
|
|
query: function (e, callback) {
|
2016-10-22 20:55:07 +08:00
|
|
|
|
if (this.options.bootstrapTable.constructor === String) $(this.options.bootstrapTable).bootstrapTable('refresh');
|
2016-11-15 14:31:53 +08:00
|
|
|
|
handlerCallback.call(this, callback, e, { oper: 'query' });
|
2016-10-22 20:55:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
2016-11-15 14:31:53 +08:00
|
|
|
|
create: function (e, callback) {
|
2016-10-25 18:47:33 +08:00
|
|
|
|
if (this.dataEntity instanceof DataEntity) this.dataEntity.reset();
|
2016-10-22 20:55:07 +08:00
|
|
|
|
if (this.options.modal.constructor === String) $('#' + this.options.modal).modal("show");
|
|
|
|
|
if (this.options.bootstrapTable.constructor === String) $(this.options.bootstrapTable).bootstrapTable('uncheckAll');
|
2016-11-15 14:31:53 +08:00
|
|
|
|
handlerCallback.call(this, callback, e, { oper: 'create' });
|
2016-10-22 20:55:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
2016-11-15 14:31:53 +08:00
|
|
|
|
edit: function (e, callback) {
|
2016-10-25 18:47:33 +08:00
|
|
|
|
var options = this.options;
|
2016-11-15 14:31:53 +08:00
|
|
|
|
var data = {};
|
|
|
|
|
if (options.bootstrapTable.constructor === String) {
|
|
|
|
|
var arrselections = $(options.bootstrapTable).bootstrapTable('getSelections');
|
|
|
|
|
if (arrselections.length == 0) {
|
|
|
|
|
swal('请选择要编辑的数据', "编辑操作", "warning");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (arrselections.length > 1) {
|
|
|
|
|
swal('请选择一个要编辑的数据', "编辑操作", "warning");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
data = arrselections[0];
|
|
|
|
|
if (this.dataEntity instanceof DataEntity) this.dataEntity.load(data);
|
|
|
|
|
if (options.modal.constructor === String) $('#' + options.modal).modal("show");
|
|
|
|
|
}
|
2016-10-22 20:55:07 +08:00
|
|
|
|
}
|
2016-11-15 14:31:53 +08:00
|
|
|
|
handlerCallback.call(this, callback, e, { oper: 'edit', data: data });
|
2016-10-22 20:55:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
2016-11-15 14:31:53 +08:00
|
|
|
|
del: function (e, callback) {
|
|
|
|
|
var that = this;
|
2016-10-22 20:55:07 +08:00
|
|
|
|
var options = this.options;
|
2016-11-15 14:31:53 +08:00
|
|
|
|
if (options.bootstrapTable.constructor === String) {
|
|
|
|
|
var arrselections = $(options.bootstrapTable).bootstrapTable('getSelections');
|
|
|
|
|
if (arrselections.length == 0) {
|
|
|
|
|
swal('请选择要删除的数据', "删除操作", "warning");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
swal({
|
|
|
|
|
title: "您确定要删除吗?",
|
|
|
|
|
text: "删除操作",
|
|
|
|
|
type: "warning",
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
closeOnConfirm: true,
|
|
|
|
|
confirmButtonText: "是的,我要删除",
|
|
|
|
|
confirmButtonColor: "#d9534f",
|
|
|
|
|
cancelButtonText: "取消"
|
|
|
|
|
}, function () {
|
|
|
|
|
var iDs = arrselections.map(function (element, index) { return element.ID }).join(",");
|
|
|
|
|
options.IDs = iDs;
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: options.url,
|
|
|
|
|
data: { "": iDs },
|
|
|
|
|
type: 'DELETE',
|
|
|
|
|
success: function (result) {
|
|
|
|
|
if (result) { swal("成功!", "删除数据", "success"); $(options.bootstrapTable).bootstrapTable('refresh'); }
|
|
|
|
|
else swal("失败", "删除数据", "error");
|
|
|
|
|
handlerCallback.call(that, callback, e, { oper: 'del', success: !!result, data: iDs });
|
|
|
|
|
},
|
|
|
|
|
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
|
|
|
|
swal("失败", "删除数据", "error");
|
|
|
|
|
handlerCallback.call(that, callback, e, { oper: 'del', success: false });
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-22 20:55:07 +08:00
|
|
|
|
});
|
2016-11-15 14:31:53 +08:00
|
|
|
|
}
|
2016-10-22 20:55:07 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2016-11-15 14:31:53 +08:00
|
|
|
|
save: function (e, callback) {
|
|
|
|
|
var that = this;
|
2016-10-25 18:47:33 +08:00
|
|
|
|
var options = $.extend({ data: {} }, this.options);
|
|
|
|
|
if (this.dataEntity instanceof DataEntity) options = $.extend(options, { data: this.dataEntity.get() });
|
2016-10-22 20:55:07 +08:00
|
|
|
|
if (options.validateForm.constructor === String && !$("#" + options.validateForm).valid()) return;
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: options.url,
|
|
|
|
|
data: options.data,
|
|
|
|
|
type: 'POST',
|
|
|
|
|
success: function (result) {
|
2016-11-15 14:31:53 +08:00
|
|
|
|
var finalData = null;
|
|
|
|
|
var index = 0;
|
2016-10-22 20:55:07 +08:00
|
|
|
|
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++) {
|
2016-11-15 14:31:53 +08:00
|
|
|
|
finalData = allTableData[index];
|
|
|
|
|
if (finalData.ID == options.data.ID) {
|
|
|
|
|
$(options.bootstrapTable).bootstrapTable('updateRow', { index: index, row: $.extend(finalData, options.data) });
|
2016-10-22 20:55:07 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$(options.bootstrapTable).bootstrapTable('refresh');
|
2016-11-15 14:31:53 +08:00
|
|
|
|
finalData = options.data;
|
2016-10-22 20:55:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (options.modal.constructor === String) $('#' + options.modal).modal("hide");
|
|
|
|
|
swal("成功", "保存数据", "success");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
swal("失败", "保存数据", "error");
|
|
|
|
|
}
|
2016-11-15 14:31:53 +08:00
|
|
|
|
handlerCallback.call(that, callback, e, { oper: 'save', success: !!result, index: index, data: finalData });
|
2016-10-22 20:55:07 +08:00
|
|
|
|
},
|
|
|
|
|
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
|
|
|
|
swal("失败", "保存数据失败", "error");
|
2016-11-15 14:31:53 +08:00
|
|
|
|
handlerCallback.call(that, callback, e, { oper: 'save', success: false });
|
2016-10-22 20:55:07 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-25 18:47:33 +08:00
|
|
|
|
},
|
|
|
|
|
|
2016-11-15 14:31:53 +08:00
|
|
|
|
assign: function (e, callback) {
|
2016-10-25 18:47:33 +08:00
|
|
|
|
var options = this.options;
|
2016-11-10 00:47:23 +08:00
|
|
|
|
var row = {};
|
|
|
|
|
if (options.bootstrapTable && options.bootstrapTable.constructor === String) {
|
|
|
|
|
var arrselections = $(options.bootstrapTable).bootstrapTable('getSelections');
|
|
|
|
|
if (arrselections.length == 0) {
|
|
|
|
|
swal('请选择要编辑的数据', "编辑操作", "warning");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (arrselections.length > 1) {
|
|
|
|
|
swal('请选择一个要编辑的数据', "编辑操作", "warning");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
row = arrselections[0];
|
2016-10-25 18:47:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-15 14:31:53 +08:00
|
|
|
|
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 });
|
|
|
|
|
}
|
2016-10-25 18:47:33 +08:00
|
|
|
|
};
|
|
|
|
|
|
2016-11-03 15:36:51 +08:00
|
|
|
|
var htmlTemplate = '<div class="form-group checkbox col-lg-3 col-xs-4"><label class="tooltips" data-placement="top" data-original-title="{3}" title="{3}"><input type="checkbox" value="{0}" {2}/>{1}</label></div>';
|
2016-11-02 15:11:09 +08:00
|
|
|
|
|
|
|
|
|
var processData = function (options) {
|
2016-11-09 00:34:47 +08:00
|
|
|
|
var data = $.extend({ data: { type: "" }, remote: true, method: "POST", Id: "", url: this.url, title: this.title, html: this.html }, options);
|
|
|
|
|
|
|
|
|
|
if (data.remote) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: data.url + data.Id,
|
|
|
|
|
data: data.data,
|
|
|
|
|
type: data.method,
|
|
|
|
|
success: function (result) {
|
|
|
|
|
success(result);
|
|
|
|
|
},
|
|
|
|
|
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
|
|
|
|
if ($.isFunction(data.callback)) data.callback(false);
|
2016-10-28 14:45:09 +08:00
|
|
|
|
}
|
2016-11-09 00:34:47 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else success()
|
|
|
|
|
|
|
|
|
|
function success(result) {
|
|
|
|
|
if ($.isFunction(data.callback)) {
|
|
|
|
|
if ($.isArray(result)) {
|
2016-11-14 20:44:08 +08:00
|
|
|
|
var formatData = result;
|
|
|
|
|
if ($.isFunction(data.html)) formatData = data.html(result);
|
|
|
|
|
data.callback(formatData);
|
2016-11-09 00:34:47 +08:00
|
|
|
|
return;
|
2016-10-28 21:26:13 +08:00
|
|
|
|
}
|
2016-11-09 00:34:47 +08:00
|
|
|
|
}
|
|
|
|
|
else if ($.isPlainObject(data.callback) && data.callback.modal !== undefined) {
|
|
|
|
|
$("#" + data.callback.modal).modal('hide');
|
|
|
|
|
}
|
|
|
|
|
if (data.remote) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
if (result) { swal("成功", data.title, "success"); }
|
|
|
|
|
else { swal("失败", data.title, "error"); }
|
2016-10-25 18:47:33 +08:00
|
|
|
|
}
|
2016-11-09 00:34:47 +08:00
|
|
|
|
if ($.isFunction(data.callback)) data.callback(result);
|
|
|
|
|
}
|
2016-10-28 13:36:43 +08:00
|
|
|
|
}
|
2016-11-02 15:11:09 +08:00
|
|
|
|
// Role
|
|
|
|
|
Role = {
|
2016-11-09 00:34:47 +08:00
|
|
|
|
url: '../api/Roles/',
|
|
|
|
|
title: "授权角色",
|
|
|
|
|
html: function (result) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
return $.map(result, function (element, index) {
|
|
|
|
|
return $.format(htmlTemplate, element.ID, element.RoleName, element.Checked, element.Description);
|
|
|
|
|
}).join('');
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-10-28 13:36:43 +08:00
|
|
|
|
Role.getRolesByUserId = function (userId, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: userId, callback: callback, data: { type: "user" } });
|
2016-10-25 18:47:33 +08:00
|
|
|
|
};
|
2016-10-27 17:56:00 +08:00
|
|
|
|
Role.getRolesByGroupId = function (groupId, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: groupId, callback: callback, data: { type: "group" } });
|
2016-10-25 18:47:33 +08:00
|
|
|
|
};
|
2016-10-28 11:12:25 +08:00
|
|
|
|
Role.getRolesByMenuId = function (menuId, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: menuId, callback: callback, data: { type: "menu" } });
|
2016-10-28 11:12:25 +08:00
|
|
|
|
};
|
2016-10-25 18:47:33 +08:00
|
|
|
|
Role.saveRolesByUserId = function (userId, roleIds, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: userId, callback: callback, method: "PUT", data: { type: "user", roleIds: roleIds } });
|
2016-10-25 18:47:33 +08:00
|
|
|
|
}
|
2016-10-27 17:56:00 +08:00
|
|
|
|
Role.saveRolesByGroupId = function (groupId, roleIds, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: groupId, callback: callback, method: "PUT", data: { type: "group", roleIds: roleIds } });
|
2016-10-27 17:56:00 +08:00
|
|
|
|
}
|
2016-10-28 11:12:25 +08:00
|
|
|
|
Role.saveRolesByMenuId = function (menuId, roleIds, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: menuId, callback: callback, method: "PUT", data: { type: "menu", roleIds: roleIds } });
|
2016-10-28 11:12:25 +08:00
|
|
|
|
};
|
2016-11-02 15:11:09 +08:00
|
|
|
|
// Users
|
|
|
|
|
User = {
|
2016-11-09 00:34:47 +08:00
|
|
|
|
url: '../api/Users/',
|
|
|
|
|
title: "授权用户",
|
|
|
|
|
html: function (result) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
return $.map(result, function (element, index) {
|
|
|
|
|
return $.format(htmlTemplate, element.ID, element.DisplayName, element.Checked, element.UserName);
|
|
|
|
|
}).join('');
|
|
|
|
|
}
|
2016-10-28 20:18:12 +08:00
|
|
|
|
}
|
|
|
|
|
User.getUsersByRoleId = function (roleId, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: roleId, callback: callback, data: { type: "role" } });
|
2016-10-28 20:18:12 +08:00
|
|
|
|
};
|
|
|
|
|
User.saveUsersByRoleId = function (roleId, userIds, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", userIds: userIds } });
|
2016-10-28 20:18:12 +08:00
|
|
|
|
}
|
2016-10-29 17:38:23 +08:00
|
|
|
|
User.getUsersByGroupeId = function (groupId, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: groupId, callback: callback, data: { type: "group" } });
|
2016-10-29 17:38:23 +08:00
|
|
|
|
};
|
|
|
|
|
User.saveUsersByGroupId = function (groupId, userIds, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: groupId, callback: callback, method: "PUT", data: { type: "group", userIds: userIds } });
|
2016-10-29 17:38:23 +08:00
|
|
|
|
}
|
2016-11-02 15:11:09 +08:00
|
|
|
|
// Groups
|
|
|
|
|
Group = {
|
2016-11-09 00:34:47 +08:00
|
|
|
|
url: '../api/Groups/',
|
|
|
|
|
title: "授权部门",
|
|
|
|
|
html: function (result) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
return $.map(result, function (element, index) {
|
|
|
|
|
return $.format(htmlTemplate, element.ID, element.GroupName, element.Checked, element.Description);
|
|
|
|
|
}).join('');
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-10-28 21:46:48 +08:00
|
|
|
|
Group.getGroupsByUserId = function (userId, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: userId, callback: callback, data: { type: "user" } });
|
2016-10-28 21:46:48 +08:00
|
|
|
|
};
|
|
|
|
|
Group.saveGroupsByUserId = function (userId, groupIds, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: userId, callback: callback, method: "PUT", data: { type: "user", groupIds: groupIds } });
|
2016-10-25 18:47:33 +08:00
|
|
|
|
};
|
2016-10-27 17:56:00 +08:00
|
|
|
|
Group.getGroupsByRoleId = function (roleId, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: roleId, callback: callback, data: { type: "role" } });
|
2016-10-29 09:24:55 +08:00
|
|
|
|
};
|
2016-10-27 17:56:00 +08:00
|
|
|
|
Group.saveGroupsByRoleId = function (roleId, groupIds, callback) {
|
2016-11-02 15:11:09 +08:00
|
|
|
|
processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", groupIds: groupIds } });
|
2016-10-29 09:24:55 +08:00
|
|
|
|
};
|
2016-11-07 21:41:17 +08:00
|
|
|
|
//Menus
|
|
|
|
|
Menu = {
|
2016-11-09 00:34:47 +08:00
|
|
|
|
url: '../api/Menus/',
|
2016-11-15 14:31:53 +08:00
|
|
|
|
title: "授权菜单",
|
|
|
|
|
html: function (result) {
|
|
|
|
|
var htmlString = "";
|
|
|
|
|
if ($.isArray(result)) {
|
|
|
|
|
htmlString = Menu.cascadeMenu(result)
|
|
|
|
|
}
|
|
|
|
|
return htmlString;
|
|
|
|
|
}
|
2016-11-07 21:41:17 +08:00
|
|
|
|
}
|
2016-11-15 14:31:53 +08:00
|
|
|
|
Menu.cascadeMenu = function (menus) {
|
|
|
|
|
var html = "";
|
|
|
|
|
$.each(menus, function (index, menu) {
|
|
|
|
|
if (menu.Menus.length == 0) {
|
|
|
|
|
html += $.format('<li class="dd-item dd3-item" data-id="{0}" data-category="{3}"><div class="dd-handle dd3-handle"></div><div class="dd3-content"><label><input type="checkbox" value="{0}"><span><i class="{1}"></i>{2}</span></label><label><input type="radio" name="menu" value="{0}"><span><i class="{1}"></i>{2}</span></label></div></li>', menu.ID, menu.Icon, menu.Name, menu.Category);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
html = $.format('<li class="dd-item dd3-item" data-id="{0}" data-category="{3}"><div class="dd-handle dd3-handle"></div><div class="dd3-content"><label><input type="checkbox" value="{0}"><span><i class="{1}"></i>{2}</span></label><label><input type="radio" name="menu" value="{0}"><span><i class="{1}"></i>{2}</span></label></div></li><ol class="dd-list">{4}</ol>', menu.ID, menu.Icon, menu.Name, menu.Category, Menu.cascadeMenu(menu.Menus));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
Menu.getMenus = function (callback) {
|
|
|
|
|
processData.call(this, { Id: 0, callback: callback, data: { type: "user" } });
|
|
|
|
|
};
|
2016-11-07 21:41:17 +08:00
|
|
|
|
Menu.getMenusByRoleId = function (roleId, callback) {
|
2016-11-14 20:44:08 +08:00
|
|
|
|
processData.call(this, { Id: roleId, callback: callback, data: { type: "role" } });
|
2016-11-07 21:41:17 +08:00
|
|
|
|
};
|
|
|
|
|
Menu.saveMenusByRoleId = function (roleId, menuIds, callback) {
|
2016-11-09 00:34:47 +08:00
|
|
|
|
processData.call(this, { Id: roleId, callback: callback, method: "PUT", data: { type: "role", menuIds: menuIds } });
|
2016-11-07 21:41:17 +08:00
|
|
|
|
};
|
2016-11-10 00:47:23 +08:00
|
|
|
|
//Profiles
|
|
|
|
|
Profiles = {
|
|
|
|
|
url: '../api/Profiles/',
|
|
|
|
|
title: "个性化维护"
|
|
|
|
|
}
|
|
|
|
|
Profiles.saveWebSite = function (options) {
|
|
|
|
|
processData.call(this, { data: options });
|
|
|
|
|
}
|
2016-10-20 17:55:29 +08:00
|
|
|
|
})(jQuery);
|