Relativizing URLs in JavaScript is slightly trickier than CSS. The strategy
here is to save our relative_url_root in a global JS variable in the topmost
application view template, then use that variable in all our included scripts.
---
app/views/layouts/application.html.haml | 2 ++
public/javascripts/application.js | 4 ++--
public/javascripts/node.js | 8 ++++----
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/app/views/layouts/application.html.haml
b/app/views/layouts/application.html.haml
index bb84873..7534a80 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -5,6 +5,8 @@
%title= [ page_title, 'Puppet Node Manager'].compact.join(' - ')
%link{ :href => "/images/favicon.ico", :rel => "shortcut icon" }
%meta{ :content => "text/html; charset=UTF-8", "http-equiv" =>
"Content-Type" }
+ :javascript
+ var relative_url_root = '#{ActionController::Base.relative_url_root}';
= javascript_include_tag
'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'
= javascript_include_tag :all
= stylesheet_link_tag 'reset', 'layout', 'application', 'header', 'forms',
'tables', 'jquery.ui.autocomplete.css', 'reports', 'typography', 'links',
'fcbkcomplete'
diff --git a/public/javascripts/application.js
b/public/javascripts/application.js
index 99df68e..25ff97e 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -85,8 +85,8 @@ $(document).ready(function() {
return val.toString() + '%'
}}});
- $('#node_group_names').facebooklist('#existing_node_groups',
{url:'/node_groups.json',cache:0}, 10, {userfilter:1,casesensetive:0}, 0);
- $('#node_class_names').facebooklist('#existing_node_classes',
{url:'/node_classes.json',cache:0}, 10, {userfilter:1,casesensetive:0}, 0);
+ $('#node_group_names').facebooklist('#existing_node_groups',
{url:relative_url_root+'/node_groups.json',cache:0}, 10,
{userfilter:1,casesensetive:0}, 0);
+ $('#node_class_names').facebooklist('#existing_node_classes',
{url:relative_url_root+'/node_classes.json',cache:0}, 10,
{userfilter:1,casesensetive:0}, 0);
$('a.in-place').click(function() {
$(this).parents('.header').hide().next('.in-place').show().find('input[type=text]').focus();
diff --git a/public/javascripts/node.js b/public/javascripts/node.js
index 4e7c41b..45e874b 100644
--- a/public/javascripts/node.js
+++ b/public/javascripts/node.js
@@ -36,13 +36,13 @@ jQuery(function($) {
$('input.node-group-search')
.autocomplete({
- ajax: '/node_groups/search.json',
+ ajax: relative_url_root+'/node_groups/search.json',
match: function(typed) { return true; },
insertText: function(node_group) { return node_group.node_group.name; }
})
.bind('activate.autocomplete', function(e, node_group) {
var item = node_group.node_group;
- var tr = "<tr class='node_group'><td class='key'><a
href='/node_groups/"+item.id+"'>"+item.name+"</a></td><td>"+item.description+"<input
type='hidden' name='node[node_groups[]' value='"+item.id+"'/></td><td
class='actions'><a class='icon delete'
href='#'><span>(add)</span></a></td></tr>";
+ var tr = "<tr class='node_group'><td class='key'><a
href='"+relative_url_root+"/node_groups/"+item.id+"'>"+item.name+"</a></td><td>"+item.description+"<input
type='hidden' name='node[node_groups[]' value='"+item.id+"'/></td><td
class='actions'><a class='icon delete'
href='#'><span>(add)</span></a></td></tr>";
$(e.target)
.attr('value', '')
.parents('table').find('tbody').append(tr);
@@ -50,13 +50,13 @@ jQuery(function($) {
$.fn.node_class_search = function(object_name) {
return this.autocomplete({
- ajax: '/node_classes/search.json',
+ ajax: relative_url_root+'/node_classes/search.json',
match: function(typed) { return true; },
insertText: function(node_class) { return node_class.node_class.name; }
})
.bind('activate.autocomplete', function(e, node_class) {
var item = node_class.node_class
- var tr = "<tr class='node_class'><td class='key'><a
href='/node_classes/"+item.id+"'>"+item.name+"</a></td><td>"+item.description+"<input
type='hidden' name='"+object_name+"[node_classes[]'
value='"+item.id+"'/></td><td class='actions'><a class='icon delete'
href='#'><span>(add)</span></a></td></tr>";
+ var tr = "<tr class='node_class'><td class='key'><a
href='"+relative_url_root+"/node_classes/"+item.id+"'>"+item.name+"</a></td><td>"+item.description+"<input
type='hidden' name='"+object_name+"[node_classes[]'
value='"+item.id+"'/></td><td class='actions'><a class='icon delete'
href='#'><span>(add)</span></a></td></tr>";
$(e.target)
.attr('value', '')
--
1.7.0.2
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.