Item13898: JQueryAjaxHelper jumpbox code does not work with short URLs

pencil
Priority: Urgent
Current State: Closed
Released In: 2.1.0
Target Release: minor
Applies To: Extension
Component: JQueryPlugin
Branches: Item13898 master Release02x00 Item13897
Reported By: GeorgeClark
Waiting For:
Last Change By: GeorgeClark
The javascript code
source: foswiki.getPreference('SCRIPTURL') + '/view/' + foswiki.getPreference('SYSTEMWEB') + "/JQueryAjaxHelper?...
always resolves to a "bin/view" URL which redirects if the site is using short URLs.

-- GeorgeClark - 19 Dec 2015

Deleted my last comment - found the issue, so after a wasted afternoon, foswiki.getScriptUrl() is being called and ... wait for it ... returning full length URLs, not short URLs.

It appears that it is looking for a variable SCRIPTURL_VIEW, which is not in the environment. So it happily concatenates back together the bin / view / ... generating a long URL.

How is this supposed to work.

So not only is JQueryAjaxHelper broken, so is foswiki.getScriptUrl() ... This is a blocker for 2.0.4 and 2.1.

-- GeorgeClark - 05 Jan 2016

Getting closer. With the following patch, Short URLs are generated, and there is no more redirecting. But the "Topic" server side is returning malformed data when used by the jumpbox. So something still isn't right.

diff --git a/JQueryPlugin/data/System/JQueryAjaxHelper.txt b/JQueryPlugin/data/System/JQueryAjaxHelper.txt
index 10e81bb..3037a9c 100644
--- a/JQueryPlugin/data/System/JQueryAjaxHelper.txt
+++ b/JQueryPlugin/data/System/JQueryAjaxHelper.txt
@@ -160,9 +160,9 @@ jQuery(function($){
     var $this = $(this), 
         opts = $.extend({}, $this.metadata());
     $this.autocomplete({
-      source: foswiki.getPreference('SCRIPTURL') + '/view/' + foswiki.getPreference('SYSTEMWEB') + "/JQueryAjaxHelper?section=topic;skin=text;contenttype=application/json;baseweb="+opts.baseweb+";format="+opts.format,
+      source: foswiki.getScriptUrl('view', foswiki.getPreference('SYSTEMWEB'), 'JQueryAjaxHelper') + "?section=topic;skin=text;contenttype=application/json;baseweb="+opts.baseweb+";format="+opts.format,
       select: function(event, ui) {
-        window.location.href=foswiki.getPreference('SCRIPTURL') + '/view/'+(opts.global?'':opts.baseweb+'/')+ui.item.value;
+        window.location.href=foswiki.getScriptUrl('view', (opts.global?'':opts.baseweb+''), ui.item.value);
       }
     });
   });
@@ -291,7 +291,7 @@ or later).
 <script type=\"text/javascript\">
 jQuery(function($){
   $(\"#%ID%\").click(function() {
-     $.get(foswiki.getPreference('SCRIPTURL') + '/view/' + foswiki.getPreference('SYSTEMWEB') + '/JQueryAjaxHelper?section=query;source=%SOURCE%;query=%QUERY%;skin=text',
+     $.get(foswiki.getScriptUrl('view', foswiki.getPreference('SYSTEMWEB'), 'JQueryAjaxHelper', '?section=query;source=%SOURCE%;query=%QUERY%;skin=text'),
          function(data) {
              // This is the function that will be executed when the
              // data is fetched
diff --git a/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm b/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
index 42e4058..05dfcfc 100644
--- a/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
+++ b/JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
@@ -89,6 +89,15 @@ sub init {
           Foswiki::Func::expandCommonVariables( '%' . $pref . '%' );
     }
 
+    foreach my $script ( keys %{ $Foswiki::cfg{ScriptUrlPaths} } ) {
+        $prefs{ 'SCRIPTURL_' . uc($script) } =
+          Foswiki::Func::expandCommonVariables(
+            '%SCRIPTURL{' . $script . '}%' );
+        $prefs{ 'SCRIPTURLPATH_' . uc($script) } =
+          Foswiki::Func::expandCommonVariables(
+            '%SCRIPTURLPATH{' . $script . '}%' );
+    }
+
     my $text =
         "<script class='\$zone \$id foswikiPreferences' type='text/json'>"
       . JSON::to_json( \%prefs, { pretty => 1 } )

-- GeorgeClark - 06 Jan 2016

Added fix in item branch

-- MichaelDaum - 06 Jan 2016
 
Topic revision: r16 - 08 Feb 2016, GeorgeClark - This page was cached on 19 May 2017 - 11:28.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License