aboutsummaryrefslogtreecommitdiff
path: root/data/assets/js/admin/dialogs/user-edit.js
diff options
context:
space:
mode:
Diffstat (limited to 'data/assets/js/admin/dialogs/user-edit.js')
-rw-r--r--data/assets/js/admin/dialogs/user-edit.js63
1 files changed, 49 insertions, 14 deletions
diff --git a/data/assets/js/admin/dialogs/user-edit.js b/data/assets/js/admin/dialogs/user-edit.js
index 2e43d42..fed9364 100644
--- a/data/assets/js/admin/dialogs/user-edit.js
+++ b/data/assets/js/admin/dialogs/user-edit.js
@@ -2,14 +2,40 @@ jQuery(function($) {
"use strict";
$('#user-edit-dialog').on('show.bs.modal', function() {
- var row = $(this).data('row');
-
- $.each({
- name: 'user_name',
- email: 'email',
- role: 'role_name',
- }, function(id, col) {
- $('#user-edit-' + id).val(row[col]);
+ var me = $(this);
+
+ $(this).find('.modal-body').addClass('hidden');
+ $(this).find('.modal-body.loading-text').removeClass('hidden');
+
+ send('user/get', {
+ user_id: me.data('user_id'),
+ }).always(function() {
+ $(this).find('.modal-body.loading-text').addClass('hidden');
+ }).fail(function(r) {
+ var error = r.responseText;
+
+ try {
+ // try to extract error message from json response
+ var data = $.parseJSON(r.responseText);
+ if ('error' in data)
+ error = data.error;
+ } catch (e) {}
+
+ me.find('.modal-body.loading-error').removeClass('hidden')
+ .find('.error-text').text(error);
+ }).done(function(r) {
+ $.each({
+ name: 'name',
+ email: 'email',
+ role: 'role',
+ }, function(id, col) {
+ $('#user-edit-' + id).val(r[col]);
+ });
+
+ $('#user-edit-password').val('');
+ $('#user-edit-active').val((r.is_active == '1') ? 'active' : 'inactive');
+
+ me.find('.modal-body.loading-done').removeClass('hidden');
});
});
@@ -34,8 +60,7 @@ jQuery(function($) {
});
$('#user-edit-confirm').click(function() {
- var me = $(this),
- user_id = $('#user-edit-dialog').data('row').user_id;
+ var me = $(this);
if (me.hasClass('disabled'))
return false;
@@ -43,18 +68,28 @@ jQuery(function($) {
// toggle loading
me.toggleClass('disabled').find('.loading').toggleClass('hidden');
- send('test/edit_user', {
- user_id: user_id,
+ send('user/set', {
+ user_id: $('#user-edit-dialog').data('user_id'),
name: $('#user-edit-name').val(),
email: $('#user-edit-email').val(),
+ password: $('#user-edit-password').val(),
role: $('#user-edit-role').val(),
+ active: ($('#user-edit-active').val() == 'active') ? 't' : 'f',
}).always(function() {
// toggle loading
me.toggleClass('disabled').find('.loading').toggleClass('hidden');
}).fail(function(r) {
- alert('Error ' + r.responseText);
+ var error = r.responseText;
+
+ try {
+ // try to extract error message from json response
+ var data = $.parseJSON(r.responseText);
+ if ('error' in data)
+ error = data.error;
+ } catch (e) {}
+
+ alert('Error: ' + error);
}).done(function(r) {
- console.log(r);
$('#users-reload').click();
$('#user-edit-dialog').modal('hide');
});