aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/admin/assets
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-16 21:09:05 +0200
committermarvin-borner@live.com2018-04-16 21:09:05 +0200
commitcf14306c2b3f82a81f8d56669a71633b4d4b5fce (patch)
tree86700651aa180026e89a66064b0364b1e4346f3f /main/app/sprinkles/admin/assets
parent619b01b3615458c4ed78bfaeabb6b1a47cc8ad8b (diff)
Main merge to user management system - files are now at /main/public/
Diffstat (limited to 'main/app/sprinkles/admin/assets')
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/css/tablesorter-custom.css30
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/activities.js16
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/dashboard.js49
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/group.js24
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/groups.js24
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/permission.js20
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/permissions.js16
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/role.js23
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/roles.js24
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/user.js25
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/pages/users.js24
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/widgets/groups.js111
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/widgets/roles.js148
-rwxr-xr-xmain/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js277
14 files changed, 811 insertions, 0 deletions
diff --git a/main/app/sprinkles/admin/assets/userfrosting/css/tablesorter-custom.css b/main/app/sprinkles/admin/assets/userfrosting/css/tablesorter-custom.css
new file mode 100755
index 0000000..405c1ca
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/css/tablesorter-custom.css
@@ -0,0 +1,30 @@
+/* ==========================================================================
+ Custom styling for tablesorter tables
+ ========================================================================== */
+
+/* Custom styling for pager controls
+ ========================================================================== */
+
+.pager-lg {
+ font-size: large;
+}
+
+.pager-control {
+ font-size: x-large;
+ padding: 4px 8px;
+ cursor: pointer;
+}
+
+/* Custom styling for panels that contain buttons in the header (eg, CSV download buttons)
+ ========================================================================== */
+
+.panel-heading-buttons h3 {
+ padding-top: 7.5px;
+}
+
+/* Don't display tablesorter filter field when disabled
+ ========================================================================== */
+
+.tablesorter thead .disabled {
+ display: none
+} \ No newline at end of file
diff --git a/main/app/sprinkles/admin/assets/userfrosting/js/pages/activities.js b/main/app/sprinkles/admin/assets/userfrosting/js/pages/activities.js
new file mode 100755
index 0000000..89ac5c1
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/activities.js
@@ -0,0 +1,16 @@
+/**
+ * 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
new file mode 100755
index 0000000..f2b8a4f
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/dashboard.js
@@ -0,0 +1,49 @@
+/**
+ * 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
new file mode 100755
index 0000000..a1ca959
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/group.js
@@ -0,0 +1,24 @@
+/**
+ * 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
new file mode 100755
index 0000000..0bfc65a
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/groups.js
@@ -0,0 +1,24 @@
+/**
+ * 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
new file mode 100755
index 0000000..87e851f
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/permission.js
@@ -0,0 +1,20 @@
+/**
+ * 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
new file mode 100755
index 0000000..6266ff4
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/permissions.js
@@ -0,0 +1,16 @@
+/**
+ * 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
new file mode 100755
index 0000000..8dae7f5
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/role.js
@@ -0,0 +1,23 @@
+/**
+ * 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
new file mode 100755
index 0000000..b1febb2
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/roles.js
@@ -0,0 +1,24 @@
+/**
+ * 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
new file mode 100755
index 0000000..70acf7c
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/user.js
@@ -0,0 +1,25 @@
+/**
+ * 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
new file mode 100755
index 0000000..d9e4bb7
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/pages/users.js
@@ -0,0 +1,24 @@
+/**
+ * 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
new file mode 100755
index 0000000..d701d81
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/widgets/groups.js
@@ -0,0 +1,111 @@
+/**
+ * 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
new file mode 100755
index 0000000..0e32651
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/widgets/roles.js
@@ -0,0 +1,148 @@
+/**
+ * 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
new file mode 100755
index 0000000..2e153e5
--- /dev/null
+++ b/main/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js
@@ -0,0 +1,277 @@
+/**
+ * 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
+ // TODO: 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();
+ });
+};