Skip to content

Commit

Permalink
Merge pull request #393 from webcompat/387/1
Browse files Browse the repository at this point in the history
Fix for #387 - Don't request /labels unless logged in.
  • Loading branch information
magsout committed Nov 14, 2014
2 parents 3fca88c + 77731f3 commit 66141be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions webcompat/static/js/lib/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ issues.AllLabels = Backbone.Model.extend({
});

issues.LabelsView = Backbone.View.extend({
_isLoggedIn: $('body').data('username'),
el: $('.Label-wrapper'),
editorButton: null,
events: {
Expand Down Expand Up @@ -45,19 +46,20 @@ issues.LabelsView = Backbone.View.extend({
this.$el.html(this.template(this.model.toJSON()));
},
fetchLabels: function() {
var self = this;
var headersBag = {headers: {'Accept': 'application/json'}};
this.editorButton = $('.LabelEditor-launcher');
this.allLabels = new issues.AllLabels();
this.labelEditor = new issues.LabelEditorView({
model: this.allLabels,
issueView: this,
});
this.allLabels.fetch(headersBag).success(function(){
self.issueLabels = _.bind(self.getIssueLabels, self);
self.repoLabels = _.pluck(self.labelEditor.model.get('labels'), 'name');
self.editorButton.show();
});
if (this._isLoggedIn) {
this.allLabels.fetch(headersBag).success(_.bind(function(){
this.issueLabels = this.getIssueLabels();
this.repoLabels = _.pluck(this.labelEditor.model.get('labels'), 'name');
this.editorButton.show();
}, this));
}
},
getIssueLabels: function() {
return _.pluck(this.model.get('labels'), 'name');
Expand Down
2 changes: 1 addition & 1 deletion webcompat/static/js/lib/models/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
url: '/api/issues/' + this.get('number') + '/labels',
success: function(response) {
//update model after success
self.set('labels', JSON.parse(response));
self.set('labels', response);
},
error: function() {
$('<div></div>', {
Expand Down

0 comments on commit 66141be

Please sign in to comment.