Merge pull request #1955 from frederic34/patch-2
Ajax On/Off for product tosell and tobuy
This commit is contained in:
commit
97f98d7e16
52
htdocs/core/ajax/productonoff.php
Normal file
52
htdocs/core/ajax/productonoff.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/ajax/productonoff.php
|
||||
* \brief File to set tosell and tobuy for product
|
||||
*/
|
||||
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
||||
if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
|
||||
|
||||
$action=GETPOST('action','alpha');
|
||||
$id=GETPOST('id', 'int');
|
||||
$value=GETPOST('value', 'int');
|
||||
|
||||
$object = new GenericObject($db);
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
top_httphead();
|
||||
|
||||
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
|
||||
|
||||
// Registering new values
|
||||
if (! empty($action) && ! empty($id) && $user->rights->produit->creer) {
|
||||
if ($action == 'setstatus')
|
||||
$object->setValueFrom('tosell', $value, 'product', $id);
|
||||
else if ($action == 'setstatus_buy')
|
||||
$object->setValueFrom('tobuy', $value, 'product', $id);
|
||||
}
|
||||
@ -459,3 +459,91 @@ 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'))
|
||||
* @return void
|
||||
*/
|
||||
function ajax_productonoff($id, $code, $input=array())
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
global $conf, $langs, $db;
|
||||
|
||||
$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'.$code.'\',
|
||||
value: \'1\',
|
||||
id: \''.$id.'\'
|
||||
},
|
||||
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: \'set'.$code.'\',
|
||||
value: \'0\',
|
||||
id: \''.$id.'\'
|
||||
},
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -1420,12 +1420,20 @@ else
|
||||
|
||||
// Status (to sell)
|
||||
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="2">';
|
||||
print $object->getLibStatut(2,0);
|
||||
if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
|
||||
print ajax_productonoff($object->id, 'status');
|
||||
} else {
|
||||
print $object->getLibStatut(2,0);
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
// Status (to buy)
|
||||
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="2">';
|
||||
print $object->getLibStatut(2,1);
|
||||
if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
|
||||
print ajax_productonoff($object->id, 'status_buy');
|
||||
} else {
|
||||
print $object->getLibStatut(2,1);
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
// Batch number management (to batch)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user