Page is cleared before it is visible

https://fedorahosted.org/freeipa/ticket/1459

Changes:
 * added clear method to widgets, section, search, details, association facets
 * clear and refresh method in facet are called only if key/filter was changed
 * added id generator for widgets
This commit is contained in:
Petr Vobornik 2011-10-24 14:53:29 +02:00 committed by Endi S. Dewata
parent 237a021848
commit 9afe4b98da
9 changed files with 173 additions and 28 deletions

View File

@ -871,8 +871,6 @@ IPA.association_facet = function (spec) {
that.facet_create_header(container); that.facet_create_header(container);
that.pkey = IPA.nav.get_state(that.entity.name+'-pkey');
if (!that.read_only) { if (!that.read_only) {
that.remove_button = IPA.action_button({ that.remove_button = IPA.action_button({
name: 'remove', name: 'remove',
@ -908,12 +906,13 @@ IPA.association_facet = function (spec) {
span.append(IPA.messages.association.show_results); span.append(IPA.messages.association.show_results);
span.append(' '); span.append(' ');
var direct_id = that.entity.name+'-'+that.attribute_member+'-'+that.other_entity+'-direct-radio'; var name = that.entity.name+'-'+that.attribute_member+'-'+that.other_entity+'-type-radio';
var direct_id = name + '-direct';
that.direct_radio = $('<input/>', { that.direct_radio = $('<input/>', {
id: direct_id, id: direct_id,
type: 'radio', type: 'radio',
name: 'type', name: name,
value: 'direct', value: 'direct',
click: function() { click: function() {
that.association_type = $(this).val(); that.association_type = $(this).val();
@ -929,12 +928,12 @@ IPA.association_facet = function (spec) {
span.append(' '); span.append(' ');
var indirect_id = that.entity.name+'-'+that.attribute_member+'-'+that.other_entity+'-indirect-radio'; var indirect_id = name + '-indirect';
that.indirect_radio = $('<input/>', { that.indirect_radio = $('<input/>', {
id: indirect_id, id: indirect_id,
type: 'radio', type: 'radio',
name: 'type', name: name,
value: 'indirect', value: 'indirect',
click: function() { click: function() {
that.association_type = $(this).val(); that.association_type = $(this).val();
@ -1201,6 +1200,16 @@ IPA.association_facet = function (spec) {
command.execute(); command.execute();
}; };
that.clear = function() {
that.header.clear();
that.table.clear();
};
that.needs_update = function() {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
return that.pkey !== pkey;
};
/*initialization*/ /*initialization*/
var adder_columns = spec.adder_columns || []; var adder_columns = spec.adder_columns || [];
for (var i=0; i<adder_columns.length; i++) { for (var i=0; i<adder_columns.length; i++) {

View File

@ -725,6 +725,15 @@ IPA.cert.status_widget = function(spec) {
} }
}; };
that.clear = function() {
that.status_valid.css('display', 'none');
that.status_missing.css('display', 'none');
that.status_revoked.css('display', 'none');
that.revoke_button.css('display', 'none');
that.restore_button.css('display', 'none');
that.revocation_reason.text('');
};
function set_status(status, revocation_reason) { function set_status(status, revocation_reason) {
that.status_valid.css('display', status == IPA.cert.CERTIFICATE_STATUS_VALID ? 'inline' : 'none'); that.status_valid.css('display', status == IPA.cert.CERTIFICATE_STATUS_VALID ? 'inline' : 'none');
that.status_missing.css('display', status == IPA.cert.CERTIFICATE_STATUS_MISSING ? 'inline' : 'none'); that.status_missing.css('display', status == IPA.cert.CERTIFICATE_STATUS_MISSING ? 'inline' : 'none');

View File

@ -199,6 +199,14 @@ IPA.details_section = function(spec) {
} }
}; };
that.clear = function() {
var fields = that.fields.values;
for (var i=0; i< fields.length; i++) {
fields[i].clear();
}
};
init(); init();
// methods that should be invoked by subclasses // methods that should be invoked by subclasses
@ -409,8 +417,6 @@ IPA.details_facet = function(spec) {
that.facet_create_header(container); that.facet_create_header(container);
that.pkey = IPA.nav.get_state(that.entity.name+'-pkey');
that.create_controls(); that.create_controls();
that.expand_button = IPA.action_button({ that.expand_button = IPA.action_button({
@ -523,7 +529,7 @@ IPA.details_facet = function(spec) {
that.needs_update = function() { that.needs_update = function() {
var pkey = IPA.nav.get_state(that.entity.name+'-pkey'); var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
return pkey != that.pkey; return pkey !== that.pkey;
}; };
that.section_dirty_changed = function(dirty) { that.section_dirty_changed = function(dirty) {
@ -720,6 +726,15 @@ IPA.details_facet = function(spec) {
command.execute(); command.execute();
}; };
that.clear = function() {
that.header.clear();
var sections = that.sections.values;
for (var i=0; i< sections.length; i++) {
sections[i].clear();
}
};
that.add_sections(spec.sections); that.add_sections(spec.sections);
that.details_facet_create_content = that.create_content; that.details_facet_create_content = that.create_content;

View File

@ -109,6 +109,9 @@ IPA.facet = function (spec) {
that.header.load(data); that.header.load(data);
}; };
that.clear = function() {
};
that.needs_update = function() { that.needs_update = function() {
return true; return true;
}; };
@ -336,6 +339,11 @@ IPA.facet_header = function(spec) {
that.load = function(data) { that.load = function(data) {
if (!that.facet.disable_facet_tabs) { if (!that.facet.disable_facet_tabs) {
var pkey = that.facet.pkey;
if(!pkey || !data) {
pkey = '';
}
var facet_groups = that.facet.entity.facet_groups.values; var facet_groups = that.facet.entity.facet_groups.values;
for (var i=0; i<facet_groups.length; i++) { for (var i=0; i<facet_groups.length; i++) {
var facet_group = facet_groups[i]; var facet_group = facet_groups[i];
@ -345,7 +353,7 @@ IPA.facet_header = function(spec) {
var label = facet_group.label; var label = facet_group.label;
if (label) { if (label) {
label = label.replace('${primary_key}', that.facet.pkey); label = label.replace('${primary_key}', pkey);
var label_container = $('.facet-group-label', span); var label_container = $('.facet-group-label', span);
label_container.text(label); label_container.text(label);
@ -356,7 +364,7 @@ IPA.facet_header = function(spec) {
var facet = facets[j]; var facet = facets[j];
var link = $('li[name='+facet.name+'] a', span); var link = $('li[name='+facet.name+'] a', span);
var values = data[facet.name]; var values = data ? data[facet.name] : null;
if (values) { if (values) {
link.text(facet.label+' ('+values.length+')'); link.text(facet.label+' ('+values.length+')');
} else { } else {
@ -367,6 +375,10 @@ IPA.facet_header = function(spec) {
} }
}; };
that.clear = function() {
that.load();
};
return that; return that;
}; };
@ -589,9 +601,15 @@ IPA.entity = function (spec) {
that.facet.create(facet_container); that.facet.create(facet_container);
} }
that.facet.show(); if (that.facet.needs_update()) {
that.facet.header.select_tab(); that.facet.clear();
that.facet.refresh(); 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() { that.get_primary_key_prefix = function() {

View File

@ -567,6 +567,11 @@ IPA.host_keytab_widget = function(spec) {
set_status(value ? 'present' : 'missing'); set_status(value ? 'present' : 'missing');
}; };
that.clear = function() {
that.present_span.css('display', 'none');
that.missing_span.css('display', 'none');
};
function set_status(status) { function set_status(status) {
that.present_span.css('display', status == 'present' ? 'inline' : 'none'); that.present_span.css('display', status == 'present' ? 'inline' : 'none');
that.missing_span.css('display', status == 'missing' ? 'inline' : 'none'); that.missing_span.css('display', status == 'missing' ? 'inline' : 'none');
@ -720,6 +725,13 @@ IPA.host_password_widget = function(spec) {
set_status(value ? 'present' : 'missing'); set_status(value ? 'present' : 'missing');
}; };
that.clear = function() {
that.missing_span.css('display', 'none');
that.present_span.css('display', 'none');
var password_label = $('.button-label', that.set_password_button);
password_label.text('');
};
function set_status(status) { function set_status(status) {
that.status = status; that.status = status;

View File

@ -165,8 +165,10 @@ IPA.search_facet = function(spec) {
that.show = function() { that.show = function() {
that.facet_show(); that.facet_show();
var filter = IPA.nav.get_state(that.entity.name+'-filter');
that.old_filter = filter || '';
if (that.filter) { if (that.filter) {
var filter = IPA.nav.get_state(that.entity.name+'-filter');
that.filter.val(filter); that.filter.val(filter);
} }
}; };
@ -266,9 +268,8 @@ IPA.search_facet = function(spec) {
var current_entity = entity; var current_entity = entity;
filter.unshift(IPA.nav.get_state(current_entity.name+'-filter')); filter.unshift(IPA.nav.get_state(current_entity.name+'-filter'));
current_entity = current_entity.get_containing_entity(); current_entity = current_entity.get_containing_entity();
while(current_entity !== null){ while (current_entity !== null) {
filter.unshift( filter.unshift(IPA.nav.get_state(current_entity.name+'-pkey'));
IPA.nav.get_state(current_entity.name+'-pkey'));
current_entity = current_entity.get_containing_entity(); current_entity = current_entity.get_containing_entity();
} }
@ -286,6 +287,17 @@ IPA.search_facet = function(spec) {
command.execute(); command.execute();
}; };
that.clear = function() {
if(that.needs_clear()) {
that.table.clear();
}
};
that.needs_clear = function() {
var filter = IPA.nav.get_state(that.entity.name+'-filter') || '';
return that.old_filter !== '' || that.old_filter !== filter;
};
// methods that should be invoked by subclasses // methods that should be invoked by subclasses
that.search_facet_create_content = that.create_content; that.search_facet_create_content = that.create_content;

View File

@ -301,6 +301,11 @@ IPA.service_provisioning_status_widget = function (spec) {
set_status(krblastpwdchange ? 'valid' : 'missing'); set_status(krblastpwdchange ? 'valid' : 'missing');
}; };
that.clear = function() {
that.status_valid.css('display', 'none');
that.status_missing.css('display', 'none');
};
function set_status(status) { function set_status(status) {
that.status_valid.css('display', status == 'valid' ? 'inline' : 'none'); that.status_valid.css('display', status == 'valid' ? 'inline' : 'none');
that.status_missing.css('display', status == 'missing' ? 'inline' : 'none'); that.status_missing.css('display', status == 'missing' ? 'inline' : 'none');

View File

@ -292,6 +292,11 @@ IPA.user_status_widget = function(spec) {
} }
}; };
that.clear = function() {
that.link_span.css('display', 'none');
that.status_span.text('');
};
that.show_activation_dialog = function() { that.show_activation_dialog = function() {
var action = that.status_link.attr('href'); var action = that.status_link.attr('href');

View File

@ -379,6 +379,9 @@ IPA.widget = function(spec) {
error_link.css('display', 'none'); error_link.css('display', 'none');
}; };
that.clear = function() {
};
that.set_enabled = function() { that.set_enabled = function() {
}; };
@ -492,6 +495,11 @@ IPA.text_widget = function(spec) {
} }
}; };
that.clear = function() {
that.input.val('');
that.display_control.text('');
};
// methods that should be invoked by subclasses // methods that should be invoked by subclasses
that.text_load = that.load; that.text_load = that.load;
@ -756,6 +764,10 @@ IPA.multivalued_text_widget = function(spec) {
that.set_dirty(false, index); that.set_dirty(false, index);
}; };
that.clear = function() {
that.remove_rows();
};
that.update = function(index) { that.update = function(index) {
var value; var value;
@ -858,6 +870,10 @@ IPA.checkbox_widget = function (spec) {
return false; return false;
}; };
that.clear = function() {
that.input.attr('checked', false);
};
that.checkbox_save = that.save; that.checkbox_save = that.save;
that.checkbox_load = that.load; that.checkbox_load = that.load;
@ -945,6 +961,10 @@ IPA.checkboxes_widget = function (spec) {
} }
}; };
that.clear = function() {
$('input[name="'+that.name+'"]').attr('checked', false);
};
// methods that should be invoked by subclasses // methods that should be invoked by subclasses
that.checkboxes_update = that.update; that.checkboxes_update = that.update;
@ -965,19 +985,18 @@ IPA.radio_widget = function(spec) {
container.addClass('radio-widget'); container.addClass('radio-widget');
var name = IPA.html_util.get_next_id(that.entity.name+'-'+that.name+'-');
that.selector = 'input[name="'+name+'"]';
for (var i=0; i<that.options.length; i++) { for (var i=0; i<that.options.length; i++) {
var option = that.options[i]; var option = that.options[i];
// TODO: Use ID generator or accept ID from spec to avoid conflicts. var id = name+'-'+i;
// Currently this ID is unique enough, but it will not work if the
// radio button is used multiple times for the same attribute, for
// example both in adder dialog and details facet.
var id = that.entity.name+'-'+that.name+'-'+i+'-radio';
$('<input/>', { $('<input/>', {
id: id, id: id,
type: 'radio', type: 'radio',
name: that.name, name: name,
value: option.value value: option.value
}).appendTo(container); }).appendTo(container);
@ -991,7 +1010,7 @@ IPA.radio_widget = function(spec) {
that.create_undo(container); that.create_undo(container);
} }
var input = $('input[name="'+that.name+'"]', that.container); var input = $(that.selector, that.container);
input.change(function() { input.change(function() {
that.set_dirty(that.test_dirty()); that.set_dirty(that.test_dirty());
}); });
@ -1008,20 +1027,20 @@ IPA.radio_widget = function(spec) {
}; };
that.save = function() { that.save = function() {
var input = $('input[name="'+that.name+'"]:checked', that.container); var input = $(that.selector+':checked', that.container);
if (!input.length) return []; if (!input.length) return [];
return [input.val()]; return [input.val()];
}; };
that.update = function() { that.update = function() {
$('input[name="'+that.name+'"]', that.container).each(function() { $(that.selector, that.container).each(function() {
var input = this; var input = this;
input.checked = false; input.checked = false;
}); });
var value = that.values && that.values.length ? that.values[0] : ''; var value = that.values && that.values.length ? that.values[0] : '';
var input = $('input[name="'+that.name+'"][value="'+value+'"]', that.container); var input = $(that.selector+'[value="'+value+'"]', that.container);
if (input.length) { if (input.length) {
input.attr('checked', true); input.attr('checked', true);
} }
@ -1032,6 +1051,10 @@ IPA.radio_widget = function(spec) {
return false; return false;
}; };
that.clear = function() {
$(that.selector, that.container).attr('checked', false);
};
// methods that should be invoked by subclasses // methods that should be invoked by subclasses
that.radio_create = that.create; that.radio_create = that.create;
that.radio_save = that.save; that.radio_save = that.save;
@ -1104,6 +1127,10 @@ IPA.select_widget = function(spec) {
$('option', that.select).remove(); $('option', that.select).remove();
}; };
that.clear = function() {
that.empty();
};
// methods that should be invoked by subclasses // methods that should be invoked by subclasses
that.select_load = that.load; that.select_load = that.load;
that.select_save = that.save; that.select_save = that.save;
@ -1166,6 +1193,10 @@ IPA.textarea_widget = function (spec) {
that.input.val(value); that.input.val(value);
}; };
that.clear = function() {
that.input.val('');
};
return that; return that;
}; };
@ -1639,6 +1670,12 @@ IPA.table_widget = function (spec) {
} }
}; };
that.clear = function() {
that.empty();
that.summary.text('');
};
//column initialization
if (spec.columns) { if (spec.columns) {
for (var i=0; i<spec.columns; i++) { for (var i=0; i<spec.columns; i++) {
that.create_column(spec.columns[i]); that.create_column(spec.columns[i]);
@ -1893,6 +1930,11 @@ IPA.combobox_widget = function(spec) {
that.list.empty(); that.list.empty();
}; };
that.clear = function() {
that.input.val('');
that.remove_options();
};
return that; return that;
}; };
@ -2008,6 +2050,11 @@ IPA.entity_link_widget = function(spec) {
}).execute(); }).execute();
}; };
that.clear = function() {
that.nonlink.text('');
that.link.text('');
};
return that; return that;
}; };
@ -2081,3 +2128,16 @@ IPA.observer = function(spec) {
return that; return that;
}; };
IPA.html_util = function() {
var that = {};
that.id_count = 0;
that.get_next_id = function(prefix) {
that.id_count++;
return prefix ? prefix + that.id_count : that.id_count;
};
return that;
}();