Skip to content

Commit

Permalink
new module style for json preview
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Sep 22, 2012
1 parent 419df38 commit 6ea5421
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
40 changes: 11 additions & 29 deletions 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 || {});
});
10 changes: 7 additions & 3 deletions ckan/templates/package/resource_jsonpreview.html
Expand Up @@ -5,13 +5,17 @@
{% block subtitle %}{{ h.dataset_display_name(c.package) }} - {{ h.resource_display_name(res) }}{% endblock %}

{% block page %}
<pre id="ckanext-jsonpreview">
{{_('loading...')}}
</pre>
<div>
<pre data-module="jsonpreview">
{{_('loading...')}}
</pre>
</div>
{% endblock %}

{% block scripts %}
{{ super() }}
{% resource 'base/main' %}
{% resource 'vendor/vendor' %}
{% resource 'datapreview/jsonpreview' %}

<script>
Expand Down

0 comments on commit 6ea5421

Please sign in to comment.