summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--install/static/add.js182
-rw-r--r--install/static/associate.js55
-rw-r--r--install/static/details.js235
-rw-r--r--install/static/entity.js127
-rw-r--r--install/static/group.js76
-rwxr-xr-xinstall/static/hbac.js702
-rwxr-xr-xinstall/static/hbacsvc.js177
-rw-r--r--install/static/index.xhtml1
-rw-r--r--install/static/ipa.js1
-rw-r--r--install/static/navigation.js7
-rw-r--r--install/static/policy.js6
-rw-r--r--install/static/search.js433
-rw-r--r--install/static/service.js233
-rw-r--r--install/static/test/details_tests.js22
-rw-r--r--install/static/test/entity_tests.js12
-rw-r--r--install/static/test/ipa_tests.html1
-rw-r--r--install/static/webui.js5
-rwxr-xr-xinstall/static/widget.js244
18 files changed, 1507 insertions, 1012 deletions
diff --git a/install/static/add.js b/install/static/add.js
index 671d11f96..9c68aea31 100644
--- a/install/static/add.js
+++ b/install/static/add.js
@@ -21,160 +21,80 @@
/* REQUIRES: ipa.js */
-var IPA_ADD_POPULATE = 1;
-var IPA_ADD_UPDATE = 2;
-
-function ipa_add_field(spec) {
-
- spec = spec || {};
-
- var that = {};
- that.name = spec.name;
- that.label = spec.label;
- that._entity_name = spec.entity_name;
-
- that.init = spec.init;
- that.setup = spec.setup;
-
- that.__defineGetter__("entity_name", function(){
- return that._entity_name;
- });
-
- that.__defineSetter__("entity_name", function(entity_name){
- that._entity_name = entity_name;
- });
-
- return that;
-}
-
function ipa_add_dialog(spec) {
spec = spec || {};
- var that = {};
+ var that = ipa_dialog(spec);
+
that.name = spec.name;
that.title = spec.title;
that._entity_name = spec.entity_name;
- that.init = spec.init;
-
- that.fields = [];
- that.fields_by_name = {};
-
- var dialog = $('<div/>');
-
- that.__defineGetter__("entity_name", function(){
- return that._entity_name;
- });
-
- that.__defineSetter__("entity_name", function(entity_name){
- that._entity_name = entity_name;
+ that.init = function() {
+
+ that.add_button('Add', function() {
+ var record = that.get_record();
+ that.add(
+ record,
+ function() {
+ var entity = IPA.get_entity(that.entity_name);
+ var facet = entity.get_facet('search');
+ var table = facet.table;
+ table.refresh(that.container);
+ that.clear(that.container);
+ }
+ );
+ });
- for (var i=0; i<that.fields.length; i++) {
- that.fields[i].entity_name = entity_name;
- }
- });
+ that.add_button('Add and Edit', function() {
+ var record = that.get_record();
+ that.add(
+ record,
+ function() {
+ that.close();
+
+ var pkey_name = IPA.metadata[that.entity_name].primary_key;
+ var pkey = record[pkey_name];
+
+ var state = {};
+ state[that.entity_name + '-facet'] = 'details';
+ state[that.entity_name + '-pkey'] = pkey;
+ $.bbq.pushState(state);
+ },
+ function() { that.close(); }
+ );
+ });
- that.get_fields = function() {
- return that.fields;
+ that.add_button('Cancel', function() {
+ that.close();
+ });
};
- that.get_field = function(name) {
- return that.fields_by_name[name];
- };
+ that.add = function(record, on_success, on_error) {
- that.add_field = function(field) {
- that.fields.push(field);
- that.fields_by_name[field.name] = field;
- };
-
- that.create_field = function(spec) {
- var field = ipa_add_field(spec);
- that.add_field(field);
- return field;
- };
+ var pkey_name = IPA.metadata[that.entity_name].primary_key;
- that.open = function() {
- dialog.empty();
- dialog.attr('id', that.name);
- dialog.attr('title', that.title);
+ var args = [];
+ var options = {};
- for (var i = 0; i < that.fields.length; ++i) {
+ for (var i=0; i<that.fields.length; i++) {
var field = that.fields[i];
- if (field.setup) {
- field.setup(dialog, IPA_ADD_POPULATE);
- } else {
- dialog.append('<label>' + field.label + '</label>');
- dialog.append('<input type="text" name="' + field.name + '" />');
- dialog.append('<br/>');
- }
- }
- dialog.dialog({
- modal: true,
- buttons: {
- 'Add': that.add,
- 'Add and edit': that.add_and_edit,
- 'Cancel': that.cancel
- }
- });
- };
+ var value = record[field.name];
+ if (!value) continue;
- that.add = function(evt, called_from_add_and_edit) {
- var pkey = [];
- var options = {};
- var pkey_name = IPA.metadata[that.entity_name].primary_key;
-
- function add_win(data, text_status, xhr) {
- if (called_from_add_and_edit) {
- var state = {};
- state[that.entity_name + '-facet'] = 'details';
- state[that.entity_name + '-pkey'] = pkey[0];
- $.bbq.pushState(state);
- }else{
- dialog.find('input').each( function () {
- $(this).val('');
- });
- }
- }
- for (var i = 0; i < that.fields.length; ++i) {
- var field = that.fields[i];
- if (field.setup) {
- var value = field.setup(dialog, IPA_ADD_UPDATE);
- if (value != null) {
- if (field.name == pkey_name){
- pkey = [value];
- } else {
- options[field.name] = value;
- }
- }
+ if (field.name == pkey_name) {
+ args.push(value);
+ } else {
+ options[field.name] = value;
}
}
- dialog.find('input').each(function () {
- var jobj = $(this);
- var attr = jobj.attr('name');
- var value = jobj.val();
- if (value) {
- if (pkey.length == 0 && attr == pkey_name)
- pkey = [jobj.val()];
- else if (options[attr] == null)
- options[attr] = jobj.val();
- }
- });
-
- ipa_cmd('add', pkey, options, add_win, null, that.entity_name);
- };
-
- that.add_and_edit = function(evt) {
- that.add(evt, true);
- dialog.dialog('close');
- };
- that.cancel = function() {
- dialog.dialog('close');
+ ipa_cmd('add', args, options, on_success, on_error, that.entity_name);
};
- if (that.init) that.init();
+ that.super_init = that.super('init');
return that;
}
diff --git a/install/static/associate.js b/install/static/associate.js
index be9ee582c..be6747a32 100644
--- a/install/static/associate.js
+++ b/install/static/associate.js
@@ -272,7 +272,7 @@ function ipa_association_widget(spec) {
'name': 'add',
'value': IPA.messages.button.enroll
}).appendTo(buttons);
- }
+ };
that.setup = function(container) {
@@ -302,7 +302,6 @@ function ipa_association_widget(spec) {
var dialog = ipa_association_adder_dialog({
'title': title,
- 'parent': container,
'entity_name': that.entity_name,
'pkey': pkey,
'other_entity': that.other_entity,
@@ -318,7 +317,9 @@ function ipa_association_widget(spec) {
}
});
- dialog.open();
+ dialog.init();
+
+ dialog.open(container);
};
that.remove = function(container) {
@@ -336,7 +337,6 @@ function ipa_association_widget(spec) {
var dialog = ipa_association_deleter_dialog({
'title': title,
- 'parent': container,
'entity_name': that.entity_name,
'pkey': pkey,
'other_entity': that.other_entity,
@@ -353,7 +353,40 @@ function ipa_association_widget(spec) {
}
});
- dialog.open();
+ dialog.init();
+
+ dialog.open(container);
+ };
+
+ that.refresh = function(container) {
+
+ function on_success(data, text_status, xhr) {
+
+ that.tbody.empty();
+
+ var column_name = that.columns[0].name;
+ var values = data.result.result[column_name];
+ //TODO, this is masking an error where the wrong
+ //direction association is presented upon page reload.
+ //if the values is unset, it is because
+ //form.associationColumns[0] doesn't exist in the results
+ if (!values) return;
+
+ for (var i = 0; i<values.length; i++){
+ var record = that.get_record(data.result.result, i);
+ that.add_row(container, record);
+ }
+ }
+
+ function on_error(xhr, text_status, error_thrown) {
+ var div = $('#'+that.id, container).empty();
+ div.append('<p>Error: '+error_thrown.name+'</p>');
+ div.append('<p>'+error_thrown.title+'</p>');
+ div.append('<p>'+error_thrown.message+'</p>');
+ }
+
+ var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
+ ipa_cmd('show', [pkey], {'rights': true}, on_success, on_error, that.entity_name);
};
return that;
@@ -373,13 +406,15 @@ function ipa_association_facet(spec) {
return pkey != that.pkey || other_entity != that.other_entity;
};
+ that.create = function(container) {
+ that.setup_views(container);
+ };
+
that.setup = function(container, unspecified) {
that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
that.other_entity = $.bbq.getState(that.entity_name + '-enroll', true) || '';
- that.setup_views(container);
-
//TODO I18N
var header_message = that.other_entity + '(s) enrolled in ' +
that.entity_name + ' ' + that.pkey;
@@ -403,12 +438,6 @@ function ipa_association_facet(spec) {
return that;
}
-
-function association_list_create(obj_name, jobj)
-{
- search_create(obj_name, [], jobj);
-}
-
function ipa_deleter_dialog_setup() {
var that = this;
diff --git a/install/static/details.js b/install/static/details.js
index 9301f3102..efb896a6c 100644
--- a/install/static/details.js
+++ b/install/static/details.js
@@ -31,23 +31,20 @@ IPA.is_field_writable = function(rights){
alert('no right');
}
return rights.indexOf('w') > -1;
-}
+};
function ipa_details_field(spec) {
spec = spec || {};
- spec.create = spec.create || create;
- spec.setup = spec.setup || setup;
- spec.load = spec.load || load;
- spec.save = spec.save || save;
-
var that = ipa_widget(spec);
- function create(container) {
- }
+ that.create = spec.create || create;
+ that.setup = spec.setup || setup;
+ that.load = spec.load || load;
+ that.save = spec.save || save;
- function setup(container) {
+ function create(container) {
var dl = $('dl', container);
@@ -65,6 +62,9 @@ function ipa_details_field(spec) {
}).appendTo(dl);
}
+ function setup(container) {
+ }
+
function load(container, result) {
var multivalue = false;
@@ -187,10 +187,6 @@ function ipa_details_section(spec){
}
});
- that.get_fields = function() {
- return that.fields;
- };
-
that.get_field = function(name) {
return that.fields_by_name[name];
};
@@ -231,6 +227,13 @@ function ipa_details_section(spec){
return field;
};
+ that.init = function() {
+ for (var i=0; i<that.fields.length; i++) {
+ var field = that.fields[i];
+ field.init();
+ }
+ };
+
// Deprecated: Used for backward compatibility only.
function input(spec){
that.create_field(spec);
@@ -253,10 +256,13 @@ function ipa_details_facet(spec) {
var that = ipa_facet(spec);
- that.init = spec.init || init;
that.is_dirty = spec.is_dirty || ipa_details_is_dirty;
- that.setup = spec.setup || ipa_details_setup;
that.create = spec.create || ipa_details_create;
+ that.setup = spec.setup || ipa_details_setup;
+ that.load = spec.load || ipa_details_load;
+ that.update = spec.update || ipa_details_update;
+ that.reset = spec.reset || ipa_details_reset;
+ that.display = spec.display || ipa_details_display;
that.sections = [];
that.sections_by_name = {};
@@ -273,10 +279,6 @@ function ipa_details_facet(spec) {
}
});
- that.get_sections = function() {
- return that.sections;
- };
-
that.get_section = function(name) {
return that.sections_by_name[name];
};
@@ -293,8 +295,12 @@ function ipa_details_facet(spec) {
return section;
};
- function init() {
- }
+ that.init = function() {
+ for (var i=0; i<that.sections.length; i++) {
+ var section = that.sections[i];
+ section.init();
+ }
+ };
return that;
}
@@ -321,38 +327,7 @@ function ipa_details_is_dirty() {
return pkey != this.pkey;
}
-function ipa_details_setup(container, unspecified) {
-
- var facet = this;
-
- facet.setup_views(container);
-
- facet.pkey = $.bbq.getState(facet.entity_name + '-pkey', true) || '';
- if (!facet.pkey && !unspecified) return;
-
- function on_success(data, text_status, xhr) {
- var result = data.result.result;
-
- ipa_details_cache[facet.entity_name] = $.extend(true, {}, result);
- facet.create(container, result);
- }
-
- function on_failure(xhr, text_status, error_thrown) {
- var details = $('.details', container).empty();
- details.append('<p>Error: '+error_thrown.name+'</p>');
- details.append('<p>'+error_thrown.title+'</p>');
- details.append('<p>'+error_thrown.message+'</p>');
- }
-
- var params = [];
- if (facet.pkey) params.push(facet.pkey);
-
- ipa_cmd(
- 'show', params, {all: true, rights: true}, on_success, on_failure, facet.entity_name
- );
-}
-
-function ipa_details_create(container, result)
+function ipa_details_create(container)
{
var facet = this;
@@ -364,6 +339,8 @@ function ipa_details_create(container, result)
var entity_name = container.attr('id');
container.attr('title', entity_name);
+ facet.setup_views(container);
+
var details = $('<div/>', {
'class': 'details'
}).appendTo(container);
@@ -377,7 +354,7 @@ function ipa_details_create(container, result)
'icon': 'ui-icon-refresh',
'class': 'details-reset',
'click': function() {
- ipa_details_reset(container);
+ facet.reset(container);
return false;
}
}));
@@ -389,7 +366,7 @@ function ipa_details_create(container, result)
'icon': 'ui-icon-check',
'class': 'details-update',
'click': function() {
- ipa_details_update(container, ipa_details_cache[facet.entity_name][pkey_name][0]);
+ facet.update(container, ipa_details_cache[facet.entity_name][pkey_name][0]);
return false;
}
}));
@@ -410,52 +387,111 @@ function ipa_details_create(container, result)
'class': 'details-section'
}).appendTo(details);
- section.setup(div, result);
+ section.create(div);
details.append('<hr/>');
}
}
+function ipa_details_setup(container, unspecified) {
+ var that = this;
-function ipa_details_section_setup(container, result) {
- var section = this;
- var fields = section.get_fields();
+ for (var i = 0; i < that.sections.length; ++i) {
+ var section = that.sections[i];
- if (section.template) {
- var template = IPA.get_template(section.template);
- container.load(template, function(data, text_status, xhr) {
- for (var i = 0; i < fields.length; ++i) {
- var field = fields[i];
- field.create(container);
- field.setup(container);
- field.load(container, result);
- }
- });
- return;
+ var div = $(
+ '#'+that.entity_name+'-'+that.name+'-'+section.name,
+ container
+ );
+
+ section.setup(div, unspecified);
}
+}
- section.create(container);
+function ipa_details_load(container, unspecified) {
- for (var i = 0; i < fields.length; ++i) {
- var field = fields[i];
- field.create(container);
- field.setup(container);
- field.load(container, result);
+ var that = this;
+
+ that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
+ if (!that.pkey && !unspecified) 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];
+
+ var div = $(
+ '#'+that.entity_name+'-'+that.name+'-'+section.name,
+ container
+ );
+
+ section.load(div, result);
+ }
}
+
+ function on_failure(xhr, text_status, error_thrown) {
+ var details = $('.details', container).empty();
+ details.append('<p>Error: '+error_thrown.name+'</p>');
+ details.append('<p>'+error_thrown.title+'</p>');
+ details.append('<p>'+error_thrown.message+'</p>');
+ }
+
+ var params = [];
+ if (that.pkey) params.push(that.pkey);
+
+ ipa_cmd(
+ 'show', params, {all: true, rights: true}, on_success, on_failure, that.entity_name
+ );
}
-function ipa_details_section_create(container, result) {
- var section = this;
+function ipa_details_section_create(container) {
+
+ var that = this;
+ if (that.template) return;
var dl = $('<dl/>', {
- 'id': section.name,
+ 'id': that.name,
'class': 'entryattrs'
}).appendTo(container);
+
+ var fields = that.fields;
+ for (var i = 0; i < fields.length; ++i) {
+ var field = fields[i];
+ field.create(container);
+ }
+}
+
+function ipa_details_section_setup(container, unspecified) {
+ var that = this;
+ if (that.template) return;
+
+ var fields = that.fields;
+ for (var i = 0; i < fields.length; ++i) {
+ var field = fields[i];
+ field.setup(container);
+ }
}
function ipa_details_section_load(container, result) {
- var section = this;
- var fields = section.get_fields();
+ var that = this;
+ var fields = that.fields;
+
+ if (that.template) {
+ var template = IPA.get_template(that.template);
+ container.load(
+ template,
+ function(data, text_status, xhr) {
+ for (var i = 0; i < fields.length; ++i) {
+ var field = fields[i];
+ field.setup(container);
+ field.load(container, result);
+ }
+ }
+ );
+ return;
+ }
for (var j=0; j<fields.length; j++) {
var field = fields[j];
@@ -465,7 +501,8 @@ function ipa_details_section_load(container, result) {
function ipa_details_update(container, pkey, on_win, on_fail)
{
- var obj_name = container.attr('id');
+ var facet = this;
+ var entity_name = facet.entity_name;
function update_on_win(data, text_status, xhr) {
if (on_win)
@@ -474,8 +511,8 @@ function ipa_details_update(container, pkey, on_win, on_fail)
return;
var result = data.result.result;
- ipa_details_cache[obj_name] = $.extend(true, {}, result);
- ipa_details_display(container, result);
+ ipa_details_cache[entity_name] = $.extend(true, {}, result);
+ facet.display(container, result);
}
function update_on_fail(xhr, text_status, error_thrown) {
@@ -490,20 +527,17 @@ function ipa_details_update(container, pkey, on_win, on_fail)
var modlist = {'all': true, 'setattr': [], 'addattr': [], 'rights': true};
var attrs_wo_option = {};
- var facet = ipa_entity_get_details_facet(obj_name);
- var sections = facet.get_sections();
- for (var i=0; i<sections.length; i++) {
- var section = sections[i];
- var fields = section.get_fields();
+ for (var i=0; i<facet.sections.length; i++) {
+ var section = facet.sections[i];
var div = $('#'+facet.entity_name+'-'+facet.name+'-'+section.name, container);
- for (var j=0; j<fields.length; j++) {
- var field = fields[j];
+ for (var j=0; j<section.fields.length; j++) {
+ var field = section.fields[j];
values = field.save(div);
- var param_info = ipa_get_param_info(obj_name, field.name);
+ var param_info = ipa_get_param_info(entity_name, field.name);
if (param_info) {
if (param_info['primary_key']) continue;
if (values.length === 1) {
@@ -526,7 +560,7 @@ function ipa_details_update(container, pkey, on_win, on_fail)
modlist['addattr'].push(attr + '=' + values[i]);
}
- ipa_cmd('mod', [pkey], modlist, update_on_win, update_on_fail, obj_name);
+ ipa_cmd('mod', [pkey], modlist, update_on_win, update_on_fail, entity_name);
}
@@ -555,16 +589,14 @@ var _ipa_span_hint_template = '<span class="attrhint">Hint: D</span>';
* (basically an associative array with attr:value pairs) */
function ipa_details_display(container, result)
{
- var entity_name = container.attr('id');
+ var facet = this;
/* remove all <dd> tags i.e. all attribute values */
$('dd', container).remove();
/* go through all <dt> tags and pair them with newly created <dd>s */
- var facet = ipa_entity_get_details_facet(entity_name);
- var sections = facet.get_sections();
- for (var i=0; i<sections.length; i++) {
- var section = sections[i];
+ for (var i=0; i<facet.sections.length; i++) {
+ var section = facet.sections[i];
var div = $('#'+facet.entity_name+'-'+facet.name+'-'+section.name, container);
@@ -752,10 +784,11 @@ function _ipa_create_text_input(attr, value, param_info, rights)
function ipa_details_reset(container)
{
- var obj_name = container.attr('id');
+ var facet = this;
+ var entity_name = facet.entity_name;
- if (ipa_details_cache[obj_name]){
- ipa_details_display(container, ipa_details_cache[obj_name]);
+ if (ipa_details_cache[entity_name]){
+ facet.display(container, ipa_details_cache[entity_name]);
}
}
diff --git a/install/static/entity.js b/install/static/entity.js
index 24a49fc76..1eadea6d9 100644
--- a/install/static/entity.js
+++ b/install/static/entity.js
@@ -30,8 +30,10 @@ function ipa_facet(spec) {
that.label = spec.label;
that._entity_name = spec.entity_name;
- that.init = spec.init;
- that.setup = spec.setup;
+ that.init = spec.init || init;
+ that.create = spec.create || create;
+ that.setup = spec.setup || setup;
+ that.load = spec.load || load;
that.__defineGetter__("entity_name", function(){
return that._entity_name;
@@ -43,6 +45,25 @@ function ipa_facet(spec) {
that.setup_views = ipa_facet_setup_views;
+ that.super = function(name) {
+ var method = that[name];
+ return function () {
+ return method.apply(that, arguments);
+ };
+ };
+
+ function init() {
+ }
+
+ function create() {
+ }
+
+ function setup() {
+ }
+
+ function load() {
+ }
+
return that;
}
@@ -54,30 +75,34 @@ function ipa_entity(spec) {
that.name = spec.name;
that.label = spec.label;
- that.setup = spec.setup;
+ that.setup = spec.setup || ipa_entity_setup;
- that.add_dialog = null;
+ that.dialogs = [];
+ that.dialogs_by_name = {};
that.facets = [];
that.facets_by_name = {};
- this.facet_name = null;
+ that.facet_name = null;
that.associations = [];
that.associations_by_name = {};
- that.get_add_dialog = function() {
- return that.add_dialog;
+ that.super = function(name) {
+ var method = that[name];
+ return function () {
+ return method.apply(that, arguments);
+ };
};
- that.create_add_dialog = function(spec) {
- spec.entity_name = that.name;
- that.add_dialog = ipa_add_dialog(spec);
- return that.add_dialog;
+ that.get_dialog = function(name) {
+ return that.dialogs_by_name[name];
};
- that.get_facets = function() {
- return that.facets;
+ that.add_dialog = function(dialog) {
+ dialog.entity_name = that.name;
+ that.dialogs.push(dialog);
+ that.dialogs_by_name[dialog.name] = dialog;
};
that.get_facet = function(name) {
@@ -90,25 +115,6 @@ function ipa_entity(spec) {
that.facets_by_name[facet.name] = facet;
};
- that.create_search_facet = function(spec) {
- var facet = ipa_search_facet(spec);
- that.add_facet(facet);
- return facet;
- };
-
- that.create_details_facet = function(spec) {
- var facet = ipa_details_facet(spec);
- that.add_facet(facet);
- facet.init();
- return facet;
- };
-
- that.create_association_facet = function(spec) {
- var facet = ipa_association_facet(spec);
- that.add_facet(facet);
- return facet;
- };
-
that.get_associations = function() {
return that.associations;
};
@@ -128,6 +134,13 @@ function ipa_entity(spec) {
return config;
};
+ that.init = function() {
+ for (var i=0; i<that.facets.length; i++) {
+ var facet = that.facets[i];
+ facet.init();
+ }
+ };
+
return that;
}
@@ -154,10 +167,11 @@ function ipa_entity_get_search_facet(entity_name) {
var facet = entity.get_facet('search');
if (facet) return facet;
- facet = entity.create_search_facet({
+ facet = ipa_search_facet({
'name': 'search',
'label': 'Search'
});
+ entity.add_facet(facet);
return facet;
}
@@ -180,18 +194,20 @@ function ipa_entity_set_add_definition(entity_name, data) {
var entity = ipa_get_entity(entity_name);
- var dialog = entity.create_add_dialog({
- 'name': data[0],
+ var dialog = ipa_add_dialog({
+ 'name': 'add',
'title': data[1]
});
+ entity.add_dialog(dialog);
+ dialog.init();
for (var i=0; i<data[2].length; i++) {
var field = data[2][i];
- dialog.create_field({
+ dialog.add_field(ipa_text_widget({
name: field[0],
label: field[1],
setup: field[2]
- });
+ }));
}
}
@@ -208,10 +224,11 @@ function ipa_entity_get_details_facet(entity_name) {
var facet = entity.get_facet('details');
if (facet) return facet;
- facet = entity.create_details_facet({
+ facet = ipa_details_facet({
'name': 'details',
'label': 'Details'
});
+ entity.add_facet(facet);
return facet;
}
@@ -233,9 +250,10 @@ function ipa_entity_get_association_facet(entity_name) {
var facet = entity.get_facet('associate');
if (facet) return facet;
- facet = entity.create_association_facet({
+ facet = ipa_association_facet({
'name': 'associate'
});
+ entity.add_facet(facet);
return facet;
}
@@ -293,9 +311,9 @@ function ipa_entity_setup(container, unspecified) {
container.empty();
- if (facet.setup) {
- facet.setup(container, unspecified);
- }
+ facet.create(container);
+ facet.setup(container, unspecified);
+ facet.load(container, unspecified);
}
function ipa_facet_setup_views(container) {
@@ -305,10 +323,9 @@ function ipa_facet_setup_views(container) {
var ul = $('<ul/>', {'class': 'entity-views'}).appendTo(container);
var entity = IPA.get_entity(facet.entity_name);
- var facets = entity.get_facets();
- for (var i=0; i<facets.length; i++) {
- var other_facet = facets[i];
+ for (var i=0; i<entity.facets.length; i++) {
+ var other_facet = entity.facets[i];
var facet_name = other_facet.name;
if (other_facet.label) {
@@ -352,17 +369,19 @@ function ipa_facet_setup_views(container) {
}
}
-function ipa_entity_quick_links(tr, attr, value, entry_attrs) {
+function ipa_entity_quick_links(container, name, value, entry_attrs) {
- var obj_name = tr.closest('.entity-container').attr('title');
+ var obj_name = container.closest('.entity-container').attr('title');
var pkey = IPA.metadata[obj_name].primary_key;
- var pkey_value = entry_attrs[pkey][0];
+ var pkey_value = entry_attrs[pkey];
- var td = $("<td/>").appendTo(tr);
+ var span = $('span[name="'+name+'"]', container);
+ span.empty();
$("<a/>", {
- href: "#details",
- title: "Details",
+ href: '#details',
+ title: 'Details',
+ text: 'Details',
click: function() {
var state = {};
state[obj_name+'-facet'] = 'details';
@@ -370,7 +389,7 @@ function ipa_entity_quick_links(tr, attr, value, entry_attrs) {
nav_push_state(state);
return false;
}
- }).appendTo(td);
+ }).appendTo(span);
var attribute_members = IPA.metadata[obj_name].attribute_members;
for (attr_name in attribute_members) {
@@ -379,6 +398,8 @@ function ipa_entity_quick_links(tr, attr, value, entry_attrs) {
var m = objs[i];
var label = IPA.metadata[m].label;
+ span.append(' | ');
+
$("<a/>", {
href: '#'+m,
title: label,
@@ -393,7 +414,7 @@ function ipa_entity_quick_links(tr, attr, value, entry_attrs) {
return false;
}
}(m)
- }).append(' | ' ).appendTo(td);
+ }).appendTo(span);
}
}
}
diff --git a/install/static/group.js b/install/static/group.js
index 1d1e9b5ce..97f498ae2 100644
--- a/install/static/group.js
+++ b/install/static/group.js
@@ -20,6 +20,52 @@
/* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */
+function ipa_group() {
+
+ var that = ipa_entity({
+ 'name': 'group'
+ });
+
+ that.super_init = that.super('init');
+
+ that.init = function() {
+
+ var dialog = ipa_group_add_dialog({
+ 'name': 'add',
+ 'title': 'Add New Group'
+ });
+ that.add_dialog(dialog);
+ dialog.init();
+
+ that.super_init();
+ };
+
+ return that;
+}
+
+IPA.add_entity(ipa_group());
+
+function ipa_group_add_dialog(spec) {
+
+ spec = spec || {};
+
+ var that = ipa_add_dialog(spec);
+
+ that.super_init = that.super('init');
+
+ that.init = function() {
+
+ this.super_init();
+
+ this.add_field(ipa_text_widget({name:'cn', label:'Name'}));
+ this.add_field(ipa_text_widget({name:'description', label:'Description'}));
+ this.add_field(ipa_checkbox_widget({name:'posix', label:'Is this a POSIX group?'}));
+ this.add_field(ipa_text_widget({name:'gidnumber', label:'GID'}));
+ };
+
+ return that;
+}
+
ipa_entity_set_search_definition('group', [
['cn', 'Name', null],
['gidnumber', 'GID', null],
@@ -27,15 +73,6 @@ ipa_entity_set_search_definition('group', [
['quick_links', 'Quick Links', ipa_entity_quick_links]
]);
-ipa_entity_set_add_definition('group', [
- 'dialog-add-group', 'Add New Group', [
- ['cn', 'Name', null],
- ['description', 'Description', null],
- ['posix', 'Is this a POSIX group?', f_posix],
- ['gidnumber', 'GID', null]
- ]
-]);
-
ipa_entity_set_details_definition('group',[
ipa_stanza({name:'identity', label:'Group Details'}).
input({name:'cn', label:'Group Name'}).
@@ -48,24 +85,3 @@ ipa_entity_set_association_definition('group', {
'rolegroup': { associator: 'serial' },
'taskgroup': { associator: 'serial' }
});
-
-function f_posix(dlg, mode)
-{
- function checkbox_on_click() {
- var jobj = $(this);
- if (jobj.attr('checked'))
- jobj.attr('checked', false);
- else
- jobj.attr('checked', true);
- };
-
- if (mode == IPA_ADD_POPULATE) {
- dlg.append('<label>Is this a POSIX group?</label>');
- dlg.append('<input type="checkbox" name="posix" />');
- dlg.children().last().click(checkbox_on_click);
- } else {
- if (dlg.find('input:checkbox[name=posix]').attr('checked'))
- return (true);
- return (false);
- }
-}
diff --git a/install/static/hbac.js b/install/static/hbac.js
index f81fe5d7d..fed645129 100755
--- a/install/static/hbac.js
+++ b/install/static/hbac.js
@@ -26,114 +26,144 @@ function ipa_hbac() {
'name': 'hbac'
});
+ that.super_init = that.super('init');
+
that.init = function() {
- that.create_add_dialog({
+ var dialog = ipa_hbac_add_dialog({
'name': 'add',
- 'title': 'Add New Rule',
- 'init': ipa_hbac_add_init
+ 'title': 'Add New Rule'
});
+ that.add_dialog(dialog);
+ dialog.init();
- that.create_search_facet({
+ var facet = ipa_hbac_search_facet({
'name': 'search',
- 'label': 'Search',
- 'init': ipa_hbac_search_init,
- 'setup': ipa_hbac_search_setup
+ 'label': 'Search'
});
+ that.add_facet(facet);
- that.create_details_facet({
+ facet = ipa_hbac_details_facet({
'name': 'details',
- 'label': 'Details',
- 'init': ipa_hbac_details_init
+ 'label': 'Details'
});
- };
+ that.add_facet(facet);
- that.init();
+ that.super_init();
+ };
return that;
}
IPA.add_entity(ipa_hbac());
-function ipa_hbac_add_init() {
- this.create_field({name:'cn', label:'Rule Name'});
- this.create_field({name:'accessruletype', label:'Rule type (allow/deny)'});
-}
+function ipa_hbac_add_dialog(spec) {
-function ipa_hbac_search_init() {
+ spec = spec || {};
- this.create_column({name:'cn', label:'Rule Name'});
- this.create_column({name:'usercategory', label:'Who'});
- this.create_column({name:'hostcategory', label:'Accessing'});
- this.create_column({name:'servicecategory', label:'Via Service'});
- this.create_column({name:'sourcehostcategory', label:'From'});
- this.create_column({name:'ipaenabledflag', label:'Active'});
+ var that = ipa_add_dialog(spec);
- this.create_column({
- name: 'quick_links',
- label: 'Quick Links',
- setup: ipa_hbac_quick_links
- });
+ that.super_init = that.super('init');
+
+ that.init = function() {
+
+ that.super_init();
+
+ that.add_field(ipa_text_widget({
+ 'name': 'cn',
+ 'label': 'Rule Name'
+ }));
+
+ that.add_field(ipa_text_widget({
+ 'name': 'accessruletype',
+ 'label': 'Rule type (allow/deny)'
+ }));
+ };
+
+ return that;
}
-function ipa_hbac_search_setup(container) {
+function ipa_hbac_search_facet(spec) {
- var that = this;
+ spec = spec || {};
- that.filter = $.bbq.getState(that.entity_name + '-filter', true) || '';
-/*
- // Not yet implemented
+ var that = ipa_search_facet(spec);
+
+ that.super_init = that.super('init');
+ that.super_create = that.super('create');
+ that.super_setup = that.super('setup');
- var left_buttons = $('<span/>', {
- 'style': 'float: left;'
- }).appendTo(container);
+ that.init = function() {
- left_buttons.append(ipa_button({
- 'label': 'Troubleshoot Rules'
- }));
+ that.create_column({name:'cn', label:'Rule Name'});
+ that.create_column({name:'usercategory', label:'Who'});
+ that.create_column({name:'hostcategory', label:'Accessing'});
+ that.create_column({name:'ipaenabledflag', label:'Active'});
+ that.create_column({name:'servicecategory', label:'Via Service'});
+ that.create_column({name:'sourcehostcategory', label:'From'});
+
+ that.create_column({
+ name: 'quick_links',
+ label: 'Quick Links',
+ setup: ipa_hbac_quick_links
+ });
- left_buttons.append(ipa_button({
- 'label': 'Cull Disabled Rules'
- }));
+ that.super_init();
+ };
- var right_buttons = $('<span/>', {
- 'style': 'float: right;'
- }).appendTo(container);
+ that.create = function(container) {
- right_buttons.append(ipa_button({
- 'label': 'Login Services'
- }));
+ var that = this;
+/*
+ // Not yet implemented
- right_buttons.append(ipa_button({
- 'label': 'Login Svc Groups'
- }));
+ var left_buttons = $('<span/>', {
+ 'style': 'float: left;'
+ }).appendTo(container);
- container.append('<br/><br/>');
+ left_buttons.append(ipa_button({
+ 'label': 'Troubleshoot Rules'
+ }));
+
+ left_buttons.append(ipa_button({
+ 'label': 'Cull Disabled Rules'
+ }));
*/
- search_create(that.entity_name, that.columns, container);
+ var right_buttons = $('<span/>', {
+ 'style': 'float: right;'
+ }).appendTo(container);
- ipa_button({
- 'label': IPA.messages.button.add,
- 'icon': 'ui-icon-plus',
- 'click': function() {
- var entity = IPA.get_entity(that.entity_name);
- entity.add_dialog.open();
- return false;
- }
- }).appendTo($('.search-controls', container));
+ right_buttons.append(ipa_button({
+ 'label': 'HBAC Services',
+ 'click': function() {
+ var state = {};
+ state['entity'] = 'hbacsvc';
+ nav_push_state(state);
+ return false;
+ }
+ }));
+/*
+ right_buttons.append(ipa_button({
+ 'label': 'Login Svc Groups'
+ }));
+*/
+ container.append('<br/><br/>');
- search_load(container, that.filter);
+ that.super_create(container);
+ };
+
+ return that;
}
-function ipa_hbac_quick_links(tr, attr, value, entry_attrs) {
+function ipa_hbac_quick_links(container, name, value, record) {
var column = this;
var facet = column.facet;
var pkey = IPA.metadata[column.entity_name].primary_key;
- var pkey_value = entry_attrs[pkey][0];
+ var pkey_value = record[pkey];
- var td = $('<td/>').appendTo(tr);
+ var span = $('span[name='+name+']', container);
$('<a/>', {
'href': '#details',
@@ -146,9 +176,9 @@ function ipa_hbac_quick_links(tr, attr, value, entry_attrs) {
nav_push_state(state);
return false;
}
- }).appendTo(td);
+ }).appendTo(span);
- td.append(' | ');
+ span.append(' | ');
$('<a/>', {
'href': '#test-rule',
@@ -161,212 +191,224 @@ function ipa_hbac_quick_links(tr, attr, value, entry_attrs) {
nav_push_state(state);
return false;
}
- }).appendTo(td);
+ }).appendTo(span);
}
-function ipa_hbac_details_init() {
+function ipa_hbac_details_facet(spec) {
- var that = this;
- var section;
+ spec = spec || {};
- if (IPA.layout) {
- section = that.create_section({
- 'name': 'general',
- 'label': 'General',
- 'template': 'hbac-details-general.html #contents'
- });
+ var that = ipa_details_facet(spec);
- } else {
- section = ipa_hbac_details_general_section({
- 'name': 'general',
- 'label': 'General'
- });
- that.add_section(section);
- }
-
- section.create_text({ 'name': 'cn', 'label': 'Name' });
- section.create_radio({ 'name': 'accessruletype', 'label': 'Rule Type' });
- section.create_textarea({ 'name': 'description', 'label': 'Description' });
- section.create_radio({ 'name': 'ipaenabledflag', 'label': 'Enabled' });
-
- if (IPA.layout) {
- section = that.create_section({
- 'name': 'user',
- 'label': 'Who',
- 'template': 'hbac-details-user.html #contents'
- });
+ that.super_init = that.super('init');
+ that.super_create = that.super('create');
+ that.super_setup = that.super('setup');
- } else {
- section = ipa_hbac_details_tables_section({
- 'name': 'user',
- 'label': 'Who',
- 'text': 'Rule applies when access is requested by:',
- 'field_name': 'usercategory',
- 'options': [
- { 'value': 'all', 'label': 'Anyone' },
- { 'value': '', 'label': 'Specified Users and Groups' }
- ],
- 'tables': [
- { 'field_name': 'memberuser_user' },
- { 'field_name': 'memberuser_group' }
- ]
- });
- that.add_section(section);
- }
-
- section.create_radio({ name: 'usercategory', label: 'User category' });
- section.add_field(ipa_hbac_association_widget({
- 'id': that.entity_name+'-memberuser_user',
- 'name': 'memberuser_user', 'label': 'Users',
- 'other_entity': 'user', 'add_method': 'add_user', 'delete_method': 'remove_user'
- }));
- section.add_field(ipa_hbac_association_widget({
- 'id': that.entity_name+'-memberuser_group',
- 'name': 'memberuser_group', 'label': 'Groups',
- 'other_entity': 'group', 'add_method': 'add_user', 'delete_method': 'remove_user'
- }));
-
- if (IPA.layout) {
- section = that.create_section({
- 'name': 'host',
- 'label': 'Accessing',
- 'template': 'hbac-details-host.html #contents'
- });
+ that.init = function() {
- } else {
- section = ipa_hbac_details_tables_section({
- 'name': 'host',
- 'label': 'Accessing',
- 'text': 'Rule applies when access is requested to:',
- 'field_name': 'hostcategory',
- 'options': [
- { 'value': 'all', 'label': 'Any Host' },
- { 'value': '', 'label': 'Specified Hosts and Groups' }
- ],
- 'tables': [
- { 'field_name': 'memberhost_host' },
- { 'field_name': 'memberhost_hostgroup' }
- ],
- 'columns': [
- ]
- });
- that.add_section(section);
- }
-
- section.create_radio({ 'name': 'hostcategory', 'label': 'Host category' });
- section.add_field(ipa_hbac_association_widget({
- 'id': that.entity_name+'-memberhost_host',
- 'name': 'memberhost_host', 'label': 'Hosts',
- 'other_entity': 'host', 'add_method': 'add_host', 'delete_method': 'remove_host'
- }));
- section.add_field(ipa_hbac_association_widget({
- 'id': that.entity_name+'-memberhost_hostgroup',
- 'name': 'memberhost_hostgroup', 'label': 'Host Groups',
- 'other_entity': 'hostgroup', 'add_method': 'add_host', 'delete_method': 'remove_host'
- }));
-
- if (IPA.layout) {
- section = that.create_section({
- 'name': 'service',
- 'label': 'Via Service',
- 'template': 'hbac-details-service.html #contents'
- });
+ var section;
- } else {
- section = ipa_hbac_details_tables_section({
- 'name': 'service',
- 'label': 'Via Service',
- 'text': 'Rule applies when access is requested via:',
- 'field_name': 'servicecategory',
- 'options': [
- { 'value': 'all', 'label': 'Any Service' },
- { 'value': '', 'label': 'Specified Services and Groups' }
- ],
- 'tables': [
- { 'field_name': 'memberservice_hbacsvc' },
- { 'field_name': 'memberservice_hbacsvcgroup' }
- ]
- });
- that.add_section(section);
- }
-
- section.create_radio({ 'name': 'servicecategory', 'label': 'Service category' });
- section.add_field(ipa_hbac_association_widget({
- 'id': that.entity_name+'-memberservice_hbacsvc',
- 'name': 'memberservice_hbacsvc', 'label': 'Services',
- 'other_entity': 'hbacsvc', 'add_method': 'add_service', 'delete_method': 'remove_service'
- }));
- section.add_field(ipa_hbac_association_widget({
- 'id': that.entity_name+'-memberservice_hbacsvcgroup',
- 'name': 'memberservice_hbacsvcgroup', 'label': 'Service Groups',
- 'other_entity': 'hbacsvcgroup', 'add_method': 'add_service', 'delete_method': 'remove_service'
- }));
-
- if (IPA.layout) {
- section = that.create_section({
- 'name': 'sourcehost',
- 'label': 'From',
- 'template': 'hbac-details-sourcehost.html #contents'
- });
+ if (IPA.layout) {
+ section = that.create_section({
+ 'name': 'general',
+ 'label': 'General',
+ 'template': 'hbac-details-general.html #contents'
+ });
- } else {
- section = ipa_hbac_details_tables_section({
- 'name': 'sourcehost',
- 'label': 'From',
- 'text': 'Rule applies when access is being initiated from:',
- 'field_name': 'sourcehostcategory',
- 'options': [
- { 'value': 'all', 'label': 'Any Host' },
- { 'value': '', 'label': 'Specified Hosts and Groups' }
- ],
- 'tables': [
- { 'field_name': 'sourcehost_host' },
- { 'field_name': 'sourcehost_hostgroup' }
- ]
- });
- that.add_section(section);
- }
-
- section.create_radio({ 'name': 'sourcehostcategory', 'label': 'Source host category' });
- section.add_field(ipa_hbac_association_widget({
- 'id': that.entity_name+'-sourcehost_host',
- 'name': 'sourcehost_host', 'label': 'Host',
- 'other_entity': 'host', 'add_method': 'add_sourcehost', 'delete_method': 'remove_sourcehost'
- }));
- section.add_field(ipa_hbac_association_widget({
- 'id': that.entity_name+'-sourcehost_hostgroup',
- 'name': 'sourcehost_hostgroup', 'label': 'Host Groups',
- 'other_entity': 'hostgroup', 'add_method': 'add_sourcehost', 'delete_method': 'remove_sourcehost'
- }));
-
- if (IPA.layout) {
- section = that.create_section({
- 'name': 'accesstime',
- 'label': 'When',
- 'template': 'hbac-details-accesstime.html #contents'
- });
+ } else {
+ section = ipa_hbac_details_general_section({
+ 'name': 'general',
+ 'label': 'General'
+ });
+ that.add_section(section);
+ }
- } else {
- section = ipa_hbac_details_tables_section({
- 'name': 'accesstime',
- 'label': 'When',
- 'text': 'Rule applies when access is being requested at:',
- 'field_name': 'accesstime',
- 'options': [
- { 'value': 'all', 'label': 'Any Time' },
- { 'value': '', 'label': 'Specified Times' }
- ],
- 'tables': [
- { 'field_name': 'accesstime' }
- ]
- });
- that.add_section(section);
- }
+ section.create_text({ 'name': 'cn', 'label': 'Name' });
+ section.create_radio({ 'name': 'accessruletype', 'label': 'Rule Type' });
+ section.create_textarea({ 'name': 'description', 'label': 'Description' });
+ section.create_radio({ 'name': 'ipaenabledflag', 'label': 'Enabled' });
+
+ if (IPA.layout) {
+ section = that.create_section({
+ 'name': 'user',
+ 'label': 'Who',
+ 'template': 'hbac-details-user.html #contents'
+ });
+
+ } else {
+ section = ipa_hbac_details_tables_section({
+ 'name': 'user',
+ 'label': 'Who',
+ 'text': 'Rule applies when access is requested by:',
+ 'field_name': 'usercategory',
+ 'options': [
+ { 'value': 'all', 'label': 'Anyone' },
+ { 'value': '', 'label': 'Specified Users and Groups' }
+ ],
+ 'tables': [
+ { 'field_name': 'memberuser_user' },
+ { 'field_name': 'memberuser_group' }
+ ]
+ });
+ that.add_section(section);
+ }
+
+ section.create_radio({ name: 'usercategory', label: 'User category' });
+ section.add_field(ipa_hbac_association_widget({
+ 'id': that.entity_name+'-memberuser_user',
+ 'name': 'memberuser_user', 'label': 'Users',
+ 'other_entity': 'user', 'add_method': 'add_user', 'delete_method': 'remove_user'
+ }));
+ section.add_field(ipa_hbac_association_widget({
+ 'id': that.entity_name+'-memberuser_group',
+ 'name': 'memberuser_group', 'label': 'Groups',
+ 'other_entity': 'group', 'add_method': 'add_user', 'delete_method': 'remove_user'
+ }));
+
+ if (IPA.layout) {
+ section = that.create_section({
+ 'name': 'host',
+ 'label': 'Accessing',
+ 'template': 'hbac-details-host.html #contents'
+ });
+
+ } else {
+ section = ipa_hbac_details_tables_section({
+ 'name': 'host',
+ 'label': 'Accessing',
+ 'text': 'Rule applies when access is requested to:',
+ 'field_name': 'hostcategory',
+ 'options': [
+ { 'value': 'all', 'label': 'Any Host' },
+ { 'value': '', 'label': 'Specified Hosts and Groups' }
+ ],
+ 'tables': [
+ { 'field_name': 'memberhost_host' },
+ { 'field_name': 'memberhost_hostgroup' }
+ ]
+ });
+ that.add_section(section);
+ }
+
+ section.create_radio({ 'name': 'hostcategory', 'label': 'Host category' });
+ section.add_field(ipa_hbac_association_widget({
+ 'id': that.entity_name+'-memberhost_host',
+ 'name': 'memberhost_host', 'label': 'Hosts',
+ 'other_entity': 'host', 'add_method': 'add_host', 'delete_method': 'remove_host'
+ }));
+ section.add_field(ipa_hbac_association_widget({
+ 'id': that.entity_name+'-memberhost_hostgroup',
+ 'name': 'memberhost_hostgroup', 'label': 'Host Groups',
+ 'other_entity': 'hostgroup', 'add_method': 'add_host', 'delete_method': 'remove_host'
+ }));
- section.add_field(ipa_hbac_accesstime_widget({
- 'id': that.entity_name+'-accesstime',
- 'name': 'accesstime', 'label': 'Access Time'
- }));
+ if (IPA.layout) {
+ section = that.create_section({
+ 'name': 'service',
+ 'label': 'Via Service',
+ 'template': 'hbac-details-service.html #contents'
+ });
+
+ } else {
+ section = ipa_hbac_details_tables_section({
+ 'name': 'service',
+ 'label': 'Via Service',
+ 'text': 'Rule applies when access is requested via:',
+ 'field_name': 'servicecategory',
+ 'options': [
+ { 'value': 'all', 'label': 'Any Service' },
+ { 'value': '', 'label': 'Specified Services and Groups' }
+ ],
+ 'tables': [
+ { 'field_name': 'memberservice_hbacsvc' },
+ { 'field_name': 'memberservice_hbacsvcgroup' }
+ ]
+ });
+ that.add_section(section);
+ }
+
+ section.create_radio({ 'name': 'servicecategory', 'label': 'Service category' });
+ section.add_field(ipa_hbac_association_widget({
+ 'id': that.entity_name+'-memberservice_hbacsvc',
+ 'name': 'memberservice_hbacsvc', 'label': 'Services',
+ 'other_entity': 'hbacsvc', 'add_method': 'add_service', 'delete_method': 'remove_service'
+ }));
+ section.add_field(ipa_hbac_association_widget({
+ 'id': that.entity_name+'-memberservice_hbacsvcgroup',
+ 'name': 'memberservice_hbacsvcgroup', 'label': 'Service Groups',
+ 'other_entity': 'hbacsvcgroup', 'add_method': 'add_service', 'delete_method': 'remove_service'
+ }));
+
+ if (IPA.layout) {
+ section = that.create_section({
+ 'name': 'sourcehost',
+ 'label': 'From',
+ 'template': 'hbac-details-sourcehost.html #contents'
+ });
+
+ } else {
+ section = ipa_hbac_details_tables_section({
+ 'name': 'sourcehost',
+ 'label': 'From',
+ 'text': 'Rule applies when access is being initiated from:',
+ 'field_name': 'sourcehostcategory',
+ 'options': [
+ { 'value': 'all', 'label': 'Any Host' },
+ { 'value': '', 'label': 'Specified Hosts and Groups' }
+ ],
+ 'tables': [
+ { 'field_name': 'sourcehost_host' },
+ { 'field_name': 'sourcehost_hostgroup' }
+ ]
+ });
+ that.add_section(section);
+ }
+
+ section.create_radio({ 'name': 'sourcehostcategory', 'label': 'Source host category' });
+ section.add_field(ipa_hbac_association_widget({
+ 'id': that.entity_name+'-sourcehost_host',
+ 'name': 'sourcehost_host', 'label': 'Host',
+ 'other_entity': 'host', 'add_method': 'add_sourcehost', 'delete_method': 'remove_sourcehost'
+ }));
+ section.add_field(ipa_hbac_association_widget({
+ 'id': that.entity_name+'-sourcehost_hostgroup',
+ 'name': 'sourcehost_hostgroup', 'label': 'Host Groups',
+ 'other_entity': 'hostgroup', 'add_method': 'add_sourcehost', 'delete_method': 'remove_sourcehost'
+ }));
+
+ if (IPA.layout) {
+ section = that.create_section({
+ 'name': 'accesstime',
+ 'label': 'When',
+ 'template': 'hbac-details-accesstime.html #contents'
+ });
+
+ } else {
+ section = ipa_hbac_details_tables_section({
+ 'name': 'accesstime',
+ 'label': 'When',
+ 'text': 'Rule applies when access is being requested at:',
+ 'field_name': 'accesstime',
+ 'options': [
+ { 'value': 'all', 'label': 'Any Time' },
+ { 'value': '', 'label': 'Specified Times' }
+ ],
+ 'tables': [
+ { 'field_name': 'accesstime' }
+ ]
+ });
+ that.add_section(section);
+ }
+
+ section.add_field(ipa_hbac_accesstime_widget({
+ 'id': that.entity_name+'-accesstime',
+ 'name': 'accesstime', 'label': 'Access Time'
+ }));
+
+ that.super_init();
+ };
+
+ return that;
}
function ipa_hbac_details_general_section(spec){
@@ -473,8 +515,6 @@ function ipa_hbac_details_tables_section(spec){
spec = spec || {};
- spec.create = create;
-
var that = ipa_details_section(spec);
that.text = spec.text;
@@ -485,7 +525,7 @@ function ipa_hbac_details_tables_section(spec){
that.super_setup = that.super('setup');
- function create(container) {
+ that.create = function(container) {
if (that.template) return;
@@ -512,7 +552,13 @@ function ipa_hbac_details_tables_section(spec){
'id': that.entity_name+'-'+table.field_name
}).appendTo(container);
}
- }
+
+ var fields = that.fields;
+ for (var i = 0; i < fields.length; ++i) {
+ var field = fields[i];
+ field.create(container);
+ }
+ };
return that;
}
@@ -528,30 +574,30 @@ function ipa_hbac_association_widget(spec) {
that.add_method = spec.add_method;
that.delete_method = spec.delete_method;
+ that.super_init = that.super('init');
that.super_create = that.super('create');
that.super_setup = that.super('setup');
- that.create = function(container) {
-
- // create a column when none defined
+ that.init = function() {
+ // create a column if none defined
if (!that.columns.length) {
that.create_column({
'name': that.name,
'label': IPA.metadata[that.other_entity].label,
- 'primary_key': true,
- 'link': false
+ 'primary_key': true
});
}
+ that.super_init();
+ };
+
+ that.create = function(container) {
+
that.super_create(container);
var div = $('#'+that.id, container);
var buttons = $('span[name=buttons]', div);
- if (buttons.children().length) {
- // widget loaded from template
- return;
- }
$('<input/>', {
'type': 'button',
@@ -588,7 +634,6 @@ function ipa_hbac_association_widget(spec) {
var dialog = ipa_association_adder_dialog({
'title': title,
- 'parent': container,
'entity_name': that.entity_name,
'pkey': pkey,
'other_entity': that.other_entity,
@@ -604,7 +649,9 @@ function ipa_hbac_association_widget(spec) {
}
});
- dialog.open();
+ dialog.init();
+
+ dialog.open(container);
};
that.remove = function(container) {
@@ -622,7 +669,6 @@ function ipa_hbac_association_widget(spec) {
var dialog = ipa_association_deleter_dialog({
'title': title,
- 'parent': container,
'entity_name': that.entity_name,
'pkey': pkey,
'other_entity': that.other_entity,
@@ -639,7 +685,40 @@ function ipa_hbac_association_widget(spec) {
}
});
- dialog.open();
+ dialog.init();
+
+ dialog.open(container);
+ };
+
+ that.refresh = function(container) {
+
+ function on_success(data, text_status, xhr) {
+
+ that.tbody.empty();
+
+ var column_name = that.columns[0].name;
+ var values = data.result.result[column_name];
+ //TODO, this is masking an error where the wrong
+ //direction association is presented upon page reload.
+ //if the values is unset, it is because
+ //form.associationColumns[0] doesn't exist in the results
+ if (!values) return;
+
+ for (var i = 0; i<values.length; i++){
+ var record = that.get_record(data.result.result, i);
+ that.add_row(container, record);
+ }
+ }
+
+ function on_error(xhr, text_status, error_thrown) {
+ var div = $('#'+that.id, container).empty();
+ div.append('<p>Error: '+error_thrown.name+'</p>');
+ div.append('<p>'+error_thrown.title+'</p>');
+ div.append('<p>'+error_thrown.message+'</p>');
+ }
+
+ var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
+ ipa_cmd('show', [pkey], {'rights': true}, on_success, on_error, that.entity_name);
};
that.save = function(container) {
@@ -655,30 +734,30 @@ function ipa_hbac_accesstime_widget(spec) {
var that = ipa_table_widget(spec);
+ that.super_init = that.super('init');
that.super_create = that.super('create');
that.super_setup = that.super('setup');
- that.create = function(container) {
-
- // create a column when none defined
+ that.init = function() {
+ // create a column if none defined
if (!that.columns.length) {
that.create_column({
'name': that.name,
'label': that.label,
- 'primary_key': true,
- 'link': false
+ 'primary_key': true
});
}
+ that.super_init();
+ };
+
+ that.create = function(container) {
+
that.super_create(container);
var div = $('#'+that.id);
var buttons = $('span[name=buttons]', div);
- if (buttons.children().length) {
- // widget loaded from template
- return;
- }
$('<input/>', {
'type': 'button',
@@ -716,8 +795,7 @@ function ipa_hbac_accesstime_widget(spec) {
var title = 'Add '+that.label+' to '+that.entity_name+' '+pkey;
var dialog = ipa_dialog({
- 'title': title,
- 'parent': container
+ 'title': title
});
dialog.add_field(ipa_text_widget({
@@ -782,7 +860,9 @@ function ipa_hbac_accesstime_widget(spec) {
}
dialog.add_button('Add', function() {
- add();
+ add(
+ function() { dialog.clear(container); }
+ );
});
dialog.add_button('Add and Close', function() {
@@ -796,7 +876,9 @@ function ipa_hbac_accesstime_widget(spec) {
dialog.close();
});
- dialog.open();
+ dialog.init();
+
+ dialog.open(container);
};
that.remove = function(container) {
@@ -813,11 +895,10 @@ function ipa_hbac_accesstime_widget(spec) {
var dialog = ipa_deleter_dialog({
'title': title,
- 'parent': container,
'values': values
});
- that.remove = function() {
+ dialog.remove = function() {
var batch = ipa_batch_command();
for (var i=0; i<values.length; i++) {
@@ -841,7 +922,36 @@ function ipa_hbac_accesstime_widget(spec) {
);
};
- dialog.open();
+ dialog.init();
+
+ dialog.open(container);
+ };
+
+ that.refresh = function(container) {
+
+ function on_success(data, text_status, xhr) {
+
+ that.tbody.empty();
+
+ var column_name = that.columns[0].name;
+ var values = data.result.result[column_name];
+ if (!values) return;
+
+ for (var i = 0; i<values.length; i++){
+ var record = that.get_record(data.result.result, i);
+ that.add_row(container, record);
+ }
+ }
+
+ function on_error(xhr, text_status, error_thrown) {
+ var div = $('#'+that.id, container).empty();
+ div.append('<p>Error: '+error_thrown.name+'</p>');
+ div.append('<p>'+error_thrown.title+'</p>');
+ div.append('<p>'+error_thrown.message+'</p>');
+ }
+
+ var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
+ ipa_cmd('show', [pkey], {'rights': true}, on_success, on_error, that.entity_name);
};
that.save = function(container) {
diff --git a/install/static/hbacsvc.js b/install/static/hbacsvc.js
new file mode 100755
index 000000000..268ce4c5d
--- /dev/null
+++ b/install/static/hbacsvc.js
@@ -0,0 +1,177 @@
+/* Authors:
+ * Endi Sukma Dewata <edewata@redhat.com>
+ *
+ * Copyright (C) 2010 Red Hat
+ * see file 'COPYING' for use and warranty information
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2 only
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */
+
+function ipa_hbacsvc() {
+
+ var that = ipa_entity({
+ 'name': 'hbacsvc'
+ });
+
+ that.super_init = that.super('init');
+
+ that.init = function() {
+
+ var dialog = ipa_hbacsvc_add_dialog({
+ 'name': 'add',
+ 'title': 'Add New HBAC Service'
+ });
+ that.add_dialog(dialog);
+ dialog.init();
+
+ var facet = ipa_hbacsvc_search_facet({
+ 'name': 'search',
+ 'label': 'Search'
+ });
+ that.add_facet(facet);
+
+ facet = ipa_hbacsvc_details_facet({
+ 'name': 'details',
+ 'label': 'Details'
+ });
+ that.add_facet(facet);
+
+ that.super_init();
+ };
+
+ return that;
+}
+
+IPA.add_entity(ipa_hbacsvc());
+
+function ipa_hbacsvc_add_dialog(spec) {
+
+ spec = spec || {};
+
+ var that = ipa_add_dialog(spec);
+
+ that.super_init = that.super('init');
+
+ that.init = function() {
+
+ this.super_init();
+
+ this.add_field(ipa_text_widget({name:'cn', label:'Name'}));
+ this.add_field(ipa_text_widget({name:'description', label:'Description'}));
+ };
+
+ return that;
+}
+
+function ipa_hbacsvc_search_facet(spec) {
+
+ spec = spec || {};
+
+ var that = ipa_search_facet(spec);
+
+ that.super_init = that.super('init');
+ that.super_create = that.super('create');
+ that.super_setup = that.super('setup');
+
+ that.init = function() {
+
+ that.create_column({name:'cn', label:'Service', primary_key: true});
+ that.create_column({name:'description', label:'Description'});
+
+ that.create_column({
+ name: 'quick_links',
+ label: 'Quick Links',
+ setup: ipa_hbacsvc_quick_links
+ });
+
+ that.super_init();
+ };
+
+ that.create = function(container) {
+
+ var that = this;
+
+ var right_buttons = $('<span/>', {
+ 'style': 'float: right;'
+ }).appendTo(container);
+
+ right_buttons.append(ipa_button({
+ 'label': 'HBAC Rules',
+ 'click': function() {
+ var state = {};
+ state['entity'] = 'hbac';
+ nav_push_state(state);
+ return false;
+ }
+ }));
+ container.append('<br/><br/>');
+
+ that.super_create(container);
+ };
+
+ return that;
+}
+
+
+function ipa_hbacsvc_quick_links(container, name, value, record) {
+
+ var that = this;
+
+ var pkey = IPA.metadata[that.entity_name].primary_key;
+ var pkey_value = record[pkey];
+
+ var link = $('<a/>', {
+ 'href': '#details',
+ 'title': 'Details',
+ 'text': 'Details',
+ 'click': function() {
+ var state = {};
+ state[that.entity_name+'-facet'] = 'details';
+ state[that.entity_name+'-pkey'] = pkey_value;
+ nav_push_state(state);
+ return false;
+ }
+ });
+
+ var span = $('span[name="'+name+'"]', container);
+ span.html(link);
+}
+
+function ipa_hbacsvc_details_facet(spec) {
+
+ spec = spec || {};
+
+ var that = ipa_details_facet(spec);
+
+ that.super_init = that.super('init');
+ that.super_create = that.super('create');
+ that.super_setup = that.super('setup');
+
+ that.init = function() {
+
+ var section = that.create_section({
+ 'name': 'general',
+ 'label': 'General'
+ });
+
+ section.create_field({ 'name': 'cn', 'label': 'Name' });
+ section.create_field({ 'name': 'description', 'label': 'Description' });
+
+ that.super_init();
+ };
+
+ return that;
+} \ No newline at end of file
diff --git a/install/static/index.xhtml b/install/static/index.xhtml
index 4ba51fa38..4ca93f712 100644
--- a/install/static/index.xhtml
+++ b/install/static/index.xhtml
@@ -24,6 +24,7 @@
<script type="text/javascript" src="user.js"></script>
<script type="text/javascript" src="group.js"></script>
<script type="text/javascript" src="hbac.js"></script>
+ <script type="text/javascript" src="hbacsvc.js"></script>
<script type="text/javascript" src="host.js"></script>
<script type="text/javascript" src="hostgroup.js"></script>
<script type="text/javascript" src="netgroup.js"></script>
diff --git a/install/static/ipa.js b/install/static/ipa.js
index f7fd90500..ca4e958d3 100644
--- a/install/static/ipa.js
+++ b/install/static/ipa.js
@@ -22,7 +22,6 @@
/*global $:true, location:true */
/*Forward defined due to circular dependency with IPA.*/
-var ipa_cmd;
var IPA = ( function () {
var that = {
diff --git a/install/static/navigation.js b/install/static/navigation.js
index 0434f58ca..6b4419c99 100644
--- a/install/static/navigation.js
+++ b/install/static/navigation.js
@@ -134,7 +134,12 @@ function _nav_update_tabs(nls, container)
_nav_update_tabs(tab.children, container2);
} else if (tab.setup) {
- var entity = IPA.get_entity(tab.name);
+ var entity_name = tab.name;
+
+ // TODO: do not hard-code
+ if (entity_name == 'hbac' && nav_get_state('entity')) entity_name = nav_get_state('entity');
+
+ var entity = IPA.get_entity(entity_name);
entity.setup(container2);
}
}
diff --git a/install/static/policy.js b/install/static/policy.js
index c5ca523a9..deefab0c6 100644
--- a/install/static/policy.js
+++ b/install/static/policy.js
@@ -249,13 +249,16 @@ function ipa_records_facet(spec){
return pkey != that.pkey || record != that.record;
};
+ function create(container) {
+ that.setup_views(container);
+ }
+
function setup(container, unspecified){
that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
that.record = $.bbq.getState(that.entity_name + '-record', true) || '';
that.container = container;
- that.setup_views(container);
container.attr('title', that.entity_name);
@@ -445,6 +448,7 @@ function ipa_records_facet(spec){
}
+ that.create = create;
that.setup = setup;
that.load = load;
diff --git a/install/static/search.js b/install/static/search.js
index 1dfeda41e..ecdf56d2b 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);
- }
-}
-
diff --git a/install/static/service.js b/install/static/service.js
index 1b467cb59..6a79af074 100644
--- a/install/static/service.js
+++ b/install/static/service.js
@@ -26,115 +26,202 @@ function ipa_service() {
'name': 'service'
});
+ that.super_init = that.super('init');
+
that.init = function() {
- that.create_add_dialog({
+
+ var dialog = ipa_service_add_dialog({
'name': 'add',
- 'title': 'Add New Service',
- 'init': ipa_service_add_init
+ 'title': 'Add New Service'
});
+ that.add_dialog(dialog);
+ dialog.init();
- that.create_search_facet({
+ var facet = ipa_service_search_facet({
'name': 'search',
- 'label': 'Search',
- 'init': ipa_service_search_init
+ 'label': 'Search'
});
+ that.add_facet(facet);
- that.create_details_facet({
+ facet = ipa_service_details_facet({
'name': 'details',
- 'label': 'Details',
- 'init': ipa_service_details_init
+ 'label': 'Details'
});
- };
+ that.add_facet(facet);
- that.init();
+ facet = ipa_association_facet({
+ 'name': 'associate'
+ });
+ that.add_facet(facet);
+
+ that.create_association({
+ 'name': 'host',
+ 'add_method': 'add_host',
+ 'delete_method': 'remove_host'
+ });
+
+ that.super_init();
+ };
return that;
}
IPA.add_entity(ipa_service());
-function ipa_service_add_init() {
+function ipa_service_add_dialog(spec) {
- this.create_field({
- name: 'krbprincipalname',
- label: 'Principal',
- setup: service_add_krbprincipalname
- });
+ spec = spec || {};
- this.create_field({name:'service', label:'Service'});
- this.create_field({name:'host', label:'Host Name'});
-}
+ var that = ipa_add_dialog(spec);
-function ipa_service_search_init() {
+ that.super_init = that.super('init');
- this.create_column({name:'krbprincipalname', label:'Principal'});
+ that.init = function() {
- this.create_column({
- name: 'quick_links',
- label: 'Quick Links',
- setup: ipa_entity_quick_links
- });
-}
+ this.super_init();
-function ipa_service_details_init() {
+ this.add_field(ipa_widget({
+ name: 'krbprincipalname',
+ label: 'Principal'
+ }));
- var section = this.create_section({name:'details', label:'Service Details'});
+ this.add_field(ipa_text_widget({name:'service', label:'Service'}));
+ this.add_field(ipa_text_widget({name:'host', label:'Host Name'}));
+ };
- section.create_field({
- name: 'krbprincipalname',
- label: 'Principal',
- setup: service_krbprincipalname_setup,
- load: service_krbprincipalname_load
- });
+ that.create = function() {
- section.create_field({
- name: 'service',
- label: 'Service',
- load: service_service_load
- });
+ var table = $('<table/>').appendTo(that.container);
- section.create_field({
- name: 'host',
- label: 'Host Name',
- load: service_host_load
- });
+ var field = that.get_field('service');
- section = this.create_section({name:'provisioning', label:'Provisioning'});
+ var tr = $('<tr/>').appendTo(table);
- section.create_field({
- name: 'provisioning_status',
- label: 'Status',
- load: service_provisioning_status_load
- });
+ var td = $('<td/>', {
+ 'style': 'vertical-align: top;'
+ }).appendTo(tr);
+ td.append(field.label+': ');
- section = this.create_section({name:'certificate', label:'Service Certificate'});
+ td = $('<td/>', {
+ 'style': 'vertical-align: top;'
+ }).appendTo(tr);
- section.create_field({
- name: 'certificate_status',
- label: 'Status',
- load: service_usercertificate_load
- });
-}
+ $('<input/>', {
+ 'type': 'text',
+ 'name': 'service',
+ 'size': 20
+ }).appendTo(td);
+
+ field = that.get_field('host');
+
+ tr = $('<tr/>').appendTo(table);
+
+ td = $('<td/>', {
+ 'style': 'vertical-align: top;'
+ }).appendTo(tr);
+ td.append(field.label+': ');
+
+ td = $('<td/>', {
+ 'style': 'vertical-align: top;'
+ }).appendTo(tr);
+
+ $('<input/>', {
+ 'type': 'text',
+ 'name': 'host',
+ 'size': 40
+ }).appendTo(td);
+ };
+
+ that.get_record = function() {
+ var record = {};
+
+ var field = that.get_field('service');
+ var service = field.save(that.container)[0];
+
+ field = that.get_field('host');
+ var host = field.save(that.container)[0];
-function service_add_krbprincipalname(add_dialog, mode) {
- if (mode == IPA_ADD_UPDATE) {
- var service = add_dialog.find('input[name=service]').val();
- var host = add_dialog.find('input[name=host]').val();
- return service+'/'+host;
- }
- return null;
+ record['krbprincipalname'] = service+'/'+host;
+
+ return record;
+ };
+
+ return that;
}
-ipa_entity_set_association_definition('service', {
- 'host': { add_method: 'add_host', delete_host: 'remove_host' }
-});
+function ipa_service_search_facet(spec) {
-function service_krbprincipalname_setup(container) {
- // skip krbprincipalname
+ spec = spec || {};
+
+ var that = ipa_search_facet(spec);
+
+ that.super_init = that.super('init');
+
+ that.init = function() {
+
+ this.create_column({name:'krbprincipalname', label:'Principal'});
+
+ this.create_column({
+ name: 'quick_links',
+ label: 'Quick Links',
+ setup: ipa_entity_quick_links
+ });
+
+ that.super_init();
+ };
+
+ return that;
}
-function service_krbprincipalname_load(container, result) {
- // skip krbprincipalname
+function ipa_service_details_facet(spec) {
+
+ spec = spec || {};
+
+ var that = ipa_details_facet(spec);
+
+ that.super_init = that.super('init');
+
+ that.init = function() {
+
+ var section = this.create_section({name:'details', label:'Service Details'});
+
+ section.create_field({
+ name: 'krbprincipalname',
+ label: 'Principal'
+ });
+
+ section.create_field({
+ name: 'service',
+ label: 'Service',
+ load: service_service_load
+ });
+
+ section.create_field({
+ name: 'host',
+ label: 'Host Name',
+ load: service_host_load
+ });
+
+ section = this.create_section({name:'provisioning', label:'Provisioning'});
+
+ section.create_field({
+ name: 'provisioning_status',
+ label: 'Status',
+ load: service_provisioning_status_load
+ });
+
+ section = this.create_section({name:'certificate', label:'Service Certificate'});
+
+ section.create_field({
+ name: 'certificate_status',
+ label: 'Status',
+ load: service_usercertificate_load
+ });
+
+ that.super_init();
+ };
+
+ return that;
}
function service_service_load(container, result) {
diff --git a/install/static/test/details_tests.js b/install/static/test/details_tests.js
index 1dd0ddf13..80dbc3986 100644
--- a/install/static/test/details_tests.js
+++ b/install/static/test/details_tests.js
@@ -19,7 +19,7 @@
*/
-test("Testing ipa_details_section.setup().", function() {
+test("Testing ipa_details_section.create().", function() {
IPA.ajax_options.async = false;
@@ -34,8 +34,6 @@ test("Testing ipa_details_section.setup().", function() {
}
);
- var result = {};
-
var section = ipa_details_section({name:'IDIDID', label:'NAMENAMENAME'}).
input({name:'cn', label:'Entity Name'}).
input({name:'description', label:'Description'}).
@@ -44,7 +42,7 @@ test("Testing ipa_details_section.setup().", function() {
var fields = section.fields;
var container = $("<div/>");
- section.setup(container, result);
+ section.create(container);
var dl = container.find('dl');
@@ -80,7 +78,7 @@ test("Testing ipa_details_section.setup().", function() {
-test("Testing details lifecycle: create, save ().", function(){
+test("Testing details lifecycle: create, setup, load.", function(){
IPA.ajax_options.async = false;
@@ -168,7 +166,9 @@ test("Testing details lifecycle: create, save ().", function(){
var entity = ipa_get_entity(obj_name);
var facet = entity.get_facet('details');
- facet.create(container, result);
+ facet.create(container);
+ facet.setup(container);
+ facet.load(container, result);
var contact = container.find('dl#contact.entryattrs');
@@ -192,7 +192,7 @@ test("Testing details lifecycle: create, save ().", function(){
);
same(
- dts[5].title, facet.get_sections()[0].get_fields()[5].name,
+ dts[5].title, facet.sections[0].fields[5].name,
'Checking dt title'
);
@@ -205,7 +205,7 @@ test("Testing details lifecycle: create, save ().", function(){
ok (load_manager_called, 'load manager called');
- ipa_details_update(container,
+ facet.update(container,
'kfrog',
function(){update_success_called = true},
function(){update_failure_called = true});
@@ -265,7 +265,11 @@ test("Testing ipa_details_section_setup again()",function(){
var details = $("<div/>");
container.append(details);
- section.setup(container, details, section);
+ var result = {};
+
+ section.create(container);
+ section.setup(container);
+ section.load(container, result);
ok(container.find('hr'),'hr');
diff --git a/install/static/test/entity_tests.js b/install/static/test/entity_tests.js
index 08fc3111d..5d98d7b1b 100644
--- a/install/static/test/entity_tests.js
+++ b/install/static/test/entity_tests.js
@@ -61,7 +61,7 @@ test('Testing ipa_entity_set_search_definition().', function() {
);
});
-test('Testing ipa_entity_generate_views().', function() {
+test('Testing ipa_facet_setup_views().', function() {
var orig_show_page = IPA.show_page;
IPA.ajax_options.async = false;
@@ -83,9 +83,10 @@ test('Testing ipa_entity_generate_views().', function() {
IPA.add_entity(entity);
- var facet = entity.create_association_facet({
+ var facet = ipa_association_facet({
'name': 'associate'
});
+ entity.add_facet(facet);
var container = $('<div/>');
@@ -179,11 +180,12 @@ test('Testing ipa_entity_quick_links().', function() {
var tbody = $('<tbody/>').appendTo(search_table);
var tr = $('<tr/>').appendTo(tbody);
+ var td = $('<td/>').appendTo(tr);
+ var span = $('<span/>', {name:'quick_links'}).appendTo(td);
- ipa_entity_quick_links(tr, null, null, entry_attrs);
+ ipa_entity_quick_links(tr, 'quick_links', null, entry_attrs);
- var td = tr.children().first();
- var link = td.children().first();
+ var link = span.children().first();
equals(
link.attr('href'), '#details',
diff --git a/install/static/test/ipa_tests.html b/install/static/test/ipa_tests.html
index 3f3c16869..903e71545 100644
--- a/install/static/test/ipa_tests.html
+++ b/install/static/test/ipa_tests.html
@@ -7,6 +7,7 @@
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../jquery.js"></script>
+ <script type="text/javascript" src="../jquery.ba-bbq.js"></script>
<script type="text/javascript" src="../jquery-ui.js"></script>
<script type="text/javascript" src="../ipa.js"></script>
<script type="text/javascript" src="ipa_tests.js"></script>
diff --git a/install/static/webui.js b/install/static/webui.js
index 804f06f86..bf367ee94 100644
--- a/install/static/webui.js
+++ b/install/static/webui.js
@@ -68,6 +68,11 @@ $(function() {
$('#loggedinas a').fragment(
{'user-facet':'details', 'user-pkey':ipa_whoami_pkey},2);
+ for (var i=0; i<IPA.entities.length; i++) {
+ var entity = IPA.entities[i];
+ entity.init();
+ }
+
var navigation = $('#navigation');
if (whoami.hasOwnProperty('memberof_rolegroup') &&
diff --git a/install/static/widget.js b/install/static/widget.js
index b4f52b1a3..281370caa 100755
--- a/install/static/widget.js
+++ b/install/static/widget.js
@@ -32,10 +32,12 @@ function ipa_widget(spec) {
that.read_only = spec.read_only;
that._entity_name = spec.entity_name;
+ that.init = spec.init || init;
that.create = spec.create || create;
that.setup = spec.setup || setup;
that.load = spec.load || load;
that.save = spec.save || save;
+ that.clear = spec.clear || clear;
that.super = function(name) {
var method = that[name];
@@ -52,6 +54,9 @@ function ipa_widget(spec) {
that._entity_name = entity_name;
});
+ function init() {
+ }
+
function create(container) {
}
@@ -65,6 +70,9 @@ function ipa_widget(spec) {
return [];
}
+ function clear(container) {
+ }
+
return that;
}
@@ -74,6 +82,16 @@ function ipa_text_widget(spec) {
var that = ipa_widget(spec);
+ that.size = spec.size || 30;
+
+ that.create = function(container) {
+ $('<input/>', {
+ 'type': 'text',
+ 'name': that.name,
+ 'size': that.size
+ }).appendTo(container);
+ };
+
that.load = function(container, result) {
that.value = result[that.name] || '';
var input = $('input[name="'+that.name+'"]', container);
@@ -101,35 +119,68 @@ function ipa_text_widget(spec) {
return values;
};
+ that.clear = function(container) {
+ var input = $('input[name="'+that.name+'"]', container);
+ input.val('');
+ };
+
return that;
}
-function ipa_radio_widget(spec) {
+function ipa_checkbox_widget(spec) {
spec = spec || {};
- spec.setup = spec.setup || setup;
- spec.load = spec.load || load;
- spec.save = spec.save || save;
-
var that = ipa_widget(spec);
- function setup(container) {
- }
+ that.create = function(container) {
+ $('<input/>', {
+ 'type': 'checkbox',
+ 'name': that.name
+ }).appendTo(container);
+ };
- function load(container, result) {
+ that.load = function(container, result) {
var value = result[that.name] || '';
$('input[name="'+that.name+'"][value="'+value+'"]', container).attr('checked', 'checked');
- }
+ };
- function save(container) {
+ that.save = function(container) {
+ var values = [];
+
+ var value = $('input[name="'+that.name+'"]', container).is(':checked');
+ values.push(value);
+
+ return values;
+ };
+
+ that.clear = function(container) {
+ var input = $('input[name="'+that.name+'"]', container).get(0);
+ input.checked = false;
+ };
+
+ return that;
+}
+
+function ipa_radio_widget(spec) {
+
+ spec = spec || {};
+
+ var that = ipa_widget(spec);
+
+ that.load = function(container, result) {
+ var value = result[that.name] || '';
+ $('input[name="'+that.name+'"][value="'+value+'"]', container).attr('checked', 'checked');
+ };
+
+ that.save = function(container) {
var values = [];
var value = $('input[name="'+that.name+'"]:checked', container).val();
values.push(value);
return values;
- }
+ };
return that;
}
@@ -138,28 +189,37 @@ function ipa_textarea_widget(spec) {
spec = spec || {};
- spec.setup = spec.setup || setup;
- spec.load = spec.load || load;
- spec.save = spec.save || save;
-
var that = ipa_widget(spec);
- function setup(container) {
- }
+ that.rows = spec.rows || 5;
+ that.cols = spec.cols || 40;
- function load(container, result) {
+ that.create = function(container) {
+ $('<textarea/>', {
+ 'rows': that.rows,
+ 'cols': that.cols,
+ 'name': that.name
+ }).appendTo(container);
+ };
+
+ that.load = function(container, result) {
var value = result[that.name] || '';
$('textarea[name="'+that.name+'"]', container).val(value);
- }
+ };
- function save(container) {
+ that.save = function(container) {
var values = [];
var value = $('textarea[name="'+that.name+'"]', container).val();
values.push(value);
return values;
- }
+ };
+
+ that.clear = function(container) {
+ var input = $('input[name="'+that.name+'"]', container);
+ input.val('');
+ };
return that;
}
@@ -199,8 +259,42 @@ function ipa_column_widget(spec) {
var that = ipa_widget(spec);
that.primary_key = spec.primary_key;
+ that.setup = spec.setup || setup;
that.link = spec.link;
+ function setup(container, name, value, record) {
+
+ var span = $('span[name="'+name+'"]', container);
+
+ var param_info = ipa_get_param_info(that.entity_name, name);
+ var primary_key = that.primary_key || param_info && param_info['primary_key'];
+
+ if (primary_key && that.link) {
+ var link = $('<a/>', {
+ 'href': '#'+value,
+ 'html': value,
+ 'click': function (value) {
+ return function() {
+ var state = {};
+ state[that.entity_name + '-facet'] = 'details';
+ state[that.entity_name + '-pkey'] = value;
+ //Before this will work, we need to set the tab one level up
+ //for example:
+ //state['identity'] = 0;
+ //but we have no way of getting the index.
+
+ $.bbq.pushState(state);
+ return false;
+ }
+ }(value)
+ });
+ span.html(link);
+
+ } else {
+ span.html(value);
+ }
+ }
+
return that;
}
@@ -244,12 +338,6 @@ function ipa_table_widget(spec) {
function create(container) {
var div = $('#'+that.id, container);
- if (div.children().length) {
- // widget loaded from template
- return;
- }
-
- div.empty();
var table = $('<table/>', {
'class': 'search-table'
@@ -269,11 +357,17 @@ function ipa_table_widget(spec) {
}).appendTo(th);
for (var i=0; i<that.columns.length; i++) {
+ var column = that.columns[i];
th = $('<th/>').appendTo(tr);
+ var label = column.label;
+
+ var param_info = ipa_get_param_info(that.entity_name, column.name);
+ if (param_info && param_info['label']) label = param_info['label'];
+
$('<span/>', {
'style': 'float: left;',
- 'html': that.columns[i].label
+ 'html': label
}).appendTo(th);
if (i == that.columns.length-1) {
@@ -303,6 +397,16 @@ function ipa_table_widget(spec) {
'name': that.columns[i].name
}).appendTo(td);
}
+
+ var tfoot = $('<tfoot/>').appendTo(table);
+
+ tr = $('<tr/>').appendTo(tfoot);
+
+ td = $('<td/>', { colspan: that.columns.length+1 }).appendTo(tr);
+
+ $('<span/>', {
+ 'name': 'summary'
+ }).appendTo(td);
}
function setup(container) {
@@ -310,6 +414,7 @@ function ipa_table_widget(spec) {
that.table = $('table', div);
that.thead = $('thead', that.table);
that.tbody = $('tbody', that.table);
+ that.tfoot = $('tfoot', that.table);
var select_all_checkbox = $('input[name=select]', that.thead);
select_all_checkbox.attr('title', 'Select All');
@@ -378,7 +483,9 @@ function ipa_table_widget(spec) {
var record = {};
for (var i=0; i<that.columns.length; i++){
var name = that.columns[i].name;
- record[name] = result[name][index];
+ var values = result[name];
+ if (!values) continue;
+ record[name] = values[index];
}
return record;
};
@@ -394,35 +501,12 @@ function ipa_table_widget(spec) {
var name = column.name;
var value = record[name];
- var span = $('span[name="'+name+'"]', tr);
- span.html(value);
-
if (column.primary_key) {
// set checkbox value
$('input[name="select"]', tr).val(value);
}
- if (column.primary_key && column.link) {
- // wrap value with a link
- var link = $('<a/>', {
- 'click': function (value) {
- return function() {
- var state = {};
- state[that.other_entity + '-facet'] = 'details';
- state[that.other_entity + '-pkey'] = value;
- //Before this will work, we need to set the tab one level up
- //for example:
- //state['identity'] = 0;
- //but we have no way of getting the index.
-
- $.bbq.pushState(state);
- return false;
- }
- }(value)
- });
- span.before(link);
- link.append(span);
- }
+ column.setup(tr, name, value, record);
}
};
@@ -475,11 +559,10 @@ function ipa_dialog(spec) {
var that = {};
+ that.name = spec.name;
that.title = spec.title;
- that.parent = spec.parent;
that._entity_name = spec.entity_name;
- that.container = $('<div/>').appendTo(that.parent);
that.width = spec.width || 400;
that.buttons = {};
@@ -520,10 +603,32 @@ function ipa_dialog(spec) {
that.fields_by_name[field.name] = field;
};
+ that.init = function() {
+ };
+
/**
* Create content layout
*/
that.create = function() {
+
+ var table = $('<table/>').appendTo(that.container);
+
+ for (var i=0; i<that.fields.length; i++) {
+ var field = that.fields[i];
+
+ var tr = $('<tr/>').appendTo(table);
+
+ var td = $('<td/>', {
+ 'style': 'vertical-align: top;'
+ }).appendTo(tr);
+ td.append(field.label+': ');
+
+ td = $('<td/>', {
+ 'style': 'vertical-align: top;'
+ }).appendTo(tr);
+
+ field.create(td);
+ }
};
/**
@@ -535,7 +640,9 @@ function ipa_dialog(spec) {
/**
* Open dialog
*/
- that.open = function() {
+ that.open = function(container) {
+
+ that.container = $('<div/>').appendTo(container);
that.create();
that.setup();
@@ -552,11 +659,28 @@ function ipa_dialog(spec) {
that.container.dialog('option', name, value);
};
+ that.get_record = function() {
+ var record = {};
+ for (var i=0; i<that.fields.length; i++) {
+ var field = that.fields[i];
+ var values = field.save(that.container);
+ record[field.name] = values[0];
+ }
+ return record;
+ };
+
that.close = function() {
that.container.dialog('destroy');
that.container.remove();
};
+ that.clear = function() {
+ for (var i=0; i<that.fields.length; i++) {
+ var field = that.fields[i];
+ field.clear(that.container);
+ }
+ };
+
return that;
}
@@ -655,13 +779,13 @@ function ipa_adder_dialog(spec) {
});
};
- that.open = function() {
+ that.open = function(container) {
that.buttons = {
'Enroll': that.add,
'Cancel': that.close
};
- that.super_open();
+ that.super_open(container);
};
that.get_filter = function() {
@@ -744,13 +868,13 @@ function ipa_deleter_dialog(spec) {
}).appendTo(that.container);
};
- that.open = function() {
+ that.open = function(container) {
that.buttons = {
'Delete': that.remove,
'Cancel': that.close
};
- that.super_open();
+ that.super_open(container);
};
return that;