From 379a9cc41f04d36538aee11839c1222d408b4f99 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 18 Nov 2010 20:17:14 -0600 Subject: SUDO Rule Search and Details Pages The search and details pages for SUDO Rule have been added. Codes that are shared with HBAC have been moved to rule.js. The following methods were renamed for consistency: - ipa_details_load() -> ipa_details_refresh() - ipa_details_display() -> ipa_details_load() The ipa_details_cache has been removed because the cache is now stored in each widget. The index.xhtml has been removed. All references to it has been changed to index.html. The Unselect All checkbox has been fixed. Unnecessary parameter 'container' has been removed. The unit test has been updated and new test data has been added. --- install/static/details.js | 173 ++++++++++++++++++++++++++-------------------- 1 file changed, 97 insertions(+), 76 deletions(-) (limited to 'install/static/details.js') diff --git a/install/static/details.js b/install/static/details.js index f7afcece..9bf54a8f 100644 --- a/install/static/details.js +++ b/install/static/details.js @@ -24,8 +24,6 @@ /* REQUIRES: ipa.js */ -var ipa_details_cache = {}; - IPA.is_field_writable = function(rights){ if (!rights){ alert('no right'); @@ -42,9 +40,15 @@ function ipa_details_field(spec) { that.load = spec.load || load; that.save = spec.save || save; - function load(container, result) { - + function load(result) { + that.record = result; that.values = result[that.name]; + that.reset(); + } + + that.set_values = function(values) { + + if (!that.record) return; /* remove all
tags i.e. all attribute values */ $('dd', that.container).remove(); @@ -67,8 +71,8 @@ function ipa_details_field(spec) { var rights = 'rsc'; - if (result.attributelevelrights){ - rights = result.attributelevelrights[this.name] || rights ; + if (that.record.attributelevelrights){ + rights = that.record.attributelevelrights[this.name] || rights ; } if (that.values) { @@ -100,9 +104,9 @@ function ipa_details_field(spec) { dd.appendTo(that.container); } } - } + }; - function save(container) { + function save() { var values = []; $('dd', that.container).each(function () { @@ -219,7 +223,7 @@ function ipa_details_section(spec){ that.setup = function(container) { - this.container = container; + that.container = container; if (that.template) return; @@ -245,7 +249,7 @@ function ipa_details_section(spec){ var field = fields[i]; var span = $('span[name='+field.name+']', this.container).first(); field.setup(span); - field.load(span, result); + field.load(result); } } ); @@ -255,7 +259,7 @@ function ipa_details_section(spec){ for (var j=0; j', { 'class': 'content' }).appendTo(container); + var entity_container = $('#' + that.entity_name); + var action_panel = $('.action-panel', entity_container); + + var ul = $('ul', action_panel); var buttons = $('
  • ', { 'class': 'details-buttons' - }).prependTo($('.action-panel ul')); - - buttons.append(ipa_button({ - 'label': 'Reset', - 'icon': 'ui-icon-refresh', - 'class': 'details-reset', - 'click': function() { - facet.reset(container); - return false; - } - })); + }).prependTo(ul); - var pkey_name = IPA.metadata[facet.entity_name].primary_key; + $('', { + 'type': 'text', + 'name': 'reset' + }).appendTo(buttons); - buttons.append(ipa_button({ - 'label': 'Update', - 'icon': 'ui-icon-check', - 'class': 'details-update', - 'click': function() { - facet.update(container, ipa_details_cache[facet.entity_name][pkey_name][0]); - return false; - } - })); + $('', { + 'type': 'text', + 'name': 'update' + }).appendTo(buttons); details.append('
    '); details.append('
    '); - for (var i = 0; i < facet.sections.length; ++i) { - var section = facet.sections[i]; + for (var i = 0; i < that.sections.length; ++i) { + var section = that.sections[i]; - details.append($('

    ',{ - click: function(){_h2_on_click(this)}, - html:"− "+section.label - })); + $('

    ', { + 'name': section.name, + 'html':"− "+section.label + }).appendTo(details); var div = $('
    ', { - 'id': facet.entity_name+'-'+facet.name+'-'+section.name, + 'id': that.entity_name+'-'+that.name+'-'+section.name, 'class': 'details-section' }).appendTo(details); @@ -498,19 +498,48 @@ function ipa_details_setup(container) { var that = this; + that.facet_setup(container); + + var button = $('input[name=reset]', that.container); + that.reset_button = ipa_button({ + 'label': 'Reset', + 'icon': 'ui-icon-refresh', + 'class': 'details-reset', + 'click': function() { + that.reset(); + return false; + } + }); + button.replaceWith(that.reset_button); + + button = $('input[name=update]', that.container); + that.update_button = ipa_button({ + 'label': 'Update', + 'icon': 'ui-icon-check', + 'class': 'details-update', + 'click': function() { + that.update(); + return false; + } + }); + button.replaceWith(that.update_button); + for (var i = 0; i < that.sections.length; ++i) { var section = that.sections[i]; + var header = $('h2[name='+section.name+']', that.container); + header.click(function(){ _h2_on_click(this) }); + var div = $( '#'+that.entity_name+'-'+that.name+'-'+section.name, - container + that.container ); section.setup(div); } } -function ipa_details_load(container) { +function ipa_details_refresh() { var that = this; var entity = IPA.get_entity(that.entity_name); @@ -519,17 +548,11 @@ function ipa_details_load(container) { if (!that.pkey && !entity.default_facet) return; function on_success(data, text_status, xhr) { - var result = data.result.result; - - ipa_details_cache[that.entity_name] = $.extend(true, {}, result); - for (var i = 0; i < that.sections.length; ++i) { - var section = that.sections[i]; - section.load(result); - } + that.load(data.result.result); } function on_failure(xhr, text_status, error_thrown) { - var details = $('.details', container).empty(); + var details = $('.details', that.container).empty(); details.append('

    Error: '+error_thrown.name+'

    '); details.append('

    '+error_thrown.title+'

    '); details.append('

    '+error_thrown.message+'

    '); @@ -543,10 +566,12 @@ function ipa_details_load(container) { ); } -function ipa_details_update(container, pkey, on_win, on_fail) +function ipa_details_update(on_win, on_fail) { - var facet = this; - var entity_name = facet.entity_name; + var that = this; + var entity_name = that.entity_name; + + var pkey = that.get_primary_key(); function update_on_win(data, text_status, xhr) { if (on_win) @@ -555,8 +580,7 @@ function ipa_details_update(container, pkey, on_win, on_fail) return; var result = data.result.result; - ipa_details_cache[entity_name] = $.extend(true, {}, result); - facet.display(result); + that.load(result); } function update_on_fail(xhr, text_status, error_thrown) { @@ -571,16 +595,17 @@ function ipa_details_update(container, pkey, on_win, on_fail) var modlist = {'all': true, 'setattr': [], 'addattr': [], 'rights': true}; var attrs_wo_option = {}; - for (var i=0; i 1){ modlist[field.name] = values; } else if (param_info['multivalue']){ - modlist[field.name] = []; + modlist[field.name] = []; } } else { if (values.length) attrs_wo_option[field.name] = values; @@ -615,13 +640,14 @@ var _ipa_span_hint_template = 'Hint: D'; -function ipa_details_display(result) +function ipa_details_load(record) { - var facet = this; + var that = this; + that.record = record; - for (var i=0; i