parent
19dbd2f520
commit
9343e4da56
@ -1,33 +0,0 @@
|
||||
(function() {
|
||||
|
||||
/**
|
||||
* contains information about the table, not the data itself
|
||||
*/
|
||||
cdb.open.PublicCartoDBTableMetadata = cdb.admin.CartoDBTableMetadata.extend({
|
||||
|
||||
fetch: function() {
|
||||
this.trigger('sync');
|
||||
//nothing to fetch here
|
||||
},
|
||||
|
||||
|
||||
data: function() {
|
||||
var self = this;
|
||||
if(this._data === undefined) {
|
||||
this._data = new cdb.admin.CartoDBTableData(null, {
|
||||
table: this
|
||||
});
|
||||
this._data.fetch = function() { };
|
||||
}
|
||||
|
||||
if(this.sqlView) {
|
||||
return this.sqlView;
|
||||
}
|
||||
return this._data;
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
})();
|
@ -1,65 +0,0 @@
|
||||
|
||||
/**
|
||||
* Public header for table view
|
||||
*
|
||||
* - It needs a table model, config and user data.
|
||||
*
|
||||
* var header = new cdb.admin.Header({
|
||||
* el: this.$('header'),
|
||||
* model: table_model,
|
||||
* user: user_model,
|
||||
* config: config
|
||||
* });
|
||||
*
|
||||
*/
|
||||
cdb.open.PublicHeader = cdb.admin.Header.extend({
|
||||
|
||||
_SQL: 'SELECT * FROM ',
|
||||
|
||||
events: {
|
||||
'click .navigation li a': '_onTabClick'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
this.$body = $('body');
|
||||
this.setInfo();
|
||||
},
|
||||
|
||||
setInfo: function() {
|
||||
this.$('h2').text(this.model.get('name'));
|
||||
this.$('.description p').text(this.model.get("description"));
|
||||
},
|
||||
|
||||
_shareVisualization: function() { /* not in public */ },
|
||||
_changeToVisualization: function(e) { /* not in public */ },
|
||||
_changePrivacy: function(ev) { /* not in public */ },
|
||||
_changeDescription: function(e) { /* not in public */ },
|
||||
_changeTitle: function(e) { /* not in public */ },
|
||||
_changeTags: function(e) { /* not in public */ },
|
||||
_onSetAttribute: function(e) { /* not in public */ },
|
||||
isVisEditable: function(e) { /* not in public */ },
|
||||
|
||||
_onTabClick: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Let's create the url ourselves //
|
||||
var url = '';
|
||||
|
||||
// Get table id
|
||||
if (this.options.belong_organization) {
|
||||
url += "/" + this.model.getUnquotedName() + '/public';
|
||||
} else {
|
||||
url += "/" + this.model.getUnqualifiedName() + '/public';
|
||||
}
|
||||
|
||||
// Get scenario parameter (table or map)
|
||||
if ($(e.target).closest('a').attr('href').search('/map') != -1) {
|
||||
url += '/map'
|
||||
} else {
|
||||
url += '/table'
|
||||
}
|
||||
|
||||
if (window.history && window.history.pushState) window.table_router.navigate(url, {trigger: true});
|
||||
|
||||
}
|
||||
});
|
@ -1,101 +0,0 @@
|
||||
|
||||
/**
|
||||
* header cell view, manages operations on table columns
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
HeaderView = cdb.open.PublicHeaderView = cdb.admin.HeaderView.extend({
|
||||
|
||||
events: {
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
var self = this;
|
||||
this.column = this.options.column;
|
||||
this.table = this.options.table;
|
||||
this.template = this.getTemplate('public_table/views/public_table_header_view');
|
||||
this.editing_name = false;
|
||||
this.changing_type = false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.html('');
|
||||
this.$el.append(this.template({
|
||||
col_name: this.column[0],
|
||||
col_type: this.column[1],
|
||||
editing_name: this.editing_name,
|
||||
}));
|
||||
|
||||
// Focus in the input if it is being edited
|
||||
if (this.editing_name) {
|
||||
this.$el.find("input").focus();
|
||||
}
|
||||
|
||||
this.delegateEvents();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
_openColOptions: function(e) {
|
||||
var self = this;
|
||||
var colOptions = HeaderView.colOptions;
|
||||
|
||||
// Unbind events
|
||||
colOptions.off();
|
||||
cdb.god.unbind('closeDialogs', HeaderView.colOptions.hide, HeaderView.colOptions);
|
||||
|
||||
// Close other dialogs
|
||||
cdb.god.trigger("closeDialogs");
|
||||
|
||||
// set data for column and table currently editing
|
||||
colOptions.setTable(this.table, this.column[0]);
|
||||
|
||||
colOptions.bind('renameColumn', this._renameColumn, this);
|
||||
colOptions.bind('changeType', this._changeType, this);
|
||||
colOptions.bind('georeference', function(column) {
|
||||
self.trigger('georeference', column);
|
||||
}, this);
|
||||
|
||||
// bind the stuff
|
||||
var container = $(e.target).parent().parent();
|
||||
container.append(colOptions.el);
|
||||
|
||||
var link_width = $(e.target).width() + 26
|
||||
, th = container.parent();
|
||||
|
||||
// align to the right of the target with a little of margin
|
||||
colOptions.openAt(link_width - colOptions.$el.width(), (th.height()/2) + 7);
|
||||
|
||||
// Bind again!
|
||||
cdb.god.bind("closeDialogs", HeaderView.colOptions.hide, HeaderView.colOptions);
|
||||
|
||||
},
|
||||
|
||||
_openColTypeOptions: function(e) {},
|
||||
|
||||
_checkEditColnameInput: function(e) {},
|
||||
|
||||
_submitEdit: function() {},
|
||||
|
||||
_finishEdit: function() {},
|
||||
|
||||
_renameColumn: function() {},
|
||||
|
||||
_changeType: function() {},
|
||||
|
||||
showColumnOptions: function(e) {
|
||||
var self = this;
|
||||
e.preventDefault();
|
||||
var colOptions = HeaderView.colOptions;
|
||||
colOptions.hide(function() {
|
||||
self._openColOptions(e);
|
||||
});
|
||||
return false;
|
||||
},
|
||||
|
||||
showColumnTypeOptions: function(e) {}
|
||||
|
||||
});
|
||||
|
||||
})();
|
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* this infowindow is shown in the map when user clicks on a feature
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
cdb.open.PublicMapInfowindow = cdb.admin.MapInfowindow.extend({
|
||||
|
||||
events: cdb.geo.ui.Infowindow.prototype.events,
|
||||
|
||||
initialize: function() {
|
||||
var self = this;
|
||||
this.table = this.options.table;
|
||||
this.model.set({ content: 'loading...' });
|
||||
// call parent
|
||||
cdb.geo.ui.Infowindow.prototype.initialize.call(this);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.html($(this.template(_.clone(this.model.attributes))));
|
||||
this._update();
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Not in public
|
||||
*/
|
||||
_editGeom: function(e) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Not in public
|
||||
*/
|
||||
_removeGeom: function(e) {
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
})();
|
@ -1,83 +0,0 @@
|
||||
/**
|
||||
* map tab shown in cartodb admin
|
||||
*/
|
||||
|
||||
cdb.open.PublicMapTab = cdb.admin.MapTab.extend({
|
||||
|
||||
className: 'map',
|
||||
|
||||
events: {
|
||||
'click .js-bounds': '_changeBounds'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
this.template = this.getTemplate('public_table/views/maptab_public');
|
||||
this.map_enabled = false;
|
||||
|
||||
this._initBinds();
|
||||
},
|
||||
|
||||
_initBinds: function() {
|
||||
this.model.bind('change:bounds', this._setBoundsCheckbox, this);
|
||||
this.model.bind('change:map', this._setBounds, this);
|
||||
},
|
||||
|
||||
_changeBounds: function() {
|
||||
this.model.set('bounds', !this.model.get('bounds'));
|
||||
},
|
||||
|
||||
_setBounds: function() {
|
||||
if (this.vis) {
|
||||
var map = this.model.get('map');
|
||||
this.vis.mapView.map.setView(map.center, map.zoom);
|
||||
}
|
||||
},
|
||||
|
||||
_setBoundsCheckbox: function() {
|
||||
this.trigger('boundsChanged', { bounds: this.model.get('bounds') });
|
||||
this.$('.js-bounds .Checkbox-input').toggleClass('is-checked', !!this.model.get('bounds'));
|
||||
},
|
||||
|
||||
/**
|
||||
* map can't be loaded from the beggining, it needs the DOM to be loaded
|
||||
* so we wait until is actually shown to create the mapview and show it
|
||||
*/
|
||||
enableMap: function() {
|
||||
if (!this.map_enabled && !this.vis) {
|
||||
this.vis = new cdb.vis.Vis({
|
||||
el: this.$('.cartodb-map')
|
||||
});
|
||||
this.vis.load(this.options.vizjson, {
|
||||
auth_token: this.options.auth_token,
|
||||
https: this.options.https,
|
||||
search: false,
|
||||
scrollwheel: false,
|
||||
shareable: false,
|
||||
fullscreen: true,
|
||||
no_cdn: cdb.config.get('debug')
|
||||
});
|
||||
}
|
||||
|
||||
this._bindBounds();
|
||||
},
|
||||
|
||||
/**
|
||||
* this function binds pan and zoom events
|
||||
* in order to change the results in the table view
|
||||
* with the new bbox
|
||||
*/
|
||||
_bindBounds: function() {
|
||||
this.vis.mapView.bind('dragend zoomend', function() {
|
||||
this.trigger('mapBoundsChanged', {
|
||||
map: this.vis.map
|
||||
});
|
||||
}, this);
|
||||
},
|
||||
|
||||
clearMap: function() {},
|
||||
|
||||
render: function() {
|
||||
this.$el.html(this.template());
|
||||
return this;
|
||||
}
|
||||
});
|
@ -1,43 +0,0 @@
|
||||
/**
|
||||
* entry point for public table view
|
||||
*/
|
||||
|
||||
|
||||
$(function() {
|
||||
|
||||
// Add easeinquad animation
|
||||
$.extend( $.easing, {
|
||||
easeInQuad: function (x, t, b, c, d) {
|
||||
return c*(t/=d)*t + b;
|
||||
}
|
||||
})
|
||||
|
||||
cdb.init(function() {
|
||||
cdb.config.set(config);
|
||||
if (api_key) cdb.config.set("api_key", api_key);
|
||||
cdb.config.set('url_prefix', window.base_url);
|
||||
cdb.templates.namespace = 'cartodb/';
|
||||
|
||||
// Check if device is a mobile
|
||||
var mobileDevice = /Android|webOS|iPad|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
||||
|
||||
// Window view
|
||||
var public_window = new cdb.open.PublicTableWindow({
|
||||
el: window,
|
||||
table_id: table_id,
|
||||
table_name: table_name,
|
||||
user_name: user_name,
|
||||
owner_username: owner_username,
|
||||
vizjson: vizjson_obj,
|
||||
auth_token: auth_token,
|
||||
https: use_https,
|
||||
api_key: api_key,
|
||||
schema: schema,
|
||||
config: config,
|
||||
isMobileDevice: mobileDevice,
|
||||
belong_organization: belong_organization
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@ -1,159 +0,0 @@
|
||||
|
||||
/**
|
||||
* Public table window "view"
|
||||
*
|
||||
*/
|
||||
|
||||
cdb.open.PublicTableWindow = cdb.core.View.extend({
|
||||
|
||||
initialize: function() {
|
||||
this.$body = $(this.el.document.body);
|
||||
this.$map = this.$body.find('#map');
|
||||
this._initBinds();
|
||||
this._initViews();
|
||||
setTimeout(this._onStart, 250);
|
||||
},
|
||||
|
||||
_initViews: function() {
|
||||
// Table view
|
||||
var table_options = _.defaults({ el: this.el.document.body, model: new cdb.core.Model({ bounds: false, map: null }) }, this.options);
|
||||
var table = new cdb.open.TablePublic(table_options);
|
||||
|
||||
// Public table router
|
||||
this.el.table_router = new cdb.open.TableRouter(table);
|
||||
|
||||
var pushState = true;
|
||||
var root = '/tables/';
|
||||
|
||||
// Push state?
|
||||
if (!this.el.history || !this.el.history.pushState) pushState = false;
|
||||
|
||||
// Organization user?
|
||||
if (this.options.belong_organization) root = '/u/' + this.options.user_name + root;
|
||||
|
||||
Backbone.history.start({
|
||||
pushState: pushState,
|
||||
root: root
|
||||
});
|
||||
},
|
||||
|
||||
_initBinds: function() {
|
||||
_.bindAll(this, '_onWindowResize', '_onOrientationChange', '_onStart');
|
||||
|
||||
this.$el.on('resize', this._onWindowResize);
|
||||
|
||||
if (!this.el.addEventListener) {
|
||||
this.el.attachEvent('orientationchange', this._onOrientationChange, this);
|
||||
} else {
|
||||
this.el.addEventListener('orientationchange', this._onOrientationChange);
|
||||
}
|
||||
},
|
||||
|
||||
// On start view!
|
||||
_onStart: function() {
|
||||
this._setupMapDimensions();
|
||||
|
||||
var windowHeight = this.$el.height();
|
||||
var top = windowHeight - this.$body.find(".cartodb-info").outerHeight(true) - this.$body.find(".cartodb-public-header").outerHeight(true);
|
||||
|
||||
if (this.options.isMobileDevice) {
|
||||
var h = 120;
|
||||
|
||||
if (windowHeight < 670) {
|
||||
h = 80;
|
||||
}
|
||||
|
||||
top = windowHeight - this.$body.find(".cartodb-public-header").outerHeight(true) - h;
|
||||
}
|
||||
|
||||
this._showNavigationBar(top)
|
||||
},
|
||||
|
||||
_onWindowResize: function() {
|
||||
// Resize window
|
||||
this._setupMapDimensions();
|
||||
// Close dialogs
|
||||
cdb.god.trigger("closeDialogs");
|
||||
},
|
||||
|
||||
_onOrientationChange: function() {
|
||||
// Reset disqus
|
||||
DISQUS && DISQUS.reset({ reload: true });
|
||||
// Resize window orientation
|
||||
this._setupMapDimensions(true);
|
||||
},
|
||||
|
||||
// When window is resized, let's touch some things ;)
|
||||
_setupMapDimensions: function(animated) {
|
||||
var windowHeight = this.$el.height();
|
||||
var mainInfoHeight = this.$body.find('.js-Navmenu').height();
|
||||
var headerHeight = this.$body.find('.Header').height();
|
||||
var landscapeMode = this.el.matchMedia && this.el.matchMedia("(orientation: landscape)").matches;
|
||||
var h, height, top;
|
||||
|
||||
if (this.options.isMobileDevice) {
|
||||
|
||||
if (landscapeMode) {
|
||||
h = headerHeight + 7;
|
||||
} else {
|
||||
if (windowHeight > 670) {
|
||||
h = 220;
|
||||
} else { // iPhone, etc.
|
||||
h = 138;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
h = 260;
|
||||
}
|
||||
|
||||
height = windowHeight - h;
|
||||
top = windowHeight - (h - 80);
|
||||
|
||||
if (animated) {
|
||||
this.$map.animate({ height: height }, { easing: "easeInQuad", duration: 150 });
|
||||
this.$body.find(".navigation").animate({ top: top - 130 }, { easing: "easeInQuad", duration: 150 });
|
||||
} else {
|
||||
if (this.options.isMobileDevice) {
|
||||
this.$map.css({ height: height, opacity: 1 });
|
||||
this.$body.find(".navigation").css({ top: top - 130 }, 250);
|
||||
} else {
|
||||
// On non mobile devices
|
||||
this.$map.css({ height: windowHeight - ( mainInfoHeight + headerHeight), opacity: 1 });
|
||||
this.$body.find(".navigation").css({ top: top - 21 }, 250);
|
||||
}
|
||||
}
|
||||
|
||||
// If landscape, let's scroll to show the map, and
|
||||
// leave the header hidden
|
||||
if (this.options.isMobileDevice && landscapeMode && $(window).scrollTop() < headerHeight) {
|
||||
this.$body.animate({ scrollTop: headerHeight }, 600);
|
||||
}
|
||||
|
||||
if (this.map_view) this.map_view.invalidateMap();
|
||||
},
|
||||
|
||||
// Show navigation (table or map view) block
|
||||
_showNavigationBar: function(top) {
|
||||
var landscapeMode = this.el.matchMedia && this.el.matchMedia("(orientation: landscape)").matches;
|
||||
var windowHeight = this.$el.height();
|
||||
|
||||
if (this.options.isMobileDevice) {
|
||||
var top_ = 108;
|
||||
|
||||
if (landscapeMode) {
|
||||
top_ = 48;
|
||||
}
|
||||
|
||||
this.$body.find(".navigation")
|
||||
.css({ top: windowHeight })
|
||||
.animate({ top: top - top_, opacity: 1 }, 250);
|
||||
} else {
|
||||
this.$body.find(".navigation")
|
||||
.css({ top: windowHeight })
|
||||
.animate({ top: top - 201, opacity: 1 }, 250);
|
||||
}
|
||||
|
||||
if (this.map_view) this.map_view.invalidateMap();
|
||||
}
|
||||
|
||||
});
|
@ -1,24 +0,0 @@
|
||||
|
||||
/**
|
||||
* view used to render each row in public tables
|
||||
*/
|
||||
cdb.open.PublicRowView = cdb.admin.RowView.extend({
|
||||
|
||||
classLabel: 'cdb.open.PublicRowView',
|
||||
|
||||
events: {},
|
||||
|
||||
initialize: function() {
|
||||
this.options.row_header = false;
|
||||
this.order = this.options.order;
|
||||
},
|
||||
|
||||
_renderGeometry: function(value) {
|
||||
return this._renderDefault('GeoJSON')
|
||||
},
|
||||
|
||||
_getRowOptions: function() {},
|
||||
|
||||
click_header: function(e) {}
|
||||
});
|
||||
|
@ -1,319 +0,0 @@
|
||||
|
||||
/**
|
||||
* Table public view
|
||||
*
|
||||
*/
|
||||
|
||||
cdb.open.TablePublic = cdb.core.View.extend({
|
||||
|
||||
events: {
|
||||
'click .js-Navmenu-link--download': '_exportTable',
|
||||
'click .js-Navmenu-link--api': '_apiCallTable'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
this._initModels();
|
||||
this._initViews();
|
||||
this._initBinds();
|
||||
},
|
||||
|
||||
_initModels: function() {
|
||||
var self = this;
|
||||
|
||||
// Table
|
||||
this.table = new cdb.open.PublicCartoDBTableMetadata({
|
||||
id: this.options.table_name,
|
||||
name: this.options.table_name,
|
||||
description: this.options.vizjson.description || ''
|
||||
});
|
||||
|
||||
this.table.set({
|
||||
user_name: this.options.user_name,
|
||||
vizjson: this.options.vizjson,
|
||||
schema: this.options.schema
|
||||
});
|
||||
|
||||
this.columns = this.table.data();
|
||||
this.sqlView = new cdb.admin.SQLViewData();
|
||||
this.sqlView.syncMethod = 'read';
|
||||
|
||||
var query = this.query = this.table.data().getSQL()
|
||||
this.table.useSQLView(this.sqlView);
|
||||
this.sqlView.options.set('rows_per_page', 20, { silent: true });
|
||||
this._fetchData(query);
|
||||
|
||||
// User
|
||||
this.user = new cdb.admin.User({ username: this.options.user_name });
|
||||
|
||||
// Authenticated user
|
||||
this.authenticated_user = new cdb.open.AuthenticatedUser();
|
||||
|
||||
},
|
||||
|
||||
_initViews: function() {
|
||||
var self = this;
|
||||
|
||||
// Public header
|
||||
if (this.$('.cartodb-public-header').length > 0) {
|
||||
var header = new cdb.open.Header({
|
||||
el: this.$('.cartodb-public-header'),
|
||||
model: this.authenticated_user,
|
||||
vis: this.table,
|
||||
current_view: this._getCurrentView(),
|
||||
owner_username: this.options.owner_username,
|
||||
isMobileDevice: this.options.isMobileDevice
|
||||
});
|
||||
this.addView(header);
|
||||
|
||||
// Fetch authenticated user model
|
||||
this.authenticated_user.fetch();
|
||||
}
|
||||
|
||||
// Navigation
|
||||
this.header = new cdb.open.PublicHeader({
|
||||
el: this.$('.navigation'),
|
||||
model: this.table,
|
||||
user: this.user,
|
||||
belong_organization: belong_organization,
|
||||
config: this.options.config
|
||||
});
|
||||
this.addView(this.header);
|
||||
|
||||
// Tabpanes
|
||||
this.workViewTable = new cdb.ui.common.TabPane({
|
||||
el: this.$('.pane_table')
|
||||
});
|
||||
this.addView(this.workViewTable);
|
||||
|
||||
this.workViewMap = new cdb.ui.common.TabPane({
|
||||
el: this.$('.pane_map')
|
||||
});
|
||||
this.addView(this.workViewMap);
|
||||
|
||||
this.workViewMobile = new cdb.ui.common.TabPane({
|
||||
el: this.$('.panes_mobile')
|
||||
});
|
||||
this.addView(this.workViewMobile);
|
||||
|
||||
// Public app tabs
|
||||
this.tabs = new cdb.admin.Tabs({
|
||||
el: this.$('.navigation ul'),
|
||||
slash: true
|
||||
});
|
||||
|
||||
this.addView(this.tabs);
|
||||
|
||||
// Help tooltip
|
||||
var tooltip = new cdb.common.TipsyTooltip({
|
||||
el: this.$("span.help"),
|
||||
gravity: $.fn.tipsy.autoBounds(250, 's')
|
||||
})
|
||||
this.addView(tooltip);
|
||||
|
||||
// Disable comments when browser is IE7
|
||||
if ($.browser.msie && parseInt($.browser.version) === 7 ) {
|
||||
this.$(".comments .content").html("<p>Your browser doesn't support comments.</p>")
|
||||
}
|
||||
|
||||
// Table tab
|
||||
this.tableTab = new cdb.open.PublicTableTab({
|
||||
model: this.table,
|
||||
vizjson: this.options.vizjson,
|
||||
user_name: this.options.user_name
|
||||
});
|
||||
|
||||
this.tableTabMobile = new cdb.open.PublicTableTab({
|
||||
model: this.table,
|
||||
vizjson: this.options.vizjson,
|
||||
user_name: this.options.user_name
|
||||
});
|
||||
|
||||
// Map tab
|
||||
this.mapTab = new cdb.open.PublicMapTab({
|
||||
vizjson: this.options.vizjson,
|
||||
auth_token: this.options.auth_token,
|
||||
https: this.options.https,
|
||||
vizjson_url: this.options.vizjson_url,
|
||||
model: new cdb.core.Model({
|
||||
bounds: false
|
||||
})
|
||||
});
|
||||
this.mapTab.bind('mapBoundsChanged', function(options) {
|
||||
self.model.set('map', {
|
||||
bounds: [
|
||||
options.map.get('view_bounds_ne')[1],
|
||||
options.map.get('view_bounds_ne')[0],
|
||||
options.map.get('view_bounds_sw')[1],
|
||||
options.map.get('view_bounds_sw')[0]
|
||||
],
|
||||
center: options.map.get('center'),
|
||||
zoom: options.map.get('zoom')
|
||||
});
|
||||
});
|
||||
this.mapTab.bind('boundsChanged', function(options) {
|
||||
self.model.set('bounds', options.bounds);
|
||||
});
|
||||
|
||||
this.mapTabMobile = new cdb.open.PublicMapTab({
|
||||
vizjson: this.options.vizjson,
|
||||
auth_token: this.options.auth_token,
|
||||
https: this.options.https,
|
||||
vizjson_url: this.options.vizjson_url,
|
||||
model: new cdb.core.Model({
|
||||
bounds: false
|
||||
})
|
||||
});
|
||||
this.mapTabMobile.bind('mapBoundsChanged', function(options) {
|
||||
self.model.set('map', {
|
||||
bounds: [
|
||||
options.map.get('view_bounds_ne')[1],
|
||||
options.map.get('view_bounds_ne')[0],
|
||||
options.map.get('view_bounds_sw')[1],
|
||||
options.map.get('view_bounds_sw')[0]
|
||||
],
|
||||
center: options.map.get('center'),
|
||||
zoom: options.map.get('zoom')
|
||||
});
|
||||
});
|
||||
this.mapTabMobile.bind('boundsChanged', function(options) {
|
||||
self.model.set('bounds', options.bounds);
|
||||
});
|
||||
|
||||
this.workViewMobile.addTab('table', this.tableTabMobile.render());
|
||||
this.workViewMobile.addTab('map', this.mapTabMobile.render());
|
||||
this.workViewMobile.bind('tabEnabled:map', this.mapTabMobile.enableMap, this.mapTabMobile);
|
||||
|
||||
this.workViewTable.addTab('table', this.tableTab.render());
|
||||
this.workViewMap.addTab('map', this.mapTab.render());
|
||||
|
||||
this.workViewMobile.bind('tabEnabled', function(mode) {
|
||||
self.$el.removeClass("table");
|
||||
self.$el.removeClass("map");
|
||||
self.$el.addClass(mode);
|
||||
$(window).trigger('resize');
|
||||
}, this.mapTabMobile);
|
||||
|
||||
this.workViewMobile.bind('tabEnabled', this.tabs.activate);
|
||||
this.workViewMobile.active('table');
|
||||
|
||||
this.workViewTable.active('table');
|
||||
this.workViewMap.active('map');
|
||||
this.mapTab.enableMap();
|
||||
|
||||
$(".pane_table").addClass("is-active");
|
||||
},
|
||||
|
||||
_updateTable: function() {
|
||||
var sql = (this.model.get('bounds') && this.model.get('map')) ? (this.query + " WHERE the_geom && ST_MakeEnvelope("+this.model.get('map')['bounds'][0]+", "+this.model.get('map')['bounds'][1]+", "+this.model.get('map')['bounds'][2]+", "+this.model.get('map')['bounds'][3]+", 4326)") : this.query;
|
||||
this._fetchData(sql);
|
||||
},
|
||||
|
||||
_fetchData: function(sql) {
|
||||
if (sql) {
|
||||
this.sqlView.setSQL(sql);
|
||||
}
|
||||
|
||||
this.sqlView.fetch({
|
||||
success: function() {
|
||||
self.$('.js-spinner').remove();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_exportTable: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// If a sql is applied but it is not valid, don't let the user export it
|
||||
if (!this.sqlView.getSQL()) return false;
|
||||
|
||||
var DialogView = cdb.editor.PublicExportView;
|
||||
var export_dialog = new DialogView({
|
||||
model: this.table,
|
||||
config: config,
|
||||
user_data: this.user.toJSON(),
|
||||
bounds: this.sqlView.getSQL() !== this.query
|
||||
});
|
||||
|
||||
export_dialog
|
||||
.appendToBody()
|
||||
.open();
|
||||
},
|
||||
|
||||
_apiCallTable: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// If a sql is applied but it is not valid, don't show the dialog
|
||||
if (!this.sqlView.getSQL()) return false;
|
||||
|
||||
api_dialog = cdb.editor.ViewFactory.createDialogByTemplate('common/dialogs/api_call', {
|
||||
url: cdb.config.getSqlApiUrl(),
|
||||
sql: this.sqlView.getSQL(),
|
||||
schema: this.table.attributes.original_schema.slice(0, 5),
|
||||
rows: this.table.dataModel.models
|
||||
});
|
||||
|
||||
api_dialog
|
||||
.appendToBody()
|
||||
.open();
|
||||
},
|
||||
|
||||
_initBinds: function() {
|
||||
var _this = this;
|
||||
|
||||
// Global click
|
||||
enableClickOut(this.$el);
|
||||
|
||||
this.model.bind('change:bounds', function() {
|
||||
_this._setBoundsCheckbox();
|
||||
_this._updateTable();
|
||||
}, this);
|
||||
|
||||
this.model.bind('change:map', function() {
|
||||
_this._setBounds();
|
||||
_this._updateTable();
|
||||
}, this);
|
||||
|
||||
this.authenticated_user.bind('change', this._onUserLogged, this);
|
||||
|
||||
this.add_related_model(this.authenticated_user);
|
||||
},
|
||||
|
||||
_setBoundsCheckbox: function() {
|
||||
this.mapTab.model.set('bounds', this.model.get('bounds'));
|
||||
this.mapTabMobile.model.set('bounds', this.model.get('bounds'));
|
||||
},
|
||||
|
||||
_setBounds: function() {
|
||||
this.mapTab.model.set('map', this.model.get('map'));
|
||||
this.mapTabMobile.model.set('map', this.model.get('map'));
|
||||
},
|
||||
|
||||
// Get type of current view
|
||||
// - It could be, dashboard, table or visualization
|
||||
_getCurrentView: function() {
|
||||
var pathname = location.pathname;
|
||||
|
||||
if (pathname.indexOf('/tables/') !== -1 ) {
|
||||
return 'table';
|
||||
}
|
||||
|
||||
if (pathname.indexOf('/viz/') !== -1 ) {
|
||||
return 'visualization';
|
||||
}
|
||||
|
||||
// Other case -> dashboard (datasets, visualizations,...)
|
||||
return 'dashboard';
|
||||
},
|
||||
|
||||
keyUp: function(e) {},
|
||||
|
||||
_onUserLogged: function() {
|
||||
// Check if edit button should be visible
|
||||
if (this.options.owner_username === this.authenticated_user.get('username')) {
|
||||
this.$('.extra_options .edit').css('display', 'inline-block');
|
||||
this.$('.extra_options .oneclick').css('display', 'none');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
@ -1,24 +0,0 @@
|
||||
|
||||
/**
|
||||
* New public table router \o/
|
||||
*
|
||||
* - No more /#/xxx routes
|
||||
*/
|
||||
|
||||
cdb.open.TableRouter = Backbone.Router.extend({
|
||||
|
||||
routes: {
|
||||
':id/public/:scenario': 'change'
|
||||
},
|
||||
|
||||
initialize: function(table) {
|
||||
this.table = table;
|
||||
},
|
||||
|
||||
change: function(_id,scenario) {
|
||||
// Check active view, if it is different, change
|
||||
if (scenario != 'table' && scenario != 'map') scenario = 'table';
|
||||
this.table.workViewMobile.active(scenario);
|
||||
}
|
||||
|
||||
});
|
@ -1,109 +0,0 @@
|
||||
|
||||
/**
|
||||
* public table view
|
||||
*/
|
||||
cdb.open.PublicTableView = cdb.admin.TableView.extend({
|
||||
|
||||
events: {},
|
||||
|
||||
rowView: cdb.open.PublicRowView,
|
||||
|
||||
initialize: function() {
|
||||
var self = this;
|
||||
this.elder('initialize');
|
||||
this.options.row_header = true;
|
||||
this._editorsOpened = null;
|
||||
|
||||
this.initializeBindings();
|
||||
this.initPaginationAndScroll();
|
||||
},
|
||||
|
||||
initializeBindings: function() {
|
||||
var self = this;
|
||||
|
||||
_.bindAll(this, "render", "rowSaving", "addEmptyRow",
|
||||
"_checkEmptyTable", "_forceScroll", "_scrollMagic",
|
||||
"rowChanged", "rowSynched", "_startPagination", "_finishPagination",
|
||||
"rowFailed", "rowDestroyed", "emptyTable");
|
||||
|
||||
this.model.data().bind('newPage', this.newPage, this);
|
||||
|
||||
//this.model.data().bind('loadingRows', this._startPagination);
|
||||
this.model.data().bind('endLoadingRows', this._finishPagination);
|
||||
|
||||
this.bind('cellDblClick', this._editCell, this);
|
||||
|
||||
//this.model.bind('change:dataSource', this._onSQLView, this);
|
||||
// when model changes the header is re rendered so the notice should be added
|
||||
//this.model.bind('change', this._onSQLView, this);
|
||||
this.model.bind('dataLoaded', function() {
|
||||
self._checkEmptyTable();
|
||||
self._forceScroll();
|
||||
}, this);
|
||||
},
|
||||
|
||||
headerView: function(column) {
|
||||
var self = this;
|
||||
if(column[1] !== 'header') {
|
||||
var v = new cdb.open.PublicHeaderView({
|
||||
column: column,
|
||||
table: this.model,
|
||||
sqlView: this.options.sqlView,
|
||||
});
|
||||
|
||||
this.addView(v);
|
||||
return v.render().el;
|
||||
} else {
|
||||
return '<div><div></div></div>';
|
||||
}
|
||||
},
|
||||
|
||||
_onSQLView: function() {},
|
||||
|
||||
_checkEmptyTable: function() {
|
||||
if(this.isEmptyTable()) {
|
||||
this.addEmptyTableInfo();
|
||||
} else {
|
||||
this.cleanEmptyTableInfo();
|
||||
this.$('footer').remove();
|
||||
}
|
||||
},
|
||||
|
||||
_swicthEnabled: function() {
|
||||
// this check is not needed in public table
|
||||
},
|
||||
|
||||
addEmptyTableInfo: function() {
|
||||
this.template_base = cdb.templates.getTemplate('public_table/views/empty_table_public');
|
||||
var content = this.template_base(this.import_);
|
||||
|
||||
var $footer = $('<tfoot><tr><td colspan="100">' + content + '</td></tr></tfoot>');
|
||||
this.$('footer').remove();
|
||||
this.$el.append($footer);
|
||||
},
|
||||
|
||||
_scrollMagic: function() { }
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Public table tab controller
|
||||
*/
|
||||
|
||||
cdb.open.PublicTableTab = cdb.admin.TableTab.extend({
|
||||
|
||||
className: 'table public',
|
||||
|
||||
initialize: function() {
|
||||
this.user = this.options.user;
|
||||
this.sqlView = this.options.sqlView;
|
||||
},
|
||||
|
||||
_createTable: function() {
|
||||
this.tableView = new cdb.open.PublicTableView({
|
||||
dataModel: this.model.data(),
|
||||
model: this.model,
|
||||
sqlView: this.sqlView
|
||||
});
|
||||
}
|
||||
});
|
@ -1,7 +0,0 @@
|
||||
<div class="Checkbox js-bounds">
|
||||
<button class="Checkbox-input"></button>
|
||||
<label class="Checkbox-label">Match rows with the map view.</label>
|
||||
</div>
|
||||
|
||||
<div class="cartodb-map public">
|
||||
</div>
|
@ -1,14 +0,0 @@
|
||||
<div>
|
||||
<label class="strong small interactuable">
|
||||
<div class="coloptions" href="#<%- col_name %>">
|
||||
<%- col_name %>
|
||||
<% if (col_type == 'geometry') { %>
|
||||
<span class="tiny geo">GEO</span>
|
||||
<% } %>
|
||||
</div>
|
||||
</label>
|
||||
<p class="small">
|
||||
<a class="disabled"><%- col_type %></a>
|
||||
</p>
|
||||
</div>
|
||||
<p class="auto"><%- col_name %>_<% if (col_type == 'geometry') { %>GEO<% } %></p>
|
@ -1,31 +0,0 @@
|
||||
|
||||
describe("mapview public", function() {
|
||||
|
||||
var view;
|
||||
|
||||
beforeEach(function() {
|
||||
|
||||
var vizjson = {id: "5ed698fa-cc85-11e3-a76b-003ee1fffe8b", version: "0.1.0", title: "untitled_table_5", description: null, url: null }
|
||||
|
||||
view = new cdb.open.PublicMapTab({
|
||||
vizjson: vizjson,
|
||||
vizjson_url: "",
|
||||
model: new cdb.core.Model({
|
||||
bounds: false
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it("should render", function() {
|
||||
view.render();
|
||||
expect(view.$('.cartodb-map').length).toEqual(1);
|
||||
});
|
||||
|
||||
it("should not render the private components", function() {
|
||||
view.render();
|
||||
expect(view.$('.base_maps').length).toEqual(0);
|
||||
expect(view.$('.share').length).toEqual(0);
|
||||
})
|
||||
|
||||
});
|
@ -1,43 +0,0 @@
|
||||
describe("PublicRowView", function() {
|
||||
|
||||
var tableview, view, model;
|
||||
beforeEach(function() {
|
||||
model = new cdb.open.PublicCartoDBTableMetadata({
|
||||
name: 'test',
|
||||
schema: [ ['cartodb_id', 'number'], ['test', 'string'], ['test2', 'number'], ['the_geom', 'geometry']],
|
||||
geometry_types: ['ST_MultiPoint']
|
||||
});
|
||||
|
||||
view = new cdb.open.PublicRowView({
|
||||
el: $('<div>'),
|
||||
model: new cdb.admin.Row({ cartodb_id: 1, test: 'test', test2: 1, the_geom: '{ "type": "Point", "coordinates": [100.0, 0.0] }' }),
|
||||
row_header: true
|
||||
});
|
||||
|
||||
tableview = new cdb.open.PublicTableView({
|
||||
model: model,
|
||||
geocoder: new cdb.admin.Geocodings(),
|
||||
dataModel: model.data()
|
||||
});
|
||||
|
||||
view.tableView = tableview;
|
||||
});
|
||||
|
||||
it("should render properly", function() {
|
||||
view.render();
|
||||
expect(view.$('td').length).toBe(5);
|
||||
|
||||
expect(view.$('td:eq(0) div.cell').text()).toBe('');
|
||||
expect(view.$('td:eq(1) div.cell').text()).toBe('1');
|
||||
expect(view.$('td:eq(2) div.cell').text()).toBe('test');
|
||||
expect(view.$('td:eq(3) div.cell').text()).toBe('1');
|
||||
expect(view.$('td:eq(4) div.cell').text()).toBe('GeoJSON');
|
||||
});
|
||||
|
||||
it("should not open row menu on click", function() {
|
||||
view.render();
|
||||
view.$('.row_header').trigger('click');
|
||||
expect(view._getRowOptions()).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
@ -1,81 +0,0 @@
|
||||
/**
|
||||
* test for table view
|
||||
*/
|
||||
describe("tableview_public", function() {
|
||||
|
||||
|
||||
describe('TableView', function() {
|
||||
var tview;
|
||||
var model;
|
||||
beforeEach(function() {
|
||||
this.server = sinon.fakeServer.create();
|
||||
|
||||
|
||||
model = new cdb.open.PublicCartoDBTableMetadata({
|
||||
name: 'test',
|
||||
schema: [
|
||||
['id', 'integer'],
|
||||
['col1', 'integer'],
|
||||
['col2', 'integer'],
|
||||
['col3', 'integer']
|
||||
]
|
||||
});
|
||||
|
||||
tview = new cdb.open.PublicTableView({
|
||||
el: $('<table>'),
|
||||
dataModel: model.data(),
|
||||
model: model,
|
||||
row_header: true
|
||||
});
|
||||
model.data().reset([
|
||||
{'id': 1, 'col1': 1, 'col2': 2, 'col3': 3},
|
||||
{'id': 2, 'col1': 4, 'col2': 5, 'col3': 6}
|
||||
]);
|
||||
});
|
||||
|
||||
it("should show the empty table layout when there's no data", function() {
|
||||
model.data().reset();
|
||||
expect(tview.$('tfoot').length).toBe(1);
|
||||
});
|
||||
|
||||
it("should show the public empty table warning, not the private one", function() {
|
||||
model.data().reset();
|
||||
model.data().trigger('dataLoaded');
|
||||
tview.render();
|
||||
|
||||
expect(tview.$('.placeholder.noRows').length).toBe(0);
|
||||
expect(tview.$('.placeholder.noRows.decoration').length).toBe(0);
|
||||
|
||||
})
|
||||
|
||||
it("should not show the empty table layout after an empty row insertion", function() {
|
||||
model.data().reset();
|
||||
tview.render();
|
||||
tview.addEmptyRow()
|
||||
expect(tview.$('tfoot').length).toBe(0);
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
describe('TableTab', function() {
|
||||
var tview;
|
||||
var model;
|
||||
beforeEach(function() {
|
||||
model = new cdb.open.PublicCartoDBTableMetadata({
|
||||
name: 'test'
|
||||
});
|
||||
|
||||
tview = new cdb.open.PublicTableTab({
|
||||
model: model
|
||||
});
|
||||
});
|
||||
|
||||
it('should render a div', function() {
|
||||
tview.render();
|
||||
expect(tview.$el.hasClass('table')).toBeTruthy();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
Loading…
Reference in new issue