Fix: use MAIN_JS_ON_PAYMENT just for the auto-completion payment

This commit is contained in:
Regis Houssin 2012-01-15 11:02:08 +01:00
parent 244af052cc
commit 196bb42636

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
*
* This program is free software; you can redistribute it and/or modify
@ -243,35 +243,48 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
// Invoice with Paypal transaction
// TODO add hook possibility (regis)
if ($conf->paypalplus->enabled && $conf->global->PAYPAL_ENABLE_TRANSACTION_MANAGEMENT && ! empty($facture->ref_int))
{
if (! empty($conf->global->PAYPAL_BANK_ACCOUNT)) $accountid=$conf->global->PAYPAL_BANK_ACCOUNT;
$paymentnum=$facture->ref_int;
}
if ($conf->use_javascript_ajax && !empty($conf->global->MAIN_JS_ON_PAYMENT))
if ($conf->use_javascript_ajax)
{
print "\n".'<script type="text/javascript" language="javascript">';
print 'jQuery(document).ready(function () {';
print 'jQuery("#selectpaiementcode").change(function() {
code=jQuery("#selectpaiementcode option:selected").val();
print '$(document).ready(function () {
setPaiementCode();
$("#selectpaiementcode").change(function() {
setPaiementCode();
});
function setPaiementCode()
{
var code = $("#selectpaiementcode option:selected").val();
if (code == \'CHQ\')
{
jQuery(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
if (jQuery(\'#fieldchqemetteur\').val() == \'\')
$(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
if ($(\'#fieldchqemetteur\').val() == \'\')
{
jQuery(\'#fieldchqemetteur\').val(jQuery(\'#thirdpartylabel\').val());
$(\'#fieldchqemetteur\').val(jQuery(\'#thirdpartylabel\').val());
}
}
else
{
jQuery(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
$(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
$(\'#fieldchqemetteur\').val(\'\');
}
});
}';
// For paiement auto-completion
if (! empty($conf->global->MAIN_JS_ON_PAYMENT))
{
print "\n".'
function elemToJson(selector)
{
var subJson = {};
jQuery.map(selector.serializeArray(), function(n,i)
$.map(selector.serializeArray(), function(n,i)
{
subJson[n["name"]] = n["value"];
});
@ -280,58 +293,60 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
function callForResult(imgId)
{
var json = {};
var form = jQuery("#payment_form");
var form = $("#payment_form");
json["amountPayment"] = jQuery("#amountpayment").attr("value");
json["amountPayment"] = $("#amountpayment").attr("value");
json["amounts"] = elemToJson(form.find("input[name*=\"amount_\"]"));
json["remains"] = elemToJson(form.find("input[name*=\"remain_\"]"));
if(imgId != null)json["imgClicked"] = imgId;
if (imgId != null) {
json["imgClicked"] = imgId;
}
jQuery.post("ajaxpayment.php", json, function(data)
$.post("ajaxpayment.php", json, function(data)
{
json = jQuery.parseJSON(data);
json = $.parseJSON(data);
form.data(json);
for(var key in json)
for (var key in json)
{
if(key == "result") {
if(json["makeRed"]) {
jQuery("#"+key).css("color", "red");
if (key == "result") {
if (json["makeRed"]) {
$("#"+key).css("color", "red");
} else {
jQuery("#"+key).removeAttr("style");
$("#"+key).removeAttr("style");
}
json[key]=json["label"]+" "+json[key];
jQuery("#"+key).text(json[key]);
$("#"+key).text(json[key]);
} else {
form.find("input[name*=\""+key+"\"]").each(function() {
jQuery(this).attr("value", json[key]);
$(this).attr("value", json[key]);
});
}
}
});
}
function callToBreakdown(imgSelector) {
var form = jQuery("#payment_form"), imgId;
var form = $("#payment_form"), imgId;
imgId = imgSelector.attr("id");
callForResult(imgId);
}
jQuery("#payment_form").find("img").click(function() {
$("#payment_form").find("img").click(function() {
callToBreakdown(jQuery(this));
});
jQuery("#payment_form").find("input[name*=\"amount_\"]").change(function() {
$("#payment_form").find("input[name*=\"amount_\"]").change(function() {
callForResult();
});
jQuery("#amountpayment").change(function() {
$("#amountpayment").change(function() {
callForResult();
});
});
});';
}
print '});
</script>'."\n";
}