From 278b6213bbdf3b044ede2be8a7a4ad390230bfbe Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Mon, 11 Aug 2014 22:31:28 -0400 Subject: [PATCH] improved explore maps pages --- .../javascripts/metamaps/Metamaps.Backbone.js | 18 +++++++++++++----- .../javascripts/metamaps/Metamaps.Router.js | 11 +++-------- .../javascripts/metamaps/Metamaps.Views.js | 10 +++++++--- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/metamaps/Metamaps.Backbone.js b/app/assets/javascripts/metamaps/Metamaps.Backbone.js index d73623de..98f9060f 100644 --- a/app/assets/javascripts/metamaps/Metamaps.Backbone.js +++ b/app/assets/javascripts/metamaps/Metamaps.Backbone.js @@ -14,15 +14,16 @@ Metamaps.Backbone.Map = Backbone.Model.extend({ }, fetchContained: function () { var bb = Metamaps.Backbone; + var that = this; var start = function (data) { - this.set('mappers', new bb.MapperCollection(data.mappers)); - this.set('topics', new bb.TopicCollection(data.topics)); - this.set('synapses', new bb.SynapseCollection(data.synapses)); - this.set('mappings', new bb.MappingCollection(data.mappings)); + that.set('mappers', new bb.MapperCollection(data.mappers)); + that.set('topics', new bb.TopicCollection(data.topics)); + that.set('synapses', new bb.SynapseCollection(data.synapses)); + that.set('mappings', new bb.MappingCollection(data.mappings)); } $.ajax({ - url: "/maps/" + this.id + "/contains", + url: "/maps/" + this.id + "/contains.json", success: start, async: false }); @@ -78,10 +79,17 @@ Metamaps.Backbone.MapsCollection = Backbone.Collection.extend({ comparator: function (a, b) { a = a.get(this.sortBy); b = b.get(this.sortBy); + var temp; if (this.sortBy === 'name') { a = a ? a.toLowerCase() : ""; b = b ? b.toLowerCase() : ""; } + else { + // this is for updated_at and created_at + temp = a; + a = b; + b = temp; + } return a > b ? 1 : a < b ? -1 : 0; }, getMaps: function () { diff --git a/app/assets/javascripts/metamaps/Metamaps.Router.js b/app/assets/javascripts/metamaps/Metamaps.Router.js index 43c2482b..a14e9bdc 100644 --- a/app/assets/javascripts/metamaps/Metamaps.Router.js +++ b/app/assets/javascripts/metamaps/Metamaps.Router.js @@ -52,15 +52,14 @@ Metamaps.GlobalUI.Search.close(0, true); $('.mapsWrapper').fadeOut(300); + setTimeout(function(){ + Metamaps.Router.navigate(""); + }, 500); } Metamaps.Famous.viz.hide(); Metamaps.Active.Map = null; Metamaps.Active.Topic = null; - - setTimeout(function(){ - Metamaps.Router.navigate(""); - }, 500); }, explore: function (section) { @@ -95,10 +94,6 @@ Metamaps.Famous.viz.hide(); Metamaps.Active.Map = null; Metamaps.Active.Topic = null; - - setTimeout(function(){ - Metamaps.Router.navigate("/explore/" + section); - }, 500); }, maps: function (id) { diff --git a/app/assets/javascripts/metamaps/Metamaps.Views.js b/app/assets/javascripts/metamaps/Metamaps.Views.js index fc4da130..4dbcc251 100644 --- a/app/assets/javascripts/metamaps/Metamaps.Views.js +++ b/app/assets/javascripts/metamaps/Metamaps.Views.js @@ -47,8 +47,6 @@ Metamaps.Views.init = function () { }, render: function () { - Metamaps.Loading.loader.hide(); - var that = this; this.$el.empty(); @@ -57,12 +55,18 @@ Metamaps.Views.init = function () { that.$el.append( view.render().el ); }); + + Metamaps.Loading.loader.hide(); + setTimeout(function(){ + var path = Metamaps.currentSection == "" ? "" : "/explore/" + Metamaps.currentPage; + Metamaps.Router.navigate(path); + }, 500); }, handleSuccess: function () { this.render(); }, handleError: function () { - alert('error!'); + console.log('error loading maps!'); //TODO } });