summaryrefslogtreecommitdiffstats
path: root/install/static/search.js
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2010-11-09 14:22:31 -0600
committerAdam Young <ayoung@redhat.com>2010-11-11 12:23:05 -0500
commit65c9442e2697f9e5d8b6cc2b7c22a6b8da426247 (patch)
treea998aa317a59102646fada66a4944d022ff2afa5 /install/static/search.js
parent569f4e1a5cb3ff4cf3a7bf3c2aa5fdfa9ced0134 (diff)
downloadfreeipa-65c9442e2697f9e5d8b6cc2b7c22a6b8da426247.tar.gz
freeipa-65c9442e2697f9e5d8b6cc2b7c22a6b8da426247.tar.xz
freeipa-65c9442e2697f9e5d8b6cc2b7c22a6b8da426247.zip
HBAC Services
The HBAC Service search and details pages have been added under the HBAC tab. This requires some changes to the framework. Currently the navigation framework doesn't support multiple entities under one tab. As a temporary solution, an 'entity' URL parameter is used to determine the entity to be displayed. This parameter is now only used by HBAC tab, but its use might be expanded later. The navigation framework needs be redesigned to provide more flexibility. The search page in all entities except DNS records have been changed to use the ipa_search_widget. The Select/Unselect All checbox and Delete button now work correctly and consistently. The Add dialog has been enhanced to render and work in a more consistent way while still supporting custom widgets & layouts. For the search page, the Add button will refresh the search results and clear the fields in the dialog box. The framework now provides some extension points which can be overriden by the subclasses: - init(): for initialization and configuration - create(): for creating the layout dynamically or from template - setup(): for setting the look and feel - load(): for loading the data Entity and facet initialization is now done after IPA.init(). This is to ensure the metadata is loaded first so the entities and facets can use localized messages/labels/titles. The group entity has been partially converted to use the new framework. The unit tests have been updated accordingly.
Diffstat (limited to 'install/static/search.js')
-rw-r--r--install/static/search.js433
1 files changed, 195 insertions, 238 deletions
diff --git a/install/static/search.js b/install/static/search.js
index 1dfeda41..ecdf56d2 100644
--- a/install/static/search.js
+++ b/install/static/search.js
@@ -1,6 +1,7 @@
/* Authors:
* Pavel Zuna <pzuna@redhat.com>
* Adam Young <ayoung@redhat.com>
+ * Endi S. Dewata <edewata@redhat.com>
*
* Copyright (C) 2010 Red Hat
* see file 'COPYING' for use and warranty information
@@ -21,299 +22,279 @@
/* REQUIRES: ipa.js */
-function ipa_search_column(spec) {
+function ipa_search_widget(spec) {
spec = spec || {};
- spec.init = spec.init || init;
- spec.setup = spec.setup || setup;
+ var that = ipa_table_widget(spec);
- var that = ipa_column_widget(spec);
+ that.super_create = that.super('create');
+ that.super_setup = that.super('setup');
- function init() {
- }
+ that.create = function(container) {
- function setup(tr, attr, value, entry_attrs) {
- search_generate_td(tr, attr, value, entry_attrs);
- }
+ var div = $('#'+that.id);
- return that;
-}
+ var search_controls = $('<div/>', {
+ 'class': 'search-controls'
+ }).appendTo(div);
-function ipa_search_facet(spec) {
+ var search_filter = $('<span/>', {
+ 'class': 'search-filter'
+ }).appendTo(search_controls);
- spec = spec || {};
-
- var that = ipa_facet(spec);
+ this.filter = $('<input/>', {
+ 'type': 'text',
+ 'name': 'search-' + that.entity_name + '-filter'
+ }).appendTo(search_filter);
- that.init = spec.init || init;
- that.setup = spec.setup || setup;
+ ipa_button({
+ 'label': IPA.messages.button.find,
+ 'icon': 'ui-icon-search',
+ 'click': function() { that.find(container); }
+ }).appendTo(search_filter);
- that.columns = [];
- that.columns_by_name = {};
+ ipa_button({
+ 'label': IPA.messages.button.remove,
+ 'icon': 'ui-icon-trash',
+ 'click': function() { that.remove(container); }
+ }).appendTo(search_filter);
- that.__defineGetter__("entity_name", function(){
- return that._entity_name;
- });
+ ipa_button({
+ 'label': IPA.messages.button.add,
+ 'icon': 'ui-icon-plus',
+ 'click': function() { that.add(container); }
+ }).appendTo(search_filter);
- that.__defineSetter__("entity_name", function(entity_name){
- that._entity_name = entity_name;
+ search_controls.append('<span class="search-buttons"></span>');
- for (var i=0; i<that.columns.length; i++) {
- that.columns[i].entity_name = entity_name;
- }
- });
+ var search_results = $('<div/>', {
+ 'class': 'search-results'
+ }).appendTo(div);
- that.get_columns = function() {
- return that.columns;
+ that.super_create(container);
};
- that.get_column = function(name) {
- return that.columns_by_name[name];
- };
+ that.setup = function(container) {
- that.add_column = function(column) {
- column.entity_name = that.entity_name;
- that.columns.push(column);
- that.columns_by_name[column.name] = column;
+ that.super_setup(container);
+
+ var filter = $.bbq.getState(that.entity_name + '-filter', true) || '';
+ this.filter.val(filter);
};
- that.create_column = function(spec) {
- var column = ipa_search_column(spec);
- that.add_column(column);
- return column;
+ that.find = function(container) {
+ var filter = this.filter.val();
+ var state = {};
+ state[that.entity_name + '-filter'] = filter;
+ $.bbq.pushState(state);
};
- function init() {
- }
+ that.add = function(container) {
- that.is_dirty = function() {
- var filter = $.bbq.getState(that.entity_name + '-filter', true) || '';
- return filter != that.filter;
+ var entity = IPA.get_entity(that.entity_name);
+
+ var dialog = entity.get_dialog('add');
+ dialog.open(container);
+
+ return false;
};
- function setup(container, unspecified) {
+ that.remove = function(container) {
- that.filter = $.bbq.getState(that.entity_name + '-filter', true) || '';
+ var values = that.get_selected_values();
- search_create(that.entity_name, that.columns, container);
+ if (!values.length) {
+ alert('Select '+that.label+' to be removed.');
+ return;
+ }
- ipa_button({
- 'label': IPA.messages.button.add,
- 'icon': 'ui-icon-plus',
- 'click': function() {
- var entity = IPA.get_entity(that.entity_name);
- if (entity) {
- entity.add_dialog.open();
- return false;
- }
+ var title = 'Remove '+that.label;
- var dialog = ipa_entity_get_add_dialog(that.entity_name);
- dialog.open();
+ var dialog = ipa_deleter_dialog({
+ 'title': title,
+ 'parent': container,
+ 'values': values
+ });
- return false;
- }
- }).appendTo($('.search-controls', container));
+ dialog.remove = function() {
+ var batch = ipa_batch_command();
- search_load(container, that.filter);
- }
+ for (var i=0; i<values.length; i++) {
+ var command = ipa_command({
+ 'method': that.entity_name+'_del'
+ });
+ command.add_arg(values[i]);
+ batch.add_command(command);
+ }
- if (spec.columns) {
- for (var i=0; i<spec.columns.length; i++) {
- var column = spec.columns[i];
- column.facet = that;
- that.add_column(column);
- }
- }
+ batch.execute(
+ function() {
+ that.refresh(container);
+ dialog.close();
+ },
+ function() {
+ that.refresh(container);
+ dialog.close();
+ }
+ );
+ };
- that.init();
+ dialog.init();
- return that;
-}
+ dialog.open(container);
+ };
+ that.refresh = function(container) {
-function search_create(entity_name, columns, container) {
+ function on_success(data, text_status, xhr) {
- function find_on_click() {
- var filter = $(this).prev('input[type=text]').val();
- var state = {};
- state[entity_name + '-filter'] = filter;
- $.bbq.pushState(state);
- }
+ that.tbody.empty();
- function delete_on_click_outer() {
- var delete_list = [];
- var delete_dialog = $('<div></div>', {
- title: IPA.messages.button.remove
- });
+ var result = data.result.result;
+ for (var i = 0; i<result.length; i++) {
+ var record = that.get_record(result[i], 0);
+ that.add_row(container, record);
+ }
- function delete_on_click() {
- ipa_cmd('del', delete_list, {}, delete_on_win, null, entity_name);
- delete_dialog.dialog('close');
- }
+ var summary = $('span[name=summary]', that.tfoot);
- function delete_on_win() {
- for (var i = 0; i < delete_list.length; ++i) {
- var chk = container.find(
- '.search-selector[title=' + delete_list[i] + ']'
+ if (data.result.truncated) {
+ summary.text(
+ 'Query returned results than configured size limit will show.' +
+ 'First ' + data.result.count + ' results shown.'
);
- if (chk)
- chk.closest('tr').remove();
+ } else {
+ summary.text(data.result.summary);
}
}
- function cancel_on_click() {
- delete_dialog.dialog('close');
+ function on_error(xhr, text_status, error_thrown) {
+ var search_results = $('.search-results', container);
+ search_results.append('<p>Error: '+error_thrown.name+'</p>');
+ search_results.append('<p>'+error_thrown.title+'</p>');
+ search_results.append('<p>'+error_thrown.message+'</p>');
}
- container.find('.search-selector').each(function () {
- var jobj = $(this);
- if (jobj.attr('checked'))
- delete_list.push(jobj.attr('title'));
- });
+ var filter = $.bbq.getState(that.entity_name + '-filter', true) || '';
+ ipa_cmd(
+ 'find', [filter], {all: true}, on_success, on_error, that.entity_name
+ );
+ };
- if (delete_list.length == 0)
- return;
+ return that;
+}
- delete_dialog.text(IPA.messages.search.delete_confirm);
+function ipa_search_column(spec) {
- delete_dialog.dialog({
- modal: true,
- buttons: {
- 'Delete': delete_on_click,
- 'Cancel': cancel_on_click
- }
- });
- }
+ spec = spec || {};
- if (!container) {
- alert('ERROR: search_create: Second argument "container" missing!');
- return null;
- }
+ var that = ipa_column_widget(spec);
- container.attr('title', entity_name);
+ return that;
+}
- var search_controls = $('<div/>', {
- 'class': 'search-controls'
- }).appendTo(container);
+function ipa_search_facet(spec) {
- var search_filter = $('<span/>', {
- 'class': 'search-filter'
- }).appendTo(search_controls);
+ spec = spec || {};
- var filter = $('<input/>', {
- 'type': 'text',
- 'name': 'search-' + entity_name + '-filter'
- }).appendTo(search_filter);
+ var that = ipa_facet(spec);
- ipa_button({
- 'label': IPA.messages.button.find,
- 'icon': 'ui-icon-search',
- 'click': find_on_click
- }).appendTo(search_filter);
+ that.init = spec.init || init;
+ that.create = spec.create || ipa_search_facet_create;
+ that.setup = spec.setup || setup;
+ that.load = spec.load || load;
- ipa_button({
- 'label': IPA.messages.button.remove,
- 'icon': 'ui-icon-trash',
- 'click': delete_on_click_outer
- }).appendTo(search_filter);
+ that.columns = [];
+ that.columns_by_name = {};
- search_controls.append('<span class="search-buttons"></span>');
+ that.__defineGetter__("entity_name", function(){
+ return that._entity_name;
+ });
- var search_results = $('<div/>', {
- 'class': 'search-results'
- }).appendTo(container);
+ that.__defineSetter__("entity_name", function(entity_name){
+ that._entity_name = entity_name;
- var search_table = $('<table/>', {
- 'class': 'search-table'
- }).appendTo(search_results);
+ for (var i=0; i<that.columns.length; i++) {
+ that.columns[i].entity_name = entity_name;
+ }
+ });
- search_table.append('<thead><tr></tr></thead>');
- search_table.append('<tbody></tbody>');
- search_table.append('<tfoot></tfoot>');
+ that.get_columns = function() {
+ return that.columns;
+ };
- var tr = search_table.find('tr');
- search_insert_checkbox_th(tr);
- for (var i = 0; i < columns.length; ++i) {
- var c = columns[i];
- search_insert_th(tr, entity_name, c.name, c.label, c.setup);
- }
-}
+ that.get_column = function(name) {
+ return that.columns_by_name[name];
+ };
-function search_insert_checkbox_th(jobj)
-{
- function select_all_on_click() {
- var jobj = $(this);
+ that.add_column = function(column) {
+ column.entity_name = that.entity_name;
+ that.columns.push(column);
+ that.columns_by_name[column.name] = column;
+ };
- var checked = jobj.is(':checked');
- if (checked) {
- jobj.attr('title', 'Unselect All');
- } else {
- jobj.attr('title', 'Select All');
- }
+ that.create_column = function(spec) {
+ var column = ipa_search_column(spec);
+ that.add_column(column);
+ return column;
+ };
- var chks = jobj.closest('.entity-container').find('.search-selector').get();
- for (var i = 0; i < chks.length; ++i)
- chks[i].checked = checked;
- }
+ function init() {
- var checkbox = $('<input />', {
- type: 'checkbox',
- title: 'Select All'
- });
- checkbox.click(select_all_on_click);
+ that.table = ipa_search_widget({
+ 'id': that.entity_name+'-search',
+ 'name': that.entity_name, 'label': IPA.metadata[that.entity_name].label,
+ 'entity_name': that.entity_name
+ });
- var th = $('<th></th>');
- th.append(checkbox);
+ for (var i=0; i<that.columns.length; i++) {
+ var column = that.columns[i];
- jobj.append(th);
-}
+ var param_info = ipa_get_param_info(that.entity_name, column.name);
+ var primary_key = param_info && param_info['primary_key'];
-var _search_th_template = '<th abbr="A" title="C">N</th>';
+ column.primary_key = primary_key;
+ column.link = primary_key;
-function search_insert_th(jobj, obj_name, attr, name, render_call)
-{
- var th = _search_th_template.replace('A', attr);
+ that.table.add_column(column);
+ }
+ }
- var param_info = ipa_get_param_info(obj_name, attr);
- if (param_info && param_info['label'])
- th = th.replace('N', param_info['label']);
- else
- th = th.replace('N', name);
+ that.is_dirty = function() {
+ var filter = $.bbq.getState(that.entity_name + '-filter', true) || '';
+ return filter != that.filter;
+ };
- if (typeof render_call == 'function')
- th = th.replace('C', render_call.name);
- else
- th = th.replace('C', '-');
+ function ipa_search_facet_create(container) {
- jobj.append(th);
-}
+ container.attr('title', that.entity_name);
-function search_load(container, criteria, on_win, on_fail)
-{
- var entity_name = container.attr('id');
+ $('<div/>', {
+ 'id': that.entity_name+'-search'
+ }).appendTo(container);
- function search_on_success(data, text_status, xhr) {
- if (on_win)
- on_win(data, text_status, xhr);
- if (data.error)
- return;
- search_display(entity_name, data);
+ that.table.create(container);
}
- function search_on_error(xhr, text_status, error_thrown) {
- if (on_fail)
- on_fail(xhr, text_status, error_thrown);
+ function setup(container, unspecified) {
+ that.table.setup(container);
+ }
+
+ function load(container, unspecified) {
+ that.filter = $.bbq.getState(that.entity_name + '-filter', true) || '';
+ that.table.refresh(container);
+ }
- var search_results = $('.search-results', container);
- search_results.append('<p>Error: '+error_thrown.name+'</p>');
- search_results.append('<p>'+error_thrown.title+'</p>');
- search_results.append('<p>'+error_thrown.message+'</p>');
+ if (spec.columns) {
+ for (var i=0; i<spec.columns.length; i++) {
+ var column = spec.columns[i];
+ column.facet = that;
+ that.add_column(column);
+ }
}
- ipa_cmd(
- 'find', [criteria], {all: true}, search_on_success, search_on_error, entity_name
- );
+ return that;
}
function search_generate_tr(thead, tbody, entry_attrs)
@@ -387,27 +368,3 @@ function search_generate_td(tr, attr, value, entry_attrs)
tr.append(_search_td_template.replace('A', attr).replace('V', value));
}
-
-function search_display(obj_name, data)
-{
- var selector = '.entity-container[title=' + obj_name + ']';
- var thead = $(selector + ' thead');
- var tbody = $(selector + ' tbody');
- var tfoot = $(selector + ' tfoot');
-
- tbody.find('tr').remove();
-
- var result = data.result.result;
- for (var i = 0; i < result.length; ++i)
- search_generate_tr(thead, tbody, result[i]);
-
- if (data.result.truncated) {
- tfoot.text(
- 'Query returned results than configured size limit will show.' +
- 'First ' + data.result.count + ' results shown.'
- );
- } else {
- tfoot.text(data.result.summary);
- }
-}
-