Skip to content

Commit

Permalink
[#1711] Integrate resource validation into application.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Murray committed Mar 7, 2012
1 parent c28df8d commit 81e5fe7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ckan/public/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ form.has-errors .field_error, form.has-errors .error-explanation {
position: relative;
background: transparent url(../images/icons/error.png) left 3px no-repeat; }

td.field_warning {
color: #d12f19; }

.fieldset_button_error {
background: transparent url(../images/icons/error.png) left center no-repeat; }

Expand Down
31 changes: 30 additions & 1 deletion ckan/public/scripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,37 @@ CKAN.View.ResourceAddLink = Backbone.View.extend({

setResourceInfo: function(e) {
e.preventDefault();
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();
this.model.set({url: urlVal, resource_type: this.mode})
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});
}

}
});

Expand Down
4 changes: 2 additions & 2 deletions ckan/public/scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ CKAN.Templates.resourceEntry = ' \
</td> \
</tr> \
<tr> \
<td class="resource-edit-label">'+CKAN.Strings.url+'</td> \
<td title="${resource.url_error}" class="resource-edit-label{{if resource.url_error}} field_warning{{/if}}">'+CKAN.Strings.url+'</td> \
<td class="resource-edit-value" colspan="3"> \
{{if resource.resource_type=="file.upload"}} \
${resource.url} \
<input name="resources__${num}__url" type="hidden" value="${resource.url}" /> \
{{/if}} \
{{if resource.resource_type!="file.upload"}} \
<input name="resources__${num}__url" type="text" value="${resource.url}" class="long" /> \
<input name="resources__${num}__url" type="text" value="${resource.url}" class="long" title="${resource.url_error}" /> \
{{/if}} \
</td> \
</tr> \
Expand Down

0 comments on commit 81e5fe7

Please sign in to comment.