diff options
Diffstat (limited to 'main/app/sprinkles/admin/assets/userfrosting/js/widgets')
3 files changed, 0 insertions, 534 deletions
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/widgets/groups.js b/main/app/sprinkles/admin/assets/userfrosting/js/widgets/groups.js deleted file mode 100644 index c25c702..0000000 --- a/main/app/sprinkles/admin/assets/userfrosting/js/widgets/groups.js +++ /dev/null @@ -1,111 +0,0 @@ -/**
- * Groups widget. Sets up dropdowns, modals, etc for a table of groups.
- */
-
-/**
- * Set up the form in a modal after being successfully attached to the body.
- */
-function attachGroupForm() {
- $("body").on('renderSuccess.ufModal', function (data) {
- var modal = $(this).ufModal('getModal');
- var form = modal.find('.js-form');
-
- /**
- * Set up modal widgets
- */
- // Set up any widgets inside the modal
- form.find(".js-select2").select2({
- width: '100%'
- });
-
- // Auto-generate slug
- form.find('input[name=name]').on('input change', function () {
- var manualSlug = form.find('#form-group-slug-override').prop('checked');
- if (!manualSlug) {
- var slug = getSlug($(this).val());
- form.find('input[name=slug]').val(slug);
- }
- });
-
- form.find('#form-group-slug-override').on('change', function () {
- if ($(this).prop('checked')) {
- form.find('input[name=slug]').prop('readonly', false);
- } else {
- form.find('input[name=slug]').prop('readonly', true);
- form.find('input[name=name]').trigger('change');
- }
- });
-
- // Set icon when changed
- form.find('input[name=icon]').on('input change', function () {
- $(this).prev(".icon-preview").find("i").removeClass().addClass($(this).val());
- });
-
- // Set up the form for submission
- form.ufForm({
- validators: page.validators
- }).on("submitSuccess.ufForm", function () {
- // Reload page on success
- window.location.reload();
- });
- });
-}
-
-/**
- * Link group action buttons, for example in a table or on a specific group's page.
- */
-function bindGroupButtons(el) {
- /**
- * Link row buttons after table is loaded.
- */
-
- /**
- * Buttons that launch a modal dialog
- */
- // Edit group details button
- el.find('.js-group-edit').click(function () {
- $("body").ufModal({
- sourceUrl: site.uri.public + "/modals/groups/edit",
- ajaxParams: {
- slug: $(this).data('slug')
- },
- msgTarget: $("#alerts-page")
- });
-
- attachGroupForm();
- });
-
- // Delete group button
- el.find('.js-group-delete').click(function () {
- $("body").ufModal({
- sourceUrl: site.uri.public + "/modals/groups/confirm-delete",
- ajaxParams: {
- slug: $(this).data('slug')
- },
- msgTarget: $("#alerts-page")
- });
-
- $("body").on('renderSuccess.ufModal', function (data) {
- var modal = $(this).ufModal('getModal');
- var form = modal.find('.js-form');
-
- form.ufForm()
- .on("submitSuccess.ufForm", function () {
- // Reload page on success
- window.location.reload();
- });
- });
- });
-}
-
-function bindGroupCreationButton(el) {
- // Link create button
- el.find('.js-group-create').click(function () {
- $("body").ufModal({
- sourceUrl: site.uri.public + "/modals/groups/create",
- msgTarget: $("#alerts-page")
- });
-
- attachGroupForm();
- });
-};
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/widgets/roles.js b/main/app/sprinkles/admin/assets/userfrosting/js/widgets/roles.js deleted file mode 100644 index 236fc53..0000000 --- a/main/app/sprinkles/admin/assets/userfrosting/js/widgets/roles.js +++ /dev/null @@ -1,147 +0,0 @@ -/**
- * Roles widget. Sets up dropdowns, modals, etc for a table of roles.
- */
-
-/**
- * Set up the form in a modal after being successfully attached to the body.
- */
-function attachRoleForm() {
- $("body").on('renderSuccess.ufModal', function (data) {
- var modal = $(this).ufModal('getModal');
- var form = modal.find('.js-form');
-
- /**
- * Set up modal widgets
- */
-
- // Auto-generate slug
- form.find('input[name=name]').on('input change', function () {
- var manualSlug = form.find('#form-role-slug-override').prop('checked');
- if (!manualSlug) {
- var slug = getSlug($(this).val());
- form.find('input[name=slug]').val(slug);
- }
- });
-
- form.find('#form-role-slug-override').on('change', function () {
- if ($(this).prop('checked')) {
- form.find('input[name=slug]').prop('readonly', false);
- } else {
- form.find('input[name=slug]').prop('readonly', true);
- form.find('input[name=name]').trigger('change');
- }
- });
-
- // Set up the form for submission
- form.ufForm({
- validators: page.validators
- }).on("submitSuccess.ufForm", function () {
- // Reload page on success
- window.location.reload();
- });
- });
-}
-
-/**
- * Link role action buttons, for example in a table or on a specific role's page.
- */
-function bindRoleButtons(el) {
- /**
- * Link row buttons after table is loaded.
- */
-
- // Manage permissions button
- el.find('.js-role-permissions').click(function () {
- var slug = $(this).data('slug');
- $("body").ufModal({
- sourceUrl: site.uri.public + "/modals/roles/permissions",
- ajaxParams: {
- slug: slug
- },
- msgTarget: $("#alerts-page")
- });
-
- $("body").on('renderSuccess.ufModal', function (data) {
- var modal = $(this).ufModal('getModal');
- var form = modal.find('.js-form');
-
- // Set up collection widget
- var permissionWidget = modal.find('.js-form-permissions');
- permissionWidget.ufCollection({
- dropdown: {
- ajax: {
- url: site.uri.public + '/api/permissions'
- },
- placeholder: "Select a permission"
- },
- dropdownTemplate: modal.find('#role-permissions-select-option').html(),
- rowTemplate: modal.find('#role-permissions-row').html()
- });
-
- // Get current roles and add to widget
- $.getJSON(site.uri.public + '/api/roles/r/' + slug + '/permissions')
- .done(function (data) {
- $.each(data.rows, function (idx, permission) {
- permission.text = permission.name;
- permissionWidget.ufCollection('addRow', permission);
- });
- });
-
- // Set up form for submission
- form.ufForm({}).on("submitSuccess.ufForm", function () {
- // Reload page on success
- window.location.reload();
- });
- });
- });
-
- /**
- * Buttons that launch a modal dialog
- */
- // Edit role details button
- el.find('.js-role-edit').click(function () {
- $("body").ufModal({
- sourceUrl: site.uri.public + "/modals/roles/edit",
- ajaxParams: {
- slug: $(this).data('slug')
- },
- msgTarget: $("#alerts-page")
- });
-
- attachRoleForm();
- });
-
- // Delete role button
- el.find('.js-role-delete').click(function () {
- $("body").ufModal({
- sourceUrl: site.uri.public + "/modals/roles/confirm-delete",
- ajaxParams: {
- slug: $(this).data('slug')
- },
- msgTarget: $("#alerts-page")
- });
-
- $("body").on('renderSuccess.ufModal', function (data) {
- var modal = $(this).ufModal('getModal');
- var form = modal.find('.js-form');
-
- form.ufForm()
- .on("submitSuccess.ufForm", function () {
- // Reload page on success
- window.location.reload();
- });
- });
- });
-}
-
-function bindRoleCreationButton(el) {
- // Link create button
- el.find('.js-role-create').click(function () {
- $("body").ufModal({
- sourceUrl: site.uri.public + "/modals/roles/create",
- msgTarget: $("#alerts-page")
- });
-
- attachRoleForm();
- });
-};
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js b/main/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js deleted file mode 100644 index 7951807..0000000 --- a/main/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js +++ /dev/null @@ -1,276 +0,0 @@ -/** - * Users widget. Sets up dropdowns, modals, etc for a table of users. - */ - -/** - * Set up the form in a modal after being successfully attached to the body. - */ -function attachUserForm() { - $("body").on('renderSuccess.ufModal', function (data) { - var modal = $(this).ufModal('getModal'); - var form = modal.find('.js-form'); - - // Set up any widgets inside the modal - form.find(".js-select2").select2({ - width: '100%' - }); - - // Set up the form for submission - form.ufForm({ - validators: page.validators - }).on("submitSuccess.ufForm", function () { - // Reload page on success - window.location.reload(); - }); - }); -} - -/** - * Enable/disable password fields when switch is toggled - */ -function toggleChangePasswordMode(el, userName, changePasswordMode) { - var form = el.find("form"); - if (changePasswordMode == 'link') { - $(".controls-password").find("input[type='password']").prop('disabled', true); - // Form submits password reset request - form.attr({ - method: 'POST', - action: site.uri.public + '/api/users/u/' + userName + '/password-reset' - }); - - var validator = form.validate(); - if (validator) { - //Iterate through named elements inside of the form, and mark them as error free - el.find("input[type='password']").each(function () { - validator.successList.push(this); //mark as error free - }); - validator.resetForm();//remove error class on name elements and clear history - validator.reset();//remove all error and success data - } - el.find("input[type='password']").closest('.form-group') - .removeClass('has-error has-success'); - el.find('.form-control-feedback').each(function () { - $(this).remove(); - }); - } else { - $(".controls-password").find("input[type='password']").prop('disabled', false); - // Form submits direct password update - form.attr({ - method: 'PUT', - action: site.uri.public + '/api/users/u/' + userName + '/password' - }); - } -} - -/** - * Update user field(s) - */ -function updateUser(userName, fieldName, fieldValue) { - var data = { - 'value': fieldValue - }; - - data[site.csrf.keys.name] = site.csrf.name; - data[site.csrf.keys.value] = site.csrf.value; - - var url = site.uri.public + '/api/users/u/' + userName + '/' + fieldName; - var debugAjax = (typeof site !== "undefined") && site.debug.ajax; - - return $.ajax({ - type: "PUT", - url: url, - data: data, - dataType: debugAjax ? 'html' : 'json', - converters: { - // Override jQuery's strict JSON parsing - 'text json': function (result) { - try { - // First try to use native browser parsing - if (typeof JSON === 'object' && typeof JSON.parse === 'function') { - return JSON.parse(result); - } else { - return $.parseJSON(result); - } - } catch (e) { - // statements to handle any exceptions - console.log("Warning: Could not parse expected JSON response."); - return {}; - } - } - } - }).fail(function (jqXHR) { - // Error messages - if (debugAjax && jqXHR.responseText) { - document.write(jqXHR.responseText); - document.close(); - } else { - console.log("Error (" + jqXHR.status + "): " + jqXHR.responseText); - - // Display errors on failure - // ufAlerts widget should have a 'destroy' method - if (!$("#alerts-page").data('ufAlerts')) { - $("#alerts-page").ufAlerts(); - } else { - $("#alerts-page").ufAlerts('clear'); - } - - $("#alerts-page").ufAlerts('fetch').ufAlerts('render'); - } - - return jqXHR; - }).done(function (response) { - window.location.reload(); - }); -} - -/** - * Link user action buttons, for example in a table or on a specific user's page. - */ -function bindUserButtons(el) { - - /** - * Buttons that launch a modal dialog - */ - // Edit general user details button - el.find('.js-user-edit').click(function () { - $("body").ufModal({ - sourceUrl: site.uri.public + "/modals/users/edit", - ajaxParams: { - user_name: $(this).data('user_name') - }, - msgTarget: $("#alerts-page") - }); - - attachUserForm(); - }); - - // Manage user roles button - el.find('.js-user-roles').click(function () { - var userName = $(this).data('user_name'); - $("body").ufModal({ - sourceUrl: site.uri.public + "/modals/users/roles", - ajaxParams: { - user_name: userName - }, - msgTarget: $("#alerts-page") - }); - - $("body").on('renderSuccess.ufModal', function (data) { - var modal = $(this).ufModal('getModal'); - var form = modal.find('.js-form'); - - // Set up collection widget - var roleWidget = modal.find('.js-form-roles'); - roleWidget.ufCollection({ - dropdown: { - ajax: { - url: site.uri.public + '/api/roles' - }, - placeholder: "Select a role" - }, - dropdownTemplate: modal.find('#user-roles-select-option').html(), - rowTemplate: modal.find('#user-roles-row').html() - }); - - // Get current roles and add to widget - $.getJSON(site.uri.public + '/api/users/u/' + userName + '/roles') - .done(function (data) { - $.each(data.rows, function (idx, role) { - role.text = role.name; - roleWidget.ufCollection('addRow', role); - }); - }); - - // Set up form for submission - form.ufForm({}).on("submitSuccess.ufForm", function () { - // Reload page on success - window.location.reload(); - }); - }); - }); - - // Change user password button - el.find('.js-user-password').click(function () { - var userName = $(this).data('user_name'); - $("body").ufModal({ - sourceUrl: site.uri.public + "/modals/users/password", - ajaxParams: { - user_name: userName - }, - msgTarget: $("#alerts-page") - }); - - $("body").on('renderSuccess.ufModal', function (data) { - var modal = $(this).ufModal('getModal'); - var form = modal.find('.js-form'); - - // Set up form for submission - form.ufForm({ - validators: page.validators - }).on("submitSuccess.ufForm", function () { - // Reload page on success - window.location.reload(); - }); - - toggleChangePasswordMode(modal, userName, 'link'); - - // On submission, submit either the PUT request, or POST for a password reset, depending on the toggle state - modal.find("input[name='change_password_mode']").click(function () { - var changePasswordMode = $(this).val(); - toggleChangePasswordMode(modal, userName, changePasswordMode); - }); - }); - }); - - // Delete user button - el.find('.js-user-delete').click(function () { - $("body").ufModal({ - sourceUrl: site.uri.public + "/modals/users/confirm-delete", - ajaxParams: { - user_name: $(this).data('user_name') - }, - msgTarget: $("#alerts-page") - }); - - $("body").on('renderSuccess.ufModal', function (data) { - var modal = $(this).ufModal('getModal'); - var form = modal.find('.js-form'); - - form.ufForm() - .on("submitSuccess.ufForm", function () { - // Reload page on success - window.location.reload(); - }); - }); - }); - - /** - * Direct action buttons - */ - el.find('.js-user-activate').click(function () { - var btn = $(this); - updateUser(btn.data('user_name'), 'flag_verified', '1'); - }); - - el.find('.js-user-enable').click(function () { - var btn = $(this); - updateUser(btn.data('user_name'), 'flag_enabled', '1'); - }); - - el.find('.js-user-disable').click(function () { - var btn = $(this); - updateUser(btn.data('user_name'), 'flag_enabled', '0'); - }); -} - -function bindUserCreationButton(el) { - // Link create button - el.find('.js-user-create').click(function () { - $("body").ufModal({ - sourceUrl: site.uri.public + "/modals/users/create", - msgTarget: $("#alerts-page") - }); - - attachUserForm(); - }); -}; |