Skip to content

Commit

Permalink
[#1788]: Refactoring to centralise uploading in application.js; ckanj…
Browse files Browse the repository at this point in the history
…s.js is not used here now.
  • Loading branch information
teajaymars committed Mar 30, 2012
1 parent cf6e3cd commit 1f3e243
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
40 changes: 12 additions & 28 deletions ckan/public/scripts/application.js
@@ -1,5 +1,9 @@
var CKAN = CKAN || {};

CKAN.View = CKAN.View || {};
CKAN.Model = CKAN.Model || {};
CKAN.Utils = CKAN.Utils || {};

/* ================================= */
/* == Initialise CKAN Application == */
/* ================================= */
Expand All @@ -17,15 +21,6 @@ var CKAN = CKAN || {};
CKAN.Utils.setupMarkdownEditor($('.markdown-editor'));
// bootstrap collapse
$('.collapse').collapse({toggle: false});
// set up ckan js
var config = {
endpoint: CKAN.SITE_URL + '/'
};
var client = new CKAN.Client(config);
// serious hack to deal with hacky code in ckanjs
CKAN.UI.workspace = {
client: client
};

// Buttons with href-action should navigate when clicked
$('input.href-action').click(function(e) {
Expand Down Expand Up @@ -282,8 +277,7 @@ CKAN.View.ResourceEditor = Backbone.View.extend({
});
new CKAN.View.ResourceAddUpload({
collection: this.collection,
el: this.el.find('.js-add-upload-form'),
client: CKAN.UI.workspace.client
el: this.el.find('.js-add-upload-form')
});


Expand Down Expand Up @@ -670,29 +664,18 @@ CKAN.View.Resource = Backbone.View.extend({
CKAN.View.ResourceAddUpload = Backbone.View.extend({
tagName: 'div',

// expects a client arguments in its options
initialize: function(options) {
this.el = $(this.el);
this.client = options.client;
_.bindAll(this, 'render', 'updateFormData', 'setMessage', 'uploadFile');
this.render();
$(CKAN.Templates.resourceUpload).appendTo(this.el);
this.$messages = this.el.find('.alert');
this.setupFileUpload();
},

events: {
'click input[type="submit"]': 'uploadFile'
},

render: function () {
this.el.empty();
tmplData = {
}
var tmpl = $.tmpl(CKAN.Templates.resourceUpload, tmplData).appendTo(this.el);
//this.el.append($(tmpl[0]));
this.$messages = this.el.find('.alert');
this.setupFileUpload();
return this;
},

setupFileUpload: function() {
var self = this;
this.el.find('.fileupload').fileupload({
Expand Down Expand Up @@ -750,7 +733,8 @@ CKAN.View.ResourceAddUpload = Backbone.View.extend({
var self = this;
self.setMessage('Checking upload permissions ... <img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" class="spinner" />');
self.el.find('.fileinfo').text(key);
self.client.getStorageAuthForm(key, {
$.ajax({
url: CKAN.SITE_URL + '/api/storage/auth/form/' + key,
async: false,
success: function(data) {
self.el.find('form').attr('action', data.action);
Expand Down Expand Up @@ -780,8 +764,8 @@ CKAN.View.ResourceAddUpload = Backbone.View.extend({

onUploadComplete: function(key) {
var self = this;
self.client.apiCall({
offset: '/storage/metadata/' + self.key,
$.ajax({
url: CKAN.SITE_URL + '/api/storage/metadata/' + self.key,
success: function(data) {
var name = data._label;
if (name && name.length > 0 && name[0] === '/') {
Expand Down
3 changes: 3 additions & 0 deletions ckan/public/scripts/templates.js
@@ -1,3 +1,6 @@
var CKAN = CKAN || {};
CKAN.Templates = CKAN.Templates || {};

CKAN.Templates.resourceUpload = ' \
<div class="fileupload"> \
<form action="http://test-ckan-net-storage.commondatastorage.googleapis.com/" class="resource-upload" \
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/layout_base.html
Expand Up @@ -227,7 +227,7 @@ <h3 class="widget-title">Meta</h3>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/jqueryui/1.8.14/jquery-ui.min.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/bootstrap/2.0.2/bootstrap.min.js')}"></script>

<!-- for ckanjs etc -->
<!-- for application.js -->
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/underscore/1.1.6/underscore.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/backbone/0.5.1/backbone.js')}"></script>
<script type="text/javascript" src="${h.url_for_static('/scripts/vendor/jquery.fileupload/20110801/jquery.iframe-transport.js')}"></script>
Expand Down

0 comments on commit 1f3e243

Please sign in to comment.