CC-4188: Playlist Builder -> Smart Playlist : sometimes elements do not index properly when add a new criteria row

-fixed
This commit is contained in:
denise 2012-08-08 16:27:03 -04:00
parent b2d3ee0aa4
commit 90ec046854
1 changed files with 4 additions and 20 deletions

View File

@ -25,18 +25,8 @@ function setSmartPlaylistEvents() {
form.find('a[id^="modifier_add"]').live('click', function(){ form.find('a[id^="modifier_add"]').live('click', function(){
var id = $(this).attr('id'), var id = $(this).attr('id'),
row_index = id.charAt(id.length-1), row_index = id.charAt(id.length-1),
mod_index,
criteria_value = $(this).siblings('select[name^="sp_criteria_field"]').val(); criteria_value = $(this).siblings('select[name^="sp_criteria_field"]').val();
//get index for the new modifier row
if ($(this).parent().find('select[name^="sp_criteria_modifier_'+row_index+'_"]').length == 0) {
mod_index = 0;
} else {
var last_mod = $(this).parent().find('select[name^="sp_criteria_modifier_'+row_index+'_"]:last');
var last_mod_id = last_mod.attr('id');
mod_index = parseInt(last_mod_id.substr(last_mod_id.length-1))+1;
}
//make new modifier row //make new modifier row
var newRow = $(this).parent().clone(), var newRow = $(this).parent().clone(),
newRowCrit = newRow.find('select[name^="sp_criteria_field"]'), newRowCrit = newRow.find('select[name^="sp_criteria_field"]'),
@ -53,27 +43,21 @@ function setSmartPlaylistEvents() {
//hide the critieria field select box //hide the critieria field select box
newRowCrit.addClass('sp-invisible'); newRowCrit.addClass('sp-invisible');
//append modifier index to the new modifier row //keep criteria value the same
newRowCrit.attr('name', 'sp_criteria_field_'+row_index+'_'+mod_index);
newRowCrit.attr('id', 'sp_criteria_field_'+row_index+'_'+mod_index);
newRowCrit.val(criteria_value); newRowCrit.val(criteria_value);
newRowMod.attr('name', 'sp_criteria_modifier_'+row_index+'_'+mod_index);
newRowMod.attr('id', 'sp_criteria_modifier_'+row_index+'_'+mod_index); //reset all other values
newRowMod.val('0'); newRowMod.val('0');
newRowVal.attr('name', 'sp_criteria_value_'+row_index+'_'+mod_index);
newRowVal.attr('id', 'sp_criteria_value_'+row_index+'_'+mod_index);
newRowVal.val(''); newRowVal.val('');
newRowExtra.attr('name', 'sp_criteria_extra_'+row_index+'_'+mod_index);
newRowExtra.attr('id', 'sp_criteria_extra_'+row_index+'_'+mod_index);
newRowExtra.val(''); newRowExtra.val('');
disableAndHideExtraField(newRowVal); disableAndHideExtraField(newRowVal);
sizeTextBoxes(newRowVal, 'sp_extra_input_text', 'sp_input_text'); sizeTextBoxes(newRowVal, 'sp_extra_input_text', 'sp_input_text');
newRowRemove.attr('id', 'criteria_remove_'+row_index+'_'+mod_index);
//remove the 'criteria add' button from new modifier row //remove the 'criteria add' button from new modifier row
newRow.find('.criteria_add').remove(); newRow.find('.criteria_add').remove();
$(this).parent().after(newRow); $(this).parent().after(newRow);
reindexElements();
appendAddButton(); appendAddButton();
appendModAddButton(); appendModAddButton();
removeButtonCheck(); removeButtonCheck();