mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Problem: When some facet perform action which modifies data, some other facet may become expired. Example: User modifies group's description. Now group search facet contains old data and has to be refreshed. Solution: New event was added to facet: on_update. It should be executed when facet performs action which modifies data ie: details facet update or add entry to dnsrecord. Then entity policies were introduced. Entity policies are a objects which are stored in entity.policies. They have similar function as facet_policies - performing communications and other functionality between facets. This way facets don't have to contain such logic and thus they aren't dependant on each other. This patch adds IPA.facet_update_policy, IPA.adder_facet_update_policy, IPA.search_facet_update_policy, IPA.details_facet_update_policy. IPA.facet_update_policy: On facets_created it bind itself to [current entity].[source facet].[event]. Default event is on_update. When the event is executed it sets expiration flag to [dest entity].[dest facet]. IPA.search_facet_update_policy: IPA.facet_update_policy where source facet = search, dest facet = details, dest entity = current entity. Its a default policy for updatein changes from search facet to details facet. Right now it isn't needed but it will be needed when action lists come to play. IPA.details_facet_update_policy: same as IPA.search_facet_update_policy just reversed. Very important. IPA.adder_facet_update_policy: similar functionality, just source of the event is dialog. Default event is added (new event in entity_adder_dialog). Entity policies should be specified in entity's spec object. If none are specified a default ones are used. Default policies are: IPA.search_facet_update_policy and IPA.details_facet_update_policy. https://fedorahosted.org/freeipa/ticket/2075
185 lines
5.4 KiB
JavaScript
185 lines
5.4 KiB
JavaScript
/*jsl:import ipa.js */
|
|
|
|
/* Authors:
|
|
* Pavel Zuna <pzuna@redhat.com>
|
|
* Endi Sukma Dewata <edewata@redhat.com>
|
|
*
|
|
* Copyright (C) 2010 Red Hat
|
|
* see file 'COPYING' for use and warranty information
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/* REQUIRES: ipa.js */
|
|
|
|
IPA.entity_adder_dialog = function(spec) {
|
|
|
|
spec = spec || {};
|
|
|
|
var that = IPA.dialog(spec);
|
|
|
|
that.method = spec.method || 'add';
|
|
that.on_error = spec.on_error ;
|
|
that.retry = typeof spec.retry !== 'undefined' ? spec.retry : true;
|
|
that.command = null;
|
|
that.added = IPA.observer();
|
|
|
|
that.show_edit_page = spec.show_edit_page || show_edit_page;
|
|
|
|
var init = function() {
|
|
that.create_button({
|
|
name: 'add',
|
|
label: IPA.messages.buttons.add,
|
|
click: function() {
|
|
that.hide_message();
|
|
that.add(
|
|
function(data, text_status, xhr) {
|
|
that.added.notify();
|
|
var facet = IPA.current_entity.get_facet();
|
|
facet.refresh();
|
|
that.close();
|
|
},
|
|
that.on_error);
|
|
}
|
|
});
|
|
|
|
that.create_button({
|
|
name: 'add_and_add_another',
|
|
label: IPA.messages.buttons.add_and_add_another,
|
|
click: function() {
|
|
that.hide_message();
|
|
that.add(
|
|
function(data, text_status, xhr) {
|
|
that.added.notify();
|
|
var label = that.entity.metadata.label_singular;
|
|
var message = IPA.messages.dialogs.add_confirmation;
|
|
message = message.replace('${entity}', label);
|
|
that.show_message(message);
|
|
|
|
var facet = IPA.current_entity.get_facet();
|
|
facet.refresh();
|
|
that.reset();
|
|
},
|
|
that.on_error);
|
|
}
|
|
});
|
|
|
|
that.create_button({
|
|
name: 'add_and_edit',
|
|
label: IPA.messages.buttons.add_and_edit,
|
|
click: function() {
|
|
that.hide_message();
|
|
that.add(
|
|
function(data, text_status, xhr) {
|
|
that.added.notify();
|
|
that.close();
|
|
var result = data.result.result;
|
|
that.show_edit_page(that.entity, result);
|
|
},
|
|
that.on_error);
|
|
}
|
|
});
|
|
|
|
that.create_button({
|
|
name: 'cancel',
|
|
label: IPA.messages.buttons.cancel,
|
|
click: function() {
|
|
that.hide_message();
|
|
that.close();
|
|
}
|
|
});
|
|
};
|
|
|
|
function show_edit_page(entity,result) {
|
|
var pkey_name = entity.metadata.primary_key;
|
|
var pkey = result[pkey_name];
|
|
if (pkey instanceof Array) {
|
|
pkey = pkey[0];
|
|
}
|
|
IPA.nav.show_entity_page(that.entity, 'default', pkey);
|
|
}
|
|
|
|
that.create_add_command = function(record) {
|
|
|
|
var pkey_name = that.entity.metadata.primary_key;
|
|
|
|
var command = IPA.command({
|
|
entity: that.entity.name,
|
|
method: that.method,
|
|
retry: that.retry
|
|
});
|
|
|
|
command.add_args(that.entity.get_primary_key_prefix());
|
|
|
|
var fields = that.fields.get_fields();
|
|
for (var j=0; j<fields.length; j++) {
|
|
var field = fields[j];
|
|
|
|
var values = record[field.param];
|
|
if (!values || values.length === 0) continue;
|
|
|
|
if (field.param === pkey_name) {
|
|
command.add_arg(values[0]);
|
|
} else if (values.length === 1) {
|
|
command.set_option(field.param, values[0]);
|
|
} else {
|
|
command.set_option(field.param, values);
|
|
}
|
|
}
|
|
|
|
return command;
|
|
};
|
|
|
|
that.add = function(on_success, on_error) {
|
|
|
|
if (!that.validate()) return;
|
|
|
|
var record = {};
|
|
that.save(record);
|
|
|
|
that.command = that.create_add_command(record);
|
|
that.command.on_success = on_success;
|
|
that.command.on_error = on_error;
|
|
|
|
that.command.execute();
|
|
};
|
|
|
|
that.create = function() {
|
|
that.dialog_create();
|
|
|
|
var div = $('<div/>', {
|
|
}).appendTo(that.container);
|
|
|
|
$('<span/>', {
|
|
'class': 'required-indicator',
|
|
text: IPA.required_indicator
|
|
}).appendTo(div);
|
|
|
|
div.append(' ');
|
|
|
|
$('<span/>', {
|
|
text: IPA.messages.widget.validation.required
|
|
}).appendTo(div);
|
|
};
|
|
|
|
// methods that should be invoked by subclasses
|
|
that.entity_adder_dialog_create = that.create;
|
|
that.entity_adder_dialog_create_add_command = that.create_add_command;
|
|
|
|
init();
|
|
|
|
return that;
|
|
};
|
|
|