Qual: Serious clean of code of formconfirm method. This also solve bugs

of ecm module when using ajax.
This commit is contained in:
Laurent Destailleur
2012-05-23 23:23:57 +02:00
parent 7801749874
commit ed93e5cc7c
4 changed files with 71 additions and 57 deletions

View File

@@ -1,6 +1,6 @@
<?PHP
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2011 Laurent Destailleur <eldy@uers.sourceforge.net>
* Copyright (C) 2005-2012 Laurent Destailleur <eldy@uers.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
@@ -112,9 +112,9 @@ if ($action == 'confirm_clone' && $confirm == 'yes')
else
{
$mesg=$object->error;
$action='';
}
}
$action='';
}
// Action send emailing for everybody
@@ -800,12 +800,12 @@ else
array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers").' ('.$langs->trans("FeatureNotYetAvailable").')', 'value' => 0, 'disabled' => true)
);
// Paiement incomplet. On demande si motif = escompte ou autre
$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneEMailing'),$langs->trans('ConfirmCloneEMailing',$object->ref),'confirm_clone',$formquestion,'yes');
$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneEMailing'),$langs->trans('ConfirmCloneEMailing',$object->ref),'confirm_clone',$formquestion,'yes',2,240);
print '<br>';
}
if ($mesg) print $mesg;
dol_htmloutput_mesg($mesg);
/*
@@ -952,8 +952,10 @@ else
* Mailing en mode edition
*/
if ($mesg) print $mesg."<br>";
if ($message) print $message."<br>";
$mesgs=array();
if ($mesg) $mesgs[]=$mesg;
if ($message) $message[]=$message;
dol_htmloutput_mesg('',$mesgs);
print '<table class="border" width="100%">';

View File

