commit
a1c0ee9ef1
8 changed files with 298 additions and 236 deletions
@ -1,52 +1,56 @@ |
|||||||
// replace
|
// replace
|
||||||
$(document).ready(function(){ |
$(document).ready(function(){ |
||||||
$('#id_theme').change(function(){ |
$('#id_theme').change(function(){ |
||||||
$.get( |
$.get("/admin/ajax_tag/", {'id': $(this).serialize()}, function(data){ |
||||||
"/admin/ajax_tag/", {'id': $(this).serialize()}, function(data){ |
var optionValues = []; |
||||||
var optionValues = []; |
var getValues = []; |
||||||
var getValues = []; |
var selectedValues = []; |
||||||
var selectedValues = [] |
|
||||||
//push values sended from server in array
|
|
||||||
$.each(data, function(i, elem){ |
|
||||||
getValues.push(elem[0].toString()) |
|
||||||
}); |
|
||||||
//delete options if they aren't in getvalues
|
|
||||||
//otherwise push it in array
|
|
||||||
//also push in array already selected values
|
|
||||||
$('#id_tag option').each(function() { |
|
||||||
var check = $.inArray($(this), getValues); |
|
||||||
if ($(this).is(':selected') ){ |
|
||||||
selectedValues.push($(this).val()) |
|
||||||
} |
|
||||||
if (check == -1){ |
|
||||||
$(this).remove() |
|
||||||
} |
|
||||||
else{ |
|
||||||
optionValues.push($(this).val()); |
|
||||||
} |
|
||||||
}); |
|
||||||
//generate new options
|
|
||||||
//old options unchanged
|
|
||||||
var html = '' |
|
||||||
$.each(data, function(i, elem){ |
|
||||||
var check = $.inArray(elem[0].toString(), optionValues); |
|
||||||
|
|
||||||
if (check == -1){ |
//push values sended from server in array
|
||||||
html += '<option value="'; |
$.each(data, function(i, elem){ |
||||||
html += elem[0]; |
getValues.push(elem[0].toString()) |
||||||
html += '">'; |
}); |
||||||
html += elem[1]; |
|
||||||
html += '</option>'; |
//delete options if they aren't in getvalues
|
||||||
} |
//otherwise push it in array
|
||||||
}); |
//also push in array already selected values
|
||||||
$('#id_tag').append(html); |
$('#id_tag option').each(function() { |
||||||
//select previous selected values
|
var check = $.inArray($(this), getValues); |
||||||
$('#id_tag option').each(function() { |
if ($(this).is(':selected') ){ |
||||||
var check = $.inArray($(this).val(), selectedValues) |
selectedValues.push($(this).val()) |
||||||
if (check != -1){ |
} |
||||||
$(this).attr('selected', 'selected'); |
if (check == -1){ |
||||||
} |
$(this).remove() |
||||||
}); |
} |
||||||
});//end get
|
else{ |
||||||
});//end change
|
optionValues.push($(this).val()); |
||||||
});//end ready
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
//generate new options
|
||||||
|
//old options unchanged
|
||||||
|
var html = ''; |
||||||
|
$.each(data, function(i, elem){ |
||||||
|
var check = $.inArray(elem[0].toString(), optionValues); |
||||||
|
|
||||||
|
if (check == -1){ |
||||||
|
html += '<option value="'; |
||||||
|
html += elem[0]; |
||||||
|
html += '">'; |
||||||
|
html += elem[1]; |
||||||
|
html += '</option>'; |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
$('#id_tag').append(html); |
||||||
|
|
||||||
|
//select previous selected values
|
||||||
|
$('#id_tag option').each(function() { |
||||||
|
var check = $.inArray($(this).val(), selectedValues) |
||||||
|
if (check != -1){ |
||||||
|
$(this).attr('selected', 'selected'); |
||||||
|
} |
||||||
|
}); |
||||||
|
});//end get
|
||||||
|
});//end change
|
||||||
|
});//end ready
|
||||||
|
|||||||
Loading…
Reference in new issue