diff --git a/.gitignore b/.gitignore index 8641f1b58..f7c829d2e 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ public/uploads/assets/*.* backups/ public/uploads/assets/upload/ + +stats\.json diff --git a/package.json b/package.json index 57b65ba18..960c50b81 100644 --- a/package.json +++ b/package.json @@ -163,6 +163,7 @@ "supertest": "3.4.1", "terser-webpack-plugin": "1.2.1", "webpack": "4.29.0", + "webpack-bundle-analyzer": "3.0.4", "webpack-cli": "3.2.1" }, "release": { diff --git a/src/public/js/angularjs/controllers.js b/src/public/js/angularjs/controllers.js index 4fcbb5ca8..64a62041c 100644 --- a/src/public/js/angularjs/controllers.js +++ b/src/public/js/angularjs/controllers.js @@ -26,7 +26,6 @@ define([ 'angularjs/controllers/notices', 'angularjs/controllers/plugins', 'angularjs/controllers/reports', - 'angularjs/controllers/settings-permissions', 'angularjs/controllers/editor' ], function ($, angular, _) { return angular @@ -42,19 +41,7 @@ define([ 'trudesk.controllers.notices', 'trudesk.controllers.plugins', 'trudesk.controllers.reports', - 'trudesk.controllers.settings.permissions', 'trudesk.controllers.editor' ]) - .controller('TrudeskController', function ($rootScope, $scope) { - $scope.submitForm = function (formName, $event) { - if (_.isNull(formName) || _.isUndefined(formName)) return true - - $event.preventDefault() - - var form = $('#' + formName) - if (!_.isUndefined(form)) { - form.submit() - } - } - }) + .controller('TrudeskController', function ($rootScope, $scope) {}) }) diff --git a/src/public/js/angularjs/controllers/accounts.js b/src/public/js/angularjs/controllers/accounts.js index 6cc364834..59cc1581d 100644 --- a/src/public/js/angularjs/controllers/accounts.js +++ b/src/public/js/angularjs/controllers/accounts.js @@ -12,428 +12,39 @@ * Copyright (c) 2014-2019. All rights reserved. */ -define([ - 'angular', - 'underscore', - 'jquery', - 'modules/helpers', - 'uikit', - 'pages/accounts', - 'history', - 'selectize', - 'formvalidator', - 'multiselect' -], function (angular, _, $, helpers, UIkit, accountsPage) { - return angular - .module('trudesk.controllers.accounts', []) - .controller('accountsCtrl', function ($scope, $http, $timeout, $window, $log) { - function checkGroupValidation () { - var data = {} - var form = $('#createAccountForm') - data.aGrps = form.find('select[name="caGrps[]"]').val() - - if (!data.aGrps || data.aGrps.length < 1) { - // Validate Group - $('label[for="caGrps"]').css('color', '#d85030') - $('select[name="caGrps[]"] + .selectize-control > .selectize-input').css('border-bottom', '1px solid #d85030') - $('.aGrps-error-message') - .removeClass('hide') - .css('display', 'block') - .css('color', '#d85030') - .css('font-weight', 'bold') - return false - } - - $('label[for="caGrps"]').css('color', '#4d4d4d') - $('select[name="caGrps[]"] + .selectize-control > .selectize-input').css( - 'border-bottom', - '1px solid rgba(0,0,0,.12)' - ) - $('.aGrps-error-message').addClass('hide') - return true - } - - $scope.createAccount = function (event) { - var data = {} - var form = $('#createAccountForm') - // if (!form.isValid(null, null, false)) return true; - if (!form.isValid(null, null, false)) { - checkGroupValidation() - return false - } - - if (!checkGroupValidation()) { - event.preventDefault() - return false - } - - event.preventDefault() - form.serializeArray().map(function (x) { - data[x.name] = x.value - }) - data.aGrps = form.find('select[name="caGrps[]"]').val() - $http({ - method: 'POST', - url: '/api/v1/users/create', - data: data, - headers: { 'Content-Type': 'application/json' } - }) - .success(function (data) { - if (!data.success) { - if (data.error) { - helpers.UI.showSnackbar('Error: ' + data.error, true) - return - } - - helpers.UI.showSnackbar('Error Creating Account', true) - } - - helpers.UI.showSnackbar({ text: 'Account Created' }) - - // Refresh UserGrid - History.pushState( - null, - null, - '/accounts/?refresh=' + (Math.floor(Math.random() * (99999 - 10000 + 1)) + 10000) - ) - - UIkit.modal('#accountCreateModal').hide() - }) - .error(function (err) { - $log.log('[trudesk:accounts:createAccount]', err) - helpers.UI.showSnackbar('An error occurred while creating the account. Check Console.', true) - }) - } - - var running = false - $scope.deleteAccount = function ($event) { - if (running) { - return true - } - - $event.preventDefault() - var self = $($event.target) - var username = self.attr('data-username') - if (_.isUndefined(username)) { - return true - } - - running = true - $http - .delete('/api/v1/users/' + username) - .success(function (data) { - if (!data.success) { - helpers.UI.showSnackbar(data.error, true) - running = false - return true - } - - if (data.disabled) { - self.parents('.tru-card-head').addClass('tru-card-head-deleted') - self.addClass('hide') - self - .parents('.uk-nav') - .find('.enable-account-action') - .removeClass('hide') - - helpers.UI.showSnackbar('Account ' + username + ' Successfully Disabled', false) - } else { - self - .parents('.tru-card[data-card-username]') - .parent() - .remove() - UIkit.$html.trigger('changed.uk.dom') - - helpers.UI.showSnackbar('Account ' + username + ' Successfully Deleted', false) - } - - running = false - }) - .error(function (err) { - $log.log('[trudesk:accounts:deleteAccount] - Error: ' + err.error) - helpers.UI.showSnackbar(err.error, true) - - running = false - }) - } - - $scope.enableAccount = function ($event) { - $event.preventDefault() - var self = $($event.target) - var username = self.attr('data-username') - if (_.isUndefined(username)) { - return true - } - - $http - .get('/api/v1/users/' + username + '/enable') - .success(function (data) { - if (!data.success) { - helpers.UI.showSnackbar(data.error, true) - return - } - - self.parents('.tru-card-head').removeClass('tru-card-head-deleted') - self.addClass('hide') - self - .parents('.uk-nav') - .find('.delete-account-action') - .removeClass('hide') - - helpers.UI.showSnackbar('Account successfully enabled', false) - }) - .error(function (err) { - $log.log('[trudesk:accounts:enableAccount] - Error: ' + err.error) - helpers.UI.showSnackbar(err.error, true) - }) - } - - $scope.editAccount = function ($event) { - $event.preventDefault() - - var self = $($event.target) - var username = self.attr('data-username') - if (_.isUndefined(username)) return true - - var $menu = self.parents('.tru-card-head-menu') - if (!_.isUndefined($menu)) $menu.find('.uk-dropdown').removeClass('uk-dropdown-shown uk-dropdown-active') - - $http - .get('/api/v1/users/' + username) - .success(function (data) { - var editAccountModal = $('#editAccountModal') - var form = editAccountModal.find('form#editAccountForm') - var user = data.user - if (_.isUndefined(user) || _.isNull(user)) return true - - var loggedInAccount = $window.trudeskSessionService.getUser() - if (loggedInAccount === null) return true - - var $userHeadingContent = $('.user-heading-content') - $userHeadingContent.find('.js-username').text(user.username) - if (!user.title) $userHeadingContent.find('.js-user-title').text('') - else $userHeadingContent.find('.js-user-title').text(user.title) - - var isEditingSelf = false - if (user.username === loggedInAccount.username) isEditingSelf = true - - var canEdit = false - var hasEdit = helpers.canUser('accounts:update') - if (isEditingSelf && hasEdit) { - hasEdit = true - canEdit = true - } - - if ( - helpers.hasHierarchyEnabled(loggedInAccount.role._id) && - helpers.hasPermOverRole(user.role._id, loggedInAccount.role._id) - ) - canEdit = true - - if (!canEdit) { - // Disable editing user with higher roles. - form - .find('#aPass') - .parent() - .hide() - form - .find('#aPassConfirm') - .parent() - .hide() - form - .find('#aRole') - .parent() - .hide() - form.find('#aFullname').attr('disabled', 'disabled') - form.find('#aTitle').attr('disabled', 'disabled') - form.find('#aEmail').attr('disabled', 'disabled') - form.find('#aGrps').attr('disabled', 'disabled') - form - .find('#aSaveButton') - .addClass('disabled') - .attr('disabled', 'disabled') - } else { - form - .find('#aPass') - .parent() - .show() - form - .find('#aPassConfirm') - .parent() - .show() - form - .find('#aRole') - .parent() - .show() - form.find('#aFullname').attr('disabled', false) - form.find('#aTitle').attr('disabled', false) - form.find('#aEmail').attr('disabled', false) - form.find('#aGrps').attr('disabled', false) - form - .find('#aSaveButton') - .removeClass('disabled') - .attr('disabled', false) - } - - form.find('#aId').val(user._id) - form - .find('#aUsername') - .val(user.username) - .prop('disabled', true) - .parent() - .addClass('md-input-filled') - form - .find('#aFullname') - .val(user.fullname) - .parent() - .addClass('md-input-filled') - form - .find('#aTitle') - .val(user.title) - .parent() - .addClass('md-input-filled') - form - .find('#aEmail') - .val(user.email) - .parent() - .addClass('md-input-filled') - form.find('#aRole option[value="' + user.role._id + '"]').prop('selected', true) - if (form.find('#aRole').length > 0) { - var $selectizeRole = form.find('#aRole')[0].selectize - $selectizeRole.setValue(user.role._id, true) - - var items = _.map($selectizeRole.options, function (m) { - return m.value - }) - - var assignableRoles = helpers.parseRoleHierarchy(loggedInAccount.role._id) - - _.each(items, function (role) { - var i = _.find(assignableRoles, function (o) { - return o.toString() === role.toString() - }) - if (_.isUndefined(i)) $selectizeRole.removeOption(role) - }) - - $selectizeRole.refreshOptions(false) - } - - form.find('#aGrps').multiSelect('deselect_all') - form.find('#aGrps').multiSelect('select', data.groups) - form.find('#aGrps').multiSelect('refresh') - - // Profile Picture - var aImageUploadForm = $('form#aUploadImageForm') - var image = aImageUploadForm.find('img') - var inputId = aImageUploadForm.find('input#imageUpload_id') - var inputUsername = aImageUploadForm.find('input#imageUpload_username') - inputId.val(user._id) - inputUsername.val(user.username) - if (user.image) - image.attr( - 'src', - '/uploads/users/' + user.image + '?r=' + (Math.floor(Math.random() * (99999 - 10000 + 1)) + 10000) - ) - else - image.attr( - 'src', - '/uploads/users/defaultProfile.jpg?r=' + (Math.floor(Math.random() * (99999 - 10000 + 1)) + 10000) - ) - - var modal = UIkit.modal('#editAccountModal') - if (!modal.isActive()) modal.show() - }) - .error(function (err) { - $log.log('[trudesk:Accounts:editAccount] - Error: ' + err.error) - helpers.UI.showSnackbar(err.error, true) - }) - } - - $scope.saveAccount = function () { - var form = $('#editAccountForm') - var data = form.serializeObject() - data.aUsername = form.find('#aUsername').val() - data.aGrps = form.find('#aGrps').val() - data.saveGroups = true - data.aRole = form.find('#aRole').val().length > 0 ? form.find('#aRole').val() : undefined - data.aPass = form.find('#aPass').val().length > 0 ? form.find('#aPass').val() : undefined - data.aPassConfirm = form.find('#aPassConfirm').val().length > 0 ? form.find('#aPassConfirm').val() : undefined - - $http({ - method: 'PUT', - url: '/api/v1/users/' + data.aUsername, - data: data, - headers: { 'Content-Type': 'application/json' } - }) - .success(function (data) { - if (!data.success) { - if (data.error) { - helpers.UI.showSnackbar('Error: ' + data.error, true) - return - } - - helpers.UI.showSnackbar('Error Saving Account', true) - } - - helpers.UI.showSnackbar('Account Saved', false) - - UIkit.modal('#editAccountModal').hide() - - accountsPage.init(null, true) - }) - .error(function (err) { - $log.log('[trudesk:accounts:saveAccount] - ' + err.error.message) - helpers.UI.showSnackbar('Error: ' + err.error.message, true) - }) - } - - $scope.accountEditPic = function () { - throttledAccountPicClick() - } - - $scope.selectAccountsImport = function (event, type) { - if ($(event.currentTarget).hasClass('card-disabled')) { - return false - } - - switch (type) { - case 'csv': - $('#csv_wizard_card').removeClass('uk-hidden') - $('#json-import-selector').addClass('card-disabled') - $('#ldap-import-selector').addClass('card-disabled') - break - case 'json': - $('#json_wizard_card').removeClass('uk-hidden') - $('#csv-import-selector').addClass('card-disabled') - $('#ldap-import-selector').addClass('card-disabled') - break - case 'ldap': - $('#ldap_wizard_card').removeClass('uk-hidden') - $('#csv-import-selector').addClass('card-disabled') - $('#json-import-selector').addClass('card-disabled') - } - } - - $scope.resetWizardSelection = function () { - $('#csv_wizard_card').addClass('uk-hidden') - $('#json_wizard_card').addClass('uk-hidden') - $('#ldap_wizard_card').addClass('uk-hidden') - - $('#csv-import-selector').removeClass('card-disabled') - $('#json-import-selector').removeClass('card-disabled') - $('#ldap-import-selector').removeClass('card-disabled') - } - - function throttledAccountPicClick () { - $timeout(function () { - var $profileImageInput = $('#profileImageInput') - $profileImageInput.on('click', function (event) { - // This function is a firefox hack to stop it from spawning 100000 file dialogs - event.stopPropagation() - }) - - $profileImageInput.trigger('click') - }, 0) - } - }) +define(['angular', 'underscore', 'jquery'], function (angular, _, $) { + return angular.module('trudesk.controllers.accounts', []).controller('accountsCtrl', function ($scope) { + $scope.selectAccountsImport = function (event, type) { + if ($(event.currentTarget).hasClass('card-disabled')) { + return false + } + + switch (type) { + case 'csv': + $('#csv_wizard_card').removeClass('uk-hidden') + $('#json-import-selector').addClass('card-disabled') + $('#ldap-import-selector').addClass('card-disabled') + break + case 'json': + $('#json_wizard_card').removeClass('uk-hidden') + $('#csv-import-selector').addClass('card-disabled') + $('#ldap-import-selector').addClass('card-disabled') + break + case 'ldap': + $('#ldap_wizard_card').removeClass('uk-hidden') + $('#csv-import-selector').addClass('card-disabled') + $('#json-import-selector').addClass('card-disabled') + } + } + + $scope.resetWizardSelection = function () { + $('#csv_wizard_card').addClass('uk-hidden') + $('#json_wizard_card').addClass('uk-hidden') + $('#ldap_wizard_card').addClass('uk-hidden') + + $('#csv-import-selector').removeClass('card-disabled') + $('#json-import-selector').removeClass('card-disabled') + $('#ldap-import-selector').removeClass('card-disabled') + } + }) }) diff --git a/src/public/js/angularjs/controllers/settings-permissions.js b/src/public/js/angularjs/controllers/settings-permissions.js deleted file mode 100644 index 062a9f067..000000000 --- a/src/public/js/angularjs/controllers/settings-permissions.js +++ /dev/null @@ -1,195 +0,0 @@ -/** - . .o8 oooo - .o8 "888 `888 - .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo - 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' - 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. - 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. - "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o - ======================================================================== - Created: 11/15/2018 - Author: Chris Brame - - **/ - -define(['angular', 'underscore', 'jquery', 'modules/helpers', 'uikit'], function (angular, _, $, helpers, UIkit) { - return angular - .module('trudesk.controllers.settings.permissions', ['ngSanitize']) - .controller('PermissionsCtrl', function ($scope, $http, $timeout, $log) { - $scope.init = function () { - $timeout(function () { - // Permissions Sortable - var permissionList = $('#permissionList') - if (permissionList.length > 0) { - var permissionSort = UIkit.sortable(permissionList, { - handleClass: 'drag-handle' - }) - - permissionSort.on('change.uk.sortable', function () { - var items = permissionList.children('li') - var arr = [] - for (var k = 0; k < items.length; k++) arr.push($(items[k]).attr('data-key')) - - $http - .put( - '/api/v1/settings/updateroleorder', - { - roleOrder: arr - }, - { - headers: { - 'Content-Type': 'application/json' - } - } - ) - .then( - function successCallback () {}, - function errorCallback (response) { - $log.error(response) - helpers.UI.showSnackbar('Error: ' + response.data.error, true) - } - ) - }) - } - - var $ticketsAllCheck = $('input[name="perm-tickets-all"]') - - $ticketsAllCheck.change(function (e) { - toggleAllPerm('tickets', e) - }) - - if ($ticketsAllCheck.is(':checked')) toggleAll($ticketsAllCheck.parents('form'), 'tickets', true) - - var $accountPermAllCheck = $('input[name="perm-accounts-all"]') - $accountPermAllCheck.change(function (e) { - toggleAllPerm('accounts', e, ['import']) - }) - - if ($accountPermAllCheck.is(':checked')) - toggleAll($accountPermAllCheck.parents('form'), 'accounts', true, ['import']) - - $('input[name="perm-accounts-import"]').change(function (e) { - var checked = $(e.currentTarget).prop('checked') - if (checked) $('input[name="perm-accounts-create"]').prop('checked', checked) - }) - }, 0) - } - - function toggleAllPerm (type, e, specials) { - var $currentTarget = $(e.currentTarget) - var checked = e.target.checked - var $form = $currentTarget.parents('form') - - toggleAll($form, type, checked, specials) - } - - function toggleAll ($form, type, checked, specials) { - $form - .find('input[name="perm-' + type + '-create"]') - .prop('checked', checked) - .prop('disabled', checked) - $form - .find('input[name="perm-' + type + '-view"]') - .prop('checked', checked) - .prop('disabled', checked) - $form - .find('input[name="perm-' + type + '-edit"]') - .prop('checked', checked) - .prop('disabled', checked) - $form - .find('input[name="perm-' + type + '-delete"]') - .prop('checked', checked) - .prop('disabled', checked) - - if (specials && specials.length > 0) { - for (var i = 0; i < specials.length; i++) - $form - .find('input[name="perm-' + type + '-' + specials[i] + '"]') - .prop('checked', checked) - .prop('disabled', checked) - } - } - - function handleAnyChange (type, e) { - var checked = e.target.checked - var $form = $(e.target).parents('form') - var $type = $form.find('input[name="perm-' + type + '"]') - - $type.prop('disabled', checked) - if (checked) $type.prop('checked', false) - } - - function sanitizePermissions (data) { - var obj = {} - var tObj = {} - var arr = [] - _.each(data, function (v, k) { - k = k.replace('perm', '').replace(/-/g, '') - tObj[k] = v - }) - - tObj = _.mapObject(tObj, function (v) { - return v === 'on' - }) - - // Admin - obj.admin = tObj.isadmin ? ['*'] : null - obj.setting = tObj.isadmin ? ['*'] : null - - // Agent - if (tObj.isagent) obj.agent = ['*'] - - // Tickets - if (tObj.ticketsall) obj.ticket = ['*'] - else { - if (tObj.ticketscreate) arr.push('create') - if (tObj.ticketsview) arr.push('view') - if (tObj.ticketsedit) arr.push('edit') - if (tObj.ticketsdelete) arr.push('delete') - - if (arr.length > 0) obj.ticket = arr - } - - // Accounts - if (tObj.accountsall) obj.account = ['*'] - else { - if (tObj.accountscreate) arr.push('create') - if (tObj.accountsview) arr.push('view') - if (tObj.accountsedit) arr.push('edit') - if (tObj.accountsdelete) arr.push('delete') - - // specials - if (tObj.accountsimport) arr.push('import') - - if (arr.length > 0) obj.account = arr - } - - return obj - } - - $scope.saveRolePermissions = function (roleId, $event) { - $event.preventDefault() - var $form = $($event.currentTarget) - if ($form.length < 1) { - helpers.showSnackbar('Invalid Form. Check Console.', true) - $log.log($form) - return false - } - - var data = $form.serializeObject() - var hierarchy = data['perm-enable-hierarchy'] === 'on' - data = sanitizePermissions(data) - data._id = roleId - data.hierarchy = hierarchy - - $http - .put('/api/v1/roles', data) - .success(function () { - helpers.UI.showSnackbar('Role Permissions Saved', false) - }) - .error(function (err) { - $log.error(err) - }) - } - }) -}) diff --git a/src/public/js/pages/accounts.js b/src/public/js/pages/accounts.js deleted file mode 100644 index cecae6267..000000000 --- a/src/public/js/pages/accounts.js +++ /dev/null @@ -1,314 +0,0 @@ -/* - * . .o8 oooo - * .o8 "888 `888 - * .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo - * 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' - * 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. - * 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. - * "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o - * ======================================================================== - * Author: Chris Brame - * Updated: 1/20/19 4:43 PM - * Copyright (c) 2014-2019. All rights reserved. - */ - -define('pages/accounts', [ - 'underscore', - 'jquery', - 'angular', - 'modules/helpers', - 'uikit', - 'modules/socket', - 'isinview', - 'datatables', - 'dt_responsive', - 'dt_grouping', - // 'dt_foundation', - 'dt_scroller', - 'history' -], function (_, $, angular, helpers, UIkit, socket) { - 'use strict' - var accountsPage = {} - - function capitalizeFirstLetter (str) { - return str.charAt(0).toUpperCase() + str.slice(1) - } - - accountsPage.init = function (callback, reset) { - $(document).ready(function () { - var $accountList = $('#account_list') - var $scroller = $accountList.parents('.scrollable') - var $scrollspy = $('#scrollspy') - var $spinner = $scrollspy.find('i') - var $filterAll = $('.filter-all') - var $nextPage = 1 - var $enabled = true - var $loading = false - - if (reset) { - $nextPage = 0 - getAccounts() - } - - UIkit.grid($accountList, { - controls: '#account_list_filter', - gutter: 20 - }) - - $scroller.scroll(function () { - if ($scrollspy.isInView($scroller)) { - var run = _.throttle(getAccounts, 500) - run() - } - }) - - $('#account_list_filter li a').on('click', function () { - $('#account_list_search').val('') - $('.tru-card[data-search-result]').remove() - setTimeout(function () { - helpers.resizeAll() - }, 280) - }) - - $('#account_list_search').keyup(function (e) { - e.preventDefault() - var key = e.keyCode || e.which - - var sValue = $(this) - .val() - .toLowerCase() - - if (key === 13) { - if (sValue.length < 3) { - $('#account_list_filter li.uk-active a').trigger('click') - return true - } - - $.ajax({ - url: '/api/v1/users?search=' + sValue, - success: function (data) { - $accountList.children().css('display', 'none') - var users = data.users - var html = '' - _.each(users, function (u) { - html += buildUserHTML(u, true) - }) - - var $injector = angular.injector(['ng', 'trudesk']) - $injector.invoke([ - '$compile', - '$rootScope', - function ($compile, $rootScope) { - var $scope = $accountList.append(html).scope() - $compile($accountList)($scope || $rootScope) - $rootScope.$digest() - } - ]) - - $('.s-ajaxify').on('click', function (e) { - e.preventDefault() - var href = $(e.target).attr('href') - - History.pushState(null, null, href) - }) - - UIkit.$html.trigger('changed.uk.dom') - helpers.resizeAll() - - socket.ui.updateUsers() - }, - error: function (error) { - console.log('[trudesk:accountsPage:setupGrid] - Error: ' + error.error) - } - }) - } - - return false - }) - - function getAccounts () { - if (!$enabled || $loading) { - return false - } - - if (!$filterAll.hasClass('uk-active')) return true - - $loading = true - $spinner.removeClass('uk-hidden') - - $.ajax({ - url: '/api/v1/users?limit=20&page=' + $nextPage - }) - .done(function (data) { - $spinner.addClass('uk-hidden') - var users = data.users - if (_.size(users) < 1) { - $enabled = false - $loading = false - return false - } - - var html = '' - - _.each(users, function (u) { - var h = null - if (reset) { - $accountList.html('') - h = buildUserHTML(u, true) - reset = false - } else { - h = buildUserHTML(u, false) - } - - if (h.length > 0) html += h - }) - - var $injector = angular.injector(['ng', 'trudesk']) - $injector.invoke([ - '$compile', - '$rootScope', - function ($compile, $rootScope) { - var $scope = $accountList.append(html).scope() - $compile($accountList)($scope || $rootScope) - $rootScope.$digest() - } - ]) - - UIkit.$html.trigger('changed.uk.dom') - helpers.resizeAll() - - $('.s-ajaxify').on('click', function (e) { - e.preventDefault() - var href = $(e.target).attr('href') - - History.pushState(null, null, href) - }) - - $nextPage = $nextPage + 1 - $loading = false - - socket.ui.updateUsers() - }) - .fail(function (err) { - console.log('[trudesk:accountsPage:setupGrid] - Error: ' + err.error) - $loading = false - }) - } - - if (typeof callback === 'function') { - return callback() - } - }) - } - - function buildUserHTML (user, addRemove) { - if (!addRemove) { - var $card = $('[data-card-username="' + user.username + '"]') - if ($card.length > 0) return '' - } - - var html = '