From ab60f370626a33d51d3096ef67df717e6fb513e0 Mon Sep 17 00:00:00 2001 From: Tom Mortimer-Jones Date: Fri, 22 Jan 2016 14:05:27 +0000 Subject: [PATCH] [noticket] Don't try and load comments on the resource page --- ckanext/dgu/theme/src/scripts/dgu-package.js | 40 ++++++++++---------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/ckanext/dgu/theme/src/scripts/dgu-package.js b/ckanext/dgu/theme/src/scripts/dgu-package.js index 6ff845c24..7635984e3 100644 --- a/ckanext/dgu/theme/src/scripts/dgu-package.js +++ b/ckanext/dgu/theme/src/scripts/dgu-package.js @@ -66,24 +66,27 @@ $(function() { var spinDiv = $('.comments-spinner')[0]; var commentsSpinner = new Spinner(spinConfig).spin(spinDiv); - var url = '/comment/get/'+window.DATASET_ID+'?comments_per_page=999999'; - $.ajax({ - url: url, - data: '', - dataType: 'html', - success: function(data, textStatus, xhr) { - commentsSpinner.stop(); - $('#comments-container').html(data); - comments(); - }, - error: function(xhr, status, exception) { - commentsSpinner.stop(); - $(spinDiv).hide(); - $('#comments .boxed') - .append('Error loading comments: '+url+'

') - .append($('
').text(JSON.stringify(exception)));
-          }
-        });
+  // DATASET_ID is only set on dataset page, not on resource page.
+  if(DATASET_ID in window) {
+    var url = '/comment/get/'+window.DATASET_ID+'?comments_per_page=999999';
+    $.ajax({
+            url: url,
+            data: '',
+            dataType: 'html',
+            success: function(data, textStatus, xhr) {
+              commentsSpinner.stop();
+              $('#comments-container').html(data);
+              comments();
+            },
+            error: function(xhr, status, exception) {
+              commentsSpinner.stop();
+              $(spinDiv).hide();
+              $('#comments .boxed')
+                .append('Error loading comments: '+url+'

') + .append($('
').text(JSON.stringify(exception)));
+            }
+          });
+  }
 
   // Year segmentation
   $(".year .year_items").hide();
@@ -95,7 +98,6 @@ $(function() {
   // Show the first 'View Less' button
   $(".year .hideyear").first().show();
 
-
   // Show all but the first 'View More' button
   $(".year .showyear").show();
   $(".year .showyear").first().hide();