parent
a74841c18a
commit
f5232a8376
8 changed files with 298 additions and 236 deletions
@ -1,52 +1,56 @@ |
||||
// replace
|
||||
$(document).ready(function(){ |
||||
$('#id_theme').change(function(){ |
||||
$.get( |
||||
"/admin/ajax_tag/", {'id': $(this).serialize()}, function(data){ |
||||
var optionValues = []; |
||||
var getValues = []; |
||||
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); |
||||
$('#id_theme').change(function(){ |
||||
$.get("/admin/ajax_tag/", {'id': $(this).serialize()}, function(data){ |
||||
var optionValues = []; |
||||
var getValues = []; |
||||
var selectedValues = []; |
||||
|
||||
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
|
||||
//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){ |
||||
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