From 0524e5742ffcc7378943e40a5071aeb535ab9f33 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 31 Jul 2014 13:57:40 -0500
Subject: [PATCH] redactor: No more link shortening

Also add a drop-down list of common links include ticket links and login
pages for both agents and end users.
---
 include/ajax.config.php | 15 +++++++++++++++
 js/redactor-osticket.js |  4 +++-
 scp/ajax.php            |  3 ++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/include/ajax.config.php b/include/ajax.config.php
index 82d92f1ca..119264c35 100644
--- a/include/ajax.config.php
+++ b/include/ajax.config.php
@@ -48,5 +48,20 @@ class ConfigAjaxAPI extends AjaxController {
 
         return $config;
     }
+
+    function templateLinks() {
+        $links = $this->json_encode(array(
+            array('name'=>'Select ...', 'url'=> false),
+            array('name'=>'Agent Ticket Link', 'url'=> '%{ticket.staff_link}'),
+            array('name'=>'Agent Login Page', 'url'=> '%{url}/scp'),
+            array('name'=>'End-User Ticket Link', 'url'=> '%{recipient.ticket_link}'),
+            array('name'=>'End-User Login Page', 'url'=> '%{url}/login.php'),
+        ));
+
+        Http::cacheable(md5($links), filemtime(__file__));
+        header('Content-Type: application/json; charset=UTF-8');
+
+        return $links;
+    }
 }
 ?>
diff --git a/js/redactor-osticket.js b/js/redactor-osticket.js
index e96d92a07..48d6a4597 100644
--- a/js/redactor-osticket.js
+++ b/js/redactor-osticket.js
@@ -241,7 +241,9 @@ $(function() {
                 'linebreaks': true,
                 'tabFocus': false,
                 'toolbarFixedBox': true,
-                'focusCallback': function() { this.$box.addClass('no-pjax'); }
+                'focusCallback': function() { this.$box.addClass('no-pjax'); },
+                'linkSize': 100000,
+                'predefinedLinks': 'ajax.php/config/links'
             }, options||{});
         if (el.data('redactor')) return;
         var reset = $('input[type=reset]', el.closest('form'));
diff --git a/scp/ajax.php b/scp/ajax.php
index a192cce8c..ab7708e0b 100644
--- a/scp/ajax.php
+++ b/scp/ajax.php
@@ -48,7 +48,8 @@ $dispatcher = patterns('',
         url_post('^(?P<id>\d+)(?:/(?P<lang>\w+))?$', 'updateContent')
     )),
     url('^/config/', patterns('ajax.config.php:ConfigAjaxAPI',
-        url_get('^scp', 'scp')
+        url_get('^scp', 'scp'),
+        url_get('^links', 'templateLinks')
     )),
     url('^/form/', patterns('ajax.forms.php:DynamicFormsAjaxAPI',
         url_get('^help-topic/(?P<id>\d+)$', 'getFormsForHelpTopic'),
-- 
GitLab