Skip to content

Commit

Permalink
Merge pull request mikekelly#39 from bootic/cleanup_empty_query_values
Browse files Browse the repository at this point in the history
Clean up empty query params before interpolating URI templates
  • Loading branch information
mikekelly committed May 6, 2014
2 parents d93d678 + e999468 commit bc354a1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions js/hal/views/query_uri_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ HAL.Views.QueryUriDialog = Backbone.View.extend({
input = {};
}
this.$el.modal('hide');
window.location.hash = this.uriTemplate.expand(input);
window.location.hash = this.uriTemplate.expand(this.cleanInput(input));
},

renderPreview: function(e) {
var input, result;
try {
input = JSON.parse($(e.target).val());
result = this.uriTemplate.expand(input);
result = this.uriTemplate.expand(this.cleanInput(input));
} catch (err) {
result = 'Invalid json input';
}
Expand Down Expand Up @@ -65,5 +65,15 @@ HAL.Views.QueryUriDialog = Backbone.View.extend({
return this;
},

cleanInput: function(inputObj) {
var obj = {}
for(var k in inputObj) {
if(inputObj.hasOwnProperty(k) && inputObj[k] != null && String(inputObj[k]).trim() != '') {
obj[k] = inputObj[k]
}
}
return obj
},

template: _.template($('#query-uri-template').html())
});

0 comments on commit bc354a1

Please sign in to comment.