Update ajax.lib.php
This commit is contained in:
parent
7dab06952c
commit
e6e953b4d8
@ -459,3 +459,95 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0,
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* On/off button for product tosell or tobuy
|
||||
*
|
||||
* @param int $id Id product to set
|
||||
* @param string $code Name of constant : status or status_buy
|
||||
* @param array $input Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid'))
|
||||
* @param int $entity Entity to set
|
||||
* @return void
|
||||
*/
|
||||
function ajax_productonoff($id, $code, $input=array(), $entity=null)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
global $conf, $langs, $db;
|
||||
|
||||
$entity = ((isset($entity) && is_numeric($entity) && $entity >= 0) ? $entity : $conf->entity);
|
||||
$object = new Product($db);
|
||||
$object->fetch($id);
|
||||
|
||||
$out= '<script type="text/javascript">
|
||||
$(function() {
|
||||
var input = '.json_encode($input).';
|
||||
|
||||
// Set constant
|
||||
$("#set_'.$code.'").click(function() {
|
||||
$.get( "'.DOL_URL_ROOT.'/core/ajax/productonoff.php", {
|
||||
action: \'set\',
|
||||
name: \''.$code.'\',
|
||||
id: \''.$id.'\',
|
||||
entity: \''.$entity.'\'
|
||||
},
|
||||
function() {
|
||||
$("#set_'.$code.'").hide();
|
||||
$("#del_'.$code.'").show();
|
||||
// Enable another element
|
||||
if (input.disabled && input.disabled.length > 0) {
|
||||
$.each(input.disabled, function(key,value) {
|
||||
$("#" + value).removeAttr("disabled");
|
||||
if ($("#" + value).hasClass("butActionRefused") == true) {
|
||||
$("#" + value).removeClass("butActionRefused");
|
||||
$("#" + value).addClass("butAction");
|
||||
}
|
||||
});
|
||||
// Show another element
|
||||
} else if (input.showhide && input.showhide.length > 0) {
|
||||
$.each(input.showhide, function(key,value) {
|
||||
$("#" + value).show();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Del constant
|
||||
$("#del_'.$code.'").click(function() {
|
||||
$.get( "'.DOL_URL_ROOT.'/core/ajax/productonoff.php", {
|
||||
action: \'del\',
|
||||
name: \''.$code.'\',
|
||||
id: \''.$id.'\',
|
||||
entity: \''.$entity.'\'
|
||||
},
|
||||
function() {
|
||||
$("#del_'.$code.'").hide();
|
||||
$("#set_'.$code.'").show();
|
||||
// Disable another element
|
||||
if (input.disabled && input.disabled.length > 0) {
|
||||
$.each(input.disabled, function(key,value) {
|
||||
$("#" + value).attr("disabled", true);
|
||||
if ($("#" + value).hasClass("butAction") == true) {
|
||||
$("#" + value).removeClass("butAction");
|
||||
$("#" + value).addClass("butActionRefused");
|
||||
}
|
||||
});
|
||||
// Hide another element
|
||||
} else if (input.showhide && input.showhide.length > 0) {
|
||||
$.each(input.showhide, function(key,value) {
|
||||
$("#" + value).hide();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
if ($code=='status') {
|
||||
$out.= '<span id="set_'.$code.'" class="linkobject '.($object->$code==1?'hideobject':'').'">'.img_picto($langs->trans("ProductStatusNotOnSell"),'switch_off').'</span>';
|
||||
$out.= '<span id="del_'.$code.'" class="linkobject '.($object->$code==1?'':'hideobject').'">'.img_picto($langs->trans("ProductStatusOnSell"),'switch_on').'</span>';
|
||||
}
|
||||
if ($code=='status_buy') {
|
||||
$out.= '<span id="set_'.$code.'" class="linkobject '.($object->$code==1?'hideobject':'').'">'.img_picto($langs->trans("ProductStatusNotOnBuy"),'switch_off').'</span>';
|
||||
$out.= '<span id="del_'.$code.'" class="linkobject '.($object->$code==1?'':'hideobject').'">'.img_picto($langs->trans("ProductStatusOnBuy"),'switch_on').'</span>';
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user