Remove IPA.nav usage, obsolete entity.get_primary_key

https://fedorahosted.org/freeipa/ticket/3236
This commit is contained in:
Petr Vobornik 2013-01-31 17:25:14 +01:00
parent 7edf044a44
commit 31d7486b88
19 changed files with 561 additions and 390 deletions

View File

@ -221,7 +221,7 @@ IPA.aci.permission_details_facet = function(spec) {
var that = IPA.details_facet(spec); var that = IPA.details_facet(spec);
that.get_refresh_command_name = function() { that.get_refresh_command_name = function() {
return that.entity.name+'_show_'+that.pkey; return that.entity.name+'_show_'+that.get_pkey();
}; };
return that; return that;

View File

@ -19,7 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
define(['./ipa', './jquery', './field', './widget', './dialog'], function(IPA, $) { define(['./ipa', './jquery', './navigation', './field', './widget', './dialog'],
function(IPA, $, navigation) {
IPA.entity_adder_dialog = function(spec) { IPA.entity_adder_dialog = function(spec) {
@ -127,7 +128,10 @@ IPA.entity_adder_dialog = function(spec) {
if (pkey instanceof Array) { if (pkey instanceof Array) {
pkey = pkey[0]; pkey = pkey[0];
} }
IPA.nav.show_entity_page(that.entity, 'default', pkey);
var pkeys = that.facet.get_pkeys();
pkeys.push(pkey);
navigation.show_entity(that.entity.name, 'default', [pkeys]);
} }
that.create_add_command = function(record) { that.create_add_command = function(record) {

View File

@ -22,7 +22,8 @@
/* CURRENTLY ALSO REQUIRES search.js, because it reuses it's code to create /* CURRENTLY ALSO REQUIRES search.js, because it reuses it's code to create
* the AssociationList elements; IT NEEDS IT'S OWN CODE! */ * the AssociationList elements; IT NEEDS IT'S OWN CODE! */
define(['./ipa', './jquery', './search', './dialog'], function(IPA, $) { define(['./ipa', './jquery', './navigation', './search', './dialog'],
function(IPA, $, navigation) {
IPA.associator = function (spec) { IPA.associator = function (spec) {
@ -384,7 +385,7 @@ IPA.association_table_widget = function (spec) {
if (column.link) { if (column.link) {
column.link_handler = function(value) { column.link_handler = function(value) {
IPA.nav.show_page(that.other_entity.name, 'default', value); navigation.show_entity(that.other_entity.name, 'default', [value]);
return false; return false;
}; };
} }
@ -536,7 +537,7 @@ IPA.association_table_widget = function (spec) {
that.create_add_dialog = function() { that.create_add_dialog = function() {
var entity_label = that.entity.metadata.label_singular; var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
var other_entity_label = that.other_entity.metadata.label; var other_entity_label = that.other_entity.metadata.label;
var title = that.add_title; var title = that.add_title;
@ -584,7 +585,7 @@ IPA.association_table_widget = function (spec) {
that.add = function(values, on_success, on_error) { that.add = function(values, on_success, on_error) {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
var command = IPA.command({ var command = IPA.command({
entity: that.entity.name, entity: that.entity.name,
@ -609,7 +610,7 @@ IPA.association_table_widget = function (spec) {
} }
var entity_label = that.entity.metadata.label_singular; var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
var other_entity_label = that.other_entity.metadata.label; var other_entity_label = that.other_entity.metadata.label;
var title = that.remove_title; var title = that.remove_title;
@ -645,7 +646,7 @@ IPA.association_table_widget = function (spec) {
that.remove = function(values, on_success, on_error) { that.remove = function(values, on_success, on_error) {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
var command = IPA.command({ var command = IPA.command({
entity: that.entity.name, entity: that.entity.name,
@ -704,7 +705,7 @@ IPA.association_table_field = function (spec) {
that.widget.summary.text(error_thrown.name+': '+error_thrown.message); that.widget.summary.text(error_thrown.name+': '+error_thrown.message);
} }
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
IPA.command({ IPA.command({
entity: that.entity.name, entity: that.entity.name,
method: 'show', method: 'show',
@ -952,15 +953,14 @@ IPA.association_facet = function (spec, no_init) {
that.show = function() { that.show = function() {
that.facet_show(); that.facet_show();
var pkey = that.get_pkey();
that.pkey = IPA.nav.get_state(that.entity.name+'-pkey'); that.header.set_pkey(pkey);
that.header.set_pkey(that.pkey);
}; };
that.show_add_dialog = function() { that.show_add_dialog = function() {
var entity_label = that.entity.metadata.label_singular; var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.get_pkey();
var other_entity_label = that.other_entity.metadata.label; var other_entity_label = that.other_entity.metadata.label;
var title = that.add_title; var title = that.add_title;
@ -986,7 +986,7 @@ IPA.association_facet = function (spec, no_init) {
dialog.execute = function() { dialog.execute = function() {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.get_pkey();
var associator = that.associator({ var associator = that.associator({
entity: that.entity, entity: that.entity,
@ -1022,7 +1022,7 @@ IPA.association_facet = function (spec, no_init) {
} }
var entity_label = that.entity.metadata.label_singular; var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.get_pkey();
var other_entity_label = that.other_entity.metadata.label; var other_entity_label = that.other_entity.metadata.label;
var title = that.remove_title; var title = that.remove_title;
@ -1086,12 +1086,13 @@ IPA.association_facet = function (spec, no_init) {
if (that.indirect_radio) that.indirect_radio.prop('checked', true); if (that.indirect_radio) that.indirect_radio.prop('checked', true);
} }
var pkey = that.entity.get_primary_key(); //var pkey = that.entity.get_primary_key();
var pkeys = that.get_pkeys();
var command = IPA.command({ var command = IPA.command({
entity: that.entity.name, entity: that.entity.name,
method: 'show', method: 'show',
args: pkey args: pkeys
}); });
command.on_success = function(data, text_status, xhr) { command.on_success = function(data, text_status, xhr) {
@ -1112,18 +1113,6 @@ IPA.association_facet = function (spec, no_init) {
that.table.clear(); that.table.clear();
}; };
that.needs_update = function() {
if (that._needs_update !== undefined) return that._needs_update;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
if (that.pkey !== pkey) return true;
var page = parseInt(IPA.nav.get_state(that.entity.name+'-page'), 10) || 1;
if (that.table.current_page !== page) return true;
return that.facet_needs_update();
};
that.init_association_facet = function() { that.init_association_facet = function() {
that.init_facet(); that.init_facet();
@ -1208,9 +1197,8 @@ IPA.attribute_facet = function(spec, no_init) {
that.show = function() { that.show = function() {
that.facet_show(); that.facet_show();
var pkey = that.get_pkey();
that.pkey = IPA.nav.get_state(that.entity.name+'-pkey'); that.header.set_pkey(pkey);
that.header.set_pkey(that.pkey);
}; };
that.get_records_map = function(data) { that.get_records_map = function(data) {
@ -1263,18 +1251,6 @@ IPA.attribute_facet = function(spec, no_init) {
that.table.clear(); that.table.clear();
}; };
that.needs_update = function() {
if (that._needs_update !== undefined) return that._needs_update;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
if (that.pkey !== pkey) return true;
var page = parseInt(IPA.nav.get_state(that.entity.name+'-page'), 10) || 1;
if (that.table.current_page !== page) return true;
return that.facet_needs_update();
};
that.show_add_dialog = function() { that.show_add_dialog = function() {
var dialog = IPA.attribute_adder_dialog({ var dialog = IPA.attribute_adder_dialog({

View File

@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
define(['./ipa', './jquery', './details', './search', './association', define(['./ipa', './jquery', './navigation', './details', './search', './association',
'./entity'], function(IPA, $) { './entity'], function(IPA, $, navigation) {
IPA.automember = {}; IPA.automember = {};
@ -82,7 +82,7 @@ IPA.automember.entity = function(spec) {
label: IPA.messages.objects.automember.usergrouprule, label: IPA.messages.objects.automember.usergrouprule,
disable_facet_tabs: true, disable_facet_tabs: true,
check_rights: false, check_rights: false,
redirect_info: { tab: 'amgroup' } redirect_info: { facet: 'searchgroup' }
}). }).
details_facet({ details_facet({
factory: IPA.automember.rule_details_facet, factory: IPA.automember.rule_details_facet,
@ -91,7 +91,7 @@ IPA.automember.entity = function(spec) {
label: IPA.messages.objects.automember.hostgrouprule, label: IPA.messages.objects.automember.hostgrouprule,
disable_facet_tabs: true, disable_facet_tabs: true,
check_rights: false, check_rights: false,
redirect_info: { tab: 'amhostgroup' } redirect_info: { facet: 'searchhostgroup' }
}). }).
adder_dialog({ adder_dialog({
factory: IPA.automember.rule_adder_dialog, factory: IPA.automember.rule_adder_dialog,
@ -335,7 +335,7 @@ IPA.automember.rule_adder_dialog = function(spec) {
var facetname = facet.group_type === 'group' ? 'usergrouprule' : var facetname = facet.group_type === 'group' ? 'usergrouprule' :
'hostgrouprule'; 'hostgrouprule';
IPA.nav.show_entity_page(that.entity, facetname, pkey); navigation.show_entity(that.entity.name, facetname, [pkey]);
}; };
that.reset = function() { that.reset = function() {

View File

@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
define(['./ipa', './jquery', './details', './search', './association', define(['./ipa', './jquery', './navigation', './details', './search', './association',
'./entity'], function(IPA, $) { './entity'], function(IPA, $, navigation) {
IPA.automount = {}; IPA.automount = {};
@ -191,11 +191,15 @@ IPA.automount.key_entity = function(spec) {
show_edit_page : function(entity, result){ show_edit_page : function(entity, result){
var key = result.automountkey[0]; var key = result.automountkey[0];
var info = result.automountinformation[0]; var info = result.automountinformation[0];
var state = IPA.nav.get_path_state(entity.name); var pkeys = that.facet.get_pkeys();
state[entity.name + '-facet'] = 'default'; pkeys.push(key);
state[entity.name + '-info'] = info;
state[entity.name + '-pkey'] = key; var args = {
IPA.nav.push_state(state); info: info,
key: key
};
navigation.show_entity(entity.name, 'details', pkeys, args);
return false; return false;
}, },
fields:['automountkey','automountinformation'] fields:['automountkey','automountinformation']
@ -215,8 +219,8 @@ IPA.automount.key_details_facet = function(spec) {
command.args.pop(); command.args.pop();
var key = IPA.nav.get_state(that.entity.name + '-pkey'); var key = that.state.key;
var info = IPA.nav.get_state(that.entity.name + '-info'); var info = that.state.info;
command.options.newautomountinformation = command.options.automountinformation; command.options.newautomountinformation = command.options.automountinformation;
command.options.automountkey = key; command.options.automountkey = key;
@ -231,8 +235,8 @@ IPA.automount.key_details_facet = function(spec) {
command.args.pop(); command.args.pop();
var key = IPA.nav.get_state(that.entity.name + '-pkey'); var key = that.state.key;
var info = IPA.nav.get_state(that.entity.name + '-info'); var info = that.state.info;
command.options.automountkey = key; command.options.automountkey = key;
command.options.automountinformation = info; command.options.automountinformation = info;
@ -260,11 +264,16 @@ IPA.automount_key_column = function(spec) {
href: '#'+key, href: '#'+key,
text: key, text: key,
click: function() { click: function() {
var state = IPA.nav.get_path_state(that.entity.name);
state[that.entity.name + '-facet'] = 'default'; var pkeys = that.facet.get_pkeys();
state[that.entity.name + '-info'] = info; pkeys.push(key);
state[that.entity.name + '-pkey'] = key;
IPA.nav.push_state(state); var args = {
info: info,
key: key
};
navigation.show_entity(that.entity.name, 'details', pkeys, args);
return false; return false;
} }
}).appendTo(container); }).appendTo(container);

View File

@ -294,26 +294,11 @@ IPA.details_facet = function(spec, no_init) {
/* the primary key used for show and update is built as an array. /* the primary key used for show and update is built as an array.
for most entities, this will be a single element long, but for some for most entities, this will be a single element long, but for some
it requires the containing entities primary keys as well.*/ it requires the containing entities primary keys as well.*/
//FIXME: obsolete this stuff
that.get_primary_key = function(from_url) { that.get_primary_key = function(from_url) {
var pkey = that.entity.get_primary_key_prefix(); var pkeys = that.get_pkeys();
return pkeys;
if (from_url) {
pkey.push(that.pkey);
} else {
var pkey_name = that.entity.metadata.primary_key;
if (!pkey_name){
return pkey;
}
var pkey_val = that.data.result.result[pkey_name];
if (pkey_val instanceof Array) {
pkey.push(pkey_val[0]);
} else {
pkey.push(pkey_val);
}
}
return pkey;
}; };
that.create = function(container) { that.create = function(container) {
@ -403,24 +388,8 @@ IPA.details_facet = function(spec, no_init) {
that.show = function() { that.show = function() {
that.facet_show(); that.facet_show();
var pkey = that.get_pkey();
that.pkey = IPA.nav.get_state(that.entity.name+'-pkey'); that.header.set_pkey(pkey);
that.old_key_prefix = that.entity.get_primary_key_prefix();
that.header.set_pkey(that.pkey);
};
that.needs_update = function() {
if (that._needs_update !== undefined) return that._needs_update;
var needs_update = that.facet_needs_update();
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
var key_prefix = that.entity.get_primary_key_prefix();
needs_update = needs_update || pkey !== that.pkey;
needs_update = needs_update || IPA.array_diff(key_prefix, that.old_key_prefix);
return needs_update;
}; };
that.field_dirty_changed = function(dirty) { that.field_dirty_changed = function(dirty) {
@ -649,7 +618,7 @@ IPA.details_facet = function(spec, no_init) {
options: options options: options
}); });
if (that.pkey) { if (that.get_pkey()) {
command.args = that.get_primary_key(true); command.args = that.get_primary_key(true);
} }
@ -668,9 +637,7 @@ IPA.details_facet = function(spec, no_init) {
that.refresh = function(on_success, on_error) { that.refresh = function(on_success, on_error) {
that.pkey = IPA.nav.get_state(that.entity.name+'-pkey'); if (!that.get_pkey() && that.entity.redirect_facet) {
if (!that.pkey && that.entity.redirect_facet) {
that.redirect(); that.redirect();
return; return;
} }
@ -1120,12 +1087,12 @@ IPA.object_action = function(spec) {
that.execute_action = function(facet, on_success, on_error) { that.execute_action = function(facet, on_success, on_error) {
var entity_name = facet.entity.name; var entity_name = facet.entity.name;
var pkey = IPA.nav.get_state(entity_name+'-pkey'); var pkeys = facet.get_pkeys();
IPA.command({ IPA.command({
entity: entity_name, entity: entity_name,
method: that.method, method: that.method,
args: [pkey], args: pkeys,
options: that.options, options: that.options,
on_success: that.get_on_success(facet, on_success), on_success: that.get_on_success(facet, on_success),
on_error: that.get_on_error(facet, on_error) on_error: that.get_on_error(facet, on_error)
@ -1156,7 +1123,7 @@ IPA.object_action = function(spec) {
}; };
that.get_confirm_message = function(facet) { that.get_confirm_message = function(facet) {
var pkey = IPA.nav.get_state(facet.entity.name+'-pkey'); var pkey = that.get_pkey();
var msg = that.confirm_msg.replace('${object}', pkey); var msg = that.confirm_msg.replace('${object}', pkey);
return msg; return msg;
}; };

View File

@ -20,8 +20,8 @@
*/ */
define(['./ipa', './jquery', './net', './details', './search', './association', define(['./ipa', './jquery', './net', './navigation', './details', './search', './association',
'./entity'], function(IPA, $, NET) { './entity'], function(IPA, $, NET, navigation) {
IPA.dns = { IPA.dns = {
zone_permission_name: 'Manage DNS zone ${dnszone}' zone_permission_name: 'Manage DNS zone ${dnszone}'
@ -332,7 +332,7 @@ IPA.dnszone_details_facet = function(spec, no_init) {
that.create_refresh_command = function() { that.create_refresh_command = function() {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.get_pkey();
var batch = IPA.batch_command({ var batch = IPA.batch_command({
name: 'dnszone_details_refresh' name: 'dnszone_details_refresh'
@ -597,7 +597,7 @@ IPA.dns.add_permission_action = function(spec) {
that.execute_action = function(facet) { that.execute_action = function(facet) {
var pkey = IPA.nav.get_state('dnszone-pkey'); var pkey = that.get_pkey();
var command = IPA.command({ var command = IPA.command({
entity: 'dnszone', entity: 'dnszone',
@ -627,7 +627,7 @@ IPA.dns.remove_permission_action = function(spec) {
that.execute_action = function(facet) { that.execute_action = function(facet) {
var pkey = IPA.nav.get_state('dnszone-pkey'); var pkey = that.get_pkey();
var command = IPA.command({ var command = IPA.command({
entity: 'dnszone', entity: 'dnszone',
@ -678,7 +678,7 @@ IPA.dns.record_search_facet = function(spec) {
on_error: on_error on_error: on_error
}); });
var zone = IPA.nav.get_state('dnszone-pkey'); var zone = that.get_pkey();
for (var i=0; i<pkeys.length; i++) { for (var i=0; i<pkeys.length; i++) {
var pkey = pkeys[i]; var pkey = pkeys[i];
@ -1267,7 +1267,7 @@ IPA.dnsrecord_redirection_dialog = function(spec) {
}; };
that.on_ok = function() { that.on_ok = function() {
IPA.nav.show_page('dnszone','default'); navigation.show_entity_page('dnszone','default');
}; };
return that; return that;
@ -1824,7 +1824,7 @@ IPA.dns.record_type_table_widget = function(spec) {
that.remove = function(values, pkey, on_success, on_error) { that.remove = function(values, pkey, on_success, on_error) {
var dnszone = IPA.nav.get_state('dnszone-pkey'); var dnszone = that.facet.get_pkey();
var command = IPA.command({ var command = IPA.command({
entity: that.entity.name, entity: that.entity.name,
@ -1921,7 +1921,7 @@ IPA.dns.record_type_table_widget = function(spec) {
dialog.create_add_command = function(record) { dialog.create_add_command = function(record) {
var dnszone = IPA.nav.get_state('dnszone-pkey'); var dnszone = that.facet.get_pkey();
var command = dialog.entity_adder_dialog_create_add_command(record); var command = dialog.entity_adder_dialog_create_add_command(record);
command.args = [dnszone, that.idnsname[0]]; command.args = [dnszone, that.idnsname[0]];
@ -2015,8 +2015,7 @@ IPA.dns.record_type_table_widget = function(spec) {
dialog.create_add_command = function(record) { dialog.create_add_command = function(record) {
var dnszone = IPA.nav.get_state('dnszone-pkey'); var dnszone = that.facet.get_pkey();
var command = dialog.entity_adder_dialog_create_add_command(record); var command = dialog.entity_adder_dialog_create_add_command(record);
command.method = 'mod'; command.method = 'mod';
@ -2259,8 +2258,10 @@ IPA.dns.ptr_redirection_dialog = function(spec) {
} else { } else {
that.reverse_address = that.address.get_reverse().toLowerCase()+'.'; that.reverse_address = that.address.get_reverse().toLowerCase()+'.';
var record = IPA.nav.get_state('dnsrecord-pkey'); var pkeys = that.facet.get_pkeys();
var zone = IPA.nav.get_state('dnszone-pkey');
var record = pkeys[1];
var zone = pkeys[0];
if (record && zone && record !== '' && zone !== '') { if (record && zone && record !== '' && zone !== '') {
that.dns_record = { that.dns_record = {
@ -2355,10 +2356,8 @@ IPA.dns.ptr_redirection_dialog = function(spec) {
//4th-a step: actual redirect //4th-a step: actual redirect
that.redirect = function() { that.redirect = function() {
var entity = IPA.get_entity('dnsrecord'); navigation.show_entity(
'dnsrecord',
IPA.nav.show_entity_page(
entity,
'default', 'default',
that.record_keys); that.record_keys);

View File

@ -163,80 +163,18 @@ IPA.entity = function(spec) {
return that; return that;
}; };
that.create = function(container) { that.get_primary_key_prefix = function(facet) {
that.container = container; window.console.log('Obsolete function usage: entity.get_primary_key_prefix');
var prefix = that.get_primary_key(facet);
prefix.pop();
return prefix;
}; };
that.display = function(container) { that.get_primary_key = function(facet) {
window.console.log('Obsolete function usage: entity.get_primary_key');
var prev_entity = IPA.current_entity; facet = facet || that.facet;
var prev_facet = prev_entity ? prev_entity.facet : null; var pkeys = facet.get_pkeys();
return pkeys;
IPA.current_entity = that;
var facet_name = IPA.nav.get_state(that.name+'-facet');
that.facet = that.get_facet(facet_name);
var needs_update = that.facet.needs_update();
// same entity, same facet, and doesn't need updating => return
if (that == prev_entity && that.facet == prev_facet && !needs_update) {
return;
}
if (prev_facet) {
prev_facet.hide();
}
var facet_container = $('.facet[name="'+that.facet.name+'"]', that.container);
if (!facet_container.length) {
facet_container = $('<div/>', {
name: that.facet.name,
'class': 'facet'
}).appendTo(that.container);
that.facet.create(facet_container);
}
if (needs_update) {
that.facet.clear();
that.facet.show();
that.facet.header.select_tab();
that.facet.refresh();
} else {
that.facet.show();
that.facet.header.select_tab();
}
};
that.get_primary_key_prefix = function() {
var pkey = [];
var current_entity = that;
current_entity = current_entity.get_containing_entity();
while(current_entity !== null){
var key = IPA.nav.get_state(current_entity.name+'-pkey');
if (key){
pkey.unshift(key);
}
current_entity = current_entity.get_containing_entity();
}
return pkey;
};
/*gets the primary key for the current entity out of the URL parameters */
that.get_primary_key = function() {
var pkey = that.get_primary_key_prefix();
var current_entity = that;
pkey.unshift(IPA.nav.get_state(current_entity.name+'-pkey'));
return pkey;
};
/* most entites only require -pkey for their primary keys, but some
are more specific. This call allows those entites a place
to override the other parameters. */
that.get_key_names = function() {
return [that.name + '-pkey'];
}; };
that.entity_init = that.init; that.entity_init = that.init;
@ -244,72 +182,6 @@ IPA.entity = function(spec) {
return that; return that;
}; };
IPA.nested_tab_labels = {};
IPA.get_nested_tab_label = function(entity_name){
if (!IPA.nested_tab_labels[entity_name]){
IPA.nested_tab_labels[entity_name] = "LABEL";
}
return IPA.nested_tab_labels[entity_name];
};
/*Returns the entity requested, as well as:
any nested tabs underneath it or
its parent tab and the others nested at the same level*/
IPA.nested_tabs = function(entity_name) {
var siblings = [];
var i;
var i2;
var nested_entities;
var sub_i;
var sub_tab;
var key = entity_name;
function push_sibling(sibling){
siblings.push (sibling);
IPA.nested_tab_labels[key] = sub_tab;
}
if (!IPA.nav.tabs) {
siblings.push(entity_name);
return siblings;
}
for (var top_i = 0; top_i < IPA.nav.tabs.length; top_i++) {
var top_tab = IPA.nav.tabs[top_i];
for (sub_i = 0; sub_i < top_tab.children.length; sub_i++) {
sub_tab = top_tab.children[sub_i];
nested_entities = sub_tab.children;
if (sub_tab.name === entity_name){
push_sibling(entity_name);
}
if (sub_tab.children){
for (i = 0; i < nested_entities.length; i += 1){
if (sub_tab.name === entity_name){
push_sibling(nested_entities[i].name);
}else{
if (nested_entities[i].name === entity_name){
push_sibling(sub_tab.name);
for (i2 = 0; i2 < nested_entities.length; i2 += 1){
key = nested_entities[i].name;
push_sibling(nested_entities[i2].name);
}
}
}
}
}
}
}
return siblings;
};
IPA.entity_builder = function() { IPA.entity_builder = function() {
var that = {}; var that = {};

View File

@ -21,8 +21,80 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
define(['./ipa', './jquery', './dialog', './field', './widget'], function(IPA, $) { define([
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/topic',
'dojo/dom-construct',
'dojo/on',
'dojo/Stateful',
'dojo/Evented',
'./ipa',
'./jquery',
'./navigation',
'./dialog',
'./field',
'./widget'
], function(declare, lang, topic, construct, on, Stateful, Evented,
IPA, $, navigation) {
/**
* Facet represents the content of currently displayed page.
*
* = Show, Clear, Refresh mechanism =
*
* Use cases:
* a) Display facet with defined arguments.
* b) Switch to facet
* c) Update facet state
*
* == Display facet by route ==
* 1) somebody sets route
* 2) Route is evaluated, arguments extracted.
* 3) Facet state is updated `update_state(args, pkeys)`.(saves previous state)
* 4) Facet show() is called
*
* == Display facet with defined arguments ==
* 1) Somebody calls navigation.show(xxx);
* 2) Facet state is updated `update_state(args, pkeys)`.(saves previous state)
* 3) Route is updated, but the hash change is ignored
* 4) Facet show() is called.
* 5.1) First time show
* a) creates DOM
* b) display DOM
* c) refresh();
* 5.2) Next time
* a) display DOM
* b) needs_update()? (compares previous state with current)
* true:
* 1) clear() - each facet can override to supress clear or
* control the behaviour
* 2) refresh()
*
* == Swith to facet ==
* Same as display facet but only without arguments. Arguments are extracted at
* step 2.
*
* == Update facet state ==
* 1) update_state(args, pkeys?)
* 2) needs_update()?
* true:
* a) clear()
* b) refresh()
* 2) Update route, ignore hash change event
*
* == Updating hash ==
* Hash updates are responsibility of navigation component and application
* controller. Application controller should listen to facet's `state_change`
* event. And call something like navigation.update_hash(facet).
*
* navigation.update_hash should find all the necessary state properties (args,
* pkeys).
*
* == needs_update method ==
*
*
*/
IPA.facet = function(spec, no_init) { IPA.facet = function(spec, no_init) {
spec = spec || {}; spec = spec || {};
@ -58,12 +130,190 @@ IPA.facet = function(spec, no_init) {
that.dialogs = $.ordered_map(); that.dialogs = $.ordered_map();
/**
* domNode of container
* Suppose to contain domNode of this and other facets.
*/
that.container_node = spec.container_node;
/**
* FIXME: that.container should be eliminated
* now it's the same as domNode
*/
//that.container
/**
* domNode which contains all content of a facet.
* Should contain error content and content. When error is moved to
* standalone facet it will replace functionality of content.
*/
that.domNode = null;
// facet group name // facet group name
that.facet_group = spec.facet_group; that.facet_group = spec.facet_group;
that.redirect_info = spec.redirect_info; that.redirect_info = spec.redirect_info;
that.state = {}; /**
* Public state
*
*/
that.state = new FacetState();
that.set_pkeys = function(pkeys) {
pkeys = that.get_pkeys(pkeys);
that.state.set('pkeys', pkeys);
};
/**
* Return THE pkey of this facet. Basically the last one of pkeys list.
*
* @type String
*/
that.get_pkey = function() {
var pkeys = that.state.get('pkeys');
if (pkeys.length) {
return pkeys[pkeys.length-1];
}
return '';
};
/**
* Gets copy of pkeys list.
* It automatically adds empty pkeys ('') for each containing entity if not
* specified.
*
* One can get merge current pkeys with supplied if `pkeys` param is
* specified.
*
* @param String[] new pkeys to merge
*/
that.get_pkeys = function(pkeys) {
var new_keys = [];
var cur_keys = that.state.get('pkeys') || [];
var current_entity = that.entity;
pkeys = pkeys || [];
var arg_l = pkeys.length;
var cur_l = cur_keys.length;
var tot_c = 0;
while (current_entity) {
current_entity = current_entity.get_containing_entity();
tot_c++;
}
if (tot_c < arg_l || tot_c < cur_l) throw {
error: 'Invalid pkeys count. Supplied more than expected.'
};
var arg_off = tot_c - arg_l;
var cur_off = cur_l - tot_c;
for (var i=0; i<tot_c; i++) {
// first try to use supplied
if (tot_c - arg_l - i <= 0) new_keys[i] = pkeys[i-arg_off];
// then current
else if (tot_c - cur_l - i <= 0) new_keys[i] = cur_keys[i-cur_off];
// then empty
else new_keys[i] = '';
}
return new_keys;
};
that.state_diff = function(a, b) {
var diff = false;
var checked = {};
var check_diff = function(a, b, skip) {
var same = true;
skip = skip || {};
for (var key in a) {
if (a.hasOwnProperty(key) && !(key in skip)) {
var va = a[key];
var vb = b[key];
if ((lang.isArray(va) && !IPA.array_diff(va,vb)) ||
(a[key] !== b[key])) {
same = false;
skip[a] = true;
break;
}
}
}
return !same;
};
diff = check_diff(a,b, checked);
diff = diff || check_diff(b,a, checked);
return diff;
};
that.set_state = function(state) {
if (state.pkeys) {
state.pkeys = that.get_pkeys(state.pkeys);
}
that.state.reset(state);
};
that.get_state = function() {
return that.state.clone();
};
/**
* Merges state into current and notifies it.
*/
that.update_state = function(state) {
if (state.pkeys) {
state.pkeys = that.get_pkeys(state.pkeys);
}
that.state.set(state);
};
that.on_state_reset = function(old_state, state) {
that._on_state_change(state);
};
that.on_state_change = function(name, old_value, value) {
var new_state = that.state.clone();
that._on_state_change(new_state);
};
that._on_state_change = function(state) {
// basically a show method without displaying the facet
// TODO: change to something fine grained
// we don't have to reflect any changes if facet dom is not yet built
that._notify_state_change(state);
if (!that.domNode) return;
var needs_update = that.needs_update();
that.old_state = state;
if (needs_update) {
that.clear();
}
that.show_content();
that.header.select_tab();
if (needs_update) {
that.refresh();
}
};
that._notify_state_change = function(state) {
topic.publish('facet-state-change', {
facet: that,
state:state
});
};
that.get_dialog = function(name) { that.get_dialog = function(name) {
return that.dialogs.get(name); return that.dialogs.get(name);
@ -74,27 +324,47 @@ IPA.facet = function(spec, no_init) {
return that; return that;
}; };
that.create = function(container) { that.create = function() {
that.container = container; if (that.domNode) {
that.domNode.empty();
that.domNode.detach();
} else {
that.domNode = $('<div/>', {
'class': 'facet',
name: that.name
});
}
if (that.disable_facet_tabs) that.container.addClass('no-facet-tabs'); var domNode = that.domNode;
that.container.addClass(that.display_class); that.container = domNode;
if (!that.container_node) throw {
error: 'Can\'t create facet. No container node defined.'
};
var node = domNode[0];
construct.place(node,that.container_node);
if (that.disable_facet_tabs) domNode.addClass('no-facet-tabs');
domNode.addClass(that.display_class);
that.header_container = $('<div/>', { that.header_container = $('<div/>', {
'class': 'facet-header' 'class': 'facet-header'
}).appendTo(container); }).appendTo(domNode);
that.create_header(that.header_container); that.create_header(that.header_container);
that.content = $('<div/>', { that.content = $('<div/>', {
'class': 'facet-content' 'class': 'facet-content'
}).appendTo(container); }).appendTo(domNode);
that.error_container = $('<div/>', { that.error_container = $('<div/>', {
'class': 'facet-content facet-error' 'class': 'facet-content facet-error'
}).appendTo(container); }).appendTo(domNode);
that.create_content(that.content); that.create_content(that.content);
}; };
that.create_header = function(container) { that.create_header = function(container) {
@ -122,8 +392,30 @@ IPA.facet = function(spec, no_init) {
}; };
that.show = function() { that.show = function() {
that.container.css('display', 'block');
that.entity.facet = that; // FIXME: remove
if (!that.domNode) {
that.create();
var needs_update = that.needs_update();
if (needs_update) {
that.clear();
}
that.domNode.css('display', 'block');
that.show_content(); that.show_content();
that.header.select_tab();
if (needs_update) {
that.refresh();
}
} else {
that.domNode.css('display', 'block');
that.show_content();
that.header.select_tab();
}
}; };
that.show_content = function() { that.show_content = function() {
@ -142,7 +434,7 @@ IPA.facet = function(spec, no_init) {
}; };
that.hide = function() { that.hide = function() {
that.container.css('display', 'none'); that.domNode.css('display', 'none');
}; };
that.load = function(data) { that.load = function(data) {
@ -175,6 +467,8 @@ IPA.facet = function(spec, no_init) {
needs_update = needs_update || that.expired_flag; needs_update = needs_update || that.expired_flag;
needs_update = needs_update || that.error_displayed(); needs_update = needs_update || that.error_displayed();
needs_update = needs_update || that.state_diff(that.old_state || {}, that.state);
return needs_update; return needs_update;
}; };
@ -191,6 +485,29 @@ IPA.facet = function(spec, no_init) {
return false; return false;
}; };
/**
* Wheater we can switch to different facet.
* @returns Boolean
*/
that.can_leave = function() {
return !that.is_dirty();
};
/**
* Show dialog displaying a message explaining why we can't switch facet.
* User can supply callback which is called when a leave is permitted.
*
* Listeneres should set 'callback' property to listen state evaluation.
*/
that.show_leave_dialog = function(permit_callback) {
var dialog = IPA.dirty_dialog({
facet: that
});
return dialog;
};
that.report_error = function(error_thrown) { that.report_error = function(error_thrown) {
var add_option = function(ul, text, handler) { var add_option = function(ul, text, handler) {
@ -235,7 +552,7 @@ IPA.facet = function(spec, no_init) {
options_list, options_list,
IPA.messages.error_report.main_page, IPA.messages.error_report.main_page,
function() { function() {
IPA.nav.show_top_level_page(); navigation.show_default();
} }
); );
@ -260,16 +577,11 @@ IPA.facet = function(spec, no_init) {
} }
var facet_name = that.entity.redirect_facet; var facet_name = that.entity.redirect_facet;
var entity_name = entity.name; var entity_name = entity.name;
var tab_name, facet; var facet;
if (that.redirect_info) { if (that.redirect_info) {
entity_name = that.redirect_info.entity || entity_name; entity_name = that.redirect_info.entity || entity_name;
facet_name = that.redirect_info.facet || facet_name; facet_name = that.redirect_info.facet || facet_name;
tab_name = that.redirect_info.tab;
}
if (tab_name) {
facet = IPA.nav.get_tab_facet(tab_name);
} }
if (!facet) { if (!facet) {
@ -284,7 +596,7 @@ IPA.facet = function(spec, no_init) {
var facet = that.get_redirect_facet(); var facet = that.get_redirect_facet();
if (!facet) return; if (!facet) return;
IPA.nav.show_page(facet.entity.name, facet.name); navigation.show(facet);
}; };
var redirect_error_codes = [4001]; var redirect_error_codes = [4001];
@ -306,6 +618,8 @@ IPA.facet = function(spec, no_init) {
that.action_state.init(that); that.action_state.init(that);
that.actions.init(that); that.actions.init(that);
that.header.init(); that.header.init();
on(that.state, 'reset', that.on_state_reset);
that.state.watch(that.on_state_change);
var buttons_spec = { var buttons_spec = {
factory: IPA.control_buttons_widget, factory: IPA.control_buttons_widget,
@ -369,7 +683,7 @@ IPA.facet_header = function(spec) {
if (that.facet.disable_facet_tabs) return; if (that.facet.disable_facet_tabs) return;
$(that.facet_tabs).find('a').removeClass('selected'); $(that.facet_tabs).find('a').removeClass('selected');
var facet_name = IPA.nav.get_state(that.facet.entity.name+'-facet'); var facet_name = that.facet.name;
if (!facet_name || facet_name === 'default') { if (!facet_name || facet_name === 'default') {
that.facet_tabs.find('a:first').addClass('selected'); that.facet_tabs.find('a:first').addClass('selected');
@ -388,26 +702,29 @@ IPA.facet_header = function(spec) {
if (!that.facet.disable_breadcrumb) { if (!that.facet.disable_breadcrumb) {
var breadcrumb = []; var breadcrumb = [];
var keys = [];
// all pkeys should be available in facet
var keys = that.facet.get_pkeys();
var entity = that.facet.entity.get_containing_entity(); var entity = that.facet.entity.get_containing_entity();
i = keys.length - 2; //set pointer to first containing entity
while (entity) { while (entity) {
key = IPA.nav.get_state(entity.name+'-pkey'); key = keys[i];
breadcrumb.unshift($('<a/>', { breadcrumb.unshift($('<a/>', {
'class': 'breadcrumb-element', 'class': 'breadcrumb-element',
text: key, text: key,
title: entity.metadata.label_singular, title: entity.metadata.label_singular,
click: function(entity) { click: function(entity) {
return function() { return function() {
IPA.nav.show_page(entity.name, 'default'); navigation.show_entity(entity.name, 'default');
return false; return false;
}; };
}(entity) }(entity)
})); }));
entity = entity.get_containing_entity(); entity = entity.get_containing_entity();
keys.unshift(key); i--;
} }
//calculation of breadcrumb keys length //calculation of breadcrumb keys length
@ -471,8 +788,8 @@ IPA.facet_header = function(spec) {
return false; return false;
} }
var pkey = IPA.nav.get_state(that.facet.entity.name+'-pkey'); var pkeys = that.facet.get_pkeys();
IPA.nav.show_page(that.facet.entity.name, other_facet.name, pkey); navigation.show(other_facet, [pkeys]);
return false; return false;
} }
@ -762,6 +1079,7 @@ IPA.table_facet = function(spec, no_init) {
that.add_column = function(column) { that.add_column = function(column) {
column.entity = that.managed_entity; column.entity = that.managed_entity;
column.facet = that;
that.columns.put(column.name, column); that.columns.put(column.name, column);
}; };
@ -865,15 +1183,12 @@ IPA.table_facet = function(spec, no_init) {
delete that.table.current_page; delete that.table.current_page;
var state = {}; var page = parseInt(that.state.page, 10) || 1;
var page = parseInt(IPA.nav.get_state(that.entity.name+'-page'), 10) || 1;
if (page < 1) { if (page < 1) {
state[that.entity.name+'-page'] = 1; that.state.set({page: 1});
IPA.nav.push_state(state);
return; return;
} else if (page > that.table.total_pages) { } else if (page > that.table.total_pages) {
state[that.entity.name+'-page'] = that.table.total_pages; that.state.set({page: that.table.total_pages});
IPA.nav.push_state(state);
return; return;
} }
that.table.current_page = page; that.table.current_page = page;
@ -1027,7 +1342,16 @@ IPA.table_facet = function(spec, no_init) {
if (column.link && column.primary_key) { if (column.link && column.primary_key) {
column.link_handler = function(value) { column.link_handler = function(value) {
IPA.nav.show_page(entity.name, that.details_facet_name, value); var pkeys = [value];
// for nested entities
var containing_entity = entity.get_containing_entity();
if (containing_entity && that.entity.name === containing_entity.name) {
pkeys = that.get_pkeys();
pkeys.push(value);
}
navigation.show_entity(entity.name, that.details_facet_name, pkeys);
return false; return false;
}; };
} }
@ -1042,19 +1366,17 @@ IPA.table_facet = function(spec, no_init) {
that.table.prev_page = function() { that.table.prev_page = function() {
if (that.table.current_page > 1) { if (that.table.current_page > 1) {
var state = {}; var page = that.table.current_page - 1;
state[that.entity.name+'-page'] = that.table.current_page - 1;
that.set_expired_flag(); that.set_expired_flag();
IPA.nav.push_state(state); that.state.set({page: page});
} }
}; };
that.table.next_page = function() { that.table.next_page = function() {
if (that.table.current_page < that.table.total_pages) { if (that.table.current_page < that.table.total_pages) {
var state = {}; var page = that.table.current_page + 1;
state[that.entity.name+'-page'] = that.table.current_page + 1;
that.set_expired_flag(); that.set_expired_flag();
IPA.nav.push_state(state); that.state.set({page: page});
} }
}; };
@ -1064,10 +1386,8 @@ IPA.table_facet = function(spec, no_init) {
} else if (page > that.total_pages) { } else if (page > that.total_pages) {
page = that.total_pages; page = that.total_pages;
} }
var state = {};
state[that.entity.name+'-page'] = page;
that.set_expired_flag(); that.set_expired_flag();
IPA.nav.push_state(state); that.state.set({page: page});
}; };
}; };
@ -1657,9 +1977,7 @@ IPA.self_service_state_evaluator = function(spec) {
var old_state = that.state; var old_state = that.state;
that.state = []; that.state = [];
var self_service = IPA.nav.name === 'self-service'; if (IPA.is_selfservice) {
if (self_service) {
that.state.push('self-service'); that.state.push('self-service');
} }
@ -2042,5 +2360,55 @@ IPA.action_list_widget = function(spec) {
return that; return that;
}; };
return {}; var FacetState = declare([Stateful, Evented], {
/**
* Properties to ignore in clear and clone operation
*/
_ignore_properties: {_watchCallbacks:1, onreset:1},
/**
* Gets object containing shallow copy of state's properties.
*/
clone: function() {
var clone = {};
for(var x in this){
if (this.hasOwnProperty(x) && !(x in this._ignore_properties)) {
clone[x] = lang.clone(this[x]);
}
}
return clone;
},
/**
* Unset all properties.
*/
clear: function() {
var undefined;
for(var x in this){
if (this.hasOwnProperty(x) && !(x in this._ignore_properties)) {
this.set(x, undefined);
}
}
},
/**
* Set completly new state. Old state is cleared.
*
* Supresses all watch callbacks.
* Others can be notified by listening to 'reset' event.
*/
reset: function(object) {
var _watchCallbacks = this._watchCallbacks;
delete this._watchCallbacks; //prevent watch callbacks
var old_state = this.clone();
this.clear();
this.set(object);
var new_state = this.clone();
this._watchCallbacks = _watchCallbacks;
this.emit('reset', new_state, old_state);
}
});
return { FacetState: FacetState};
}); });

View File

@ -21,7 +21,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
define(['dojo/_base/array', './ipa', './jquery'], function(array, IPA, $) {
define(['dojo/_base/array', './ipa', './jquery', './navigation'],
function(array, IPA, $, navigation) {
IPA.field = function(spec) { IPA.field = function(spec) {
spec = spec || {}; spec = spec || {};
@ -735,8 +737,8 @@ IPA.link_field = function(spec) {
that.on_link_clicked = function() { that.on_link_clicked = function() {
IPA.nav.show_entity_page( navigation.show_entity(
that.other_entity, that.other_entity.name,
'default', 'default',
that.other_pkeys()); that.other_pkeys());
}; };

View File

@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
define(['./ipa', './jquery', './details', './search', './association', define(['./ipa', './jquery', './navigation', './details', './search',
'./entity', './hbac'], function(IPA, $) { './association', './entity', './hbac'], function(IPA, $, navigation) {
IPA.hbac.test_entity = function(spec) { IPA.hbac.test_entity = function(spec) {
@ -198,9 +198,7 @@ IPA.hbac.test_facet = function(spec) {
var facet = facet_group.get_facet_by_index(index - 1); var facet = facet_group.get_facet_by_index(index - 1);
var state = {}; navigation.show(facet);
state[that.entity.name+'-facet'] = facet.name;
IPA.nav.push_state(state);
}; };
that.next = function() { that.next = function() {
@ -210,9 +208,7 @@ IPA.hbac.test_facet = function(spec) {
var facet = facet_group.get_facet_by_index(index + 1); var facet = facet_group.get_facet_by_index(index + 1);
var state = {}; navigation.show(facet);
state[that.entity.name+'-facet'] = facet.name;
IPA.nav.push_state(state);
}; };
that.get_search_command_name = function() { that.get_search_command_name = function() {
@ -221,7 +217,7 @@ IPA.hbac.test_facet = function(spec) {
that.refresh = function() { that.refresh = function() {
var filter = IPA.nav.get_state(that.entity.name+'-'+that.name+'-filter'); var filter = that.state.filter;
var command = IPA.command({ var command = IPA.command({
name: that.get_search_command_name(), name: that.get_search_command_name(),
@ -357,7 +353,7 @@ IPA.hbac.test_select_facet = function(spec) {
that.find = function() { that.find = function() {
var old_filter = IPA.nav.get_state(that.entity.name+'-'+that.name+'-filter'); var old_filter = that.state.filter;
var filter = that.filter.val(); var filter = that.filter.val();
that.set_expired_flag(); that.set_expired_flag();
@ -365,9 +361,7 @@ IPA.hbac.test_select_facet = function(spec) {
if (old_filter === filter) { if (old_filter === filter) {
that.refresh(); that.refresh();
} else { } else {
var state = {}; that.state.set({filter: filter});
state[that.entity.name+'-'+that.name+'-filter'] = filter;
IPA.nav.push_state(state);
} }
}; };
@ -621,6 +615,7 @@ IPA.hbac.test_run_facet = function(spec) {
that.new_test = function() { that.new_test = function() {
var facet = that.entity.get_facet('user'); var facet = that.entity.get_facet('user');
facet.reset(); facet.reset();
var entry_point = facet;
facet = that.entity.get_facet('targethost'); facet = that.entity.get_facet('targethost');
facet.reset(); facet.reset();
@ -634,9 +629,7 @@ IPA.hbac.test_run_facet = function(spec) {
facet = that.entity.get_facet('run_test'); facet = that.entity.get_facet('run_test');
facet.reset(); facet.reset();
var state = {}; navigation.show(entry_point);
state[that.entity.name+'-facet'] = 'user';
IPA.nav.push_state(state);
}; };
that.reset = function() { that.reset = function() {
@ -806,9 +799,7 @@ IPA.hbac.validation_dialog = function(spec) {
that.redirect_to_facet = function(facet) { that.redirect_to_facet = function(facet) {
that.close(); that.close();
var state = {}; navigation.show(facet);
state[facet.entity.name+'-facet'] = facet.name;
IPA.nav.push_state(state);
}; };
return that; return that;

View File

@ -248,7 +248,7 @@ IPA.host.details_facet = function(spec, no_init) {
that.certificate_updated = IPA.observer(); that.certificate_updated = IPA.observer();
that.get_refresh_command_name = function() { that.get_refresh_command_name = function() {
return that.entity.name+'_show_'+that.pkey; return that.entity.name+'_show_'+that.get_pkey();
}; };
if (!no_init) that.init_details_facet(); if (!no_init) that.init_details_facet();

View File

@ -2058,9 +2058,16 @@ IPA.is_empty = function(value) {
if (value instanceof Array) { if (value instanceof Array) {
empty = empty || value.length === 0 || empty = empty || value.length === 0 ||
(value.length === 1) && (value[0] === ''); (value.length === 1) && (value[0] === '');
} else if (typeof value === 'object') {
var has_p = false;
for (var p in value) {
if (value.hasOwnProperty(p)) {
has_p = true;
break;
} }
}
if (value === '') empty = true; empty = !has_p;
} else if (value === '') empty = true;
return empty; return empty;
}; };

View File

@ -132,7 +132,7 @@ IPA.rule_association_table_widget = function(spec) {
that.create_add_dialog = function() { that.create_add_dialog = function() {
var entity_label = that.entity.metadata.label_singular; var entity_label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
var other_entity_label = that.other_entity.metadata.label; var other_entity_label = that.other_entity.metadata.label;
var title = that.add_title; var title = that.add_title;

View File

@ -114,27 +114,13 @@ IPA.search_facet = function(spec, no_init) {
that.show = function() { that.show = function() {
that.facet_show(); that.facet_show();
var filter = IPA.nav.get_state(that.entity.name+'-filter'); var filter = that.state.filter || '';
that.old_filter = filter || '';
that.old_pkeys = that.managed_entity.get_primary_key_prefix();
if (that.filter) { if (that.filter) {
that.filter.val(filter); that.filter.val(filter);
} }
}; };
that.needs_update = function() {
if (that._needs_update !== undefined) return that._needs_update;
var needs_update = that.facet_needs_update();
//check if state changed
var pkeys = that.managed_entity.get_primary_key_prefix();
needs_update = needs_update || IPA.array_diff(pkeys, that.old_pkeys);
return needs_update;
};
that.show_add_dialog = function() { that.show_add_dialog = function() {
var dialog = that.managed_entity.get_dialog('add'); var dialog = that.managed_entity.get_dialog('add');
dialog.open(that.container); dialog.open(that.container);
@ -172,13 +158,13 @@ IPA.search_facet = function(spec, no_init) {
that.find = function() { that.find = function() {
var filter = that.filter.val(); var filter = that.filter.val();
var old_filter = IPA.nav.get_state(that.managed_entity.name+'-filter'); var old_filter = that.state.filter;
var state = {}; var state = {};
state[that.managed_entity.name + '-filter'] = filter; state[that.managed_entity.name + '-filter'] = filter;
if (filter !== old_filter) that.set_expired_flag(); if (filter !== old_filter) that.set_expired_flag();
IPA.nav.push_state(state); that.state.set({filter: filter});
}; };
that.get_search_command_name = function() { that.get_search_command_name = function() {
@ -191,8 +177,7 @@ IPA.search_facet = function(spec, no_init) {
that.create_refresh_command = function() { that.create_refresh_command = function() {
var filter = that.managed_entity.get_primary_key_prefix(); var filter = that.state.filter || '';
filter.push(IPA.nav.get_state(that.managed_entity.name+'-filter'));
var command = IPA.command({ var command = IPA.command({
name: that.get_search_command_name(), name: that.get_search_command_name(),
@ -237,10 +222,11 @@ IPA.search_facet = function(spec, no_init) {
that.needs_clear = function() { that.needs_clear = function() {
var clear = false; var clear = false;
var filter = IPA.nav.get_state(that.entity.name+'-filter') || '';
var filter = that.state.filter;
clear = that.old_filter !== '' || that.old_filter !== filter; clear = that.old_filter !== '' || that.old_filter !== filter;
var pkeys = that.managed_entity.get_primary_key_prefix(); var pkeys = that.get_pkeys();
clear = clear || IPA.array_diff(pkeys, that.old_pkeys); clear = clear || IPA.array_diff(pkeys, that.old_pkeys);
return clear; return clear;
@ -275,7 +261,8 @@ IPA.search_deleter_dialog = function(spec) {
error_message: IPA.messages.search.partial_delete error_message: IPA.messages.search.partial_delete
}); });
var pkeys = that.entity.get_primary_key_prefix(); var pkeys = that.facet.get_pkeys();
pkeys.pop();
for (var i=0; i<that.values.length; i++) { for (var i=0; i<that.values.length; i++) {
var command = IPA.command({ var command = IPA.command({
@ -345,14 +332,9 @@ IPA.nested_search_facet = function(spec) {
that.show = function() { that.show = function() {
that.facet_show(); that.facet_show();
var pkey = that.get_pkey();
that.header.set_pkey( that.header.set_pkey(pkey);
IPA.nav.get_state(IPA.current_entity.name+'-pkey')); var filter = that.state.filter || '';
var filter = IPA.nav.get_state(that.managed_entity.name+'-filter');
that.old_filter = filter || '';
that.old_pkeys = that.managed_entity.get_primary_key_prefix();
if (that.filter) { if (that.filter) {
that.filter.val(filter); that.filter.val(filter);
} }
@ -360,7 +342,7 @@ IPA.nested_search_facet = function(spec) {
that.refresh = function() { that.refresh = function() {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.get_pkey();
if ((!pkey) && (that.entity.redirect_facet)) { if ((!pkey) && (that.entity.redirect_facet)) {
that.redirect(); that.redirect();

View File

@ -807,7 +807,7 @@ IPA.sudo.options_section = function(spec) {
var ipasudoopt = dialog.fields.get_field('ipasudoopt'); var ipasudoopt = dialog.fields.get_field('ipasudoopt');
var value = ipasudoopt.save()[0]; var value = ipasudoopt.save()[0];
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
var command = IPA.command({ var command = IPA.command({
entity: 'sudorule', entity: 'sudorule',
@ -853,7 +853,7 @@ IPA.sudo.options_section = function(spec) {
return; return;
} }
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
var title = IPA.messages.dialogs.remove_title; var title = IPA.messages.dialogs.remove_title;
title = title.replace('${entity}', label); title = title.replace('${entity}', label);

View File

@ -33,7 +33,7 @@ IPA.user.entity = function(spec) {
that.init = function() { that.init = function() {
that.entity_init(); that.entity_init();
var self_service = IPA.nav.name === 'self-service'; var self_service = IPA.is_selfservice;
var link = self_service ? false : undefined; var link = self_service ? false : undefined;
that.builder.search_facet({ that.builder.search_facet({
@ -330,7 +330,7 @@ IPA.user.details_facet = function(spec) {
that.create_refresh_command = function() { that.create_refresh_command = function() {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.get_pkey();
var batch = IPA.batch_command({ var batch = IPA.batch_command({
name: 'user_details_refresh' name: 'user_details_refresh'
@ -509,20 +509,10 @@ IPA.user_password_dialog = function(spec) {
that.success_handler = spec.on_success; that.success_handler = spec.on_success;
that.error_handler = spec.on_error; that.error_handler = spec.on_error;
that.self_service = spec.self_service; //option to force self-service that.self_service = spec.self_service; //option to force self-service
that.pkey = spec.pkey;
that.get_pkey = function() {
var pkey;
if (that.self_service) {
pkey = IPA.whoami.uid[0];
} else {
pkey = IPA.nav.get_state('user-pkey');
}
return pkey;
};
that.is_self_service = function() { that.is_self_service = function() {
var pkey = that.get_pkey(); var self_service = that.pkey === IPA.whoami.uid[0];
var self_service = pkey === IPA.whoami.uid[0];
return self_service; return self_service;
}; };
@ -563,7 +553,6 @@ IPA.user_password_dialog = function(spec) {
if (!that.validate()) return; if (!that.validate()) return;
var pkey = that.get_pkey();
var self_service = that.is_self_service(); var self_service = that.is_self_service();
var record = {}; var record = {};
@ -574,7 +563,7 @@ IPA.user_password_dialog = function(spec) {
var repeat_password = record.password2[0]; var repeat_password = record.password2[0];
that.set_password( that.set_password(
pkey, that.pkey,
current_password, current_password,
new_password, new_password,
that.on_reset_success, that.on_reset_success,
@ -642,7 +631,8 @@ IPA.user.reset_password_action = function(spec) {
that.execute_action = function(facet) { that.execute_action = function(facet) {
var dialog = IPA.user_password_dialog({ var dialog = IPA.user_password_dialog({
entity: facet.entity entity: facet.entity,
pkey: facet.get_pkey()
}); });
dialog.open(); dialog.open();

View File

@ -1468,6 +1468,10 @@ IPA.table_widget = function (spec) {
that.add_column = function(column) { that.add_column = function(column) {
column.entity = that.entity; column.entity = that.entity;
// check for facet to avoid overriding with undefined, because of
// initialization bug - column may be already created by facet (and
// therefore facet set) but this table widget may not have facet set.
if (that.facet) column.facet = that.facet;
that.columns.put(column.name, column); that.columns.put(column.name, column);
}; };
@ -2158,7 +2162,7 @@ IPA.attribute_table_widget = function(spec) {
}; };
that.get_pkeys = function() { that.get_pkeys = function() {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
return [pkey]; return [pkey];
}; };
@ -2201,7 +2205,7 @@ IPA.attribute_table_widget = function(spec) {
} }
var label = that.entity.metadata.label_singular; var label = that.entity.metadata.label_singular;
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = that.facet.get_pkey();
dialog_spec.title = dialog_spec.title || IPA.messages.dialogs.add_title; dialog_spec.title = dialog_spec.title || IPA.messages.dialogs.add_title;
dialog_spec.title = dialog_spec.title.replace('${entity}', label); dialog_spec.title = dialog_spec.title.replace('${entity}', label);
dialog_spec.title = dialog_spec.title.replace('${pkey}', pkey); dialog_spec.title = dialog_spec.title.replace('${pkey}', pkey);