aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/admin/assets/userfrosting/js
diff options
context:
space:
mode:
authorMarvin Borner2018-06-28 21:15:57 +0200
committerMarvin Borner2018-06-28 21:15:57 +0200
commit15793496e8d56769c792cf39673c6e6dea3ec4d9 (patch)
tree1038f86603cdb52d7d9be5f125e5a88a25086995 /main/app/sprinkles/admin/assets/userfrosting/js
parent8781338896a0cfb47c871a0ecb13cd3fdee09d8e (diff)
Preparing for complete rewrite..
Diffstat (limited to 'main/app/sprinkles/admin/assets/userfrosting/js')
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/activities.js16
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/dashboard.js49
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/group.js24
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/groups.js24
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/permission.js20
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/permissions.js16
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/role.js23
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/roles.js24
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/user.js25
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/pages/users.js24
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/widgets/groups.js111
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/widgets/roles.js147
-rw-r--r--main/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js276
13 files changed, 0 insertions, 779 deletions
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/activities.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/activities.js
deleted file mode 100644
index 2dc31e1..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/activities.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * This script depends on uf-table.js, moment.js, handlebars-helpers.js
- *
- * Target page: /activities
- */
-
-$(document).ready(function () {
- // Set up table of activities
- $("#widget-activities").ufTable({
- dataUrl: site.uri.public + "/api/activities",
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-});
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/dashboard.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/dashboard.js
deleted file mode 100644
index 3ff241d..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/dashboard.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * Target page: /dashboard
- */
-
-$(document).ready(function () {
- $('.js-clear-cache').click(function () {
- $("body").ufModal({
- sourceUrl: site.uri.public + "/modals/dashboard/clear-cache",
- 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();
- });
- });
- });
-
- // Table of site activities
- $("#widget-activities").ufTable({
- dataUrl: site.uri.public + "/api/activities",
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-
- // Table of users in current user's group
- $("#widget-group-users").ufTable({
- dataUrl: site.uri.public + "/api/groups/g/" + page.group_slug + "/users",
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-
- // Bind user creation button
- bindUserCreationButton($("#widget-group-users"));
-
- // Bind user table buttons
- $("#widget-group-users").on("pagerComplete.ufTable", function () {
- bindUserButtons($(this));
- });
-});
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/group.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/group.js
deleted file mode 100644
index 57cd98d..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/group.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * This script depends on uf-table.js, moment.js, handlebars-helpers.js
- *
- * Target page: /groups/g/{slug}
- */
-
-$(document).ready(function () {
- // Control buttons
- bindGroupButtons($("#view-group"));
-
- // Table of users in this group
- $("#widget-group-users").ufTable({
- dataUrl: site.uri.public + '/api/groups/g/' + page.group_slug + '/users',
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-
- // Bind user table buttons
- $("#widget-group-users").on("pagerComplete.ufTable", function () {
- bindUserButtons($(this));
- });
-});
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/groups.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/groups.js
deleted file mode 100644
index f06eda8..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/groups.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * This script depends on widgets/groups.js, uf-table.js, moment.js, handlebars-helpers.js
- *
- * Target page: /groups
- */
-
-$(document).ready(function () {
-
- $("#widget-groups").ufTable({
- dataUrl: site.uri.public + "/api/groups",
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-
- // Bind creation button
- bindGroupCreationButton($("#widget-groups"));
-
- // Bind table buttons
- $("#widget-groups").on("pagerComplete.ufTable", function () {
- bindGroupButtons($(this));
- });
-});
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/permission.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/permission.js
deleted file mode 100644
index ccb6bde..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/permission.js
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * This script depends on uf-table.js, moment.js, handlebars-helpers.js
- *
- * Target page: /permissions/p/{id}
- */
-
-$(document).ready(function () {
- $("#widget-permission-users").ufTable({
- dataUrl: site.uri.public + '/api/permissions/p/' + page.permission_id + '/users',
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-
- // Bind table buttons
- $("#widget-permission-users").on("pagerComplete.ufTable", function () {
- bindUserButtons($(this));
- });
-});
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/permissions.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/permissions.js
deleted file mode 100644
index 46dfd3a..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/permissions.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * This script depends on widgets/permissions.js, uf-table.js, moment.js, handlebars-helpers.js
- *
- * Target page: /permissions
- */
-
-$(document).ready(function () {
- // Set up table of permissions
- $("#widget-permissions").ufTable({
- dataUrl: site.uri.public + "/api/permissions",
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-});
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/role.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/role.js
deleted file mode 100644
index f8f75b2..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/role.js
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * This script depends on uf-table.js, moment.js, handlebars-helpers.js
- *
- * Target page: /roles/r/{slug}
- */
-
-$(document).ready(function () {
- // Control buttons
- bindRoleButtons($("#view-role"));
-
- $("#widget-role-permissions").ufTable({
- dataUrl: site.uri.public + '/api/roles/r/' + page.role_slug + '/permissions',
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-
- $("#widget-role-users").ufTable({
- dataUrl: site.uri.public + '/api/roles/r/' + page.role_slug + '/users',
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-});
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/roles.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/roles.js
deleted file mode 100644
index 8818cb5..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/roles.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * This script depends on widgets/roles.js, uf-table.js, moment.js, handlebars-helpers.js
- *
- * Target page: /roles
- */
-
-$(document).ready(function () {
- // Set up table of roles
- $("#widget-roles").ufTable({
- dataUrl: site.uri.public + "/api/roles",
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-
- // Bind creation button
- bindRoleCreationButton($("#widget-roles"));
-
- // Bind table buttons
- $("#widget-roles").on("pagerComplete.ufTable", function () {
- bindRoleButtons($(this));
- });
-});
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/user.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/user.js
deleted file mode 100644
index ce75bd5..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/user.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * This script depends on uf-table.js, moment.js, handlebars-helpers.js
- *
- * Target page: /users/u/{user_name}
- */
-
-$(document).ready(function () {
- // Control buttons
- bindUserButtons($("#view-user"));
-
- // Table of activities
- $("#widget-user-activities").ufTable({
- dataUrl: site.uri.public + '/api/users/u/' + page.user_name + '/activities',
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-
- // Table of permissions
- $("#widget-permissions").ufTable({
- dataUrl: site.uri.public + '/api/users/u/' + page.user_name + '/permissions',
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-});
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/users.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/users.js
deleted file mode 100644
index 2051012..0000000
--- a/main/app/sprinkles/admin/assets/userfrosting/js/pages/users.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
- * example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
- *
- * This script depends on widgets/users.js, uf-table.js, moment.js, handlebars-helpers.js
- *
- * Target page: /users
- */
-
-$(document).ready(function () {
- // Set up table of users
- $("#widget-users").ufTable({
- dataUrl: site.uri.public + "/api/users",
- useLoadingTransition: site.uf_table.use_loading_transition
- });
-
- // Bind creation button
- bindUserCreationButton($("#widget-users"));
-
- // Bind table buttons
- $("#widget-users").on("pagerComplete.ufTable", function () {
- bindUserButtons($(this));
- });
-});
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();
- });
-};