BootstrapAdmin/Bootstrap.Admin/wwwroot/js/settings.js

115 lines
4.9 KiB
JavaScript
Raw Normal View History

2018-06-07 00:45:47 +08:00
$(function () {
$('a[data-admin="False"]').hide();
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':
data = dataBinder.get();
$.bc({
url: Settings.url, data: { name: '网站页脚', code: data.Footer, category: Settings.title }, title: Settings.title,
callback: function (result) {
if (result) $('#websiteFooter').text(data.Footer);
2018-06-07 00:45:47 +08:00
}
});
break;
case 'title':
data = dataBinder.get();
$.bc({
url: Settings.url, data: { name: '网站标题', code: data.Title, category: Settings.title }, title: Settings.title,
callback: function (result) {
if (result) $('#websiteTitle').text(data.Title);
2018-06-07 00:45:47 +08:00
}
});
break;
case 'css':
var cssDefine = $css.val();
$.bc({
url: Settings.url, data: { name: '使用样式', code: cssDefine, category: '当前样式' }, title: '网站样式',
callback: function (result) {
if (result) {
window.setTimeout(function () { window.location.reload(true); }, 1000);
2018-06-07 00:45:47 +08:00
}
}
});
break;
2018-06-07 00:45:47 +08:00
}
});
var $sortable = $('#sortable');
var $refresh = $('a[data-method="refresh"]');
2018-06-07 00:45:47 +08:00
var listCacheUrl = function (options) {
$refresh.addClass('fa-spin');
options = $.extend({ clear: false }, options);
2018-06-07 00:45:47 +08:00
$sortable.html('');
$.bc({
url: Settings.url,
method: 'GET',
callback: function (urls) {
if (urls && $.isArray(urls)) {
$.each(urls, function (index, item) {
if (options.clear) options.url = item.Url + "?clear=clear";
else options.url = item.Url;
$.bc({
url: options.url,
xhrFields: {
withCredentials: true
},
callback: function (result) {
if ($.isArray(result)) {
var html = '<div class="cache-item"><i class="fa fa-ellipsis-v"></i><div><span data-toggle="tooltip" title="{2}">{2}</span><span class="badge badge-pill badge-success">{0}</span></div><span title="{3}">{3}</span><div><span>{7}</span><button class="btn btn-danger" title="{1}" data-url="{5}?cacheKey={1}" data-toggle="tooltip" data-self="{6}" data-placement="left"><i class="fa fa-trash-o"></i></button></div></div>';
var content = result.sort(function (x, y) {
return x.Key > y.Key ? 1 : -1;
}).map(function (ele) {
return $.format(html, ele.Interval, ele.Key, ele.Desc, ele.Value, '', $.format(item.Url, ele.Key), item.Self, Math.max(0, ele.Interval - Math.round((new Date() - new Date(ele.CreateTime.replace(/-/g, '/'))) / 1000)));
}).join('');
$sortable.append($.format('<h6 class="cache-title">{0}</h6>', item.Desc));
$sortable.append(content);
$sortable.find('[data-toggle="tooltip"]').tooltip();
}
if (index === urls.length - 1) $refresh.removeClass('fa-spin');
}
});
2018-06-07 00:45:47 +08:00
});
}
else $refresh.removeClass('fa-spin');
2018-06-07 00:45:47 +08:00
}
});
};
2018-06-07 00:45:47 +08:00
var listCache = function (options) {
$.bc({
url: options.url,
xhrFields: {
withCredentials: true
}
2018-06-07 00:45:47 +08:00
});
};
$('a[data-method]').on('click', function (e) {
e.preventDefault();
e.stopPropagation();
var $this = $(this).tooltip('hide');
var options = {};
switch ($this.attr('data-method')) {
case 'clear':
options.clear = true;
break;
case 'refresh':
break;
}
listCacheUrl(options);
}).last().trigger('click');
2018-06-07 00:45:47 +08:00
$sortable.on('click', '.btn', function () {
2018-08-03 18:12:35 +08:00
$(this).tooltip('dispose');
listCache({ url: $(this).attr('data-url') });
2018-06-07 00:45:47 +08:00
listCacheUrl();
});
var $css = $('#dictCssDefine').dropdown('val');
});