Skip to content

Commit

Permalink
Merge pull request #3021 from CartoDB/3008-fix-select-all-switch
Browse files Browse the repository at this point in the history
Fixes "all" infowindow field switch
  • Loading branch information
alonsogarciapablo committed Apr 6, 2015
2 parents e7a29e7 + f09e2c0 commit 88f6fbc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,27 @@
_storeSortedFields: function() {
var self = this;

if (this.model.fieldCount() > 0) {
this.sortedFields.reset([]);

var names = this._getSortedColumnNames();
_(names).each(function(name, position) {
self.sortedFields.add({
name: name,
position: position
})
});
}
this.sortedFields.reset([]);

var names = this._getSortedColumnNames();
_(names).each(function(name, position) {
self.sortedFields.add({
name: name,
position: position
})
});
},

_getSortedColumnNames: function() {
var self = this;
var names = this.getColumnNames();
names.sort(function(a, b) {
var pos_a = self.model.getFieldPos(a);
var pos_b = self.model.getFieldPos(b);
return pos_a - pos_b;
});
if (this.model.fieldCount() > 0) {
names.sort(function(a, b) {
var pos_a = self.model.getFieldPos(a);
var pos_b = self.model.getFieldPos(b);
return pos_a - pos_b;
});
}
return names;
},
// when fields are sorted in the iu we should recalculate all models positions
Expand Down
17 changes: 17 additions & 0 deletions lib/assets/test/spec/cartodb/table/menu_modules/infowindow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,23 @@ describe("mod.infowindow", function() {
expect($(view.$el.find('.switch')[1]).hasClass('enabled')).toEqual(true);
});

it("should enable/disable all fields", function() {
view.render();

expect($(view.$el.find('.fields .switch:not(.enabled)')).length).toEqual(3);

// Select all
view.$el.find('.selectall').trigger('click');

expect($(view.$el.find('.fields .switch.enabled')).length).toEqual(3);

// Unselect all
view.$el.find('.selectall').trigger('click');

expect($(view.$el.find('.fields .switch:not(.enabled)')).length).toEqual(3);
});


it("should disable select-all when all chosen", function() {
view.render();
model.addField('name1').addField('name2').addField('name3');
Expand Down

0 comments on commit 88f6fbc

Please sign in to comment.