Skip to content

Commit

Permalink
Qual: Move common javascript function into lib_head.js
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Feb 19, 2014
1 parent 03a6023 commit 8c9d241
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 50 deletions.
18 changes: 18 additions & 0 deletions htdocs/core/js/lib_head.js
Expand Up @@ -899,6 +899,24 @@ function confirmConstantAction(action, url, code, input, box, entity, yesButton,
});
})( 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
*
Expand Down
74 changes: 25 additions & 49 deletions htdocs/core/lib/company.lib.php
Expand Up @@ -637,12 +637,12 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
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 .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
$sql .= " WHERE p.fk_soc = ".$object->id;
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";

dol_syslog('core/lib/company.lib.php :: show_contacts sql='.$sql,LOG_DEBUG);
Expand All @@ -665,12 +665,13 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
$contactstatic->statut = $obj->statut;
$contactstatic->lastname = $obj->lastname;
$contactstatic->firstname = $obj->firstname;
$contactstatic->civilite = $obj->civilite;
print $contactstatic->getNomUrl(1);
print '</td>';

print '<td>'.$obj->poste.'</td>';

$country_code = getCountry($obj->fk_pays, 'all');
$country_code = getCountry($obj->country_id, 'all');

// Lien click to dial
print '<td>';
Expand All @@ -695,41 +696,26 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
// Status
print '<td>'.$contactstatic->getLibStatut(5).'</td>';

// Copy to clipboard
$coords = '';
if (!empty($object->name))
$coords .= addslashes($object->name)."<br />";
if (!empty($obj->civilite))
$coords .= addslashes($obj->civilite).' ';
if (!empty($obj->firstname))
$coords .= addslashes($obj->firstname).' ';
if (!empty($obj->lastname))
$coords .= addslashes($obj->lastname);
$coords .= "<br />";
if (!empty($obj->address))
{
$coords .= addslashes(dol_nl2br($obj->address,1,true))."<br />";
if (!empty($obj->cp))
$coords .= addslashes($obj->zip).' ';
if (!empty($obj->ville))
$coords .= addslashes($obj->town);
if (!empty($obj->pays))
$coords .= "<br />".addslashes($country_code['label']);
}
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>';
print '<td align="center">';
if (! empty($conf->use_javascript_ajax))
{
// Copy to clipboard
$coords = '';
if (!empty($object->name)) $coords .= $object->name."<br>";
$coords .= $contactstatic->getFullName($langs,1).' ';
$coords .= "<br>";
if (!empty($obj->address))
{
$coords .= dol_nl2br($obj->address,1,true)."<br>";
if (!empty($obj->zip)) $coords .= $obj->zip.' ';
if (!empty($obj->town)) $coords .= $obj->town;
if (!empty($obj->country_id)) $coords .= "<br>".$country_code['label'];
}
print '<a href="#" onclick="return copyToClipboard(\''.dol_escape_js($coords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
print img_picto($langs->trans("Address"), 'object_address.png');
print '</a>';
}
print '</td>';

// Add to agenda
if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
Expand Down Expand Up @@ -761,7 +747,7 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
}
}
else
{
{
print "<tr ".$bc[$var].">";
print '<td colspan="'.$colspan.'">'.$langs->trans("None").'</td>';
print "</tr>\n";
Expand All @@ -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>
<?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;
}
Expand Down
3 changes: 2 additions & 1 deletion htdocs/core/lib/functions.lib.php
Expand Up @@ -438,7 +438,7 @@ function dol_string_nospecial($str,$newstr='_',$badchars='')
* Returns text escaped for inclusion into javascript code
*
* @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.
*/
function dol_escape_js($stringtoescape, $mode=0)
Expand All @@ -449,6 +449,7 @@ function dol_escape_js($stringtoescape, $mode=0)
if (empty($mode)) { $substitjs["'"]="\\'"; $substitjs['"']="\\'"; }
else if ($mode == 1) $substitjs["'"]="\\'";
else if ($mode == 2) { $substitjs['"']='\\"'; }
else if ($mode == 3) { $substitjs["'"]="\\'"; $substitjs['"']="\\\""; }
return strtr($stringtoescape, $substitjs);
}

Expand Down

0 comments on commit 8c9d241

Please sign in to comment.