CC-4170: Smart Playlist Builder: elements don't organize properly after deleting a row

-fixed
This commit is contained in:
denise 2012-08-08 13:07:00 -04:00
parent 9510c1a295
commit 85259e5bba
1 changed files with 48 additions and 20 deletions

View File

@ -17,6 +17,7 @@ function setSmartPlaylistEvents() {
$(this).hide(); $(this).hide();
} }
appendAddButton(); appendAddButton();
appendModAddButton();
removeButtonCheck(); removeButtonCheck();
}); });
@ -87,6 +88,8 @@ function setSmartPlaylistEvents() {
var count = list_length - curr_pos; var count = list_length - curr_pos;
var next = curr.next(); var next = curr.next();
var item_to_hide; var item_to_hide;
var prev;
var index;
//remove error message from current row, if any //remove error message from current row, if any
var error_element = curr.find('span[class="errors sp-errors"]'); var error_element = curr.find('span[class="errors sp-errors"]');
@ -94,10 +97,13 @@ function setSmartPlaylistEvents() {
error_element.remove(); error_element.remove();
} }
/* assign next row to current row for all rows below and including /* assign next row to current row for all rows below and including
* the row getting removed * the row getting removed
*/ */
for (var i=0; i<count; i++) { for (var i=0; i<count; i++) {
index = getRowIndex(curr);
var criteria = next.find('[name^="sp_criteria_field"]').val(); var criteria = next.find('[name^="sp_criteria_field"]').val();
curr.find('[name^="sp_criteria_field"]').val(criteria); curr.find('[name^="sp_criteria_field"]').val(criteria);
@ -107,12 +113,6 @@ function setSmartPlaylistEvents() {
var criteria_value = next.find('[name^="sp_criteria_value"]').val(); var criteria_value = next.find('[name^="sp_criteria_value"]').val();
curr.find('[name^="sp_criteria_value"]').val(criteria_value); curr.find('[name^="sp_criteria_value"]').val(criteria_value);
var id = curr.find('[name^="sp_criteria"]').attr('id'),
delimiter = '_',
start = 3,
tokens = id.split(delimiter).slice(start),
index = tokens.join(delimiter);
/* if current and next row have the extra criteria value /* if current and next row have the extra criteria value
* (for 'is in the range' modifier), then assign the next * (for 'is in the range' modifier), then assign the next
@ -143,16 +143,34 @@ function setSmartPlaylistEvents() {
curr.find('[name^="sp_criteria_extra"]').val(criteria_extra); curr.find('[name^="sp_criteria_extra"]').val(criteria_extra);
} }
/* determine if current row is a modifier row
* if it is, make the criteria select invisible
*/
prev = curr.prev();
if (curr.find('[name^="sp_criteria_field"]').val() == prev.find('[name^="sp_criteria_field"]').val()) {
if (!curr.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
curr.find('select[name^="sp_criteria_field"]').addClass('sp-invisible');
}
} else {
if (curr.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
curr.find('select[name^="sp_criteria_field"]').removeClass('sp-invisible');
}
}
curr = next; curr = next;
next = curr.next(); next = curr.next();
} }
/* Disable the last visible row since it holds the values the user removed /* Disable the last visible row since it holds the values the user removed
* Reset the values to empty and resize the criteria value textbox * Reset the values to empty and resize the criteria value textbox
* in case the row had the extra criteria textbox * in case the row had the extra criteria textbox
*/ */
item_to_hide = list.find('div:visible:last'); item_to_hide = list.find('div:visible:last');
item_to_hide.children().attr('disabled', 'disabled'); item_to_hide.children().attr('disabled', 'disabled');
if (item_to_hide.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
item_to_hide.find('select[name^="sp_criteria_field"]').removeClass('sp-invisible');
}
item_to_hide.find('[name^="sp_criteria_field"]').val(0).end() item_to_hide.find('[name^="sp_criteria_field"]').val(0).end()
.find('[name^="sp_criteria_modifier"]').val(0).end() .find('[name^="sp_criteria_modifier"]').val(0).end()
.find('[name^="sp_criteria_value"]').val('').end() .find('[name^="sp_criteria_value"]').val('').end()
@ -163,12 +181,22 @@ function setSmartPlaylistEvents() {
list.next().show(); list.next().show();
//check if last row is a modifier row
var last_row = list.find('div:visible:last');
if (last_row.find('[name^="sp_criteria_field"]').val() == last_row.prev().find('[name^="sp_criteria_field"]').val()) {
if (!last_row.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
last_row.find('select[name^="sp_criteria_field"]').addClass('sp-invisible');
}
}
// always put '+' button on the last enabled row // always put '+' button on the last enabled row
appendAddButton(); appendAddButton();
reindexElements();
// always put '+' button on the last modifier row // always put '+' button on the last modifier row
appendModAddButton(); appendModAddButton();
reindexElements();
// remove the 'x' button if only one row is enabled // remove the 'x' button if only one row is enabled
removeButtonCheck(); removeButtonCheck();
}); });
@ -246,13 +274,15 @@ function setSmartPlaylistEvents() {
removeButtonCheck(); removeButtonCheck();
} }
var static_length = $('.playlist_title').children('h4[id$="_length"]').text(); function getRowIndex(ele) {
var id = ele.find('[name^="sp_criteria"]').attr('id'),
/* delimiter = '_',
function setStaticLengthHolder(lenVal) { start = 3,
static_length = lenVal; tokens = id.split(delimiter).slice(start),
index = tokens.join(delimiter);
return index;
} }
*/
/* This function appends a '+' button for the last /* This function appends a '+' button for the last
* modifier row of each criteria. * modifier row of each criteria.
@ -339,12 +369,10 @@ function setupUI() {
$('button[id="generate_button"]').show(); $('button[id="generate_button"]').show();
$('button[id="shuffle_button"]').show(); $('button[id="shuffle_button"]').show();
$('#spl_sortable').show(); $('#spl_sortable').show();
//$('.playlist_title').children('h4[id$="_length"]').text(static_length);
} else { } else {
$('button[id="generate_button"]').hide(); $('button[id="generate_button"]').hide();
$('button[id="shuffle_button"]').hide(); $('button[id="shuffle_button"]').hide();
$('#spl_sortable').hide(); $('#spl_sortable').hide();
//$('.playlist_title').children('h4[id$="_length"]').text(dynamic_length);
} }
} }