Skip to content

Commit

Permalink
New: add possibility to set and del anothers constants
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Sep 2, 2012
1 parent b9ac974 commit a00205a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 37 deletions.
9 changes: 5 additions & 4 deletions htdocs/core/ajax/constantonoff.php
Expand Up @@ -30,6 +30,8 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';

$action=GETPOST('action','alpha');
$name=GETPOST('name','alpha');

/*
* View
Expand All @@ -45,17 +47,16 @@
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";

// 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');
$action = GETPOST('action', 'alpha');
$name = GETPOST('name', 'alpha');
$value = (GETPOST('value')?GETPOST('value'):1);

if ($user->admin)
{
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')
{
Expand Down
94 changes: 61 additions & 33 deletions htdocs/core/lib/ajax.lib.php
Expand Up @@ -346,7 +346,7 @@ function(response) {
* On/off button for 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
* @return void
*/
Expand All @@ -359,60 +359,88 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
$out= '<script type="text/javascript">
$(function() {
var input = '.json_encode($input).';
var url = \''.DOL_URL_ROOT.'/core/ajax/constantonoff.php\';
// Set constant
$("#set_'.$code.'").click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
$.get( url, {
action: \'set\',
name: \''.$code.'\',
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();
});
}
$.each(input, function(type, data) {
// Enable another element
if (type == "disabled") {
$.each(data, function(key, value) {
$("#" + value).removeAttr("disabled");
if ($("#" + value).hasClass("butActionRefused") == true) {
$("#" + value).removeClass("butActionRefused");
$("#" + value).addClass("butAction");
}
});
// Show another element
} else if (type == "showhide" || type == "show") {
$.each(data, function(key, value) {
$("#" + 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_'.$code.'").click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
$.get( url, {
action: \'del\',
name: \''.$code.'\',
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();
});
}
$.each(input, function(type, data) {
// Disable another element
if (type == "disabled") {
$.each(data, function(key, value) {
$("#" + value).attr("disabled", true);
if ($("#" + value).hasClass("butAction") == true) {
$("#" + value).removeClass("butAction");
$("#" + value).addClass("butActionRefused");
}
});
// Hide another element
} else if (type == "showhide" || type == "hide") {
$.each(data, function(key, value) {
$("#" + 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.'\'
});
});
}
});
});
});
});
Expand Down

0 comments on commit a00205a

Please sign in to comment.