2
0
forked from Wavyzz/dolibarr

Qual: Move common javascript function into lib_head.js

This commit is contained in:
Laurent Destailleur
2014-02-19 11:08:43 +01:00
parent 03a60236af
commit 8c9d2418d2
3 changed files with 45 additions and 50 deletions

View File

@@ -899,6 +899,24 @@ function confirmConstantAction(action, url, code, input, box, entity, yesButton,
}); });
})( jQuery ); })( jQuery );
/*
* Function to output a dialog bog for copy/paste
*
* @param string text Text to put into copy/paste area
* @param string text2 Text to put under the copy/paste area
*/
function copyToClipboard(text,text2)
{
text = text.replace(/<br>/g,"\n");
var newElem = "<textarea id=\"coords\" style=\"border: none; width: 90%; height: 120px;\">"+text+"</textarea><br><br>"+text2;
$("#dialog").html(newElem);
$("#dialog").dialog();
$("#coords").select();
return false;
}
/* /*
* Timer for delayed keyup function * Timer for delayed keyup function
* *

View File

@@ -637,12 +637,12 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
print "</tr>"; print "</tr>";
$sql = "SELECT p.rowid, p.lastname, p.firstname, p.fk_pays, p.poste, p.phone, p.phone_mobile, p.fax, p.email, p.skype, p.statut "; $sql = "SELECT p.rowid, p.lastname, p.firstname, p.fk_pays as country_id, p.poste, p.phone, p.phone_mobile, p.fax, p.email, p.skype, p.statut ";
$sql .= ", p.civilite, p.address, p.zip, p.town"; $sql .= ", p.civilite, p.address, p.zip, p.town";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
$sql .= " WHERE p.fk_soc = ".$object->id; $sql .= " WHERE p.fk_soc = ".$object->id;
if ($search_status!='') $sql .= " AND p.statut = ".$db->escape($search_status); if ($search_status!='') $sql .= " AND p.statut = ".$db->escape($search_status);
if ($search_name) $sql .= " AND (p.lastname LIKE '%".$db->escape(strtolower($search_name))."%' OR p.firstname LIKE '%".$db->escape(strtolower($search_name))."%')"; if ($search_name) $sql .= " AND (p.lastname LIKE '%".$db->escape($search_name)."%' OR p.firstname LIKE '%".$db->escape($search_name)."%')";
$sql.= " ORDER BY $sortfield $sortorder"; $sql.= " ORDER BY $sortfield $sortorder";
dol_syslog('core/lib/company.lib.php :: show_contacts sql='.$sql,LOG_DEBUG); dol_syslog('core/lib/company.lib.php :: show_contacts sql='.$sql,LOG_DEBUG);
@@ -665,12 +665,13 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
$contactstatic->statut = $obj->statut; $contactstatic->statut = $obj->statut;
$contactstatic->lastname = $obj->lastname; $contactstatic->lastname = $obj->lastname;
$contactstatic->firstname = $obj->firstname; $contactstatic->firstname = $obj->firstname;
$contactstatic->civilite = $obj->civilite;
print $contactstatic->getNomUrl(1); print $contactstatic->getNomUrl(1);
print '</td>'; print '</td>';
print '<td>'.$obj->poste.'</td>'; print '<td>'.$obj->poste.'</td>';
$country_code = getCountry($obj->fk_pays, 'all'); $country_code = getCountry($obj->country_id, 'all');
// Lien click to dial // Lien click to dial
print '<td>'; print '<td>';
@@ -695,41 +696,26 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
// Status // Status
print '<td>'.$contactstatic->getLibStatut(5).'</td>'; print '<td>'.$contactstatic->getLibStatut(5).'</td>';
// Copy to clipboard print '<td align="center">';
$coords = ''; if (! empty($conf->use_javascript_ajax))
if (!empty($object->name)) {
$coords .= addslashes($object->name)."<br />"; // Copy to clipboard
if (!empty($obj->civilite)) $coords = '';
$coords .= addslashes($obj->civilite).' '; if (!empty($object->name)) $coords .= $object->name."<br>";
if (!empty($obj->firstname)) $coords .= $contactstatic->getFullName($langs,1).' ';
$coords .= addslashes($obj->firstname).' '; $coords .= "<br>";
if (!empty($obj->lastname)) if (!empty($obj->address))
$coords .= addslashes($obj->lastname); {
$coords .= "<br />"; $coords .= dol_nl2br($obj->address,1,true)."<br>";
if (!empty($obj->address)) if (!empty($obj->zip)) $coords .= $obj->zip.' ';
{ if (!empty($obj->town)) $coords .= $obj->town;
$coords .= addslashes(dol_nl2br($obj->address,1,true))."<br />"; if (!empty($obj->country_id)) $coords .= "<br>".$country_code['label'];
if (!empty($obj->cp)) }
$coords .= addslashes($obj->zip).' '; print '<a href="#" onclick="return copyToClipboard(\''.dol_escape_js($coords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
if (!empty($obj->ville)) print img_picto($langs->trans("Address"), 'object_address.png');
$coords .= addslashes($obj->town); print '</a>';
if (!empty($obj->pays)) }
$coords .= "<br />".addslashes($country_code['label']); print '</td>';
}
elseif (!empty($object->address))
{
$coords .= addslashes(dol_nl2br($object->address,1,true))."<br />";
if (!empty($object->zip))
$coords .= addslashes($object->zip).' ';
if (!empty($object->town))
$coords .= addslashes($object->town);
if (!empty($object->country))
$coords .= "<br />".addslashes($object->country);
}
print '<td align="center"><a href="#" onclick="return copyToClipboard(\''.$coords.'\');">';
print img_picto($langs->trans("Address"), 'object_address.png');
print '</a></td>';
// Add to agenda // Add to agenda
if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create) if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
@@ -761,7 +747,7 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
} }
} }
else else
{ {
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
print '<td colspan="'.$colspan.'">'.$langs->trans("None").'</td>'; print '<td colspan="'.$colspan.'">'.$langs->trans("None").'</td>';
print "</tr>\n"; print "</tr>\n";
@@ -775,16 +761,6 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
<div id="dialog" title="<?php echo dol_escape_htmltag($langs->trans('Address')); ?>" style="display: none;"> <div id="dialog" title="<?php echo dol_escape_htmltag($langs->trans('Address')); ?>" style="display: none;">
</div> </div>
<?php <?php
print '<script type="text/javascript">
function copyToClipboard (text) {
text = text.replace(/<br \/>/g,"\n");
var newElem = "<textarea id=\"coords\" style=\"border: none; width: 90%; height: 120px;\">"+text+"</textarea><br/><br/>'.$langs->trans('HelpCopyToClipboard').'";
$("#dialog").html(newElem);
$( "#dialog" ).dialog();
$("#coords").select();
return false;
}
</script>';
return $i; return $i;
} }

View File

@@ -438,7 +438,7 @@ function dol_string_nospecial($str,$newstr='_',$badchars='')
* Returns text escaped for inclusion into javascript code * Returns text escaped for inclusion into javascript code
* *
* @param string $stringtoescape String to escape * @param string $stringtoescape String to escape
* @param string $mode 0=Escape also ' and " into ', 1=Escape ' but not " for usage into 'string', 2=Escape " but not ' for usage into "string" * @param string $mode 0=Escape also ' and " into ', 1=Escape ' but not " for usage into 'string', 2=Escape " but not ' for usage into "string", 3=Escape ' and " with \
* @return string Escaped string. Both ' and " are escaped into ' if they are escaped. * @return string Escaped string. Both ' and " are escaped into ' if they are escaped.
*/ */
function dol_escape_js($stringtoescape, $mode=0) function dol_escape_js($stringtoescape, $mode=0)
@@ -449,6 +449,7 @@ function dol_escape_js($stringtoescape, $mode=0)
if (empty($mode)) { $substitjs["'"]="\\'"; $substitjs['"']="\\'"; } if (empty($mode)) { $substitjs["'"]="\\'"; $substitjs['"']="\\'"; }
else if ($mode == 1) $substitjs["'"]="\\'"; else if ($mode == 1) $substitjs["'"]="\\'";
else if ($mode == 2) { $substitjs['"']='\\"'; } else if ($mode == 2) { $substitjs['"']='\\"'; }
else if ($mode == 3) { $substitjs["'"]="\\'"; $substitjs['"']="\\\""; }
return strtr($stringtoescape, $substitjs); return strtr($stringtoescape, $substitjs);
} }