2018-07-18 02:55:09 -04:00
|
|
|
const Mn = require('backbone.marionette');
|
|
|
|
const App = require('../main');
|
|
|
|
const template = require('./password.ejs');
|
2018-06-25 02:56:13 -04:00
|
|
|
|
|
|
|
require('jquery-serializejson');
|
|
|
|
|
|
|
|
module.exports = Mn.View.extend({
|
|
|
|
template: template,
|
|
|
|
className: 'modal-dialog',
|
|
|
|
|
|
|
|
ui: {
|
|
|
|
form: 'form',
|
|
|
|
buttons: '.modal-footer button',
|
|
|
|
cancel: 'button.cancel',
|
|
|
|
save: 'button.save',
|
|
|
|
error: '.secret-error'
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click @ui.save': function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.ui.error.hide();
|
|
|
|
let form = this.ui.form.serializeJSON();
|
|
|
|
|
|
|
|
if (form.new_password1 !== form.new_password2) {
|
|
|
|
this.ui.error.text('Passwords do not match!').show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
type: 'password',
|
|
|
|
current: form.current_password,
|
|
|
|
secret: form.new_password1
|
|
|
|
};
|
|
|
|
|
|
|
|
this.ui.buttons.prop('disabled', true).addClass('btn-disabled');
|
2018-07-18 02:55:09 -04:00
|
|
|
App.Api.Users.setPassword(this.model.get('id'), data)
|
2018-06-25 02:56:13 -04:00
|
|
|
.then(() => {
|
|
|
|
App.UI.closeModal();
|
2018-07-18 02:55:09 -04:00
|
|
|
App.Controller.showUsers();
|
2018-06-25 02:56:13 -04:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
this.ui.error.text(err.message).show();
|
|
|
|
this.ui.buttons.prop('disabled', false).removeClass('btn-disabled');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
isSelf: function () {
|
2018-07-18 02:55:09 -04:00
|
|
|
return App.Cache.User.get('id') === this.model.get('id');
|
2018-06-25 02:56:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
templateContext: function () {
|
|
|
|
return {
|
|
|
|
isSelf: this.isSelf.bind(this)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|