From 03df3233284e732ee3e57fd0c7aaba11be19d153 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 14 May 2014 18:14:28 -0500
Subject: [PATCH] Rework the layout of the email template edit page

---
 include/class.template.php |  3 +-
 include/staff/tpl.inc.php  | 69 ++++++++++++++++++--------------------
 scp/js/tips.js             | 10 ++++--
 3 files changed, 42 insertions(+), 40 deletions(-)

diff --git a/include/class.template.php b/include/class.template.php
index 4394c0fc1..d73640cf6 100644
--- a/include/class.template.php
+++ b/include/class.template.php
@@ -518,7 +518,8 @@ class EmailTemplate {
         $inst = self::lookup(self::create($vars, $errors));
 
         // Inline images (attached to the draft)
-        $inst->attachments->upload(Draft::getAttachmentIds($inst->getBody()), true);
+        if ($inst)
+            $inst->attachments->upload(Draft::getAttachmentIds($inst->getBody()), true);
 
         return $inst;
     }
diff --git a/include/staff/tpl.inc.php b/include/staff/tpl.inc.php
index 650b70ad3..5146b5c47 100644
--- a/include/staff/tpl.inc.php
+++ b/include/staff/tpl.inc.php
@@ -34,12 +34,12 @@ if (is_a($template, EmailTemplateGroup)) {
 $tpl=$msgtemplates[$selected];
 
 ?>
-<h2>Email Template Message - <span><?php echo $name; ?></span></h2>
-<div style="padding-top:10px;padding-bottom:5px;">
-    <form method="get" action="templates.php?">
+<form method="get" action="templates.php?">
+<h2><span>Email Template Set &nbsp;/&nbsp; <span><a href="templates.php?tpl_id=<?php echo $tpl_id; ?>"><?php echo $name; ?></a>
     <input type="hidden" name="a" value="manage">
     <input type="hidden" name="tpl_id" value="<?php echo $tpl_id; ?>">
-    Message Template:
+<div class="pull-right">
+    <span style="font-size:10pt">Viewing:</span>
     <select id="tpl_options" name="id" style="width:300px;">
         <option value="">&mdash; Select Setting Group &mdash;</option>
         <?php
@@ -70,9 +70,10 @@ $tpl=$msgtemplates[$selected];
         ?>
     </select>
     <input type="submit" value="Go">
-    &nbsp;&nbsp;&nbsp;<font color="red"><?php echo $errors['tpl']; ?></font>
-    </form>
-</div>
+    </div>
+</h2>
+</form>
+<hr/>
 <form action="templates.php?id=<?php echo $id; ?>&amp;a=manage" method="post" id="save">
 <?php csrf_token(); ?>
 <?php foreach ($extras as $k=>$v) { ?>
@@ -82,36 +83,30 @@ $tpl=$msgtemplates[$selected];
 <input type="hidden" name="a" value="manage">
 <input type="hidden" name="do" value="<?php echo $action; ?>">
 
-<table class="form_table settings_table" width="940" border="0" cellspacing="0" cellpadding="2">
-   <thead>
-     <tr>
-        <th colspan="2">
-            <h4><?php echo Format::htmlchars($desc['desc']); ?></h4>
-            <em>Subject and body required.  <a class="tip" href="#ticket_variables.txt">Supported Variables</a>.</em>
-        </th>
-     </tr>
-    </thead>
-    <tbody>
-        <tr>
-            <td colspan=2>
-                <strong>Message Subject:</strong> <em>Email message subject</em> <font class="error">*&nbsp;<?php echo $errors['subject']; ?></font><br>
-                <input type="text" name="subject" size="60" value="<?php echo $info['subject']; ?>" >
-            </td>
-        </tr>
-        <tr>
-            <td colspan="2">
-                <div style="margin-bottom:0.5em;margin-top:0.5em">
-                <strong>Message Body:</strong> <em>Email message body.</em> <font class="error">*&nbsp;<?php echo $errors['body']; ?></font>
-                </div>
-                <input type="hidden" name="draft_id" value=""/>
-                <textarea name="body" cols="21" rows="16" style="width:98%;" wrap="soft"
-                    class="richtext draft" data-draft-namespace="tpl.<?php echo $selected; ?>"
-                    data-draft-object-id="<?php echo $tpl_id; ?>"><?php echo $info['body']; ?></textarea>
-            </td>
-        </tr>
-    </tbody>
-</table>
-<p style="padding-left:210px;">
+<p>
+<h3 style="font-size:12pt;"><?php echo $desc['name']; ?>
+    &nbsp;<i class="help-tip icon-question-sign"
+        data-content="<?php echo Format::htmlchars($desc['desc']); ?>"
+        data-title="<?php echo Format::htmlchars($desc['name']); ?>"></i>
+    <a style="font-size:10pt" class="tip pull-right" href="#ticket_variables.txt">Supported Variables</a>
+    </h3>
+<?php if ($errors) { ?>
+    <font class="error"><?php echo $errors['subject']; ?>&nbsp;<?php echo $errors['body']; ?></font>
+<?php } ?>
+</p>
+
+<div>
+    <input type="text" name="subject" size="65" value="<?php echo $info['subject']; ?>"
+    style="font-size:14pt">
+    <div style="margin-bottom:0.5em;margin-top:0.5em">
+    </div>
+    <input type="hidden" name="draft_id" value=""/>
+    <textarea name="body" cols="21" rows="16" style="width:98%;" wrap="soft"
+        class="richtext draft" data-draft-namespace="tpl.<?php echo $selected; ?>"
+        data-draft-object-id="<?php echo $tpl_id; ?>"><?php echo $info['body']; ?></textarea>
+</div>
+
+<p style="text-align:center">
     <input class="button" type="submit" name="submit" value="Save Changes">
     <input class="button" type="reset" name="reset" value="Reset Changes" onclick="javascript:
         setTimeout('location.reload()', 25);" />
diff --git a/scp/js/tips.js b/scp/js/tips.js
index ee7764f80..d59cdd842 100644
--- a/scp/js/tips.js
+++ b/scp/js/tips.js
@@ -111,8 +111,14 @@ jQuery(function() {
         });
 
         getHelpTips().then(function(tips) {
-            var section = tips[elem.attr('href').substr(1)];
-            if (!section) {
+            var href = elem.attr('href');
+            if (href) {
+                section = tips[elem.attr('href').substr(1)];
+            }
+            else if (elem.data('content')) {
+                section = {title: elem.data('title'), content: elem.data('content')};
+            }
+            else {
                 elem.remove();
                 clearTimeout(tip_timer);
                 return;
-- 
GitLab