@@ -148,13 +148,14 @@ if (! dol_is_dir($upload_dir))
print '<!-- TYPE='.$type.' -->'."\n";
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
$param='';
// Dir
if ($type == 'directory')
{
$formfile=new FormFile($db);
$param=($sortfield?'&sortfield='.$sortfield:'').($sortorder?'&sortorder='.$sortorder:'');
$param.=($sortfield?'&sortfield='.$sortfield:'').($sortorder?'&sortorder='.$sortorder:'');
$maxlengthname=40;
// Right area
@@ -242,12 +243,11 @@ if ($type == 'directory')
}
else // Manual area
{
$relativepath=$ecmdir->getRelativePath();
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
$filearray=dol_dir_list($upload_dir,"files",0,'',array('^\.','\.meta$','^temp$','^CVS$'),$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$param.='&section='.$section;
if ($section) $param.='&section='.$section;
$textifempty=($section?$langs->trans("NoFileFound"):($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection")));
$formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->upload,1,$textifempty,$maxlengthname);
@@ -255,14 +255,24 @@ if ($type == 'directory')
}
if ((! isset($mode) || $mode != 'noajax') && empty($conf->global->MAIN_ECM_DISABLE_JS))
if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))
{
// Enable jquery handlers on new generated HTML objects
print "\n".'<script type="text/javascript">'."\n";
print 'jQuery(".deletefilelink").click(function(e) { jQuery("#dialog-confirm-deletefile").dialog("open"); return false; });'."\n";
print '</script>'."\n";
if ($section)
{
require_once(DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php');
$form = new Form($db);
$formquestion=array('urlfile'=>array('type'=>'hidden','value'=>'','name'=>'urlfile'));
print $form->formconfirm(DOL_URL_ROOT.'/ecm/index.php'.($param?'?':'').(preg_replace('/^&/','',$param)),$langs->trans("DeleteFile"),$langs->trans("ConfirmDeleteFile"),'confirm_deletefile',$formquestion,"no",'deletefile');
if (is_object($db)) $db->close();
// Enable jquery handlers on new generated HTML objects
print '<script type="text/javascript">'."\n";
print 'jQuery(document).ready(function() {'."\n";
print 'jQuery(".deletefilelink").click(function(e) { jQuery("#urlfile").val(jQuery(this).attr("rel")); jQuery("#dialog-confirm-deletefile").dialog("open"); return false; });'."\n";
print '});'."\n";
print '</script>'."\n";
}
}
// Close db if mode is not noajax
if ((! isset($mode) || $mode != 'noajax') && is_object($db)) $db->close();
?>

View File

@@ -2146,7 +2146,8 @@ class Form
$more='';
$formconfirm='';
$inputarray=array();
$inputok=array();
$inputko=array();
if (is_array($formquestion) && count($formquestion) > 0)
{
@@ -2207,13 +2208,16 @@ class Form
$more.=$input['value'];
$more.='</td></tr>'."\n";
}
if ($input['type'] != 'hidden') array_push($inputarray,$input['name']);
else if ($input['type'] == 'hidden')
{
$more.='<input type="hidden" id="'.$input['name'].'" name="'.$input['name'].'" value="'.$input['value'].'">';
}
}
}
$more.='</table>'."\n";
}
$formconfirm.= "\n<!-- begin form_confirm -->\n";
$formconfirm.= "\n<!-- begin form_confirm page=".$page." -->\n";
if ($useajax && $conf->use_javascript_ajax)
{
@@ -2228,16 +2232,13 @@ class Form
}
$pageyes=$page.'&action='.$action.'&confirm=yes';
$pageno=($useajax == 2?$page.'&confirm=no':'');
// Add hidden fields
// Add input fields into list of fields to read during submit (inputok and inputko)
if (is_array($formquestion))
{
foreach ($formquestion as $key => $input)
{
if ($input['type'] == 'hidden')
{
$pageyes.='&'.$input['name'].'='.urlencode($input['value']);
$pageno.=($useajax == 2?$page.'&'.$input['name'].'='.urlencode($input['value']):'');
}
array_push($inputok,$input['name']);
if ($input['inputko'] == 1) array_push($inputko,$input['name']);
}
}
@@ -2247,13 +2248,15 @@ class Form
$formconfirm.= img_help('','').' '.$question;
$formconfirm.= '</div>'."\n";
$formconfirm.= '<script type="text/javascript">
$(function() {
var choice=\'ko\';
var $inputarray='.json_encode($inputarray).';
var button=\''.$button.'\';
var dialogconfirm=\''.$dialogconfirm.'\';
var choice=\'ko\';
var inputok='.json_encode($inputok).';
var inputko='.json_encode($inputko).';
var pageyes=\''.($pageyes?$pageyes:'').'\';
var pageno=\''.($pageno?$pageno:'').'\';
$( "#" + dialogconfirm ).dialog({
/* Warning: This function is loaded once and not overwritten if loaded by another ajax page */
$(function() {
$( "#'.$dialogconfirm.'" ).dialog({
autoOpen: '.($autoOpen?'true':'false').',
resizable: false,
height:'.$height.',
@@ -2261,23 +2264,37 @@ class Form
modal: true,
closeOnEscape: false,
close: function(event, ui) {
if (choice == \'ok\') {
if (choice == \'ok\') {
var options="";
if ($inputarray.length>0) {
$.each($inputarray, function() {
var inputname = this;
var more = \'\';
if (inputok.length>0) {
$.each(inputok, function() {
var inputname = this; var more = \'\';
if ($("#" + this).attr("type") == \'checkbox\') { more = \':checked\'; }
var inputvalue = $("#" + this + more).val();
if (typeof inputvalue == \'undefined\') { inputvalue=\'\'; }
options += \'&\' + inputname + \'=\' + inputvalue;
});
//alert(options);
}
location.href=\''.$pageyes.'\' + options;
}
'.($pageno?'if (choice == \'ko\') location.href=\''.$pageno.'\';':'').'
},
var urljump=pageyes + (pageyes.indexOf(\'?\')<0?\'?\':\'\') + options;
//alert(urljump);
if (pageyes.length > 0) { location.href=urljump; }
}
if (choice == \'ko\') {
var options="";
if (inputko.length>0) {
$.each(inputko, function() {
var inputname = this; var more = \'\';
if ($("#" + this).attr("type") == \'checkbox\') { more = \':checked\'; }
var inputvalue = $("#" + this + 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; }
}
},
buttons: {
\''.dol_escape_js($langs->transnoentities("Yes")).'\': function() {
choice=\'ok\';
@@ -2289,12 +2306,6 @@ class Form
}
}
});
if (button.length > 0) {
$( "#" + button ).click(function() {
$("#" + dialogconfirm ).dialog(\'open\');
});
}
});
</script>';
@@ -2331,15 +2342,6 @@ class Form
$formconfirm.= '</table>'."\n";
// Add hidden fields
if (is_array($formquestion))
{
foreach ($formquestion as $key => $input)
{
if ($input['type'] == 'hidden') $formconfirm.= '<input type="hidden" name="'.$input['name'].'" value="'.$input['value'].'">';
}
}
$formconfirm.= "</form>\n";
$formconfirm.= '<br>';
}
@@ -2903,7 +2905,7 @@ class Form
function load_cache_vatrates($country_code)
{
global $langs;
$num = count($this->cache_vatrates);
if ($num > 0) return $num; // Cache deja charge

View File

@@ -608,7 +608,7 @@ class FormFile
// Delete or view link
print '<td align="right">';
if ($useinecm) print '<a href="'.DOL_URL_ROOT.'/ecm/docfile.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_view().'</a> &nbsp; ';
if ($permtodelete) print '<a href="'.(($useinecm && empty($conf->global->MAIN_ECM_DISABLE_JS))?'#':$url.'?id='.$object->id.'&action=delete&urlfile='.urlencode($file['name']).$param).'" class="deletefilelink" rel="'.urlencode($file['name']).'">'.img_delete().'</a>';
if ($permtodelete) print '<a href="'.(($useinecm && !empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))?'#':$url.'?id='.$object->id.'&action=delete&urlfile='.urlencode($file['name']).$param).'" class="deletefilelink" rel="'.urlencode($file['name']).'">'.img_delete().'</a>';
else print '&nbsp;';
print "</td>";
print "</tr>\n";