i18n and improvements
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const Mn = require('backbone.marionette');
|
||||
const template = require('./form.ejs');
|
||||
const Controller = require('../controller');
|
||||
const Cache = require('../cache');
|
||||
const Api = require('../api');
|
||||
const App = require('../main');
|
||||
const UserModel = require('../../models/user');
|
||||
const Mn = require('backbone.marionette');
|
||||
const App = require('../main');
|
||||
const UserModel = require('../../models/user');
|
||||
const template = require('./form.ejs');
|
||||
|
||||
require('jquery-serializejson');
|
||||
|
||||
@@ -34,45 +31,45 @@ module.exports = Mn.View.extend({
|
||||
|
||||
// admin@example.com is not allowed
|
||||
if (data.email === 'admin@example.com') {
|
||||
this.ui.error.text('Default email address must be changed').show();
|
||||
this.ui.error.text(App.i18n('users', 'default_error')).show();
|
||||
this.ui.buttons.prop('disabled', false).removeClass('btn-disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
// Manipulate
|
||||
data.roles = [];
|
||||
if ((this.model.get('id') === Cache.User.get('id') && this.model.isAdmin()) || (typeof data.is_admin !== 'undefined' && data.is_admin)) {
|
||||
if ((this.model.get('id') === App.Cache.User.get('id') && this.model.isAdmin()) || (typeof data.is_admin !== 'undefined' && data.is_admin)) {
|
||||
data.roles.push('admin');
|
||||
delete data.is_admin;
|
||||
}
|
||||
|
||||
data.is_disabled = typeof data.is_disabled !== 'undefined' ? !!data.is_disabled : false;
|
||||
this.ui.buttons.prop('disabled', true).addClass('btn-disabled');
|
||||
let method = Api.Users.create;
|
||||
let method = App.Api.Users.create;
|
||||
|
||||
if (this.model.get('id')) {
|
||||
// edit
|
||||
method = Api.Users.update;
|
||||
method = App.Api.Users.update;
|
||||
data.id = this.model.get('id');
|
||||
}
|
||||
|
||||
method(data)
|
||||
.then(result => {
|
||||
if (result.id === Cache.User.get('id')) {
|
||||
Cache.User.set(result);
|
||||
if (result.id === App.Cache.User.get('id')) {
|
||||
App.Cache.User.set(result);
|
||||
}
|
||||
|
||||
if (view.model.get('id') !== Cache.User.get('id')) {
|
||||
Controller.showUsers();
|
||||
if (view.model.get('id') !== App.Cache.User.get('id')) {
|
||||
App.Controller.showUsers();
|
||||
}
|
||||
|
||||
view.model.set(result);
|
||||
App.UI.closeModal(function () {
|
||||
if (method === Api.Users.create) {
|
||||
App.App.UI.closeModal(function () {
|
||||
if (method === App.Api.Users.create) {
|
||||
// Show permissions dialog immediately
|
||||
Controller.showUserPermissions(view.model);
|
||||
App.Controller.showUserPermissions(view.model);
|
||||
} else if (show_password) {
|
||||
Controller.showUserPasswordForm(view.model);
|
||||
App.Controller.showUserPasswordForm(view.model);
|
||||
}
|
||||
});
|
||||
})
|
||||
@@ -88,7 +85,7 @@ module.exports = Mn.View.extend({
|
||||
|
||||
return {
|
||||
isSelf: function () {
|
||||
return view.model.get('id') === Cache.User.get('id');
|
||||
return view.model.get('id') === App.Cache.User.get('id');
|
||||
},
|
||||
|
||||
isAdmin: function () {
|
||||
|
||||
Reference in New Issue
Block a user