From a4aba826a0e1327ba8df05da19d9ad0055d8269d Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 28 Apr 2011 19:17:58 -0500 Subject: Added facet container. Facet container has been added to hold facet header (i.e. title, search fields, buttons, links) and facet content. Each facet now occupies separate container, so it can be shown/hidden without having to redraw the content. --- install/ui/associate.js | 83 +++--- install/ui/details.js | 396 ++++++++++++++------------- install/ui/dns.js | 124 +++++---- install/ui/entitle.js | 66 ++--- install/ui/entity.js | 471 +++++++++++++++++++------------- install/ui/ipa.css | 96 ++++--- install/ui/ipa.js | 20 +- install/ui/navigation.js | 33 ++- install/ui/search.js | 265 +++++------------- install/ui/test/data/i18n_messages.json | 2 +- install/ui/test/data/ipa_init.json | 2 +- install/ui/test/details_tests.js | 35 ++- install/ui/test/entity_tests.js | 22 +- ipalib/plugins/internal.py | 2 +- 14 files changed, 789 insertions(+), 828 deletions(-) diff --git a/install/ui/associate.js b/install/ui/associate.js index 68009b571..15fdfbd72 100644 --- a/install/ui/associate.js +++ b/install/ui/associate.js @@ -799,7 +799,9 @@ IPA.association_facet = function (spec) { return pkey != that.pkey; }; - that.create_content = function(container) { + that.create_header = function(container) { + + that.facet_create_header(container); that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; @@ -812,41 +814,44 @@ IPA.association_facet = function (spec) { var other_label = IPA.metadata.objects[that.other_entity].label; /* TODO: generic handling of different relationships */ - var header_message = ''; + var title = ''; if (relationship[0] == 'Member') { - header_message = IPA.messages.association.member; - - } else if (relationship[0] == 'Parent') { - header_message = IPA.messages.association.parent; + title = IPA.messages.association.member; + + } else if (relationship[0] == 'Member Of') { + title = IPA.messages.association.parent; } - header_message = header_message.replace('${entity}', that.entity_name); - header_message = header_message.replace('${primary_key}', that.pkey); - header_message = header_message.replace('${other_entity}', other_label); + title = title.replace('${entity}', that.entity_name); + title = title.replace('${primary_key}', that.pkey); + title = title.replace('${other_entity}', other_label); - $('
', { - 'id': that.entity_name+'-'+that.other_entity, - html: $('

',{ html: header_message }) - }).appendTo(container); + that.set_title(container, title); - var span = $('', { 'name': 'association' }).appendTo(container); + that.remove_button = IPA.action_button({ + label: IPA.messages.buttons.remove, + icon: 'ui-icon-trash', + click: function() { + that.show_remove_dialog(); + return false; + } + }).appendTo(that.controls); - that.table.create(span); + that.add_button = IPA.action_button({ + label: IPA.messages.buttons.enroll, + icon: 'ui-icon-plus', + click: function() { + that.show_add_dialog(); + return false; + } + }).appendTo(that.controls); + }; - var li = that.entity_header.buttons; + that.create_content = function(container) { - // creating generic buttons for layout - $('', { - 'type': 'button', - 'name': 'remove', - 'value': IPA.messages.buttons.remove - }).appendTo(li); + var span = $('', { 'name': 'association' }).appendTo(container); - $('', { - 'type': 'button', - 'name': 'add', - 'value': IPA.messages.buttons.enroll - }).appendTo(li); + that.table.create(span); }; that.setup = function(container) { @@ -856,22 +861,16 @@ IPA.association_facet = function (spec) { var span = $('span[name=association]', that.container); that.table.setup(span); + }; - // replacing generic buttons with IPA.button and setting click handler + that.show = function() { + that.facet_show(); - var button = $('input[name=remove]', that.entity_header.buttons); - button.replaceWith(IPA.action_button({ - 'label': button.val(), - 'icon': 'ui-icon-trash', - 'click': function() { that.show_remove_dialog(); } - })); + that.pkey = $.bbq.getState(that.entity_name+'-pkey', true) || ''; + that.entity.header.set_pkey(that.pkey); - button = $('input[name=add]', that.entity_header.buttons); - button.replaceWith(IPA.action_button({ - 'label': button.val(), - 'icon': 'ui-icon-plus', - 'click': function() { that.show_add_dialog(); } - })); + that.entity.header.back_link.css('visibility', 'visible'); + that.entity.header.facet_tabs.css('visibility', 'visible'); }; that.show_add_dialog = function() { @@ -1010,9 +1009,7 @@ IPA.association_facet = function (spec) { that.refresh = function() { function on_success(data, text_status, xhr) { - if (that.pkey){ - that.entity_header.set_pkey(that.pkey); - } + that.table.empty(); var pkeys = data.result.result[that.name]; diff --git a/install/ui/details.js b/install/ui/details.js index 433f682f0..a4b36db73 100644 --- a/install/ui/details.js +++ b/install/ui/details.js @@ -266,9 +266,6 @@ IPA.details_facet = function(spec) { that.label = (IPA.messages && IPA.messages.facets && IPA.messages.facets.details) || spec.label; - that.update = spec.update || IPA.details_update; - that.refresh = spec.refresh || IPA.details_refresh; - that.sections = []; that.__defineGetter__("entity_name", function(){ @@ -319,38 +316,82 @@ IPA.details_facet = function(spec) { } }; - that.create_content = function(container) { + that.create_header = function(container) { + + that.facet_create_header(container); + that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var label = IPA.metadata.objects[that.entity_name].label; var title = IPA.messages.details.settings; title = title.replace('${entity}', label); + title = title.replace('${primary_key}', that.pkey); - $('

',{ - html: ""+title - }).append(IPA.create_network_spinner()). - appendTo(container); + that.set_title(container, title); - var details = $('
', { - 'name': 'details' - }).appendTo(container); + that.reset_button = IPA.action_button({ + label: IPA.messages.buttons.reset, + icon: 'ui-icon-refresh', + 'class': 'details-reset', + click: function() { + that.reset(); + return false; + } + }).appendTo(that.controls); + + that.update_button = IPA.action_button({ + label: IPA.messages.buttons.update, + icon: 'ui-icon-check', + 'class': 'details-update', + click: function() { + that.update(); + return false; + } + }).appendTo(that.controls); - $('', { + that.expand_button = $('', { name: 'expand_all', href: 'expand_all', text: 'Expand All', 'class': 'expand-collapse-all', - style: 'display: none;' - }).appendTo(details); + style: 'display: none;', + click: function() { + that.expand_button.css('display', 'none'); + that.collapse_button.css('display', 'inline'); + + for (var i=0; i', { + that.collapse_button = $('', { name: 'collapse_all', href: 'collapse_all', text: 'Collapse All', - 'class': 'expand-collapse-all' - }).appendTo(details); + 'class': 'expand-collapse-all', + click: function() { + that.expand_button.css('display', 'inline'); + that.collapse_button.css('display', 'none'); + + for (var i=0; i'); + var details = $('
', { + 'name': 'details' + }).appendTo(container); for (var i = 0; i < that.sections.length; ++i) { var section = that.sections[i]; @@ -374,6 +415,13 @@ IPA.details_facet = function(spec) { 'class': 'details-section' }).appendTo(details); + header.click(function(section, div) { + return function() { + var visible = div.is(":visible"); + that.toggle(section, !visible); + }; + }(section, div)); + section.create(div); details.append('
'); @@ -384,72 +432,33 @@ IPA.details_facet = function(spec) { that.facet_setup(container); - that.reset_button = IPA.action_button({ - 'label': 'Reset', - 'icon': 'ui-icon-refresh', - 'class': 'details-reset', - 'click': function() { - that.reset(); - return false; - } - }).appendTo(that.entity_header.buttons); - - that.update_button = IPA.action_button({ - 'label': 'Update', - 'icon': 'ui-icon-check', - 'class': 'details-update', - 'click': function() { - that.update(); - return false; - } - }).appendTo(that.entity_header.buttons); - var details = $('div[name=details]', that.container); - var expand_all = $('a[name=expand_all]', details); - expand_all.click(function() { - expand_all.css('display', 'none'); - collapse_all.css('display', 'inline'); - - for (var i=0; i 1){ + if (field.join) { + modlist[field.name] = values.join(','); + } else { + modlist[field.name] = values; + } + } else if (param_info['multivalue']){ + modlist[field.name] = []; + } + } else { + if (values.length) attrs_wo_option[field.name] = values; + } + } + } + + for (var attr in attrs_wo_option) { + values = attrs_wo_option[attr]; + modlist['setattr'].push(attr + '=' + values[0]); + for (var k = 1; k < values.length; ++k){ + modlist['addattr'].push(attr + '=' + values[k]); + } + } + + var pkey = that.get_primary_key(); + + var args = pkey ? [pkey] : []; + + var command = IPA.command({ + entity: entity_name, + method: 'mod', + args: args, + options: modlist, + on_success: on_success, + on_error: on_error + }); + + //alert(JSON.stringify(command.to_json())); + + command.execute(); + }; + + that.refresh = function() { + + that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) ; + + var command = IPA.command({ + entity: that.entity_name, + method: 'show', + options: { all: true, rights: true } + }); + + if (IPA.details_refresh_devel_hook){ + IPA.details_refresh_devel_hook(that.entity_name,command,that.pkey); + } + + + if (that.pkey){ + command.args = [that.pkey]; + } + + command.on_success = function(data, text_status, xhr) { + that.load(data.result.result); + }; + + command.on_error = function(xhr, text_status, error_thrown) { + var details = $('.details', that.container).empty(); + details.append('

Error: '+error_thrown.name+'

'); + details.append('

'+error_thrown.title+'

'); + details.append('

'+error_thrown.message+'

'); + }; + + command.execute(); + }; + that.details_facet_init = that.init; that.details_facet_create_content = that.create_content; that.details_facet_load = that.load; @@ -540,122 +663,3 @@ IPA.button = function(spec) { return button; }; - -IPA.details_refresh = function() { - - var that = this; - - that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) ; - - var command = IPA.command({ - entity: that.entity_name, - method: 'show', - options: { all: true, rights: true } - }); - - if (IPA.details_refresh_devel_hook){ - IPA.details_refresh_devel_hook(that.entity_name,command,that.pkey); - } - - - if (that.pkey){ - command.args = [that.pkey]; - } - - command.on_success = function(data, text_status, xhr) { - that.load(data.result.result); - }; - - command.on_error = function(xhr, text_status, error_thrown) { - var details = $('.details', that.container).empty(); - details.append('

Error: '+error_thrown.name+'

'); - details.append('

'+error_thrown.title+'

'); - details.append('

'+error_thrown.message+'

'); - }; - - command.execute(); -}; - -IPA.details_update = function(on_win, on_fail) { - var that = this; - var entity_name = that.entity_name; - - function on_success(data, text_status, xhr) { - if (on_win) - on_win(data, text_status, xhr); - if (data.error) - return; - - var result = data.result.result; - that.load(result); - } - - function on_error(xhr, text_status, error_thrown) { - if (on_fail) - on_fail(xhr, text_status, error_thrown); - } - - var values; - var modlist = {'all': true, 'setattr': [], 'addattr': [], 'rights': true}; - var attrs_wo_option = {}; - - for (var i=0; i 1){ - if (field.join) { - modlist[field.name] = values.join(','); - } else { - modlist[field.name] = values; - } - } else if (param_info['multivalue']){ - modlist[field.name] = []; - } - } else { - if (values.length) attrs_wo_option[field.name] = values; - } - } - } - - for (var attr in attrs_wo_option) { - values = attrs_wo_option[attr]; - modlist['setattr'].push(attr + '=' + values[0]); - for (var k = 1; k < values.length; ++k){ - modlist['addattr'].push(attr + '=' + values[k]); - } - } - - var pkey = that.get_primary_key(); - - var args = pkey ? [pkey] : []; - - var command = IPA.command({ - entity: entity_name, - method: 'mod', - args: args, - options: modlist, - on_success: on_success, - on_error: on_error - }); - - //alert(JSON.stringify(command.to_json())); - - command.execute(); -}; diff --git a/install/ui/dns.js b/install/ui/dns.js index 5af6e7a32..bd8d6e185 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -112,11 +112,7 @@ IPA.records_facet = function (spec){ return type_select; } - - var entry_attrs = {}; - - - function add_click(){ + that.add = function() { var dialog = IPA.dialog({ title: IPA.messages.objects.dnsrecord.add @@ -194,17 +190,17 @@ IPA.records_facet = function (spec){ dialog.init(); dialog.open(that.container); - } + }; - function delete_records(records_table){ + that.remove = function() { var zone = $.bbq.getState('dnszone-pkey', true); - var thead = records_table.find('thead'); + var thead = that.records_table.find('thead'); thead.find("INPUT[type='checkbox']"). attr('checked', false); - var tbody = records_table.find('tbody'); + var tbody = that.records_table.find('tbody'); var records = []; @@ -296,7 +292,7 @@ IPA.records_facet = function (spec){ dialog.init(); dialog.open(that.container); - } + }; that.is_dirty = function() { var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; @@ -304,73 +300,76 @@ IPA.records_facet = function (spec){ return pkey != that.pkey || record != that.record; }; - function create_content(container) { + that.create_header = function(container) { - $('

',{ - }).append(IPA.create_network_spinner()). - appendTo(container); + that.facet_create_header(container); - var details = $('
', { - 'name': 'details' - }).appendTo(container); - - var div = $('
'). - appendTo(details); - - var control_span =$('').appendTo(div); - control_span.append(IPA.messages.objects.dnsrecord.resource); - control_span.append($('',{ - type: "text", + $('', { + type: 'text', id: 'dns-record-resource-filter', - name: 'search-' + that.entity_name + '-filter' - })); + name: 'filter' + }).appendTo(that.controls); /* THe OLD DNS plugin allowed for search based on record type. This one does not. If the plugin gets modified to support - Record type searches, uncomment the followin lines and + Record type searches, uncomment the following lines and adjust the code that modifies the search parameters. - control_span.append('Type'); + that.controls.append('Type'); create_type_select('dns-record-type-filter',true). - appendTo(control_span); + appendTo(that.controls); */ - IPA.button({ - 'label': IPA.messages.buttons.find, - 'icon': 'ui-icon-search', - 'click': function(){refresh();} - }).appendTo(control_span); - + that.find_button = IPA.button({ + label: IPA.messages.buttons.find, + icon: 'ui-icon-search', + click: function(){ + that.refresh(); + return false; + } + }).appendTo(that.controls); - var buttons = that.entity_header.buttons; + that.controls.append(IPA.create_network_spinner()); - var button = $('input[name=remove]', buttons); that.remove_button = IPA.action_button({ label: IPA.messages.buttons.remove, icon: 'ui-icon-trash', - click: function(){ delete_records(records_table); } - }).appendTo(buttons); + click: function() { + that.remove(); + return false; + } + }).appendTo(that.controls); that.add_button = IPA.action_button({ label: IPA.messages.buttons.add, icon: 'ui-icon-plus', - click: add_click - }).appendTo(buttons); + click: function() { + that.add(); + return false; + } + }).appendTo(that.controls); + }; + + that.create_content = function(container) { - div.append(''); + var details = $('
', { + 'name': 'details' + }).appendTo(container); + + details.append(''); var records_results = $('
', { 'class': 'records-results' }).appendTo(details); - var records_table = $('', { + that.records_table = $('
', { 'class': 'search-table' }).appendTo(records_results); - var thead = $('').appendTo(records_table); - var tbody = $('').appendTo(records_table); - var tfoot = $('').appendTo(records_table); + var thead = $('').appendTo(that.records_table); + var tbody = $('').appendTo(that.records_table); + var tfoot = $('').appendTo(that.records_table); var tr = thead.find('tr'); tr.append($('')); tr.append($('')); - } + }; - function setup(container){ + that.setup = function(container) { that.facet_setup(container); - that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; that.record = $.bbq.getState(that.entity_name + '-record', true) || ''; - + that.pkey = $.bbq.getState(that.entity_name+'-pkey', true) || ''; $('h1',container). html(""+IPA.messages.objects.dnsrecord.title+":" + that.pkey); - //commented out until data is searchable //control_span.append('Data'); //control_span.append($('',{ @@ -407,12 +404,17 @@ IPA.records_facet = function (spec){ // id: 'dns-record-data-filter', // name: 'search-' + obj_name + '-filter' //})); + }; + that.show = function() { + that.facet_show(); + that.pkey = $.bbq.getState(that.entity_name+'-pkey', true) || ''; + that.entity.header.set_pkey(that.pkey); - refresh(); - } - + that.entity.header.back_link.css('visibility', 'visible'); + that.entity.header.facet_tabs.css('visibility', 'visible'); + }; function load_on_win(data){ display(that.entity_name,data); @@ -423,11 +425,11 @@ IPA.records_facet = function (spec){ } function reload(){ - refresh(); + that.refresh(); } - function refresh(){ + that.refresh = function() { var options = {}; @@ -460,7 +462,7 @@ IPA.records_facet = function (spec){ on_success: load_on_win, on_error:load_on_fail }).execute(); - } + }; function generate_tr(thead, tbody, result){ @@ -518,7 +520,7 @@ IPA.records_facet = function (spec){ //TODO this is cut and pasted from search, we need to unify function display(obj_name, data){ - var selector = '.entity-container[name=' + obj_name + ']'; + var selector = '.entity[name=' + obj_name + ']'; var thead = $(selector + ' thead'); var tbody = $(selector + ' tbody'); var tfoot = $(selector + ' tfoot'); @@ -545,10 +547,6 @@ IPA.records_facet = function (spec){ } - that.create_content = create_content; - that.setup = setup; - that.refresh = refresh; - return that; }; diff --git a/install/ui/entitle.js b/install/ui/entitle.js index 193468c2a..513cb6b41 100644 --- a/install/ui/entitle.js +++ b/install/ui/entitle.js @@ -260,47 +260,14 @@ IPA.entitle.search_facet = function(spec) { var that = IPA.search_facet(spec); - that.setup = function(container) { + that.create_header = function(container) { - that.search_facet_setup(container); - - var buttons = that.entity_header.buttons; - - $('a', buttons).remove(); + that.facet_create_header(container); that.register_buttons = $('', { style: 'display: none;' - }).appendTo(buttons); - - $('', { - type: 'button', - name: 'register_online', - value: 'Register' - }).appendTo(that.register_buttons); - - $('', { - type: 'button', - name: 'register_offline', - value: 'Import' - }).appendTo(that.register_buttons); - - that.consume_buttons = $('', { - style: 'display: none;' - }).appendTo(buttons); - - $('', { - type: 'button', - name: 'consume', - value: 'Consume' - }).appendTo(that.consume_buttons); - - $('', { - type: 'button', - name: 'import', - value: 'Import' - }).appendTo(that.consume_buttons); + }).appendTo(that.controls); - var button = $('input[name=register_online]', that.entity_header.buttons); that.register_online_button = IPA.action_button({ label: 'Register', icon: 'ui-icon-plus', @@ -308,10 +275,8 @@ IPA.entitle.search_facet = function(spec) { var dialog = that.entity.get_dialog('online_registration'); dialog.open(that.container); } - }); - button.replaceWith(that.register_online_button); + }).appendTo(that.register_buttons); - button = $('input[name=register_offline]', that.entity_header.buttons); that.register_offline_button = IPA.action_button({ label: 'Import', icon: 'ui-icon-plus', @@ -319,10 +284,12 @@ IPA.entitle.search_facet = function(spec) { var dialog = that.entity.get_dialog('offline_registration'); dialog.open(that.container); } - }); - button.replaceWith(that.register_offline_button); + }).appendTo(that.register_buttons); + + that.consume_buttons = $('', { + style: 'display: none;' + }).appendTo(that.controls); - button = $('input[name=consume]', that.entity_header.buttons); that.consume_button = IPA.action_button({ label: 'Consume', icon: 'ui-icon-plus', @@ -331,10 +298,8 @@ IPA.entitle.search_facet = function(spec) { var dialog = that.entity.get_dialog('consume'); dialog.open(that.container); } - }); - button.replaceWith(that.consume_button); + }).appendTo(that.consume_buttons); - button = $('input[name=import]', that.entity_header.buttons); that.import_button = IPA.action_button({ label: 'Import', icon: 'ui-icon-plus', @@ -343,8 +308,15 @@ IPA.entitle.search_facet = function(spec) { var dialog = that.entity.get_dialog('import'); dialog.open(that.container); } - }); - button.replaceWith(that.import_button); + }).appendTo(that.consume_buttons); + }; + + that.show = function() { + that.facet_show(); + + that.entity.header.set_pkey(null); + that.entity.header.back_link.css('visibility', 'hidden'); + that.entity.header.facet_tabs.css('visibility', 'hidden'); }; that.refresh = function() { diff --git a/install/ui/entity.js b/install/ui/entity.js index 161f34e6c..f649833e1 100644 --- a/install/ui/entity.js +++ b/install/ui/entity.js @@ -30,16 +30,12 @@ IPA.facet = function (spec) { spec = spec || {}; var that = {}; + that.display_class = spec.display_class || 'entity-facet'; that.name = spec.name; that.label = spec.label; that._entity_name = spec.entity_name; - that.init = spec.init || init; - that.create_content = spec.create_content || create_content; - that.setup = spec.setup || setup; - that.load = spec.load || load; - that.dialogs = []; that.dialogs_by_name = {}; @@ -63,29 +59,67 @@ IPA.facet = function (spec) { return that; }; - function init() { - - that.entity = IPA.get_entity(that.entity_name); + that.init = function() { for (var i=0; i', { + 'class': 'facet-header' + }).appendTo(container); + that.create_header(that.header); + + that.content = $('
', { + 'class': 'facet-content' + }).appendTo(container); + that.create_content(that.content); + }; + + that.create_header = function(container) { + + that.title = $('
', { + 'class': 'facet-title' + }).appendTo(container); + + $('

').append(IPA.create_network_spinner()).appendTo(that.title); + + that.set_title(container, that.label); + + that.controls = $('
', { + 'class': 'facet-controls' + }).appendTo(container); + }; + + that.create_content = function(container) { + }; + + that.set_title = function(container, title) { + var element = $('h1', that.title); + element.html(title); + }; + + that.setup = function(container) { + that.container = container; + }; + + that.show = function() { + that.container.css('display', 'inline'); + }; + + that.hide = function() { + that.container.css('display', 'none'); + }; + + that.load = function() { + }; that.is_dirty = function (){ return false; @@ -97,12 +131,77 @@ IPA.facet = function (spec) { // methods that should be invoked by subclasses that.facet_init = that.init; + that.facet_create_header = that.create_header; that.facet_create_content = that.create_content; that.facet_setup = that.setup; + that.facet_show = that.show; + that.facet_hide = that.hide; return that; }; +IPA.table_facet = function(spec) { + + spec = spec || {}; + + var that = IPA.facet(spec); + + that.columns = []; + that.columns_by_name = {}; + + that.__defineGetter__('entity_name', function() { + return that._entity_name; + }); + + that.__defineSetter__('entity_name', function(entity_name) { + that._entity_name = entity_name; + + for (var i=0; i', { + 'class': 'entity-header' + }).appendTo(container); + that.header.create(entity_header); - return that; -}; + that.content = $('
', { + 'class': 'entity-content' + }).appendTo(container); + }; + that.setup = function(container) { -IPA.current_facet = function (entity){ - var facet_name = $.bbq.getState(entity.name + '-facet', true); - if (!facet_name && entity.facets.length) { - facet_name = entity.facets[0].name; - } - return facet_name; -}; + var prev_facet = that.facet; + + IPA.current_entity = that; + var facet_name = IPA.current_facet(that); -IPA.entity_setup = function(container) { + that.facet = that.get_facet(facet_name); + if (!that.facet) return; - var entity = this; + if (IPA.entity_name == that.name) { + if (that.facet_name == that.facet.name) { + if (that.facet.new_key && (!that.facet.new_key())) return; + } else { + that.facet_name = that.facet.name; + } + } else { + IPA.entity_name = that.name; + } - IPA.current_entity = this; - var facet_name = IPA.current_facet(entity); + if (prev_facet) { + prev_facet.hide(); + } - var facet = entity.get_facet(facet_name); - if (!facet) return; + var facet_container = $('.facet[name="'+that.facet.name+'"]', that.content); + if (!facet_container.length) { + facet_container = $('
', { + name: that.facet.name, + 'class': 'facet' + }).appendTo(that.content); - if (IPA.entity_name == entity.name) { - if (entity.facet_name == facet.name) { - if (facet.new_key && (!facet.new_key())) return; - } else { - entity.facet_name = facet.name; + that.facet.create(facet_container); + that.facet.setup(facet_container); } - } else { - IPA.entity_name = entity.name; - } - if (!entity.header){ - entity.header = IPA.entity_header({entity:entity,container:container}); - } - facet.entity_header = entity.header; + that.facet.show(); + that.header.select_tab(); + that.facet.refresh(); + }; - entity.header.reset(); - facet.create_content(facet.entity_header.content); - facet.setup(facet.entity_header.content); - entity.header.select_tab(); - facet.refresh(); + that.entity_init = that.init; + + return that; +}; + +IPA.current_facet = function (entity){ + var facet_name = $.bbq.getState(entity.name + '-facet', true); + if (!facet_name && entity.facets.length) { + facet_name = entity.facets[0].name; + } + return facet_name; }; IPA.nested_tab_labels = {}; @@ -383,177 +497,140 @@ IPA.nested_tabs = function(entity_name) { IPA.selected_icon = ''; IPA.back_icon = ''; +IPA.entity_header = function(spec) { -IPA.entity_header = function(spec){ - var entity = spec.entity; - var container = spec.container; + spec = spec || {}; var that = {}; - that.entity = entity; - - function pkey(){ - that.pkey_field = $(""); - return that.pkey_field; - } + that.entity = spec.entity; - function select_tab(){ + that.select_tab = function() { $(that.facet_tabs).find('a').removeClass('selected'); - var facet_name = $.bbq.getState(entity.name + '-facet', true); + var facet_name = $.bbq.getState(that.entity.name + '-facet', true); - if (!facet_name) return; - - if (facet_name === 'default'){ + if (!facet_name || facet_name === 'default') { that.facet_tabs.find('a:first').addClass('selected'); - }else{ + } else { that.facet_tabs.find('a#' + facet_name ).addClass('selected'); } + }; - } - that.select_tab = select_tab; - - function set_pkey(val){ - that.pkey_field.val(val); - that.title.empty(); - var title = $('

',{ text: entity.metadata.label+": "}); - title.append ($('',{text:val})); - that.title.append(title); - } - that.set_pkey = set_pkey; + that.set_pkey = function(value) { - function title(){ - that.title = - $("
", - { - 'class':'entity-title' - }); + if (value) { + var span = $('.entity-pkey', that.pkey); + span.text(value); + that.pkey.css('display', 'inline'); - var title = $('

',{ text: entity.metadata.label}); - that.title.append(title); + } else { + that.pkey.css('display', 'none'); + } + }; - return that.title; - } + that.facet_link = function(container, other_facet) { - function buttons(){ - that.buttons = $(""); - return that.buttons; + var li = $('
  • ', { + title: other_facet.name, + click: function() { + if (li.hasClass('entity-facet-disabled')) { + return false; + } - } - function search_bar(){ - that.search_bar = - $(""); - - if (entity.facets_by_name.search){ - that.search_bar.prepend( - $('',{ - id:'back_to_search', - "class":"input_link", - click: function(){ - if($(this).hasClass('entity-facet-disabled')){ - return false; - } + var pkey = $.bbq.getState(that.entity.name+'-pkey', true); - IPA.nav.show_page(entity.name, 'search'); - $(that.facet_tabs).find('a').removeClass('selected'); - return false; + IPA.nav.show_page(that.entity.name, other_facet.name, pkey); + $('a', that.facet_tabs).removeClass('selected'); + $('a', li).addClass('selected'); - } - }). - append(IPA.back_icon + ' ' + - IPA.messages.buttons.back_to_list+' ')); + return false; + } + }).appendTo(container); + + $('', { + text: other_facet.label, + id: other_facet.name + }).appendTo(li); + }; + + that.facet_group = function(container, label) { + var facets = that.entity.facet_groups[label]; + if (facets) { + that.tab_section(container, label, facets); } + }; - return that.search_bar; - } + that.tab_section = function(container, label, facets) { - function facet_link(other_facet){ - var entity_name = that.entity.name; - var other_facet_name = other_facet.name; - var li = $('
  • ', { - title: other_facet.name, - html: $('',{ - text: other_facet.label, - id: other_facet_name - }), - click: function(entity_name, other_facet_name) { - return function() { - if($(this).hasClass('entity-facet-disabled')){ - return false; - } - var this_pkey = that.pkey_field.val(); - IPA.nav.show_page( - entity_name, other_facet_name, - this_pkey); - $(that.facet_tabs).find('a').removeClass('selected'); - $(this).find('a').addClass('selected'); + var section = $('', { + 'class': 'facet-tab-group' + }).appendTo(container); - return false; - }; - }(entity_name, other_facet_name) - }); - return li; - } + $('
  • ').append( @@ -386,20 +385,18 @@ IPA.records_facet = function (spec){ tr.append($('Record TypeData