diff --git a/js/app.js b/js/app.js index 9e7ae368..b96d33b3 100644 --- a/js/app.js +++ b/js/app.js @@ -332,6 +332,14 @@ app = Sammy('#main', function (sam) { } return 0; }); + }, + + arrayDiff: function(arr1, arr2) { + arr1 = arr1 || []; + arr2 = arr2 || []; + return arr1.filter(function (a) { + return ((arr2.indexOf(a) == -1) && (a != "")); + }); } }); @@ -705,13 +713,14 @@ app = Sammy('#main', function (sam) { c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_info_get_0 c.api('/domains', function(dataDomains) { // http://api.yunohost.org/#!/domain/domain_list_get_2 + // User email use a fake splitted field email = data.mail.split('@'); data.email = { username : email[0], domain : email[1] } - + // Domains data.domains = [] $.each(dataDomains.domains, function(key, value) { data.domains.push({ @@ -727,50 +736,70 @@ app = Sammy('#main', function (sam) { // Update user information sam.put('#/users/:user', function (c) { - params = {} + // Get full user object + c.api('/users/'+ c.params['user'], function(user) { - // concat email/domain pseudo field - if (c.params['mail'] !== c.params['email'] + c.params['domain']) { - c.params['mail'] = c.params['email'] + c.params['domain']; - } - else { - c.params['mail'] = ''; - } - c.params['email'] = ''; - c.params['domain'] = ''; - - $.each(c.params.toHash(), function(key, value) { - if (value !== '' && key !== 'user') { params[key] = value; } - }); - - if ($.isEmptyObject(params)) { - c.flash('fail', y18n.t('error_modify_something')); - store.clear('slide'); - // c.redirect('#/users/'+ c.params['user'] + '/edit'); - } else { - if (params['password']) { - if (params['password'] == params['confirmation']) { - if (params['password'].length < 4) { - c.flash('fail', y18n.t('password_too_short')); - store.clear('slide'); - } - else { - params['change_password'] = params['password']; - c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1 - c.redirect('#/users/'+ c.params['user']); - }, 'PUT', params); - } - } else { - c.flash('fail', y18n.t('passwords_dont_match')); - store.clear('slide'); - } + // concat email/domain pseudo field + if (c.params['mail'] !== c.params['email'] + c.params['domain']) { + c.params['mail'] = c.params['email'] + c.params['domain']; } else { - c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1 - c.redirect('#/users/'+ c.params['user']); - }, 'PUT', params); + c.params['mail'] = ''; } - } + // Clear temporary inputs + c.params['email'] = c.params['domain'] = ''; + + + // force array type for mail aliases and redirections + if (typeof c.params['mailalias'] == 'string') {c.params['mailalias'] = [c.params['mailalias']]}; + if (typeof c.params['mailforward'] == 'string') {c.params['mailforward'] = [c.params['mailforward']]}; + + // Check for added/removed aliases and redirections + c.params['add_mailalias'] = c.arrayDiff(c.params['mailalias'], user['mail-aliases']); + c.params['remove_mailalias'] = c.arrayDiff(user['mail-aliases'], c.params['mailalias']); + c.params['add_mailforward'] = c.arrayDiff(c.params['mailforward'], user['mail-forward']); + c.params['remove_mailforward'] = c.arrayDiff(user['mail-forward'], c.params['mailforward']); + + // Clear temporary inputs + c.params['mailalias'] = c.params['mailforward'] = ''; + + // Remove empty inputs + params = {} + $.each(c.params.toHash(), function(key, value) { + if (value.length > 0 && key !== 'user') { params[key] = value; } + }); + + if ($.isEmptyObject(params)) { + c.flash('fail', y18n.t('error_modify_something')); + store.clear('slide'); + c.redirect('#/users/'+ c.params['user'] + '/edit'); + } else { + if (params['password']) { + if (params['password'] == params['confirmation']) { + if (params['password'].length < 4) { + c.flash('fail', y18n.t('password_too_short')); + store.clear('slide'); + c.redirect('#/users/'+ c.params['user'] + '/edit'); + } + else { + params['change_password'] = params['password']; + c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1 + c.redirect('#/users/'+ c.params['user']); + }, 'PUT', params); + } + } else { + c.flash('fail', y18n.t('passwords_dont_match')); + store.clear('slide'); + c.redirect('#/users/'+ c.params['user'] + '/edit'); + } + } + else { + c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1 + c.redirect('#/users/'+ c.params['user']); + }, 'PUT', params); + } + } + }, 'GET'); }); // Remove existing user diff --git a/locales/en.json b/locales/en.json index ca518f87..a6fb8348 100644 --- a/locales/en.json +++ b/locales/en.json @@ -235,5 +235,7 @@ "user_fullname" : "Fullname", "user_email" : "Email", "user_emailaliases" : "Mail aliases", - "user_emailforward" : "Mail forward" + "user_emailforward" : "Mail forward", + "user_new_mail": "newmail@mydomain.org", + "user_new_forward": "newforward@myforeigndomain.org" } diff --git a/locales/fr.json b/locales/fr.json index 6ad3ef06..a749f192 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -235,5 +235,7 @@ "user_fullname" : "Nom complet", "user_email" : "Email", "user_emailaliases" : "Adresses supplémentaires", - "user_emailforward" : "Adresses de transfert" -} + "user_emailforward" : "Adresses de transfert", + "user_new_mail": "nouvelle_adresse@domaine.org", + "user_new_forward": "nouveau_transfert@domainedistant.org" +} \ No newline at end of file diff --git a/views/user/user_edit.ms b/views/user/user_edit.ms index de0351f0..347cac42 100644 --- a/views/user/user_edit.ms +++ b/views/user/user_edit.ms @@ -44,6 +44,29 @@ + +