From 51d3d2407e9221b2fe6cf945ac94cdaa7178c8d4 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 14 Nov 2014 18:03:13 -0600
Subject: [PATCH] i18n: Let the browser truncate long texts

This helps in long UTF-8 characters as the bytes were previously counted and
the width of the characters was assumed to correlate with the count of the
bytes in the text. This method allows the browser to calmly truncate the
text according to the available space in the page where the text is
rendered.
---
 assets/default/css/theme.css             | 12 +++++++++++-
 include/client/tickets.inc.php           |  8 ++++----
 include/staff/templates/tickets.tmpl.php | 11 ++++++-----
 include/staff/ticket-view.inc.php        |  4 ++--
 include/staff/tickets.inc.php            | 21 +++++++++++----------
 scp/css/scp.css                          |  8 ++++++++
 6 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/assets/default/css/theme.css b/assets/default/css/theme.css
index e50724e19..ebc3ca69b 100644
--- a/assets/default/css/theme.css
+++ b/assets/default/css/theme.css
@@ -749,6 +749,7 @@ label.required {
   border: 1px solid #aaa;
   border-left: none;
   border-bottom: none;
+  table-layout: fixed;
 }
 #ticketTable caption {
   padding: 5px;
@@ -766,12 +767,13 @@ label.required {
   border: 1px solid #aaa;
   border-right: none;
   border-top: none;
+  padding: 0 5px;
 }
 #ticketTable th a {
   color: #000;
 }
 #ticketTable td {
-  padding: 2px;
+  padding: 3px 5px;
   border: 1px solid #aaa;
   border-right: none;
   border-top: none;
