From 1f6c72d706d261578cd5c37a50e72c19bf3dae34 Mon Sep 17 00:00:00 2001 From: Ian Murray Date: Mon, 12 Mar 2012 18:31:25 +0000 Subject: [PATCH] [master][js] Re-instated the client-side resource-validation integration. - Lost in the large merge of UX changes. - Original integration: 81e5fe717a070db41a2f3660e6ff499c053843e2 - Haven't re-integrated the highlighting of url errors though; just the auto-population of some resource fields. --- ckan/public/scripts/application.js | 33 ++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/ckan/public/scripts/application.js b/ckan/public/scripts/application.js index dc9e5e9d3e2..a19b0e18a20 100644 --- a/ckan/public/scripts/application.js +++ b/ckan/public/scripts/application.js @@ -767,8 +767,37 @@ CKAN.View.ResourceAddLink = Backbone.View.extend({ setResourceInfo: function(e) { e.preventDefault(); - var urlVal=this.el.find('input[name=url]').val(); - this.model.set({url: urlVal, resource_type: this.mode}) + + this.el.find('input[name=save]').addClass("disabled"); + this.el.find('input[name=reset]').addClass("disabled"); + var urlVal=this.el.find('input[name=url]').val(); + var qaEnabled = $.inArray('qa',CKAN.plugins)>=0; + + if(qaEnabled && this.mode=='file') { + $.ajax({ + url: CKAN.SITE_URL + '/qa/link_checker', + context: this.model, + data: {url: urlVal}, + dataType: 'json', + error: function(){ + this.set({url: urlVal, resource_type: 'file'}); + }, + success: function(data){ + data = data[0]; + this.set({ + url: urlVal, + resource_type: 'file', + format: data.format, + size: data.size, + mimetype: data.mimetype, + last_modified: data.last_modified, + url_error: (data.url_errors || [""])[0] + }); + } + }); + } else { + this.model.set({url: urlVal, resource_type: this.mode}); + } } });