2
0
forked from Wavyzz/dolibarr

New: add possibility to set and del anothers constants

This commit is contained in:
Regis Houssin
2012-08-13 11:42:50 +02:00
parent b9ac974013
commit a00205a17d
2 changed files with 66 additions and 37 deletions

View File

@@ -30,6 +30,8 @@ if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
require '../../main.inc.php'; require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
$action=GETPOST('action','alpha');
$name=GETPOST('name','alpha');
/* /*
* View * View
@@ -45,17 +47,16 @@ top_httphead();
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n"; print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
// Registering the location of boxes // Registering the location of boxes
if ((isset($_GET['action']) && ! empty($_GET['action'])) && (isset($_GET['name']) && ! empty($_GET['name'])) ) if (! empty($action) && ! empty($name))
{ {
$entity = GETPOST('entity','int'); $entity = GETPOST('entity','int');
$action = GETPOST('action', 'alpha'); $value = (GETPOST('value')?GETPOST('value'):1);
$name = GETPOST('name', 'alpha');
if ($user->admin) if ($user->admin)
{ {
if ($action == 'set') if ($action == 'set')
{ {
dolibarr_set_const($db, $name, 1, 'chaine', 0, '', $entity); dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
} }
else if ($action == 'del') else if ($action == 'del')
{ {

View File

@@ -346,7 +346,7 @@ function ajax_combobox($htmlname, $event=array())
* On/off button for constant * On/off button for constant
* *
* @param string $code Name of constant * @param string $code Name of constant
* @param array $input Input element * @param array $input Input element (enable/disable or show/hide another element, set/del another constant)
* @param int $entity Entity to set * @param int $entity Entity to set
* @return void * @return void
*/ */
@@ -359,10 +359,11 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
$out= '<script type="text/javascript"> $out= '<script type="text/javascript">
$(function() { $(function() {
var input = '.json_encode($input).'; var input = '.json_encode($input).';
var url = \''.DOL_URL_ROOT.'/core/ajax/constantonoff.php\';
// Set constant // Set constant
$("#set_'.$code.'").click(function() { $("#set_'.$code.'").click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", { $.get( url, {
action: \'set\', action: \'set\',
name: \''.$code.'\', name: \''.$code.'\',
entity: \''.$entity.'\' entity: \''.$entity.'\'
@@ -370,9 +371,10 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
function() { function() {
$("#set_'.$code.'").hide(); $("#set_'.$code.'").hide();
$("#del_'.$code.'").show(); $("#del_'.$code.'").show();
$.each(input, function(type, data) {
// Enable another element // Enable another element
if (input.disabled && input.disabled.length > 0) { if (type == "disabled") {
$.each(input.disabled, function(key,value) { $.each(data, function(key, value) {
$("#" + value).removeAttr("disabled"); $("#" + value).removeAttr("disabled");
if ($("#" + value).hasClass("butActionRefused") == true) { if ($("#" + value).hasClass("butActionRefused") == true) {
$("#" + value).removeClass("butActionRefused"); $("#" + value).removeClass("butActionRefused");
@@ -380,17 +382,30 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
} }
}); });
// Show another element // Show another element
} else if (input.showhide && input.showhide.length > 0) { } else if (type == "showhide" || type == "show") {
$.each(input.showhide, function(key,value) { $.each(data, function(key, value) {
$("#" + value).show(); $("#" + value).show();
}); });
// Set another constant
} else if (type == "set") {
$.each(data, function(key, value) {
$("#set_" + key).hide();
$("#del_" + key).show();
$.get( url, {
action: \'set\',
name: key,
value: value,
entity: \''.$entity.'\'
});
});
} }
}); });
}); });
});
// Del constant // Del constant
$("#del_'.$code.'").click(function() { $("#del_'.$code.'").click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", { $.get( url, {
action: \'del\', action: \'del\',
name: \''.$code.'\', name: \''.$code.'\',
entity: \''.$entity.'\' entity: \''.$entity.'\'
@@ -398,9 +413,10 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
function() { function() {
$("#del_'.$code.'").hide(); $("#del_'.$code.'").hide();
$("#set_'.$code.'").show(); $("#set_'.$code.'").show();
$.each(input, function(type, data) {
// Disable another element // Disable another element
if (input.disabled && input.disabled.length > 0) { if (type == "disabled") {
$.each(input.disabled, function(key,value) { $.each(data, function(key, value) {
$("#" + value).attr("disabled", true); $("#" + value).attr("disabled", true);
if ($("#" + value).hasClass("butAction") == true) { if ($("#" + value).hasClass("butAction") == true) {
$("#" + value).removeClass("butAction"); $("#" + value).removeClass("butAction");
@@ -408,14 +424,26 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
} }
}); });
// Hide another element // Hide another element
} else if (input.showhide && input.showhide.length > 0) { } else if (type == "showhide" || type == "hide") {
$.each(input.showhide, function(key,value) { $.each(data, function(key, value) {
$("#" + value).hide(); $("#" + value).hide();
}); });
// Delete another constant
} else if (type == "del") {
$.each(data, function(key, value) {
$("#del_" + value).hide();
$("#set_" + value).show();
$.get( url, {
action: \'del\',
name: value,
entity: \''.$entity.'\'
});
});
} }
}); });
}); });
}); });
});
</script>'; </script>';
$out.= '<span id="set_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'hideobject':'').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>'; $out.= '<span id="set_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'hideobject':'').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>';