@@ -935,3 +937,11 @@ img.sign-in-image {
 .flush-left {
     text-align: left;
 }
+.truncate {
+    display: inline-block;
+    width: auto;
+    max-width: 100%;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+}
diff --git a/include/client/tickets.inc.php b/include/client/tickets.inc.php
index 6b8e9df1a..190cefa8e 100644
--- a/include/client/tickets.inc.php
+++ b/include/client/tickets.inc.php
@@ -162,9 +162,9 @@ $negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting
         $defaultDept=Dept::getDefaultDeptName(); //Default public dept.
         while ($row = db_fetch_array($res)) {
             $dept= $row['ispublic']? $row['dept_name'] : $defaultDept;
-            $subject = Format::truncate($subject_field->display(
+            $subject = $subject_field->display(
                 $subject_field->to_php($row['subject']) ?: $row['subject']
-            ), 40);
+            );
             if($row['attachments'])
                 $subject.='  &nbsp;&nbsp;<span class="Icon file"></span>';
 
@@ -182,9 +182,9 @@ $negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting
                 <td>&nbsp;<?php echo Format::db_date($row['created']); ?></td>
                 <td>&nbsp;<?php echo $row['status']; ?></td>
                 <td>
-                    <a href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $subject; ?></a>
+                    <a class="truncate" href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $subject; ?></a>
                 </td>
-                <td>&nbsp;<?php echo Format::truncate($dept,30); ?></td>
+                <td>&nbsp;<span class="truncate"><?php echo $dept; ?></span></td>
             </tr>
         <?php
         }
diff --git a/include/staff/templates/tickets.tmpl.php b/include/staff/templates/tickets.tmpl.php
index ea0aae0b7..d56bc5c70 100644
--- a/include/staff/templates/tickets.tmpl.php
+++ b/include/staff/templates/tickets.tmpl.php
@@ -116,15 +116,15 @@ if ($results) { ?>
 
         $assigned='';
         if ($row['staff_id'])
-            $assigned=sprintf('<span class="Icon staffAssigned">%s</span>',Format::truncate($row['staff'],40));
+            $assigned=sprintf('<span class="truncate Icon staffAssigned">%s</span>',$row['staff']);
         elseif ($row['team_id'])
-            $assigned=sprintf('<span class="Icon teamAssigned">%s</span>',Format::truncate($row['team'],40));
+            $assigned=sprintf('<span class="truncate Icon teamAssigned">%s</span>',$row['team']);
         else
             $assigned=' ';
 
         $status = ucfirst($row['status']);
         $tid=$row['number'];
-        $subject = Format::htmlchars(Format::truncate($row['subject'],40));
+        $subject = Format::htmlchars($row['subject']);
         $threadcount=$row['thread_count'];
         ?>
         <tr id="<?php echo $row['ticket_id']; ?>">
@@ -142,7 +142,8 @@ if ($results) { ?>
                 href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $tid; ?></a></td>
             <td align="center" nowrap><?php echo Format::db_datetime($row['effective_date']); ?></td>
             <td><?php echo $status; ?></td>
-            <td><a <?php if ($flag) { ?> class="Icon <?php echo $flag; ?>Ticket" title="<?php echo ucfirst($flag); ?> Ticket" <?php } ?>
+            <td><a class="truncate <?php if ($flag) { ?> Icon <?php echo $flag; ?>Ticket" title="<?php echo ucfirst($flag); ?> Ticket<?php } ?>"
+                style="max-width: 80%; max-width: calc(100% - 86px);"
                 href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $subject; ?></a>
                  <?php
                     if ($threadcount>1)
@@ -156,7 +157,7 @@ if ($results) { ?>
             </td>
             <?php
             if ($user) { ?>
-            <td><?php echo Format::truncate($row['dept_name'], 40); ?></td>
+            <td><span class="truncate"><?php echo $row['dept_name']; ?></span></td>
             <td>&nbsp;<?php echo $assigned; ?></td>
             <?php
             } else { ?>
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 078af3a0a..83a425dbf 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -392,8 +392,8 @@ $tcount+= $ticket->getNumNotes();
                     <span class="pull-left">
                     <span style="display:inline-block"><?php
                         echo Format::db_datetime($entry['created']);?></span>
-                    <span style="display:inline-block;padding:0 1em" class="faded title"><?php
-                        echo Format::truncate($entry['title'], 100); ?></span>
+                    <span style="padding:0 1em; max-width: 500px" class="faded title truncate"><?php
+                        echo $entry['title']; ?></span>
                     </span>
                     <span class="pull-right" style="white-space:no-wrap;display:inline-block">
                         <span style="vertical-align:middle;" class="textra"></span>
diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php
index 70acec919..a1eb406fc 100644
--- a/include/staff/tickets.inc.php
+++ b/include/staff/tickets.inc.php
@@ -352,11 +352,11 @@ if ($results) {
  <input type="hidden" name="a" value="mass_process" >
  <input type="hidden" name="do" id="action" value="" >
  <input type="hidden" name="status" value="<?php echo Format::htmlchars($_REQUEST['status']); ?>" >
- <table class="list" border="0" cellspacing="1" cellpadding="2" width="940">
+ <table class="list fixed" border="0" cellspacing="1" cellpadding="2" width="940">
     <thead>
         <tr>
             <?php if($thisstaff->canManageTickets()) { ?>
-	        <th width="8px">&nbsp;</th>
+	        <th width="12">&nbsp;</th>
             <?php } ?>
 	        <th width="70">
                 <a <?php echo $id_sort; ?> href="tickets.php?sort=ID&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
@@ -423,19 +423,19 @@ if ($results) {
                 $lc='';
                 if($showassigned) {
                     if($row['staff_id'])
-                        $lc=sprintf('<span class="Icon staffAssigned">%s</span>',Format::truncate($row['staff'],40));
+                        $lc=sprintf('<span class="truncate Icon staffAssigned">%s</span>',$row['staff'],40);
                     elseif($row['team_id'])
-                        $lc=sprintf('<span class="Icon teamAssigned">%s</span>',Format::truncate($row['team'],40));
+                        $lc=sprintf('<span class="truncate Icon teamAssigned">%s</span>',$row['team'],40);
                     else
                         $lc=' ';
                 }else{
-                    $lc=Format::truncate($row['dept_name'],40);
+                    $lc=$row['dept_name'];
                 }
                 $tid=$row['number'];
 
-                $subject = Format::truncate($subject_field->display(
+                $subject = $subject_field->display(
                     $subject_field->to_php($row['subject']) ?: $row['subject']
-                ), 40);
+                );
                 $threadcount=$row['thread_count'];
                 if(!strcasecmp($row['state'],'open') && !$row['isanswered'] && !$row['lock_id']) {
                     $tid=sprintf('<b>%s</b>',$tid);
@@ -458,7 +458,9 @@ if ($results) {
                     href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $tid; ?></a></td>
                 <td align="center" nowrap><?php echo Format::db_datetime($row['effective_date']); ?></td>
                 <td><a <?php if ($flag) { ?> class="Icon <?php echo $flag; ?>Ticket" title="<?php echo ucfirst($flag); ?> Ticket" <?php } ?>
-                    href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><?php echo $subject; ?></a>
+                    style="max-width: 80%; max-width: calc(100% - 86px);"
+                    href="tickets.php?id=<?php echo $row['ticket_id']; ?>"><span class="truncate"
+                    ><?php echo $subject; ?></span></a>
                      <?php
                         if ($threadcount>1)
                             echo "<small>($threadcount)</small>&nbsp;".'<i
@@ -469,8 +471,7 @@ if ($results) {
                             echo '<i class="icon-fixed-width icon-paperclip"></i>&nbsp;';
                     ?>
                 </td>
-                <td nowrap>&nbsp;<?php echo Format::htmlchars(
-                        Format::truncate($row['name'], 22, strpos($row['name'], '@'))); ?>&nbsp;</td>
+                <td nowrap><span class="truncate"><?php echo Format::htmlchars($row['name']); ?></span></td>
                 <?php
                 if($search && !$status){
                     $displaystatus=ucfirst($row['status']);
diff --git a/scp/css/scp.css b/scp/css/scp.css
index 2fe63818d..eb132a809 100644
--- a/scp/css/scp.css
+++ b/scp/css/scp.css
@@ -1956,3 +1956,11 @@ table.custom-info td {
 .required {
     font-weight: bold;
 }
+.truncate {
+    display: inline-block;
+    width: auto;
+    max-width: 100%;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+}
-- 
GitLab