(function ($) { var cascadeMenu = function (menus) { var html = ""; $.each(menus, function (index, menu) { if (menu.Menus.length == 0) { html += $.format('
  • {5}{4}
  • ', menu.Id, menu.Icon, menu.Name, menu.Category, menu.Order, menu.CategoryName); } else { html += $.format('
  • {6}{5}
      {4}
  • ', menu.Id, menu.Icon, menu.Name, menu.Category, cascadeSubMenu(menu.Menus), menu.Order, menu.CategoryName); } }); return html; }; var cascadeSubMenu = function (menus) { var html = "" $.each(menus, function (index, menu) { html += $.format('
  • {5}{4}
  • ', menu.Id, menu.Icon, menu.Name, menu.Category, menu.Order, menu.CategoryName); }); return html; }; $.fn.extend({ nestMenu: function (callback) { var $this = $(this); $.bc({ Id: 0, url: Menu.url, data: { type: "user" }, swal: false, callback: function (result) { var html = ""; if ($.isArray(result)) html = cascadeMenu(result); $this.find('ol:first').html(html); $this.nestable(); callback(); } }); }, resetWidget: function () { var widgets = $(this).children('li'); widgets.each(function () { var widget = $(this).children('ul'); if (widget.children().length === 3) return; var last = widget.children(':last'); while (widget.children().length > 3) { widget.children(':eq(2)').remove(); } }); return $(this); } }); $.extend({ pullNotification: function () { if ($('.notify-row').length == 0) return; setTimeout(function () { NProgress.status = true; NProgress.configure({ trickle: false }); $.bc({ url: 'api/WS', method: 'GET', swal: false, callback: function (result) { NProgress.status = false; for (index in result) { var cate = result[index].Category; var msg = result[index].Message; switch (cate) { case "Notification": toastr.error(msg, "应用程序出现错误"); break; case "Users": toastr.info(msg, "新用户注册"); break; } }; if (result.length > 0) $.reloadWidget(); $.pullNotification(); } }); }, 5000); }, reloadWidget: function () { if ($('.notify-row').length == 0) return; $.bc({ url: Notifications.url, swal: false, method: 'GET', callback: function (result) { $('#logoutNoti').text(result.NewUsersCount); $('.notify-row').resetWidget(); // tasks // new users $('#msgHeaderTask').text(result.TasksCount); $('#msgHeaderTaskBadge').text(result.TasksCount); var htmlUserTemplate = '
  • {0}-{2}{1}%
    {1}% 完成
  • '; var html = result.Tasks.map(function (u) { return $.format(htmlUserTemplate, u.TaskName, u.TaskProgress, u.AssignDisplayName, u.Id); }).join(''); $(html).insertAfter($('#msgHeaderTaskContent')); // new users $('#msgHeaderUser').text(result.NewUsersCount); $('#msgHeaderUserBadge').text(result.NewUsersCount); htmlUserTemplate = '
  • {1}({0})
    {3}
  • '; html = result.Users.map(function (u) { return $.format(htmlUserTemplate, u.UserName, u.DisplayName, u.Description, u.Period); }).join(''); $(html).insertAfter($('#msgHeaderUserContent')); // apps $('#msgHeaderApp').text(result.AppExceptionsCount); $('#msgHeaderAppBadge').text(result.AppExceptionsCount); htmlUserTemplate = '
  • {0}
    {2}
  • '; html = result.Apps.map(function (u) { return $.format(htmlUserTemplate, u.ExceptionType, u.Message, u.Period); }).join(''); $(html).insertAfter($('#msgHeaderAppContent')); // dbs $('#msgHeaderDb').text(result.DbExceptionsCount); $('#msgHeaderDbBadge').text(result.DbExceptionsCount); htmlUserTemplate = '
  • {0}
    {2}
  • '; html = result.Dbs.map(function (u) { return $.format(htmlUserTemplate, u.ErrorPage, u.Message, u.Period); }).join(''); $(html).insertAfter($('#msgHeaderDbContent')); // messages $('#msgHeaderMsg').text(result.MessagesCount); $('#msgHeaderMsgBadge').text(result.MessagesCount); htmlUserTemplate = '
  • avatar{2}{4}{3}
  • '; html = result.Messages.map(function (u) { return $.format(htmlUserTemplate, u.Id, u.FromIcon, u.FromDisplayName, u.Title, u.Period, u.Content); }).join(''); $(html).insertAfter($('#msgHeaderMsgContent')); } }); } }); })(jQuery); $(function () { toastr.options = { "closeButton": true, "debug": false, "progressBar": true, "positionClass": "toast-bottom-right", "onclick": null, "showDuration": "600", "hideDuration": "2000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": "fadeIn", "hideMethod": "fadeOut" } var $sidebar = $("#sidebar"); var $main = $('#main-content'); var $breadNav = $('#breadNav'); $('#nav-accordion').dcAccordion({ autoExpand: true }); // custom scrollbar if (!$.browser.versions.ios) $("#sidebar").niceScroll({ styler: "fb", cursorcolor: "#e8403f", cursorwidth: '3', cursorborderradius: '10px', background: '#404040', spacebarenabled: false, cursorborder: '', scrollspeed: 60 }); $("#gotoTop").on('click', function (e) { e.preventDefault(); $('#main-content, .content-body, body').animate({ scrollTop: 0 }, 200); }); $('[role="tooltip"]').lgbTooltip(); // breadcrumb var arch = $('#nav-accordion').find('a.active').last(); $breadNav.text(arch.text() || $('title').text()); var top = (arch.offset() || { top: 0 }).top; if (top > 0) { var middle = $('header').outerHeight() + $sidebar.outerHeight() / 2; if (top > middle) $sidebar.animate({ scrollTop: top + arch.outerHeight() / 2 - middle }, 500); } $sidebar.on('click', 'a.dcjq-parent', function () { var o = ($(this).offset()); diff = 110 - o.top; if (diff > 0) $sidebar.scrollTo("-=" + Math.abs(diff), 500); else $sidebar.scrollTo("+=" + Math.abs(diff), 500); }); $('.sidebar-toggle-box').on('click', function () { if ($sidebar.is(":visible") === true) { $main.addClass('closed').removeClass('open'); $sidebar.parent().toggleClass('open') $(window).width() <= 768 ? setTimeout(function () { $sidebar.hide() }, 400) : $sidebar.hide(); } else { $sidebar.show() $sidebar.parent().toggleClass('open') $(window).width() <= 768 ? setTimeout(function () { $main.addClass('open').removeClass('closed') }, 400) : $main.addClass('open').removeClass('closed'); } }); $('.lgbDropdown').lgbDropdown(); // load widget data $.reloadWidget(); $.pullNotification(); });