// #PI-116 JS refactoring in BO
This commit is contained in:
-61
@@ -230,67 +230,6 @@ function getE(name)
|
||||
return elem;
|
||||
}
|
||||
|
||||
function addAccessory(event, data, formatted)
|
||||
{
|
||||
if (data == null)
|
||||
return false;
|
||||
var productId = data[1];
|
||||
var productName = data[0];
|
||||
|
||||
var $divAccessories = $('#divAccessories');
|
||||
var $inputAccessories = $('#inputAccessories');
|
||||
var $nameAccessories = $('#nameAccessories');
|
||||
|
||||
/* delete product from select + add product line to the div, input_name, input_ids elements */
|
||||
$divAccessories.html($divAccessories.html() + productName + ' <span onclick="delAccessory(' + productId + ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />');
|
||||
$nameAccessories.val($nameAccessories.val() + productName + '¤');
|
||||
$inputAccessories.val($inputAccessories.val() + productId + '-');
|
||||
$('#product_autocomplete_input').val('');
|
||||
$('#product_autocomplete_input').setOptions({
|
||||
extraParams: {excludeIds : getAccessorieIds()}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function delAccessory(id)
|
||||
{
|
||||
var div = getE('divAccessories');
|
||||
var input = getE('inputAccessories');
|
||||
var name = getE('nameAccessories');
|
||||
|
||||
// Cut hidden fields in array
|
||||
var inputCut = input.value.split('-');
|
||||
var nameCut = name.value.split('¤');
|
||||
|
||||
if (inputCut.length != nameCut.length)
|
||||
return jAlert('Bad size');
|
||||
|
||||
// Reset all hidden fields
|
||||
input.value = '';
|
||||
name.value = '';
|
||||
div.innerHTML = '';
|
||||
for (i in inputCut)
|
||||
{
|
||||
// If empty, error, next
|
||||
if (!inputCut[i] || !nameCut[i])
|
||||
continue ;
|
||||
|
||||
// Add to hidden fields no selected products OR add to select field selected product
|
||||
if (inputCut[i] != id)
|
||||
{
|
||||
input.value += inputCut[i] + '-';
|
||||
name.value += nameCut[i] + '¤';
|
||||
div.innerHTML += nameCut[i] + ' <span onclick="delAccessory(' + inputCut[i] + ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />';
|
||||
}
|
||||
else
|
||||
$('#selectAccessories').append('<option selected="selected" value="' + inputCut[i] + '-' + nameCut[i] + '">' + inputCut[i] + ' - ' + nameCut[i] + '</option>');
|
||||
}
|
||||
|
||||
$('#product_autocomplete_input').setOptions({
|
||||
extraParams: {excludeIds : getAccessorieIds()}
|
||||
});
|
||||
}
|
||||
|
||||
function formSubmit(e, button)
|
||||
{
|
||||
var key;
|
||||
|
||||
Reference in New Issue
Block a user