$(function () { var url = '../api/Notifications/'; var htmlNewUsers = '
  • {0}{1}{2}
  • '; var htmlApp = '
  • {0}{1}{2}
  • '; var htmlDb = '
  • {0}{1}{2}
  • '; function listData(options) { options = $.extend({ url: url, animation: true, ctl: $('a.fa-refresh') }, options); var category = options.ctl.length == 1 ? options.ctl.attr('data-category') : ""; if (options.animation) options.ctl.toggleClass('fa-spin'); $.ajax({ url: options.url + category, type: 'GET', success: function (result) { if (result) { if (category == '0' || category == '') { var content = result.Users.map(function (noti) { return $.format(htmlNewUsers, noti.Title, noti.Content, noti.RegisterTime, noti.ID); }).join(''); $('#tasks-users').html(content); } if (category == '1' || category == '') { var content = result.Apps.map(function (noti) { return $.format(htmlApp, noti.Title, noti.Content, noti.RegisterTime, noti.ID); }).join(''); $('#tasks-app').html(content); } if (category == '2' || category == '') { var content = result.Dbs.map(function (noti) { return $.format(htmlDb, noti.Title, noti.Content, noti.RegisterTime, noti.ID); }).join(''); $('#tasks-db').html(content); } } if (options.animation) options.ctl.toggleClass('fa-spin'); }, error: function (XMLHttpRequest, textStatus, errorThrown) { if (options.animation) options.ctl.toggleClass('fa-spin'); } }); } listData(); $('a.fa-refresh').on('click', function () { listData({ ctl: $(this) }); }); $('#tasks-users').on('click', 'button', function () { var id = $(this).attr('data-id'); var result = $(this).attr('data-result'); var data = { type: "user", userIds: result }; var title = result == "1" ? "授权用户" : "拒绝用户"; $.ajax({ url: '../api/Users/' + id, data: data, type: 'PUT', success: function (result) { if (result) swal("成功!", title, "success"); else swal("失败", title, "error"); var refresh = $('#tasks-users').parentsUntil('div.panel').last().prev().find('a.fa-refresh'); listData(refresh); }, error: function (XMLHttpRequest, textStatus, errorThrown) { swal("失败", title, "error"); } }); }); });