From ed78dcfa3acde7aeb1f381f49988c6911c5277ee Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Jun 04 2015 11:20:44 +0000 Subject: webui: use command_dialog as a base class for password dialog refactoring for: https://fedorahosted.org/freeipa/ticket/4997 Reviewed-By: Martin Babinsky --- diff --git a/install/ui/doc/categories.json b/install/ui/doc/categories.json index 8741d82..555367a 100644 --- a/install/ui/doc/categories.json +++ b/install/ui/doc/categories.json @@ -49,7 +49,6 @@ "IPA.opened_dialogs", "IPA.dialog_button", "IPA.confirm_mixin", - "dialogs.password.dialog", "*_dialog" ] }, diff --git a/install/ui/src/freeipa/dialogs/password.js b/install/ui/src/freeipa/dialogs/password.js index fa67290..f25f7ac 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 -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);