From 1f3e243d2494bb9f63d69dcad7e0593ca25d5255 Mon Sep 17 00:00:00 2001 From: Tom Rees Date: Fri, 30 Mar 2012 16:39:35 +0100 Subject: [PATCH] [#1788]: Refactoring to centralise uploading in application.js; ckanjs.js is not used here now. --- ckan/public/scripts/application.js | 40 +++++++++--------------------- ckan/public/scripts/templates.js | 3 +++ ckan/templates/layout_base.html | 2 +- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/ckan/public/scripts/application.js b/ckan/public/scripts/application.js index ab9832ed950..181c0a84f58 100644 --- a/ckan/public/scripts/application.js +++ b/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 == */ /* ================================= */ @@ -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) { @@ -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') }); @@ -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({ @@ -750,7 +733,8 @@ CKAN.View.ResourceAddUpload = Backbone.View.extend({ var self = this; self.setMessage('Checking upload permissions ... '); 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); @@ -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] === '/') { diff --git a/ckan/public/scripts/templates.js b/ckan/public/scripts/templates.js index b56b537a6ad..fdcd4a954de 100644 --- a/ckan/public/scripts/templates.js +++ b/ckan/public/scripts/templates.js @@ -1,3 +1,6 @@ +var CKAN = CKAN || {}; +CKAN.Templates = CKAN.Templates || {}; + CKAN.Templates.resourceUpload = ' \
\
Meta - +