2014-08-06 14:09:01 +00:00
|
|
|
(function () {
|
|
|
|
Metamaps.Views = {};
|
|
|
|
|
2014-08-10 17:06:58 +00:00
|
|
|
Metamaps.Views.init = function () {
|
|
|
|
|
2014-08-06 14:09:01 +00:00
|
|
|
Metamaps.Views.MapCard = Backbone.View.extend({
|
|
|
|
|
2014-08-10 17:06:58 +00:00
|
|
|
template: Hogan.compile( $('#mapCardTemplate').html() ),
|
|
|
|
|
2014-08-06 14:09:01 +00:00
|
|
|
tagName: "div",
|
|
|
|
|
|
|
|
className: "map",
|
|
|
|
|
2014-08-10 17:06:58 +00:00
|
|
|
id: function() {
|
|
|
|
return this.model.id;
|
|
|
|
},
|
|
|
|
|
2014-08-06 14:09:01 +00:00
|
|
|
events: {
|
|
|
|
"click .icon": "open",
|
|
|
|
"click .button.edit": "openEditDialog",
|
|
|
|
"click .button.delete": "destroy"
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
this.listenTo(this.model, "change", this.render);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function () {
|
2014-08-10 17:06:58 +00:00
|
|
|
this.$el.html( this.template.render(this.model.attrForCards()) );
|
|
|
|
return this;
|
2014-08-06 14:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-08-10 17:06:58 +00:00
|
|
|
var mapsWrapper = Backbone.View.extend({
|
|
|
|
|
|
|
|
el: '.mapsWrapper',
|
|
|
|
|
|
|
|
initialize: function (opts) {
|
|
|
|
|
|
|
|
},
|
|
|
|
setCollection: function (collection) {
|
|
|
|
if (this.collection) this.stopListening(this.collection);
|
|
|
|
this.collection = collection;
|
|
|
|
this.listenTo(this.collection, 'successOnFetch', this.handleSuccess);
|
|
|
|
this.listenTo(this.collection, 'errorOnFetch', this.handleError);
|
|
|
|
},
|
|
|
|
render: function () {
|
2014-08-10 20:20:21 +00:00
|
|
|
|
|
|
|
Metamaps.Loading.loader.hide();
|
|
|
|
|
2014-08-10 17:06:58 +00:00
|
|
|
var that = this;
|
|
|
|
this.$el.empty();
|
|
|
|
|
|
|
|
this.collection.each(function (map) {
|
|
|
|
var view = new Metamaps.Views.MapCard({ model: map });
|
|
|
|
|
|
|
|
that.$el.append( view.render().el );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleSuccess: function () {
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
handleError: function () {
|
|
|
|
alert('error!');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Metamaps.Views.exploreMaps = new mapsWrapper();
|
|
|
|
};
|
|
|
|
|
2014-08-06 14:09:01 +00:00
|
|
|
})();
|