mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Fixed problem deleting value in text field.
Previously deleting a value in a text field did not work because the field is not included in the modify operation when the value is empty. The details facet's update() method has been modified to update only dirty fields. The section lists in details facet and dialog have been converted into ordered maps. Ticket #1256
This commit is contained in:
committed by
Adam Young
parent
e91aa64d4a
commit
6304d9173c
@@ -128,8 +128,9 @@ IPA.add_dialog = function (spec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j=0; j<that.sections.length; j++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[j];
|
for (var j=0; j<sections.length; j++) {
|
||||||
|
var section = sections[j];
|
||||||
|
|
||||||
var section_fields = section.fields.values;
|
var section_fields = section.fields.values;
|
||||||
for (var k=0; k<section_fields.length; k++) {
|
for (var k=0; k<section_fields.length; k++) {
|
||||||
|
@@ -269,7 +269,7 @@ IPA.details_facet = function(spec) {
|
|||||||
that.label = (IPA.messages && IPA.messages.facets && IPA.messages.facets.details) || spec.label;
|
that.label = (IPA.messages && IPA.messages.facets && IPA.messages.facets.details) || spec.label;
|
||||||
that.facet_group = spec.facet_group || 'settings';
|
that.facet_group = spec.facet_group || 'settings';
|
||||||
|
|
||||||
that.sections = [];
|
that.sections = $.ordered_map();
|
||||||
|
|
||||||
that.__defineGetter__("entity_name", function(){
|
that.__defineGetter__("entity_name", function(){
|
||||||
return that._entity_name;
|
return that._entity_name;
|
||||||
@@ -278,14 +278,15 @@ IPA.details_facet = function(spec) {
|
|||||||
that.__defineSetter__("entity_name", function(entity_name){
|
that.__defineSetter__("entity_name", function(entity_name){
|
||||||
that._entity_name = entity_name;
|
that._entity_name = entity_name;
|
||||||
|
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
var sections = that.sections.values;
|
||||||
that.sections[i].entity_name = entity_name;
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
sections[i].entity_name = entity_name;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
that.add_section = function(section) {
|
that.add_section = function(section) {
|
||||||
section.entity_name = that.entity_name;
|
section.entity_name = that.entity_name;
|
||||||
that.sections.push(section);
|
that.sections.put(section.name, section);
|
||||||
return section;
|
return section;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -304,8 +305,9 @@ IPA.details_facet = function(spec) {
|
|||||||
|
|
||||||
that.facet_init();
|
that.facet_init();
|
||||||
|
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[i];
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
var section = sections[i];
|
||||||
section.init();
|
section.init();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -375,8 +377,9 @@ IPA.details_facet = function(spec) {
|
|||||||
that.expand_button.css('display', 'none');
|
that.expand_button.css('display', 'none');
|
||||||
that.collapse_button.css('display', 'inline');
|
that.collapse_button.css('display', 'inline');
|
||||||
|
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[i];
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
var section = sections[i];
|
||||||
that.toggle(section, true);
|
that.toggle(section, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,8 +396,9 @@ IPA.details_facet = function(spec) {
|
|||||||
that.expand_button.css('display', 'inline');
|
that.expand_button.css('display', 'inline');
|
||||||
that.collapse_button.css('display', 'none');
|
that.collapse_button.css('display', 'none');
|
||||||
|
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[i];
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
var section = sections[i];
|
||||||
that.toggle(section, false);
|
that.toggle(section, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,8 +413,9 @@ IPA.details_facet = function(spec) {
|
|||||||
'name': 'details'
|
'name': 'details'
|
||||||
}).appendTo(container);
|
}).appendTo(container);
|
||||||
|
|
||||||
for (var i = 0; i < that.sections.length; ++i) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[i];
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
var section = sections[i];
|
||||||
|
|
||||||
var header = $('<h2/>', {
|
var header = $('<h2/>', {
|
||||||
name: section.name,
|
name: section.name,
|
||||||
@@ -450,8 +455,9 @@ IPA.details_facet = function(spec) {
|
|||||||
|
|
||||||
var details = $('div[name=details]', that.container);
|
var details = $('div[name=details]', that.container);
|
||||||
|
|
||||||
for (var i = 0; i < that.sections.length; ++i) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[i];
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
var section = sections[i];
|
||||||
|
|
||||||
var div = $('div.details-section[name='+section.name+']', that.container);
|
var div = $('div.details-section[name='+section.name+']', that.container);
|
||||||
|
|
||||||
@@ -496,8 +502,9 @@ IPA.details_facet = function(spec) {
|
|||||||
|
|
||||||
|
|
||||||
that.is_dirty = function() {
|
that.is_dirty = function() {
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
var sections = that.sections.values;
|
||||||
if (that.sections[i].is_dirty()) {
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
if (sections[i].is_dirty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -506,16 +513,17 @@ IPA.details_facet = function(spec) {
|
|||||||
|
|
||||||
that.load = function (record) {
|
that.load = function (record) {
|
||||||
that.record = record;
|
that.record = record;
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[i];
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
var section = sections[i];
|
||||||
section.load(record);
|
section.load(record);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
that.reset = function() {
|
that.reset = function() {
|
||||||
|
var sections = that.sections.values;
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
for (var i=0; i<sections.length; i++) {
|
||||||
var section = that.sections[i];
|
var section = sections[i];
|
||||||
section.reset();
|
section.reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -539,21 +547,35 @@ IPA.details_facet = function(spec) {
|
|||||||
on_fail(xhr, text_status, error_thrown);
|
on_fail(xhr, text_status, error_thrown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var args = that.get_primary_key();
|
||||||
|
|
||||||
|
var command = IPA.command({
|
||||||
|
entity: entity_name,
|
||||||
|
method: 'mod',
|
||||||
|
args: args,
|
||||||
|
options: {
|
||||||
|
all: true,
|
||||||
|
rights: true
|
||||||
|
},
|
||||||
|
on_success: on_success,
|
||||||
|
on_error: on_error
|
||||||
|
});
|
||||||
|
|
||||||
var values;
|
var values;
|
||||||
var modlist = {'all': true, 'setattr': [], 'addattr': [], 'rights': true};
|
|
||||||
var attrs_wo_option = {};
|
|
||||||
|
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[i];
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
var section = sections[i];
|
||||||
|
|
||||||
if (section.save){
|
if (section.save) {
|
||||||
section.save(modlist);
|
section.save(command.options);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var section_fields = section.fields.values;
|
var section_fields = section.fields.values;
|
||||||
for (var j=0; j<section_fields.length; j++) {
|
for (var j=0; j<section_fields.length; j++) {
|
||||||
var field = section_fields[j];
|
var field = section_fields[j];
|
||||||
|
if (!field.is_dirty()) continue;
|
||||||
|
|
||||||
values = field.save();
|
values = field.save();
|
||||||
if (!values) continue;
|
if (!values) continue;
|
||||||
@@ -562,41 +584,26 @@ IPA.details_facet = function(spec) {
|
|||||||
if (param_info) {
|
if (param_info) {
|
||||||
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];
|
command.set_option(field.name, values[0]);
|
||||||
} else if (values.length > 1){
|
} else if (field.join) {
|
||||||
if (field.join) {
|
command.set_option(field.name, values.join(','));
|
||||||
modlist[field.name] = values.join(',');
|
} else {
|
||||||
} else {
|
command.set_option(field.name, values);
|
||||||
modlist[field.name] = values;
|
|
||||||
}
|
|
||||||
} else if (param_info['multivalue']){
|
|
||||||
modlist[field.name] = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (values.length) attrs_wo_option[field.name] = values;
|
if (values.length) {
|
||||||
|
command.add_option('setattr', field.name+'='+values[0]);
|
||||||
|
} else {
|
||||||
|
command.add_option('setattr', field.name+'=');
|
||||||
|
}
|
||||||
|
for (var k=1; k<values.length; k++) {
|
||||||
|
command.add_option('addattr', field.name+'='+values[k]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var attr in attrs_wo_option) {
|
|
||||||
values = attrs_wo_option[attr];
|
|
||||||
modlist['setattr'].push(attr + '=' + values[0]);
|
|
||||||
for (var k = 1; k < values.length; ++k){
|
|
||||||
modlist['addattr'].push(attr + '=' + values[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var args = that.get_primary_key();
|
|
||||||
|
|
||||||
var command = IPA.command({
|
|
||||||
entity: entity_name,
|
|
||||||
method: 'mod',
|
|
||||||
args: args,
|
|
||||||
options: modlist,
|
|
||||||
on_success: on_success,
|
|
||||||
on_error: on_error
|
|
||||||
});
|
|
||||||
|
|
||||||
//alert(JSON.stringify(command.to_json()));
|
//alert(JSON.stringify(command.to_json()));
|
||||||
|
|
||||||
command.execute();
|
command.execute();
|
||||||
|
@@ -41,8 +41,7 @@ IPA.dialog = function(spec) {
|
|||||||
that.buttons = {};
|
that.buttons = {};
|
||||||
|
|
||||||
that.fields = $.ordered_map();
|
that.fields = $.ordered_map();
|
||||||
|
that.sections = $.ordered_map();
|
||||||
that.sections = [];
|
|
||||||
|
|
||||||
that.__defineGetter__("entity_name", function(){
|
that.__defineGetter__("entity_name", function(){
|
||||||
return that._entity_name;
|
return that._entity_name;
|
||||||
@@ -56,8 +55,9 @@ IPA.dialog = function(spec) {
|
|||||||
fields[i].entity_name = entity_name;
|
fields[i].entity_name = entity_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j=0; j<that.sections.length; j++) {
|
var sections = that.sections.values;
|
||||||
that.sections[j].entity_name = entity_name;
|
for (var j=0; j<sections.length; j++) {
|
||||||
|
sections[j].entity_name = entity_name;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ IPA.dialog = function(spec) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
that.add_section = function(section) {
|
that.add_section = function(section) {
|
||||||
that.sections.push(section);
|
that.sections.put(section.name, section);
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -123,8 +123,9 @@ IPA.dialog = function(spec) {
|
|||||||
field.init();
|
field.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j=0; j<that.sections.length; j++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[j];
|
for (var j=0; j<sections.length; j++) {
|
||||||
|
var section = sections[j];
|
||||||
section.entity_name = that.entity_name;
|
section.entity_name = that.entity_name;
|
||||||
section.init();
|
section.init();
|
||||||
}
|
}
|
||||||
@@ -158,8 +159,9 @@ IPA.dialog = function(spec) {
|
|||||||
field.create(span);
|
field.create(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j=0; j<that.sections.length; j++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[j];
|
for (var j=0; j<sections.length; j++) {
|
||||||
|
var section = sections[j];
|
||||||
|
|
||||||
var div = $('<div/>', {
|
var div = $('<div/>', {
|
||||||
name: section.name,
|
name: section.name,
|
||||||
@@ -182,8 +184,9 @@ IPA.dialog = function(spec) {
|
|||||||
field.setup(span);
|
field.setup(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j=0; j<that.sections.length; j++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[j];
|
for (var j=0; j<sections.length; j++) {
|
||||||
|
var section = sections[j];
|
||||||
|
|
||||||
var div = $('div.details-section[name='+section.name+']',
|
var div = $('div.details-section[name='+section.name+']',
|
||||||
that.container);
|
that.container);
|
||||||
@@ -251,8 +254,9 @@ IPA.dialog = function(spec) {
|
|||||||
record[field.name] = values.join(',');
|
record[field.name] = values.join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j=0; j<that.sections.length; j++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[j];
|
for (var j=0; j<sections.length; j++) {
|
||||||
|
var section = sections[j];
|
||||||
|
|
||||||
if (section.save) {
|
if (section.save) {
|
||||||
section.save(record);
|
section.save(record);
|
||||||
@@ -271,8 +275,10 @@ IPA.dialog = function(spec) {
|
|||||||
var field = fields[i];
|
var field = fields[i];
|
||||||
field.reset();
|
field.reset();
|
||||||
}
|
}
|
||||||
for (var j=0; j<that.sections.length; j++) {
|
|
||||||
that.sections[j].reset();
|
var sections = that.sections.values;
|
||||||
|
for (var j=0; j<sections.length; j++) {
|
||||||
|
sections[j].reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -431,12 +431,14 @@ IPA.hbacrule_details_facet = function (spec) {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[i];
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
var section = sections[i];
|
||||||
|
|
||||||
var section_fields = section.fields.values;
|
var section_fields = section.fields.values;
|
||||||
for (var j=0; j<section_fields.length; j++) {
|
for (var j=0; j<section_fields.length; j++) {
|
||||||
var field = section_fields[j];
|
var field = section_fields[j];
|
||||||
|
if (!field.is_dirty()) continue;
|
||||||
|
|
||||||
var values = field.save();
|
var values = field.save();
|
||||||
if (!values) continue;
|
if (!values) continue;
|
||||||
@@ -486,23 +488,26 @@ IPA.hbacrule_details_facet = function (spec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use setattr/addattr if param_info not available
|
if (param_info) {
|
||||||
if (!param_info) {
|
if (values.length == 1) {
|
||||||
for (var l=0; l<values.length; l++) {
|
modify_operation.command.set_option(field.name, values[0]);
|
||||||
modify_operation.command.set_option(
|
} else if (field.join) {
|
||||||
l === 0 ? 'setattr' : 'addattr',
|
modify_operation.command.set_option(field.name, values.join(','));
|
||||||
field.name+'='+values[l]);
|
} else {
|
||||||
modify_operation.execute = true;
|
modify_operation.command.set_option(field.name, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (values.length) {
|
||||||
|
modify_operation.command.set_option('setattr', field.name+'='+values[0]);
|
||||||
|
} else {
|
||||||
|
modify_operation.command.set_option('setattr', field.name+'=');
|
||||||
|
}
|
||||||
|
for (var l=1; l<values.length; l++) {
|
||||||
|
modify_operation.command.set_option('addattr', field.name+'='+values[l]);
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set modify options
|
|
||||||
if (values.length == 1) {
|
|
||||||
modify_operation.command.set_option(field.name, values[0]);
|
|
||||||
} else {
|
|
||||||
modify_operation.command.set_option(field.name, values);
|
|
||||||
}
|
|
||||||
modify_operation.execute = true;
|
modify_operation.execute = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -538,13 +543,6 @@ IPA.hbacrule_details_facet = function (spec) {
|
|||||||
batch.execute();
|
batch.execute();
|
||||||
};
|
};
|
||||||
|
|
||||||
that.reset = function() {
|
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
|
||||||
var section = that.sections[i];
|
|
||||||
section.reset();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -214,6 +214,15 @@ IPA.command = function(spec) {
|
|||||||
that.options[name] = value;
|
that.options[name] = value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.add_option = function(name, value) {
|
||||||
|
var values = that.options[name];
|
||||||
|
if (!values) {
|
||||||
|
values = [];
|
||||||
|
that.options[name] = values;
|
||||||
|
}
|
||||||
|
values.push(value);
|
||||||
|
};
|
||||||
|
|
||||||
that.get_option = function(name) {
|
that.get_option = function(name) {
|
||||||
return that.options[name];
|
return that.options[name];
|
||||||
};
|
};
|
||||||
|
@@ -447,12 +447,14 @@ IPA.sudorule_details_facet = function (spec) {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var i=0; i<that.sections.length; i++) {
|
var sections = that.sections.values;
|
||||||
var section = that.sections[i];
|
for (var i=0; i<sections.length; i++) {
|
||||||
|
var section = sections[i];
|
||||||
|
|
||||||
var section_fields = section.fields.values;
|
var section_fields = section.fields.values;
|
||||||
for (var j=0; j<section_fields.length; j++) {
|
for (var j=0; j<section_fields.length; j++) {
|
||||||
var field = section_fields[j];
|
var field = section_fields[j];
|
||||||
|
if (!field.is_dirty()) continue;
|
||||||
|
|
||||||
var values = field.save();
|
var values = field.save();
|
||||||
if (!values) continue;
|
if (!values) continue;
|
||||||
@@ -490,23 +492,26 @@ IPA.sudorule_details_facet = function (spec) {
|
|||||||
categories[field.name].remove_values = true;
|
categories[field.name].remove_values = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// use setattr/addattr if param_info not available
|
if (param_info) {
|
||||||
if (!param_info) {
|
if (values.length == 1) {
|
||||||
for (var k=0; k<values.length; k++) {
|
modify_operation.command.set_option(field.name, values[0]);
|
||||||
modify_operation.command.set_option(
|
} else if (field.join) {
|
||||||
k === 0 ? 'setattr' : 'addattr',
|
modify_operation.command.set_option(field.name, values.join(','));
|
||||||
field.name+'='+values[k]);
|
} else {
|
||||||
modify_operation.execute = true;
|
modify_operation.command.set_option(field.name, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (values.length) {
|
||||||
|
modify_operation.command.set_option('setattr', field.name+'='+values[0]);
|
||||||
|
} else {
|
||||||
|
modify_operation.command.set_option('setattr', field.name+'=');
|
||||||
|
}
|
||||||
|
for (var k=1; k<values.length; k++) {
|
||||||
|
modify_operation.command.set_option('addattr', field.name+'='+values[k]);
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set modify options
|
|
||||||
if (values.length == 1) {
|
|
||||||
modify_operation.command.set_option(field.name, values[0]);
|
|
||||||
} else {
|
|
||||||
modify_operation.command.set_option(field.name, values);
|
|
||||||
}
|
|
||||||
modify_operation.execute = true;
|
modify_operation.execute = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -128,7 +128,7 @@ test("Testing details lifecycle: create, setup, load.", function(){
|
|||||||
}).execute();
|
}).execute();
|
||||||
|
|
||||||
var setup_called = false;
|
var setup_called = false;
|
||||||
var save_called= false;
|
var save_called = false;
|
||||||
var load_called = false;
|
var load_called = false;
|
||||||
|
|
||||||
var load_success_called = false;
|
var load_success_called = false;
|
||||||
@@ -149,8 +149,8 @@ test("Testing details lifecycle: create, setup, load.", function(){
|
|||||||
load_called = true;
|
load_called = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_widget(){
|
function test_widget(spec){
|
||||||
var widget = IPA.widget({name: 'cn'});
|
var widget = IPA.widget(spec);
|
||||||
|
|
||||||
widget.setup = function(container) {
|
widget.setup = function(container) {
|
||||||
setup_called = true;
|
setup_called = true;
|
||||||
@@ -244,6 +244,10 @@ test("Testing details lifecycle: create, setup, load.", function(){
|
|||||||
|
|
||||||
ok (load_called, 'load manager called');
|
ok (load_called, 'load manager called');
|
||||||
|
|
||||||
|
var section = facet.sections.get('contact');
|
||||||
|
var field = section.fields.get('test');
|
||||||
|
field.set_dirty(true);
|
||||||
|
|
||||||
facet.update(
|
facet.update(
|
||||||
function(){update_success_called = true},
|
function(){update_success_called = true},
|
||||||
function(){update_failure_called = true}
|
function(){update_failure_called = true}
|
||||||
|
Reference in New Issue
Block a user