Files
dolibarr/htdocs/core/tpl/ajax/formconfirm.tpl.php
Laurent Destailleur 158930eb7b Fix: function is loaded once and not overwritten if loaded
by another ajax page. So if we need inputok/ko and pageyes/no to be
different according to ajax calls (to have several confirm box
loaded from different ajax parts of page, we must place such variables
outside of function. For this $useglobalvars must be set to 1.
2012-06-08 23:48:53 +02:00

102 lines
4.2 KiB
PHP

<?php
/* Copyright (C) 2011-2012 Regis Houssin <regis@dolibarr.fr>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
?>
<!-- START TEMPLATE FORMCONFIRM PAGE="<?php echo $page; ?>" -->
<div id="<?php echo $dialogconfirm; ?>" title="<?php echo dol_escape_htmltag($title); ?>" style="display: none;">
<?php if (! empty($more)) { ?>
<p><?php echo $more; ?></p>
<?php } ?>
<?php echo img_help('','').' '.$question; ?>
</div>
<script type="text/javascript">
/*
* Warning: function is loaded once and not overwritten if loaded by another ajax page.
* So if we need inputok/ko and pageyes/no to be different according to ajax calls (to have several confirm box loaded
* from different ajax parts of page, we must place such variables outside of function. For this $useglobalvars must be set to 1.
*/
<?php if (! empty($useglobalvars)) { ?>
var inputok=<?php echo json_encode($inputok); ?>;
var inputko=<?php echo json_encode($inputko); ?>;
var pageyes='<?php echo dol_escape_js($pageyes?$pageyes:''); ?>';
var pageno='<?php echo dol_escape_js($pageno?$pageno:''); ?>';
<?php } ?>
$(function() {
$( "#<?php echo $dialogconfirm; ?>" ).dialog({
autoOpen: <?php echo ($autoOpen ? 'true' : 'false'); ?>,
resizable: false,
height: '<?php echo $height; ?>',
width: '<?php echo $width; ?>',
modal: true,
closeOnEscape: false,
buttons: {
'<?php echo dol_escape_js($langs->transnoentities("Yes")); ?>': function() {
var options="";
<?php if (empty($useglobalvars)) { ?>
var inputok = <?php echo json_encode($inputok); ?>;
var pageyes = '<?php echo dol_escape_js($pageyes?$pageyes:''); ?>';
<?php } ?>
if (inputok.length>0) {
$.each(inputok, function(i, inputname) {
var more = '';
if ($("#" + inputname).attr("type") == 'checkbox') { more = ':checked'; }
var inputvalue = $("#" + inputname + more).val();
if (typeof inputvalue == 'undefined') { inputvalue=''; }
options += '&' + inputname + '=' + inputvalue;
});
}
var urljump = pageyes + (pageyes.indexOf('?') < 0 ? '?' : '') + options;
//alert(urljump);
if (pageyes.length > 0) { location.href = urljump; }
$(this).dialog('close');
},
'<?php echo dol_escape_js($langs->transnoentities("No")); ?>': function() {
var options = '';
<?php if (empty($useglobalvars)) { ?>
var inputko = <?php echo json_encode($inputko); ?>;
var pageno='<?php echo dol_escape_js($pageno?$pageno:''); ?>';
<?php } ?>
if (inputko.length>0) {
$.each(inputko, function(i, inputname) {
var more = '';
if ($("#" + inputname).attr("type") == 'checkbox') { more = ':checked'; }
var inputvalue = $("#" + inputname + more).val();
if (typeof inputvalue == 'undefined') { inputvalue=''; }
options += '&' + inputname + '=' + inputvalue;
});
}
var urljump=pageno + (pageno.indexOf('?') < 0 ? '?' : '') + options;
//alert(urljump);
if (pageno.length > 0) { location.href = urljump; }
$(this).dialog('close');
}
}
});
var button = '<?php echo $button; ?>';
if (button.length > 0) {
$( "#" + button ).click(function() {
$("#<?php echo $dialogconfirm; ?>").dialog('open');
});
}
});
</script>
<!-- END TEMPLATE FORM CONFIRM -->