From 6ea5421513ef3b9e600906a3e2afb262391d6d5c Mon Sep 17 00:00:00 2001 From: Dominik Moritz Date: Sat, 22 Sep 2012 10:43:28 +0100 Subject: [PATCH] new module style for json preview --- ckan/public/base/datapreview/jsonpreview.js | 40 +++++-------------- .../package/resource_jsonpreview.html | 10 +++-- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/ckan/public/base/datapreview/jsonpreview.js b/ckan/public/base/datapreview/jsonpreview.js index ffa1b64cab9..6d0215db709 100644 --- a/ckan/public/base/datapreview/jsonpreview.js +++ b/ckan/public/base/datapreview/jsonpreview.js @@ -1,30 +1,12 @@ -var CKAN = CKAN || {}; - -(function ($) { - $(document).ready(function () { - CKAN.JsonPreview.loadPreview(preload_resource); - }); -}(jQuery)); - -/* ==================== */ -/* == JSON Previewer == */ -/* ==================== */ -CKAN.JsonPreview = function ($, my) { - my.dialogId = 'ckanext-jsonpreview'; - - // **Public: Loads the json preview ** - // - // Returns nothing. - my.loadPreview = function(resourceData) { - - $.getJSON(resourceData['url'], function(data) { - var html = JSON.stringify(data, null, 4); - $('#'+my.dialogId).html(html); - }); +// json preview module +ckan.module('jsonpreview', function (jQuery, _) { + return { + initialize: function () { + var self = this; + $.getJSON(preload_resource['url'], function(data) { + var html = JSON.stringify(data, null, 4); + $(self.el).html(html); + }); + } }; - - // Export the CKANEXT object onto the window. - $.extend(true, window, {CKANEXT: {}}); - CKANEXT.JSONPREVIEW = my; - return my; -}(jQuery, CKAN.JsonPreview || {}); +}); \ No newline at end of file diff --git a/ckan/templates/package/resource_jsonpreview.html b/ckan/templates/package/resource_jsonpreview.html index cab4a190d12..3af1c490951 100644 --- a/ckan/templates/package/resource_jsonpreview.html +++ b/ckan/templates/package/resource_jsonpreview.html @@ -5,13 +5,17 @@ {% block subtitle %}{{ h.dataset_display_name(c.package) }} - {{ h.resource_display_name(res) }}{% endblock %} {% block page %} -
-  	{{_('loading...')}}
-  
+
+
+	  	{{_('loading...')}}
+	  
+
{% endblock %} {% block scripts %} {{ super() }} + {% resource 'base/main' %} + {% resource 'vendor/vendor' %} {% resource 'datapreview/jsonpreview' %}