summaryrefslogtreecommitdiffstats
path: root/install/static/hbac.js
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2010-11-04 21:42:37 -0500
committerAdam Young <ayoung@redhat.com>2010-11-08 20:06:49 -0500
commitc854435a27e0595c17661e80d38d5fa0016f8c96 (patch)
tree345245bcbbdf10fe29fca565581b6bd2aedd8822 /install/static/hbac.js
parent537f4074d1606e9608773868ea630ca58effa61f (diff)
downloadfreeipa-c854435a27e0595c17661e80d38d5fa0016f8c96.tar.gz
freeipa-c854435a27e0595c17661e80d38d5fa0016f8c96.tar.xz
freeipa-c854435a27e0595c17661e80d38d5fa0016f8c96.zip
HBAC Access Time
IPA commands now can be defined in these classes: - ipa_command: a single IPA command - ipa_batch_command: a batch command for executing multiple commands on the server side using the new batch plugin The dialog boxes for adding and removing entries have been refactored: - ipa_dialog: base class for dialog boxes - ipa_adder_dialog: generic adder dialog box - ipa_deleter_dialog: generic deleter dialog box - ipa_association_adder_dialog: adding entity association - ipa_association_deleter_dialog: removing entity association Dialog boxes for adding/deleting HBAC users, hosts, services, and sourcehosts are implemented using the association dialog boxes. The dialog box for adding access time is implemented using ipa_dialog and currently contains only a text field. This will be replaced with a custom dialog box in a separate patch. The dialog box for removing access time is implemented using the generic deleter class because it's not an association. Removing multiple access times is implemented using batch operations. New test data files for access times have been added.
Diffstat (limited to 'install/static/hbac.js')
-rwxr-xr-xinstall/static/hbac.js182
1 files changed, 152 insertions, 30 deletions
diff --git a/install/static/hbac.js b/install/static/hbac.js
index 528fdec9..f81fe5d7 100755
--- a/install/static/hbac.js
+++ b/install/static/hbac.js
@@ -351,7 +351,7 @@ function ipa_hbac_details_init() {
'name': 'accesstime',
'label': 'When',
'text': 'Rule applies when access is being requested at:',
- 'field_name': 'sourcehostcategory',
+ 'field_name': 'accesstime',
'options': [
{ 'value': 'all', 'label': 'Any Time' },
{ 'value': '', 'label': 'Specified Times' }
@@ -517,18 +517,10 @@ function ipa_hbac_details_tables_section(spec){
return that;
}
-/**
- * This widget adds & deletes the rows of the table in the UI, but does not
- * execute IPA command to apply the changes on the server.
- */
function ipa_hbac_association_widget(spec) {
spec = spec || {};
- spec.add = spec.add || add;
- spec.remove = spec.remove || remove;
- spec.save = spec.save || save;
-
var that = ipa_table_widget(spec);
that.other_entity = spec.other_entity;
@@ -588,15 +580,15 @@ function ipa_hbac_association_widget(spec) {
}
};
- function add(container) {
+ that.add = function(container) {
var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
var label = IPA.metadata[that.other_entity].label;
var title = 'Add '+label+' to '+that.entity_name+' '+pkey;
- var dialog = ipa_adder_dialog({
- 'name': 'adder_dialog',
+ var dialog = ipa_association_adder_dialog({
'title': title,
+ 'parent': container,
'entity_name': that.entity_name,
'pkey': pkey,
'other_entity': that.other_entity,
@@ -613,9 +605,9 @@ function ipa_hbac_association_widget(spec) {
});
dialog.open();
- }
+ };
- function remove(container) {
+ that.remove = function(container) {
var values = that.get_selected_values();
@@ -628,9 +620,9 @@ function ipa_hbac_association_widget(spec) {
var label = IPA.metadata[that.other_entity].label;
var title = 'Remove '+label+' from '+that.entity_name+' '+pkey;
- var dialog = ipa_deleter_dialog({
- 'name': 'deleter_dialog',
+ var dialog = ipa_association_deleter_dialog({
'title': title,
+ 'parent': container,
'entity_name': that.entity_name,
'pkey': pkey,
'other_entity': that.other_entity,
@@ -648,11 +640,11 @@ function ipa_hbac_association_widget(spec) {
});
dialog.open();
- }
+ };
- function save(container) {
+ that.save = function(container) {
return [];
- }
+ };
return that;
}
@@ -661,9 +653,6 @@ function ipa_hbac_accesstime_widget(spec) {
spec = spec || {};
- spec.load = spec.load || load;
- spec.save = spec.save || save;
-
var that = ipa_table_widget(spec);
that.super_create = that.super('create');
@@ -704,13 +693,12 @@ function ipa_hbac_accesstime_widget(spec) {
}).appendTo(buttons);
};
- function load(container, result) {
+ that.load = function(container, result) {
var values = result[that.name] || '';
-
- if (values == '') {
- $('input[name="'+that.name+'"][value="all"]', container).attr('checked', 'checked');
- } else {
+ if (values) {
$('input[name="'+that.name+'"][value=""]', container).attr('checked', 'checked');
+ } else {
+ $('input[name="'+that.name+'"][value="all"]', container).attr('checked', 'checked');
}
that.tbody.empty();
@@ -720,11 +708,145 @@ function ipa_hbac_accesstime_widget(spec) {
$('span[name="'+that.name+'"]', tr).html(values[i]);
tr.appendTo(that.tbody);
}
- }
+ };
+
+ that.add = function(container) {
+
+ var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
+ var title = 'Add '+that.label+' to '+that.entity_name+' '+pkey;
+
+ var dialog = ipa_dialog({
+ 'title': title,
+ 'parent': container
+ });
+
+ dialog.add_field(ipa_text_widget({
+ 'name': that.name,
+ 'label': that.label
+ }));
+
+ dialog.create = function() {
+ var table = $('<table/>').appendTo(dialog.container);
+
+ var tr = $('<tr/>').appendTo(table);
+
+ var td = $('<td/>', {
+ 'style': 'vertical-align: top;'
+ }).appendTo(tr);
+ td.append(that.label+': ');
+
+ td = $('<td/>').appendTo(tr);
+ $('<input/>', {
+ 'type': 'text',
+ 'name': that.name,
+ 'size': 40
+ }).appendTo(td);
+
+ tr = $('<tr/>').appendTo(table);
+
+ td = $('<td/>', {
+ 'style': 'vertical-align: top;'
+ }).appendTo(tr);
+ td.append('Example:');
+
+ td = $('<td/>').appendTo(tr);
+
+ td.append('<b>Every day between 0800 and 1400:</b><br/>');
+ td.append('periodic daily 0800-1400<br/><br/>');
+
+ td.append('<b>December 16, 2010 from 10:32 until 10:33:</b><br/>');
+ td.append('absolute 201012161032 ~ 201012161033<td/>');
+ };
+
+ function add(on_success, on_error) {
- function save(container) {
+ var field = dialog.get_field(that.name);
+ var value = field.save(dialog.container)[0];
+
+ var command = ipa_command({
+ 'method': that.entity_name+'_add_'+that.name
+ });
+ command.add_arg(pkey);
+ command.set_option(that.name, value);
+
+ command.execute(
+ function() {
+ that.refresh(container);
+ if (on_success) on_success();
+ },
+ function() {
+ that.refresh(container);
+ if (on_error) on_error();
+ }
+ );
+ }
+
+ dialog.add_button('Add', function() {
+ add();
+ });
+
+ dialog.add_button('Add and Close', function() {
+ add(
+ function() { dialog.close(); },
+ function() { dialog.close(); }
+ );
+ });
+
+ dialog.add_button('Cancel', function() {
+ dialog.close();
+ });
+
+ dialog.open();
+ };
+
+ that.remove = function(container) {
+
+ var values = that.get_selected_values();
+
+ if (!values.length) {
+ alert('Select '+that.label+' to be removed.');
+ return;
+ }
+
+ var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
+ var title = 'Remove '+that.label+' from '+that.entity_name+' '+pkey;
+
+ var dialog = ipa_deleter_dialog({
+ 'title': title,
+ 'parent': container,
+ 'values': values
+ });
+
+ that.remove = function() {
+ var batch = ipa_batch_command();
+
+ for (var i=0; i<values.length; i++) {
+ var command = ipa_command({
+ 'method': that.entity_name+'_remove_'+that.name
+ });
+ command.add_arg(pkey);
+ command.set_option(that.name, values[i]);
+ batch.add_command(command);
+ }
+
+ batch.execute(
+ function() {
+ that.refresh(container);
+ dialog.close();
+ },
+ function() {
+ that.refresh(container);
+ dialog.close();
+ }
+ );
+ };
+
+ dialog.open();
+ };
+
+ that.save = function(container) {
return [];
- }
+ };
return that;
}