Skip to content

Commit

Permalink
Merge CDB-1514 into release/2.13.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Kart Ofante committed May 13, 2014
2 parents 748dcde + aba8528 commit e34ff1b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/assets/javascripts/cartodb/table/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cdb.admin.Tooltip = cdb.geo.ui.Tooltip.extend({

initialize: function() {
this.table = this.options.table;
this.options.empty_fields = true; // render empty fields
cdb.geo.ui.Tooltip.prototype.initialize.call(this);
this.model.bind('change:template_name', this._setTemplate, this);
this.model.bind('change:template', this._compileTemplate, this);
Expand Down
2 changes: 1 addition & 1 deletion lib/assets/javascripts/cdb
Submodule cdb updated from d693f1 to 650642
19 changes: 17 additions & 2 deletions lib/assets/test/spec/cartodb/table/tooltip.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
describe('cdb.admin.Tooltip', function() {
var model, tooltip;
var model, tooltip, layer;
beforeEach(function() {
model = new cdb.geo.ui.InfowindowModel({
fields: [{ name:'name1', title:true, position:0 }],
template_name: 'tooltip_light'
});
layer = new Backbone.Model();
tooltip = new cdb.admin.Tooltip({
model: model
model: model,
layer: layer
});
});

Expand Down Expand Up @@ -36,5 +38,18 @@ describe('cdb.admin.Tooltip', function() {
expect(tooltip.$el.html()).toEqual('test');
});

it("should render empty fields", function() {
model.addField('test2');
layer.trigger('mouseover', null, null, { x:0, y: 0}, {
test: 'test'
});
expect(tooltip.$el.html().indexOf('test2') === -1).toEqual(false)
tooltip.options.empty_fields = false;
layer.trigger('mouseover', null, null, { x:0, y: 0}, {
test: 'test'
});
expect(tooltip.$el.html().indexOf('test2') === -1).toEqual(true)

});

});
9 changes: 6 additions & 3 deletions vendor/assets/javascripts/cartodb.uncompressed.js
Original file line number Diff line number Diff line change
Expand Up @@ -24413,12 +24413,13 @@ cdb.geo.ui.InfowindowModel = Backbone.Model.extend({
}

}, {
contentForFields: function(attributes, fields) {
contentForFields: function(attributes, fields, options) {
options = options || {};
var render_fields = [];
for(var j = 0; j < fields.length; ++j) {
var f = fields[j];
var value = String(attributes[f.name]);
if(attributes[f.name] !== undefined && value != "") {
if(options.empty_fields || (attributes[f.name] !== undefined && value != "")) {
render_fields.push({
title: f.title ? f.name : null,
value: attributes[f.name],
Expand Down Expand Up @@ -25597,7 +25598,9 @@ cdb.geo.ui.Tooltip = cdb.geo.ui.InfoBox.extend({
non_valid_keys = non_valid_keys.concat(this.options.omit_columns);
}

var c = cdb.geo.ui.InfowindowModel.contentForFields(data, this.options.fields);
var c = cdb.geo.ui.InfowindowModel.contentForFields(data, this.options.fields, {
empty_fields: this.options.empty_fields
});
// Remove fields and content from data
// and make them visible for custom templates
data.content = _.omit(data, non_valid_keys);
Expand Down

0 comments on commit e34ff1b

Please sign in to comment.