Fixed delegation UI issues

This patch fixes several issues in delegation UI:

When adding a new delegation, only the first attribute selected
was saved. Now all attributes will be saved properly.

When loading the details page, the custom widgets did not store
the original values properly so is_dirty() did not work correctly.
Now this has been fixed except for the memberof attribute because
of these issues:
 - https://fedorahosted.org/freeipa/ticket/869
 - https://fedorahosted.org/freeipa/ticket/870

When saving the details page, the attrs were saved as an array
which was rejected by the server. Now it is stored as comma-
separated list.
This commit is contained in:
Endi S. Dewata
2011-01-28 09:36:25 -06:00
committed by Adam Young
parent 4486341c83
commit b96138ba56
6 changed files with 80 additions and 69 deletions

View File

@@ -81,35 +81,27 @@ IPA.attribute_table_widget= function (spec){
}; };
that.save = function(){ that.save = function(){
var attrs_boxes = $('table#'+id+" td :checked"); var values = [];
if (!attrs_boxes.length){
return []; var attrs_boxes = $('table#'+id+" td :checked");
}
var retval = ""; for (var i = 0; i < attrs_boxes.length; i += 1) {
for (var i = 0; i < attrs_boxes.length; i += 1){ var value = attrs_boxes[i].id.substring("aciattr-".length);
if (i > 0){ values.push(value);
retval += ',';
}
retval += attrs_boxes[i].id.substring("aciattr-".length);
} }
return [retval]; return values;
}; };
var attrs = [];
that.reset =function(){ that.reset =function(){
$('input[type=checkbox]', table).attr('checked',''); $('input[type=checkbox]', table).attr('checked','');
for (var i = 0; i < attrs.length; i+=1){ for (var i = 0; i < that.values.length; i+=1){
$(attrs[i], table).attr('checked','checked'); $('#aciattr-'+that.values[i], table).attr('checked','checked');
} }
}; };
that.load = function(record){ that.load = function(record){
if (!record.attrs) return; that.values = record[that.name] || [];
attrs = [];
for (var i = 0; i < record.attrs.length; i+=1){
attrs.push('#aciattr-' +record.attrs[i]);
}
that.reset(); that.reset();
}; };
@@ -122,7 +114,6 @@ IPA.entity_select_widget = function(spec){
var entity = spec.entity || 'group'; var entity = spec.entity || 'group';
function populate_select(value){ function populate_select(value){
var selected = value;
function find_success(result){ function find_success(result){
$('option', that.entity_select).remove(); $('option', that.entity_select).remove();
var entities = result.result.result; var entities = result.result.result;
@@ -132,7 +123,7 @@ IPA.entity_select_widget = function(spec){
text:entities[i].cn[0], text:entities[i].cn[0],
value:entities[i].cn[0] value:entities[i].cn[0]
})); }));
if (selected === entities[i].cn[0]){ if (value === entities[i].cn[0]){
option.attr('selected','selected'); option.attr('selected','selected');
} }
} }
@@ -180,14 +171,18 @@ IPA.entity_select_widget = function(spec){
}).appendTo(dd); }).appendTo(dd);
populate_select(); populate_select();
}; };
var value = '';
that.reset = function(){ that.reset = function(){
that.entity_filter.val(value ); that.entity_filter.val(that.values[0]);
populate_select(value); populate_select(that.values[0]);
}; };
that.load = function(record){ that.load = function(record){
value = record[that.name]; var value = record[that.name];
if (value instanceof Array) {
that.values = value;
} else {
that.values = value ? [value] : [''];
}
that.reset(); that.reset();
}; };
@@ -735,13 +730,13 @@ IPA.entity_factories.delegation = function() {
custom_input(IPA.entity_select_widget( custom_input(IPA.entity_select_widget(
{name:'group', entity:'group'})). {name:'group', entity:'group'})).
custom_input(IPA.entity_select_widget( custom_input(IPA.entity_select_widget(
{name:'memberof', entity:'group'})). {name:'memberof', entity:'group', join: true})).
custom_input( custom_input(
IPA.rights_widget({ IPA.rights_widget({
id:'delegation_rights'})). id:'delegation_rights'})).
custom_input( custom_input(
IPA.attribute_table_widget({ IPA.attribute_table_widget({
name:'attrs'})))). name:'attrs', join: true})))).
add_dialog(IPA.add_dialog({ add_dialog(IPA.add_dialog({
name: 'add', name: 'add',
title: 'Add Delegation' title: 'Add Delegation'
@@ -750,8 +745,8 @@ IPA.entity_factories.delegation = function() {
field(IPA.entity_select_widget({name:'group', field(IPA.entity_select_widget({name:'group',
entity:'group'})). entity:'group'})).
field(IPA.entity_select_widget({name:'memberof', field(IPA.entity_select_widget({name:'memberof',
entity:'group'})). entity:'group', join: true})).
field(IPA.attribute_table_widget({ name: 'attrs'}))). field(IPA.attribute_table_widget({ name: 'attrs', join: true}))).
standard_associations(); standard_associations();
return that; return that;

View File

@@ -36,7 +36,8 @@ IPA.add_dialog = function (spec) {
that.init = function() { that.init = function() {
that.add_button('Add', function() { that.add_button('Add', function() {
var record = that.get_record(); var record = {};
that.save(record);
that.add( that.add(
record, record,
function() { function() {
@@ -51,7 +52,8 @@ IPA.add_dialog = function (spec) {
that.add_button('Add and Add Another', function() { that.add_button('Add and Add Another', function() {
var record = that.get_record(); var record = {};
that.save(record);
that.add( that.add(
record, record,
function() { function() {
@@ -65,7 +67,8 @@ IPA.add_dialog = function (spec) {
}); });
that.add_button('Add and Edit', function() { that.add_button('Add and Edit', function() {
var record = that.get_record(); var record = {};
that.save(record);
that.add( that.add(
record, record,
function() { function() {
@@ -113,6 +116,8 @@ IPA.add_dialog = function (spec) {
} }
} }
//alert(JSON.stringify(command.to_json()));
command.execute(); command.execute();
}; };

View File

@@ -781,7 +781,7 @@ IPA.details_update = function (on_win, on_fail)
var that = this; var that = this;
var entity_name = that.entity_name; var entity_name = that.entity_name;
function update_on_win(data, text_status, xhr) { function on_success(data, text_status, xhr) {
if (on_win) if (on_win)
on_win(data, text_status, xhr); on_win(data, text_status, xhr);
if (data.error) if (data.error)
@@ -791,7 +791,7 @@ IPA.details_update = function (on_win, on_fail)
that.load(result); that.load(result);
} }
function update_on_fail(xhr, text_status, error_thrown) { function on_error(xhr, text_status, error_thrown) {
if (on_fail) if (on_fail)
on_fail(xhr, text_status, error_thrown); on_fail(xhr, text_status, error_thrown);
} }
@@ -822,8 +822,12 @@ IPA.details_update = function (on_win, on_fail)
if (param_info['primary_key']) continue; if (param_info['primary_key']) continue;
if (values.length === 1) { if (values.length === 1) {
modlist[field.name] = values[0]; modlist[field.name] = values[0];
}else if (values.length > 1){ } else if (values.length > 1){
modlist[field.name] = values; if (field.join) {
modlist[field.name] = values.join(',');
} else {
modlist[field.name] = values;
}
} else if (param_info['multivalue']){ } else if (param_info['multivalue']){
modlist[field.name] = []; modlist[field.name] = [];
} }
@@ -841,14 +845,21 @@ IPA.details_update = function (on_win, on_fail)
} }
} }
var pkey = that.get_primary_key() ; var pkey = that.get_primary_key();
if (pkey){
pkey = [pkey];
}else{
pkey = [];
}
IPA.cmd('mod', pkey, modlist, update_on_win, null, entity_name); var args = pkey ? [pkey] : [];
var command = IPA.command({
method: entity_name+'_mod',
args: args,
options: modlist,
on_success: on_success,
on_error: on_error
});
//alert(JSON.stringify(command.to_json()));
command.execute();
}; };

View File

@@ -163,8 +163,7 @@ IPA.service_add_dialog = function (spec) {
field.create(span); field.create(span);
}; };
that.get_record = function() { that.save = function(record) {
var record = {};
var field = that.get_field('service'); var field = that.get_field('service');
var service = field.save()[0]; var service = field.save()[0];
@@ -175,11 +174,7 @@ IPA.service_add_dialog = function (spec) {
record['krbprincipalname'] = service+'/'+host; record['krbprincipalname'] = service+'/'+host;
field = that.get_field('force'); field = that.get_field('force');
var force = field.save()[0]; record['force'] = field.save()[0];
record['force'] = force;
return record;
}; };
return that; return that;

View File

@@ -8,8 +8,10 @@
"cn" "cn"
], ],
"filter": "(memberOf=cn=ipausers,cn=groups,cn=accounts,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com)", "filter": "(memberOf=cn=ipausers,cn=groups,cn=accounts,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com)",
"group": "muppets", "group": "admins",
"membergroup": "cn=ipausers,cn=groups,cn=accounts,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com", "membergroup": [
"admins"
],
"permissions": [ "permissions": [
"write" "write"
] ]

View File

@@ -38,6 +38,7 @@ IPA.widget = function(spec) {
that.height = spec.height; that.height = spec.height;
that.undo = typeof spec.undo == 'undefined' ? true : spec.undo; that.undo = typeof spec.undo == 'undefined' ? true : spec.undo;
that.join = spec.join;
that.init = spec.init || init; that.init = spec.init || init;
that.create = spec.create || create; that.create = spec.create || create;
@@ -110,6 +111,7 @@ IPA.widget = function(spec) {
function load(record) { function load(record) {
that.record = record; that.record = record;
that.values = record[that.name];
that.reset(); that.reset();
} }
@@ -126,36 +128,39 @@ IPA.widget = function(spec) {
} }
that.is_dirty = function() { that.is_dirty = function() {
if (that.read_only) { if (that.read_only) {
return false; return false;
} }
var values = that.save(); var values = that.save();
if (!that.values){ if (!that.values) {
if (!values) { if (!values) {
return false; return false;
} }
if ( values === "" ){
return false; if (values === '') {
}
if ((values instanceof Array) &&
(values.length ===1) &&
(values[0] === "")){
return false; return false;
} }
if ((values instanceof Array) && if (values instanceof Array) {
(values.length === 0)){
return false; if ((values.length === 0) ||
(values.length === 1) &&
(values[0] === '')) {
return false;
}
} }
if (values) { return true;
return true;
}
} }
if (values.length != that.values.length) { if (values.length != that.values.length) {
return true; return true;
} }
for (var i=0; i<values.length; i++) { for (var i=0; i<values.length; i++) {
if (values[i] != that.values[i]) { if (values[i] != that.values[i]) {
return true; return true;
@@ -1017,14 +1022,12 @@ IPA.dialog = function(spec) {
that.container.dialog('option', name, value); that.container.dialog('option', name, value);
}; };
that.get_record = function() { that.save = function(record) {
var record = {};
for (var i=0; i<that.fields.length; i++) { for (var i=0; i<that.fields.length; i++) {
var field = that.fields[i]; var field = that.fields[i];
var values = field.save(); var values = field.save();
record[field.name] = values[0]; record[field.name] = values.join(',');
} }
return record;
}; };
that.close = function() { that.close = function() {