diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/web/static/src/js/widgets/change_password.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/web/static/src/js/widgets/change_password.js')
| -rw-r--r-- | addons/web/static/src/js/widgets/change_password.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/addons/web/static/src/js/widgets/change_password.js b/addons/web/static/src/js/widgets/change_password.js new file mode 100644 index 00000000..e75d8dfd --- /dev/null +++ b/addons/web/static/src/js/widgets/change_password.js @@ -0,0 +1,75 @@ +odoo.define('web.ChangePassword', function (require) { +"use strict"; + +/** + * This file defines a client action that opens in a dialog (target='new') and + * allows the user to change his password. + */ + +var AbstractAction = require('web.AbstractAction'); +var core = require('web.core'); +var Dialog = require('web.Dialog'); +var web_client = require('web.web_client'); + +var _t = core._t; + +var ChangePassword = AbstractAction.extend({ + template: "ChangePassword", + + /** + * @fixme: weird interaction with the parent for the $buttons handling + * + * @override + * @returns {Promise} + */ + start: function () { + var self = this; + web_client.set_title(_t("Change Password")); + var $button = self.$('.oe_form_button'); + $button.appendTo(this.getParent().$footer); + $button.eq(1).click(function () { + self.$el.parents('.modal').modal('hide'); + }); + $button.eq(0).click(function () { + self._rpc({ + route: '/web/session/change_password', + params: { + fields: $('form[name=change_password_form]').serializeArray() + } + }) + .then(function (result) { + if (result.error) { + self._display_error(result); + } else { + self.do_action('logout'); + } + }); + }); + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Displays the error in a dialog + * + * @private + * @param {Object} error + * @param {string} error.error + * @param {string} error.title + */ + _display_error: function (error) { + return new Dialog(this, { + size: 'medium', + title: error.title, + $content: $('<div>').html(error.error) + }).open(); + }, +}); + +core.action_registry.add("change_password", ChangePassword); + +return ChangePassword; + +}); |
