diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2015-05-22 14:17:08 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2015-06-04 13:20:44 +0200 |
commit | ed78dcfa3acde7aeb1f381f49988c6911c5277ee (patch) | |
tree | 246ec8c8b0dee5c2adc16ea19260866de40be886 /install/ui/src/freeipa | |
parent | 604331f0bedf65b6c61a9c1b2d743d5d965576a9 (diff) | |
download | freeipa-ed78dcfa3acde7aeb1f381f49988c6911c5277ee.tar.gz freeipa-ed78dcfa3acde7aeb1f381f49988c6911c5277ee.tar.xz freeipa-ed78dcfa3acde7aeb1f381f49988c6911c5277ee.zip |
webui: use command_dialog as a base class for password dialog
refactoring for:
https://fedorahosted.org/freeipa/ticket/4997
Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
Diffstat (limited to 'install/ui/src/freeipa')
-rw-r--r-- | install/ui/src/freeipa/dialogs/password.js | 202 |
1 files changed, 6 insertions, 196 deletions
diff --git a/install/ui/src/freeipa/dialogs/password.js b/install/ui/src/freeipa/dialogs/password.js index fa672901d..f25f7ac60 100644 --- a/install/ui/src/freeipa/dialogs/password.js +++ b/install/ui/src/freeipa/dialogs/password.js @@ -27,9 +27,8 @@ define([ '../rpc', '../text', '../dialog'], - function(lang, builder, IPA, phases, reg, rpc, text) { + function(lang, builder, IPA, phases, reg, rpc, text, dialogs) { -var dialogs = {}; // dummy object /** * Password dialog module * @class @@ -49,6 +48,9 @@ dialogs.password.default_fields_pre_op = function(spec) { spec.title = spec.title || '@i18n:password.reset_password'; spec.width = spec.width || 400; + spec.method = spec.method || 'mod'; + spec.success_message = spec.success_message || '@i18n:password.password_change_complete'; + spec.confirm_button_label = spec.confirm_button_label || '@i18n:password.reset_password'; spec.sections = spec.sections || [ { name: 'general', @@ -77,198 +79,6 @@ dialogs.password.default_fields_pre_op = function(spec) { }; /** - * Dialog's post_ops - */ -dialogs.password.default_post_op = function(dialog, spec) { - dialog.init(); - return dialog; -}; - -/** - * Password dialog - * @class - * @extends IPA.dialog - * @mixins IPA.confirm_mixin - */ -dialogs.password.dialog = function(spec) { - - var that = IPA.dialog(spec); - - IPA.confirm_mixin().apply(that); - - /** - * Method for setting password - * @property {string} - */ - that.method = spec.method || 'mod'; - - /** - * Command args - * @property {string[]} - */ - that.args = spec.args || []; - - /** - * Command additional options - * @property {Object} - */ - that.options = spec.options || {}; - - /** - * Success message - * @property {string} - */ - that.success_message = spec.success_message || '@i18n:password.password_change_complete'; - - /** - * Set button label - * @property {string} - */ - that.confirm_button_label = spec.confirm_button_label || '@i18n:password.reset_password'; - - /** - * Failed event - * @event - */ - that.failed = IPA.observer(); - - /** - * Succeeded event - * @event - */ - that.succeeded = IPA.observer(); - - /** - * Execute password change - */ - that.execute = function() { - - var command = that.create_command(); - command.execute(); - }; - - /** - * Confirm handler - * @protected - */ - that.on_confirm = function() { - - if (!that.validate()) return; - that.execute(); - that.close(); - }; - - /** - * Create buttons - * @protected - */ - that.create_buttons = function() { - - that.create_button({ - name: 'confirm', - label: that.confirm_button_label, - click: function() { - that.on_confirm(); - } - }); - - that.create_button({ - name: 'cancel', - label: '@i18n:buttons.cancel', - click: function() { - that.close(); - } - }); - }; - - /** - * Make options for command - * @protected - */ - that.make_otions = function() { - - var options = {}; - lang.mixin(options, that.options); - - var fields = that.fields.get_fields(); - for (var j=0; j<fields.length; j++) { - var field = fields[j]; - var values = field.save(); - if (!values || values.length === 0 || !field.enabled) continue; - if (field.flags.indexOf('no_command') > -1) continue; - - if (values.length === 1) { - options[field.param] = values[0]; - } else { - options[field.param] = values; - } - } - return options; - }; - - /** - * Create command - * @protected - */ - that.create_command = function() { - - var options = that.make_otions(); - var entity = null; - if (that.entity) entity = that.entity.name; - var command = rpc.command({ - entity: entity, - method: that.method, - args: that.args, - options: options, - on_success: function(data) { - that.on_success(); - }, - on_error: function() { - that.on_error(); - } - }); - return command; - }; - - /** - * Get success message - * @protected - */ - that.get_success_message = function() { - return text.get(that.success_message); - }; - - /** - * Success handler - * @protected - * @param {Object} data - */ - that.on_success = function(data) { - that.succeeded.notify([data], that); - IPA.notify_success(that.get_success_message()); - }; - - /** - * Error handler - * @protected - */ - that.on_error = function(xhr, status, error) { - that.failed.notify([xhr, status, error], that); - }; - - /** - * Init function - * - * - should be called right after instance creation - */ - that.init = function() { - that.create_buttons(); - }; - - return that; -}; - -/** * Action to open a password dialog * @class * @extends facet.action @@ -324,9 +134,9 @@ dialogs.password.register = function() { d.register({ type: 'password', - factory: DP.dialog, + factory: dialogs.command_dialog, pre_ops: [DP.default_fields_pre_op], - post_ops: [DP.default_post_op] + post_ops: [dialogs.command_dialog_post_op] }); a.register('password', DP.action); |