mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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>
This commit is contained in:
parent
604331f0be
commit
ed78dcfa3a
@ -49,7 +49,6 @@
|
||||
"IPA.opened_dialogs",
|
||||
"IPA.dialog_button",
|
||||
"IPA.confirm_mixin",
|
||||
"dialogs.password.dialog",
|
||||
"*_dialog"
|
||||
]
|
||||
},
|
||||
|
@ -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',
|
||||
@ -76,198 +78,6 @@ dialogs.password.default_fields_pre_op = function(spec) {
|
||||
return 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
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user