From 86f1d59e3cfa7d82f7ed3461bb3debd95473321d Mon Sep 17 00:00:00 2001 From: Regis Houssin <regis.houssin@capnetworks.com> Date: Sun, 17 Aug 2014 15:12:20 +0200 Subject: [PATCH] Fix: broken feature: add param for use only "disabled" with delConstant and "enabled" with setConstant --- htdocs/core/js/lib_head.js | 21 ++++++++++++--------- htdocs/core/lib/ajax.lib.php | 14 ++++++++------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/htdocs/core/js/lib_head.js b/htdocs/core/js/lib_head.js index 9221843d575..18dc2258c70 100644 --- a/htdocs/core/js/lib_head.js +++ b/htdocs/core/js/lib_head.js @@ -1,5 +1,5 @@ // Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net> -// Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> +// Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com> // // 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 @@ -631,7 +631,7 @@ function hideMessage(fieldId,message) { /* * TODO Used by admin page only ? */ -function setConstant(url, code, input, entity) { +function setConstant(url, code, input, entity, strict) { $.get( url, { action: "set", name: code, @@ -642,7 +642,7 @@ function setConstant(url, code, input, entity) { $("#del_" + code).show(); $.each(input, function(type, data) { // Enable another element - if (type == "disabled") { + if (type == "disabled" && strict != 1) { $.each(data, function(key, value) { var newvalue=((value.search("^#") < 0 && value.search("^\.") < 0) ? "#" : "") + value; $(newvalue).removeAttr("disabled"); @@ -654,7 +654,10 @@ function setConstant(url, code, input, entity) { } else if (type == "enabled") { $.each(data, function(key, value) { var newvalue=((value.search("^#") < 0 && value.search("^\.") < 0) ? "#" : "") + value; - $(newvalue).attr("disabled", true); + if (strict == 1) + $(newvalue).removeAttr("disabled"); + else + $(newvalue).attr("disabled", true); if ($(newvalue).hasClass("butAction") == true) { $(newvalue).removeClass("butAction"); $(newvalue).addClass("butActionRefused"); @@ -686,7 +689,7 @@ function setConstant(url, code, input, entity) { /* * TODO Used by admin page only ? */ -function delConstant(url, code, input, entity) { +function delConstant(url, code, input, entity, strict) { $.get( url, { action: "del", name: code, @@ -706,7 +709,7 @@ function delConstant(url, code, input, entity) { $(newvalue).addClass("butActionRefused"); } }); - } else if (type == "enabled") { + } else if (type == "enabled" && strict != 1) { $.each(data, function(key, value) { var newvalue=((value.search("^#") < 0 && value.search("^\.") < 0) ? "#" : "") + value; $(newvalue).removeAttr("disabled"); @@ -740,7 +743,7 @@ function delConstant(url, code, input, entity) { /* * TODO Used by admin page only ? */ -function confirmConstantAction(action, url, code, input, box, entity, yesButton, noButton) { +function confirmConstantAction(action, url, code, input, box, entity, yesButton, noButton, strict) { var boxConfirm = box; $("#confirm_" + code) .attr("title", boxConfirm.title) @@ -756,9 +759,9 @@ function confirmConstantAction(action, url, code, input, box, entity, yesButton, text : yesButton, click : function() { if (action == "set") { - setConstant(url, code, input, entity); + setConstant(url, code, input, entity, strict); } else if (action == "del") { - delConstant(url, code, input, entity); + delConstant(url, code, input, entity, strict); } // Close dialog $(this).dialog("close"); diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index e24d12dbc52..46aed9ec1c9 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -1,6 +1,6 @@ <?php /* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net> - * Copyright (C) 2007-2012 Regis Houssin <regis.houssin@capnetworks.com> + * Copyright (C) 2007-2014 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr> * * This program is free software; you can redistribute it and/or modify @@ -380,9 +380,10 @@ function ajax_combobox($htmlname, $event=array(), $minLengthToAutocomplete=0) * @param array $input Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid')) * @param int $entity Entity to set * @param int $revertonoff Revert on/off + * @param bool $strict Use only "disabled" with delConstant and "enabled" with setConstant * @return void */ -function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0) +function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0) { global $conf, $langs; @@ -395,6 +396,7 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0) var url = \''.DOL_URL_ROOT.'/core/ajax/constantonoff.php\'; var code = \''.$code.'\'; var entity = \''.$entity.'\'; + var strict = \''.$strict.'\'; var yesButton = "'.dol_escape_js($langs->transnoentities("Yes")).'"; var noButton = "'.dol_escape_js($langs->transnoentities("No")).'"; @@ -403,9 +405,9 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0) if (input.alert && input.alert.set) { if (input.alert.set.yesButton) yesButton = input.alert.set.yesButton; if (input.alert.set.noButton) noButton = input.alert.set.noButton; - confirmConstantAction("set", url, code, input, input.alert.set, entity, yesButton, noButton); + confirmConstantAction("set", url, code, input, input.alert.set, entity, yesButton, noButton, strict); } else { - setConstant(url, code, input, entity); + setConstant(url, code, input, entity, strict); } }); @@ -414,9 +416,9 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0) if (input.alert && input.alert.del) { if (input.alert.del.yesButton) yesButton = input.alert.del.yesButton; if (input.alert.del.noButton) noButton = input.alert.del.noButton; - confirmConstantAction("del", url, code, input, input.alert.del, entity, yesButton, noButton); + confirmConstantAction("del", url, code, input, input.alert.del, entity, yesButton, noButton, strict); } else { - delConstant(url, code, input, entity); + delConstant(url, code, input, entity, strict); } }); }); -- GitLab