New: add possibility to disable or show/hide another elements
This commit is contained in:
parent
72304505cb
commit
303521d14c
@ -221,60 +221,70 @@ function ajax_combobox($htmlname)
|
|||||||
* @param string $code Name of constant
|
* @param string $code Name of constant
|
||||||
* @param array $input Input element
|
* @param array $input Input element
|
||||||
* @param int $entity Entity to set
|
* @param int $entity Entity to set
|
||||||
* TODO add different method for other input (show/hide, disable, ..)
|
* @return void
|
||||||
*/
|
*/
|
||||||
function ajax_constantonoff($code,$input=array(),$entity=false)
|
function ajax_constantonoff($code,$input=array(),$entity=false)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
$entity = ((! empty($entity) && is_numeric($entity) && $entity > 0) || $entity == 0 ? $entity : $conf->entity);
|
$entity = ((! empty($entity) && is_numeric($entity) && $entity > 0) || $entity == 0 ? $entity : $conf->entity);
|
||||||
|
|
||||||
$out= '<script type="text/javascript">
|
$out= '<script type="text/javascript">
|
||||||
$(function() {
|
$(function() {
|
||||||
var input='.json_encode($input).';
|
var input = '.json_encode($input).';
|
||||||
|
|
||||||
// Set constant
|
// Set constant
|
||||||
$( "#set_'.$code.'" ).click(function() {
|
$("#set_'.$code.'").click(function() {
|
||||||
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
|
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
|
||||||
action: \'set\',
|
action: \'set\',
|
||||||
name: \''.$code.'\',
|
name: \''.$code.'\',
|
||||||
entity: \''.$entity.'\'
|
entity: \''.$entity.'\'
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
$("#set_'.$code.'" ).hide();
|
$("#set_'.$code.'").hide();
|
||||||
$("#del_'.$code.'" ).show();
|
$("#del_'.$code.'").show();
|
||||||
// Enable another object
|
// Enable another element
|
||||||
if (input.length > 0) {
|
if (input.disabled && input.disabled.length > 0) {
|
||||||
$.each(input, function(key,value) {
|
$.each(input.disabled, 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");
|
||||||
$("#" + value).addClass("butAction");
|
$("#" + 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 constant
|
||||||
$( "#del_'.$code.'" ).click(function() {
|
$("#del_'.$code.'").click(function() {
|
||||||
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
|
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
|
||||||
action: \'del\',
|
action: \'del\',
|
||||||
name: \''.$code.'\',
|
name: \''.$code.'\',
|
||||||
entity: \''.$entity.'\'
|
entity: \''.$entity.'\'
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
$("#del_'.$code.'" ).hide();
|
$("#del_'.$code.'").hide();
|
||||||
$("#set_'.$code.'" ).show();
|
$("#set_'.$code.'").show();
|
||||||
// Disable another object
|
// Disable another element
|
||||||
if (input.length > 0) {
|
if (input.disabled && input.disabled.length > 0) {
|
||||||
$.each(input, function(key,value) {
|
$.each(input.disabled, 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");
|
||||||
$("#" + value).addClass("butActionRefused");
|
$("#" + value).addClass("butActionRefused");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// Hide another element
|
||||||
|
} else if (input.showhide && input.showhide.length > 0) {
|
||||||
|
$.each(input.showhide, function(key,value) {
|
||||||
|
$("#" + value).hide();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user