Added undo for permission target.

https://fedorahosted.org/freeipa/ticket/885
This commit is contained in:
Endi S. Dewata 2011-02-02 10:35:23 -06:00 committed by Adam Young
parent 0353a2be67
commit d389e054f6
5 changed files with 269 additions and 187 deletions

View File

@ -24,7 +24,7 @@
/* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */ /* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */
IPA.attribute_table_widget = function(spec) { IPA.attributes_widget = function(spec) {
spec = spec || {}; spec = spec || {};
@ -35,38 +35,43 @@ IPA.attribute_table_widget = function(spec) {
var id = spec.name; var id = spec.name;
var dd_class = "other"; var dd_class = "other";
that.create = function(container){ that.create = function(container) {
var dd = $('<dd/>', { var dd = $('<dd/>', {
'class': dd_class 'class': dd_class
}).appendTo(container); }).appendTo(container);
var span = $('<span/>', {
name: 'attrs'
}).appendTo(dd);
that.table = $('<table/>', { that.table = $('<table/>', {
id:id, id:id,
'class':'search-table aci-attribute-table'}). 'class':'search-table aci-attribute-table'
}).
append('<thead/>'). append('<thead/>').
append($('<tbody/>')). append('<tbody/>').
appendTo(span); appendTo(dd);
var tr = $('<tr></tr>').appendTo($('thead', that.table)); var tr = $('<tr></tr>').appendTo($('thead', that.table));
tr.append($('<th/>',{ tr.append($('<th/>', {
style:"height:2em; vertical-align:bottom;", style:"height:2em; vertical-align:bottom;",
html:$('<input/>',{ html:$('<input/>',{
type: "checkbox", type: "checkbox",
click: function(){ click: function(){
$('.aci-attribute'). $('.aci-attribute').
attr('checked', $(this).attr('checked')); attr('checked', $(this).attr('checked'));
}}) },
change: function() {
that.show_undo();
}
})
})). })).
append('<th class="aci-attribute-column">Attribute</th>'); append('<th class="aci-attribute-column">Attribute</th>');
if (that.undo) {
that.create_undo(dd);
}
if (that.object_type){ if (that.object_type){
that.populate (that.object_type); that.populate (that.object_type);
} }
}; };
that.load = function(record) { that.load = function(record) {
@ -85,11 +90,11 @@ IPA.attribute_table_widget = function(spec) {
that.update = function() { that.update = function() {
that.populate(that.object_type); that.populate(that.object_type);
that.checkboxes_update();
that.append(); that.append();
that.checkboxes_update();
}; };
that.populate = function(object_type){ that.populate = function(object_type) {
$('tbody tr', that.table).remove(); $('tbody tr', that.table).remove();
@ -100,22 +105,21 @@ IPA.attribute_table_widget = function(spec) {
var aciattrs = metadata.aciattrs; var aciattrs = metadata.aciattrs;
var attr_per_col = 400;
var col_span = aciattrs.length / attr_per_col + 1;
var tbody = $('tbody', that.table); var tbody = $('tbody', that.table);
var td;
for (var a = 0; a < aciattrs.length ; a += 1){ for (var i=0; i<aciattrs.length ; i++){
var value = aciattrs[a].toLowerCase(); var value = aciattrs[i].toLowerCase();
var aci_tr = $('<tr/>').appendTo(tbody); var aci_tr = $('<tr/>').appendTo(tbody);
td = $('<td/>').appendTo(aci_tr); var td = $('<td/>').appendTo(aci_tr);
td.append($('<input/>',{ td.append($('<input/>',{
type: 'checkbox', type: 'checkbox',
id: 'aciattr-'+value, name: that.name,
name: 'attrs',
value: value, value: value,
'class': 'aci-attribute' 'class': 'aci-attribute',
change: function() {
that.show_undo();
}
})); }));
td = $('<td/>').appendTo(aci_tr); td = $('<td/>').appendTo(aci_tr);
td.append($('<label/>',{ td.append($('<label/>',{
@ -130,14 +134,13 @@ IPA.attribute_table_widget = function(spec) {
var unmatched = []; var unmatched = [];
for (var i=0; i<that.values.length; i++) { for (var i=0; i<that.values.length; i++) {
var cb = $('#aciattr-'+that.values[i]); var input = $('input[name="'+that.name+'"][value="'+that.values[i]+'"]', that.container);
if (!cb.length){ if (!input.length) {
unmatched.push(that.values[i]); unmatched.push(that.values[i]);
} }
cb.attr('checked',true);
} }
if (unmatched.length > 0){ if (unmatched.length > 0) {
var tbody = $('tbody', that.table); var tbody = $('tbody', that.table);
for (var j=0; j<unmatched.length; j++) { for (var j=0; j<unmatched.length; j++) {
@ -147,11 +150,12 @@ IPA.attribute_table_widget = function(spec) {
var td = $('<td/>').appendTo(tr); var td = $('<td/>').appendTo(tr);
td.append($('<input/>', { td.append($('<input/>', {
type: 'checkbox', type: 'checkbox',
checked: true, name: that.name,
id: 'aciattr-'+value,
name: 'attrs',
value: value, value: value,
'class': 'aci-attribute' 'class': 'aci-attribute',
change: function() {
that.show_undo();
}
})); }));
td = $('<td/>').appendTo(tr); td = $('<td/>').appendTo(tr);
@ -165,47 +169,24 @@ IPA.attribute_table_widget = function(spec) {
return that; return that;
}; };
IPA.rights_widget = function(spec) {
IPA.type_widget = function(spec) {
spec = spec || {};
var that = IPA.select_widget(spec);
that.filter = spec.filter || '';
that.create = function(container) {
that.select = $('<select/>', {
name: that.name,
id: 'object_type_select'
}).appendTo(container);
};
return that;
};
IPA.rights_widget = function(spec){
var rights = ['write','add','delete'];
var that = IPA.checkboxes_widget(spec); var that = IPA.checkboxes_widget(spec);
that.id = spec.id;
that.rights = ['write', 'add', 'delete'];
that.create = function(container){ that.create = function(container){
for (var i = 0; i < rights.length; i++){ for (var i = 0; i<that.rights.length; i++) {
$('<dd/>'). $('<dd/>').
append($('<input/>', { append($('<input/>', {
type: 'checkbox', type: 'checkbox',
id: rights[i],
name: that.name, name: that.name,
value: rights[i], value: that.rights[i],
'class': that.entity_name +'_'+ that.name 'class': that.entity_name +'_'+ that.name
})). })).
append($('<label/>', { append($('<label/>', {
text: rights[i] text: that.rights[i]
})). })).
appendTo(container); appendTo(container);
} }
@ -220,7 +201,7 @@ IPA.rights_widget = function(spec){
}; };
IPA.hidden_widget = function(spec){ IPA.hidden_widget = function(spec) {
spec.label = ''; spec.label = '';
var that = IPA.widget(spec); var that = IPA.widget(spec);
that.id = spec.id; that.id = spec.id;
@ -244,7 +225,7 @@ IPA.hidden_widget = function(spec){
}; };
IPA.rights_section = function () { IPA.rights_section = function() {
var spec = { var spec = {
'name':'rights', 'name':'rights',
'label': 'Rights' 'label': 'Rights'
@ -256,20 +237,19 @@ IPA.rights_section = function () {
}; };
IPA.target_section = function () { IPA.target_section = function(spec) {
var spec = { spec = spec || {};
'name':'target',
'label': 'Target'
};
var that = IPA.details_section(spec); var that = IPA.details_section(spec);
that.undo = typeof spec.undo == 'undefined' ? true : spec.undo;
var groupings = ['aci_by_type', 'aci_by_query', 'aci_by_group', var groupings = ['aci_by_type', 'aci_by_query', 'aci_by_group',
'aci_by_filter' ]; 'aci_by_filter' ];
var inputs = ['input', 'select', 'textarea']; var inputs = ['input', 'select', 'textarea'];
function disable_inputs(){ function disable_inputs() {
for (var g = 0; g < groupings.length; g += 1 ){ for (var g = 0; g < groupings.length; g += 1 ){
for (var t = 0 ; t < inputs.length; t += 1){ for (var t = 0 ; t < inputs.length; t += 1){
$('.' + groupings[g] + ' '+ inputs[t]). $('.' + groupings[g] + ' '+ inputs[t]).
@ -277,14 +257,14 @@ IPA.target_section = function () {
} }
} }
} }
function enable_by(grouping){ function enable_by(grouping) {
for (var t = 0 ; t < inputs.length; t += 1){ for (var t = 0 ; t < inputs.length; t += 1){
$('.' + grouping + ' '+ inputs[t]). $('.' + grouping + ' '+ inputs[t]).
attr('disabled', ''); attr('disabled', '');
} }
} }
function display_filter_target(dl){ function display_filter_target(dl) {
$('<dt/>'). $('<dt/>').
append($('<input/>', { append($('<input/>', {
type: 'radio', type: 'radio',
@ -297,25 +277,21 @@ IPA.target_section = function () {
})). })).
appendTo(dl); appendTo(dl);
$('<dd/>', { var span = $('<span/>', {
'class': 'aci_by_filter first'
}).
append(
$('<span/>', {
name: 'filter' name: 'filter'
}). }).
append(
$('<input/>', {
name: 'filter',
disabled: 'true',
type: 'text',
id: 'aci_filter'
}))).
appendTo(dl); appendTo(dl);
var dd = $('<dd/>', {
'class': 'aci_by_filter first'
}).
appendTo(span);
that.filter_text.create(dd);
} }
function display_type_target(dl){ function display_type_target(dl) {
$('<dt/>'). $('<dt/>').
append($('<input/>', { append($('<input/>', {
type: 'radio', type: 'radio',
@ -338,31 +314,14 @@ IPA.target_section = function () {
that.type_select.create(span); that.type_select.create(span);
var select = that.type_select.select; span = $('<span/>', {
select.change(function() { name: 'attrs'
that.attribute_table.object_type = this.options[this.selectedIndex].value; }).appendTo(dl);
that.attribute_table.reset();
});
select.append($('<option/>', { that.attribute_table.create(span);
value: '',
text: ''
}));
var type_params = IPA.get_param_info('permission', 'type');
for (var pc =0; pc < type_params.values.length; pc += 1){
select.append($('<option/>', {
value: type_params.values[pc],
text: type_params.values[pc]
}));
} }
that.attribute_table = that.get_field('attrs'); function display_query_target(dl) {
that.attribute_table.create(dl);
}
function display_query_target(dl){
$('<dt/>'). $('<dt/>').
append($('<input/>', { append($('<input/>', {
type: 'radio', type: 'radio',
@ -374,25 +333,19 @@ IPA.target_section = function () {
})). })).
appendTo(dl); appendTo(dl);
$('<dd/>', { var span = $('<span/>', {
'class': 'aci_by_query first'
}).append(
$('<span/>', {
name: 'subtree' name: 'subtree'
}).append( }).appendTo(dl);
$('<textarea/>', {
name: 'subtree', var dd = $('<dd/>', {
id: 'aci_query_text', 'class': 'aci_by_query first'
cols: '30', }).appendTo(span);
rows: '1'
}))). that.subtree_textarea.create(dd);
appendTo(dl);
} }
function display_group_target(dl){ function display_group_target(dl) {
$('<dt/>').
$('<dt/>' ).
append($('<input />', { append($('<input />', {
type: 'radio', type: 'radio',
name: 'aci_type', name: 'aci_type',
@ -403,7 +356,6 @@ IPA.target_section = function () {
})). })).
appendTo(dl); appendTo(dl);
var span = $('<span/>', { var span = $('<span/>', {
name: 'targetgroup' name: 'targetgroup'
}).appendTo(dl); }).appendTo(dl);
@ -413,7 +365,6 @@ IPA.target_section = function () {
}). }).
appendTo(span); appendTo(span);
that.group_select.create(dd); that.group_select.create(dd);
} }
@ -427,22 +378,22 @@ IPA.target_section = function () {
display_group_target(dl); display_group_target(dl);
display_type_target(dl); display_type_target(dl);
$('#aci_by_filter', dl).click(function (){ $('#aci_by_filter', dl).click(function() {
disable_inputs(); disable_inputs();
enable_by(groupings[3]); enable_by(groupings[3]);
}); });
$('#aci_by_type', dl).click(function (){ $('#aci_by_type', dl).click(function() {
disable_inputs(); disable_inputs();
enable_by(groupings[0]); enable_by(groupings[0]);
}); });
$('#aci_by_query', dl).click(function (){ $('#aci_by_query', dl).click(function() {
disable_inputs(); disable_inputs();
enable_by(groupings[1]); enable_by(groupings[1]);
}); });
$('#aci_by_group', dl).click(function (){ $('#aci_by_group', dl).click(function() {
disable_inputs(); disable_inputs();
enable_by(groupings[2]); enable_by(groupings[2]);
}); });
@ -452,6 +403,32 @@ IPA.target_section = function () {
that.setup = function(container) { that.setup = function(container) {
that.section_setup(container); that.section_setup(container);
var select = that.type_select.select;
select.change(function() {
that.attribute_table.object_type = that.type_select.save()[0];
that.attribute_table.reset();
});
select.append($('<option/>', {
value: '',
text: ''
}));
var type_params = IPA.get_param_info('permission', 'type');
for (var i=0; i<type_params.values.length; i++){
select.append($('<option/>', {
value: type_params.values[i],
text: type_params.values[i]
}));
}
that.type_select.update = function() {
that.type_select.select_update();
that.attribute_table.object_type = that.type_select.save()[0];
that.attribute_table.reset();
};
}; };
function set_aci_type(record) { function set_aci_type(record) {
@ -489,34 +466,43 @@ IPA.target_section = function () {
}; };
that.init = function() { that.init = function() {
that.add_field(IPA.text_widget({name: 'filter'})); that.filter_text = IPA.text_widget({name: 'filter', undo: that.undo});
that.add_field(IPA.textarea_widget({name: 'subtree'})); that.add_field(that.filter_text);
that.subtree_textarea = IPA.textarea_widget({
name: 'subtree',
cols: 30, rows: 1,
undo: that.undo
});
that.add_field(that.subtree_textarea);
that.group_select = IPA.entity_select_widget( that.group_select = IPA.entity_select_widget(
{name: 'targetgroup', entity:'group'}); {name: 'targetgroup', entity:'group', undo: that.undo});
that.add_field(that.group_select); that.add_field(that.group_select);
that.type_select = IPA.type_widget({name: 'type'}); that.type_select = IPA.select_widget({name: 'type', undo: that.undo});
that.add_field(that.type_select); that.add_field(that.type_select);
that.attribute_table = IPA.attribute_table_widget({name: 'attrs'}); that.attribute_table = IPA.attributes_widget({name: 'attrs', undo: that.undo});
that.add_field(that.attribute_table); that.add_field(that.attribute_table);
}; };
that.save = function (record){ that.save = function(record) {
var record_type = $("input[name='aci_type']:checked").attr('id'); var record_type = $("input[name='aci_type']:checked").attr('id');
if (record_type === 'aci_by_group'){ if (record_type === 'aci_by_group') {
record.targetgroup = that.group_select.save()[0]; record.targetgroup = that.group_select.save()[0];
}else if (record_type === 'aci_by_type'){
record.type = $('#object_type_select option:selected').val(); } else if (record_type === 'aci_by_type') {
record.type = that.type_select.save()[0];
record.attrs = that.attribute_table.save().join(','); record.attrs = that.attribute_table.save().join(',');
}else if (record_type === 'aci_by_query'){
record.subtree = $('#aci_query_text').val(); } else if (record_type === 'aci_by_query') {
}else if (record_type === 'aci_by_filter'){ record.subtree = that.subtree_textarea.save([0]);
var filter = $('#aci_filter').val();
record.filter = filter; } else if (record_type === 'aci_by_filter') {
record.filter = that.filter_text.save()[0];
} }
}; };
@ -557,7 +543,7 @@ IPA.permission_details_facet = function(spec) {
return that; return that;
}; };
IPA.entity_factories.permission = function () { IPA.entity_factories.permission = function() {
return IPA.entity({ return IPA.entity({
'name': 'permission' 'name': 'permission'
@ -572,7 +558,7 @@ IPA.entity_factories.permission = function () {
undo: false undo: false
})). })).
field(IPA.rights_widget({name: 'permissions', label: 'Permissions', join: true, undo: false})). field(IPA.rights_widget({name: 'permissions', label: 'Permissions', join: true, undo: false})).
section(IPA.target_section())). section(IPA.target_section({name: 'target', label: 'Target', undo: false}))).
facet(IPA.search_facet(). facet(IPA.search_facet().
column({name:'cn'})). column({name:'cn'})).
facet(IPA.permission_details_facet({ name: 'details' }). facet(IPA.permission_details_facet({ name: 'details' }).
@ -580,7 +566,7 @@ IPA.entity_factories.permission = function () {
IPA.stanza({name:'identity', label:'Identity'}). IPA.stanza({name:'identity', label:'Identity'}).
input({name: 'cn', 'read_only': true})). input({name: 'cn', 'read_only': true})).
section(IPA.rights_section()). section(IPA.rights_section()).
section(IPA.target_section())); section(IPA.target_section({name: 'target', label: 'Target'})));
}; };
@ -659,7 +645,7 @@ IPA.entity_factories.selfservice = function() {
section( section(
IPA.stanza({name:'general', label:'General'}). IPA.stanza({name:'general', label:'General'}).
input({name:'aciname'}). input({name:'aciname'}).
custom_input(IPA.attribute_table_widget({ custom_input(IPA.attributes_widget({
object_type:'user', object_type:'user',
name:'attrs' name:'attrs'
})))). })))).
@ -669,7 +655,7 @@ IPA.entity_factories.selfservice = function() {
title: 'Add Self Service Definition' title: 'Add Self Service Definition'
}). }).
field(IPA.text_widget({ name: 'aciname', undo: false})). field(IPA.text_widget({ name: 'aciname', undo: false})).
field(IPA.attribute_table_widget({ field(IPA.attributes_widget({
object_type:'user', object_type:'user',
name:'attrs' name:'attrs'
}))); })));
@ -694,20 +680,22 @@ IPA.entity_factories.delegation = function() {
entity:'group', join: true})). entity:'group', join: true})).
custom_input( custom_input(
IPA.rights_widget({name: 'permissions', label: 'Permissions', IPA.rights_widget({name: 'permissions', label: 'Permissions',
id:'delegation_rights', join: true})). join: true})).
custom_input( custom_input(
IPA.attribute_table_widget({ IPA.attributes_widget({
name:'attrs', object_type:'user', join: true})))). name:'attrs', object_type:'user', join: true})))).
add_dialog(IPA.add_dialog({ add_dialog(IPA.add_dialog({
name: 'add', name: 'add',
title: 'Add Delegation' title: 'Add Delegation',
width: '700px'
}). }).
field(IPA.text_widget({ name: 'aciname', undo: false})). field(IPA.text_widget({ name: 'aciname', undo: false})).
field(IPA.entity_select_widget({name:'group', field(IPA.entity_select_widget({name:'group',
entity:'group'})). entity:'group', undo: false})).
field(IPA.entity_select_widget({name:'memberof', field(IPA.entity_select_widget({name:'memberof', entity:'group',
entity:'group', join: true})). join: true, undo: false})).
field(IPA.attribute_table_widget({ name: 'attrs', object_type:'user', join: true}))). field(IPA.attributes_widget({ name: 'attrs', object_type:'user',
join: true, undo: false}))).
standard_associations(); standard_associations();
return that; return that;

View File

@ -157,7 +157,7 @@ IPA.dialog = function(spec) {
field.setup(span); field.setup(span);
} }
for (var j = 0; i<that.sections.length; j++) { for (var j=0; j<that.sections.length; j++) {
var section = that.sections[j]; var section = that.sections[j];
var div = $('#'+that.entity_name+'-'+that.name+'-'+section.name, var div = $('#'+that.entity_name+'-'+that.name+'-'+section.name,

View File

@ -308,12 +308,6 @@ dl.aci-target input {
} }
#aci_target_group_select {
display: block;
margin-left: 32em !important;
margin-top: -4em;
}
#group_filter { #group_filter {
margin-right: 2em; margin-right: 2em;
} }

View File

@ -19,8 +19,8 @@
*/ */
var target_container;
var target_section; var target_section;
var aci_container;
module('aci',{ module('aci',{
setup: function() { setup: function() {
@ -29,23 +29,104 @@ module('aci',{
"data", "data",
true, true,
function(data, text_status, xhr) { function(data, text_status, xhr) {
ok(true, "ipa_init() succeeded.");
}, },
function(xhr, text_status, error_thrown) { function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown); ok(false, "ipa_init() failed: "+error_thrown);
} }
); );
aci_container = $('<div id="aci"/>').appendTo(document.body);
target_section = IPA.target_section(); target_container = $('<div id="target"/>').appendTo(document.body);
target_section = IPA.target_section({name: 'target', label: 'Target'});
target_section.init(); target_section.init();
target_section.create(aci_container); target_section.create(target_container);
}, },
teardown: function() { teardown: function() {
aci_container.remove(); target_container.remove();
}} }}
); );
test("IPA.attributes_widget.", function() {
var aciattrs = IPA.metadata['user'].aciattrs;
var container = $('<span/>', {
name: 'attrs'
});
var widget = IPA.attributes_widget({
name: 'attrs',
object_type: 'user'
});
widget.init();
widget.create(container);
widget.setup(container);
var table = $('table', container);
ok(
table,
'Widget contains table'
);
var tr = $('tbody tr', table);
same(
tr.length, aciattrs.length,
'Widget contains all user ACI attributes'
);
var record = {
'attrs': [
"unmatched",
"cn",
"description"
]
};
same(
widget.save(), [],
'Widget has no initial values'
);
widget.load(record);
tr = $('tbody tr', table);
same(
tr.length, aciattrs.length+1,
'Widget contains all user ACI attributes plus 1 unmatched attribute'
);
same(
widget.save(), record.attrs.sort(),
'All loaded values are saved and sorted'
);
});
test("IPA.rights_widget.", function() {
var container = $('<span/>', {
name: 'permissions'
});
var widget = IPA.rights_widget({
name: 'permissions'
});
widget.init();
widget.create(container);
widget.setup(container);
var inputs = $('input', container);
same(
inputs.length, widget.rights.length,
'Widget displays all permissions'
);
});
test("Testing aci grouptarget.", function() { test("Testing aci grouptarget.", function() {
var sample_data_filter_only = {"targetgroup":"ipausers"}; var sample_data_filter_only = {"targetgroup":"ipausers"};
target_section.load(sample_data_filter_only); target_section.load(sample_data_filter_only);
@ -59,7 +140,7 @@ test("Testing aci grouptarget.", function() {
test("Testing aci object type.", function() { test("Testing aci object type.", function() {
var sample_data_filter_only = {"type":"hostgroup"}; var sample_data_filter_only = {"type":"hostgroup"};
target_section.load(sample_data_filter_only); target_section.load(sample_data_filter_only);
ok($('.aci-attribute', aci_container).length > 4); ok($('.aci-attribute', target_container).length > 4);
ok($('#aci_by_type')[0].checked, 'aci_by_type control selected'); ok($('#aci_by_type')[0].checked, 'aci_by_type control selected');
}); });

View File

@ -32,7 +32,10 @@ IPA.widget = function(spec) {
that.name = spec.name; that.name = spec.name;
that.label = spec.label; that.label = spec.label;
that.tooltip = spec.tooltip; that.tooltip = spec.tooltip;
that.disabled = spec.disabled;
that.read_only = spec.read_only; that.read_only = spec.read_only;
that._entity_name = spec.entity_name; that._entity_name = spec.entity_name;
that.width = spec.width; that.width = spec.width;
@ -257,14 +260,18 @@ IPA.text_widget = function(spec) {
$('<input/>', { $('<input/>', {
type: 'text', type: 'text',
name: that.name, name: that.name,
disabled: that.disabled,
size: that.size, size: that.size,
title: that.tooltip title: that.tooltip
}).appendTo(container); }).appendTo(container);
if (that.undo) { if (that.undo) {
container.append(' ');
that.create_undo(container); that.create_undo(container);
} }
container.append(' ');
$("<span/>",{ $("<span/>",{
name:'error_link', name:'error_link',
html:"Text does not match field pattern", html:"Text does not match field pattern",
@ -452,11 +459,11 @@ IPA.checkboxes_widget = function (spec) {
inputs.get(i).checked = false; inputs.get(i).checked = false;
} }
for (var j=0; j<that.values.length; j++) { for (var j=0; that.values && j<that.values.length; j++) {
var value = that.values[j]; var value = that.values[j];
var input = $('input[name="'+that.name+'"][value="'+value+'"]', that.container); var input = $('input[name="'+that.name+'"][value="'+value+'"]', that.container);
if (!input.length) continue; if (!input.length) continue;
input.get(0).checked = true; input.attr('checked', true);
} }
}; };
@ -521,13 +528,11 @@ IPA.radio_widget = function(spec) {
that.update = function() { that.update = function() {
if (that.values) { if (that.values) {
var value; var value;
if ((that.values instanceof Array ) && that.values.length){ if ((that.values instanceof Array) && that.values.length) {
value = that.values[0] value = that.values[0];
}else{ } else {
value = that.values; value = that.values;
} }
@ -575,6 +580,7 @@ IPA.select_widget = function(spec) {
} }
if (that.undo) { if (that.undo) {
container.append(' ');
that.create_undo(container); that.create_undo(container);
} }
}; };
@ -623,6 +629,7 @@ IPA.select_widget = function(spec) {
// methods that should be invoked by subclasses // methods that should be invoked by subclasses
that.select_load = that.load; that.select_load = that.load;
that.select_save = that.save; that.select_save = that.save;
that.select_update = that.update;
return that; return that;
}; };
@ -639,13 +646,15 @@ IPA.textarea_widget = function (spec) {
that.create = function(container) { that.create = function(container) {
$('<textarea/>', { $('<textarea/>', {
name: that.name,
rows: that.rows, rows: that.rows,
cols: that.cols, cols: that.cols,
name: that.name, disabled: that.disabled,
title: that.tooltip title: that.tooltip
}).appendTo(container); }).appendTo(container);
if (that.undo) { if (that.undo) {
container.append(' ');
that.create_undo(container); that.create_undo(container);
} }
@ -663,7 +672,7 @@ IPA.textarea_widget = function (spec) {
var input = $('textarea[name="'+that.name+'"]', that.container); var input = $('textarea[name="'+that.name+'"]', that.container);
input.keyup(function() { input.keyup(function() {
undo.css('display', 'inline'); that.show_undo();
var value = $(this).val(); var value = $(this).val();
that.validate_input(value); that.validate_input(value);
@ -1055,6 +1064,7 @@ IPA.table_widget = function (spec) {
return that; return that;
}; };
IPA.entity_select_widget = function(spec){ IPA.entity_select_widget = function(spec){
var that = IPA.widget(spec); var that = IPA.widget(spec);
@ -1064,6 +1074,14 @@ IPA.entity_select_widget = function(spec){
function populate_select(value){ function populate_select(value){
function find_success(result){ function find_success(result){
$('option', that.entity_select).remove(); $('option', that.entity_select).remove();
// add default empty value
$('<option/>', {
text: '',
value: ''
}).
appendTo(that.entity_select);
var entities = result.result.result; var entities = result.result.result;
for (var i =0; i < result.result.count; i +=1){ for (var i =0; i < result.result.count; i +=1){
var entity = entities[i]; var entity = entities[i];
@ -1155,7 +1173,8 @@ IPA.entity_select_widget = function(spec){
}; };
that.save = function(){ that.save = function(){
return [$('option:selected', that.entity_select).val()]; var value = $('option:selected', that.entity_select).val();
return [value];
}; };
return that; return that;