2014-08-06 10:09:01 -04:00
|
|
|
(function () {
|
|
|
|
Metamaps.Views = {};
|
2014-08-15 18:04:22 -04:00
|
|
|
|
|
|
|
var initialized = false;
|
2014-08-06 10:09:01 -04:00
|
|
|
|
2014-08-10 13:06:58 -04:00
|
|
|
Metamaps.Views.init = function () {
|
|
|
|
|
2014-11-25 15:06:30 -05:00
|
|
|
Metamaps.Views.MapperCard = Backbone.View.extend({
|
|
|
|
|
|
|
|
template: Hogan.compile( $('#mapperCardTemplate').html() ),
|
|
|
|
|
|
|
|
tagName: "div",
|
|
|
|
|
|
|
|
className: "mapper",
|
|
|
|
|
|
|
|
render: function () {
|
|
|
|
this.$el.html( this.template.render(this.model) );
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-08-06 10:09:01 -04:00
|
|
|
Metamaps.Views.MapCard = Backbone.View.extend({
|
|
|
|
|
2014-08-10 13:06:58 -04:00
|
|
|
template: Hogan.compile( $('#mapCardTemplate').html() ),
|
|
|
|
|
2014-08-06 10:09:01 -04:00
|
|
|
tagName: "div",
|
|
|
|
|
|
|
|
className: "map",
|
|
|
|
|
2014-08-10 13:06:58 -04:00
|
|
|
id: function() {
|
|
|
|
return this.model.id;
|
|
|
|
},
|
|
|
|
|
2014-08-06 10:09:01 -04:00
|
|
|
initialize: function () {
|
|
|
|
this.listenTo(this.model, "change", this.render);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function () {
|
2014-08-10 13:06:58 -04:00
|
|
|
this.$el.html( this.template.render(this.model.attrForCards()) );
|
|
|
|
return this;
|
2014-08-06 10:09:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-08-10 13:06:58 -04:00
|
|
|
var mapsWrapper = Backbone.View.extend({
|
|
|
|
|
|
|
|
initialize: function (opts) {
|
|
|
|
|
|
|
|
},
|
|
|
|
setCollection: function (collection) {
|
|
|
|
if (this.collection) this.stopListening(this.collection);
|
|
|
|
this.collection = collection;
|
2014-10-14 23:20:40 -04:00
|
|
|
this.listenTo(this.collection, 'add', this.render);
|
2014-08-10 13:06:58 -04:00
|
|
|
this.listenTo(this.collection, 'successOnFetch', this.handleSuccess);
|
|
|
|
this.listenTo(this.collection, 'errorOnFetch', this.handleError);
|
|
|
|
},
|
2014-11-25 15:06:30 -05:00
|
|
|
render: function (mapperObj) {
|
2014-08-10 16:20:21 -04:00
|
|
|
|
2014-08-10 13:06:58 -04:00
|
|
|
var that = this;
|
2014-08-12 19:20:46 -04:00
|
|
|
|
|
|
|
this.el.innerHTML = "";
|
2014-08-10 13:06:58 -04:00
|
|
|
|
2014-11-25 15:06:30 -05:00
|
|
|
// in case it is a page where we have to display the mapper card
|
|
|
|
if (mapperObj) {
|
|
|
|
var view = new Metamaps.Views.MapperCard({ model: mapperObj });
|
|
|
|
|
|
|
|
that.el.appendChild( view.render().el );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-10 13:06:58 -04:00
|
|
|
this.collection.each(function (map) {
|
|
|
|
var view = new Metamaps.Views.MapCard({ model: map });
|
|
|
|
|
2014-08-12 19:20:46 -04:00
|
|
|
that.el.appendChild( view.render().el );
|
2014-08-10 13:06:58 -04:00
|
|
|
});
|
2014-08-20 15:37:18 -04:00
|
|
|
this.$el.append('<div class="clearfloat"></div>');
|
2014-08-12 19:20:46 -04:00
|
|
|
var m = Metamaps.Famous.maps.surf;
|
|
|
|
m.setContent(this.el);
|
2014-08-20 15:37:18 -04:00
|
|
|
setTimeout(function(){
|
|
|
|
var height = $(that.el).height() + 32 + 56;
|
|
|
|
m.setSize([undefined, height]);
|
|
|
|
}, 100);
|
|
|
|
|
2014-08-15 18:04:22 -04:00
|
|
|
if (!initialized) {
|
2014-08-12 19:20:46 -04:00
|
|
|
m.deploy(m._currTarget);
|
2014-08-15 18:04:22 -04:00
|
|
|
initialized = true;
|
2014-08-20 15:37:18 -04:00
|
|
|
setTimeout(function(){
|
|
|
|
var height = $(that.el).height() + 32 + 56;
|
|
|
|
m.setSize([undefined, height]);
|
|
|
|
}, 100);
|
2014-08-12 19:20:46 -04:00
|
|
|
}
|
2014-08-11 22:31:28 -04:00
|
|
|
|
2014-09-09 18:17:39 -04:00
|
|
|
Metamaps.Loading.hide();
|
2014-08-11 22:31:28 -04:00
|
|
|
setTimeout(function(){
|
2014-11-25 15:06:30 -05:00
|
|
|
var path = Metamaps.currentSection == "" ? "" : "/explore/" + Metamaps.currentPage;
|
|
|
|
|
|
|
|
// alter url if for mapper profile page
|
|
|
|
if (that.collection && that.collection.mapperId) {
|
|
|
|
path += "/" + that.collection.mapperId;
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:31:28 -04:00
|
|
|
Metamaps.Router.navigate(path);
|
|
|
|
}, 500);
|
2014-08-10 13:06:58 -04:00
|
|
|
},
|
|
|
|
handleSuccess: function () {
|
2014-11-25 15:06:30 -05:00
|
|
|
var that = this;
|
|
|
|
|
|
|
|
if (this.collection && this.collection.id === "mapper") {
|
|
|
|
this.fetchUserThenRender();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.render();
|
|
|
|
}
|
2014-08-10 13:06:58 -04:00
|
|
|
},
|
|
|
|
handleError: function () {
|
2014-08-11 22:31:28 -04:00
|
|
|
console.log('error loading maps!'); //TODO
|
2014-11-25 15:06:30 -05:00
|
|
|
},
|
|
|
|
fetchUserThenRender: function () {
|
|
|
|
var that = this;
|
|
|
|
// first load the mapper object and then call the render function
|
|
|
|
$.ajax({
|
|
|
|
url: "/users/" + this.collection.mapperId + "/details.json",
|
|
|
|
success: function (response) {
|
|
|
|
that.render(response);
|
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2014-08-10 13:06:58 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Metamaps.Views.exploreMaps = new mapsWrapper();
|
|
|
|
};
|
|
|
|
|
2014-08-06 10:09:01 -04:00
|
|
|
})();
|