diff options
author | Struan Donald <struan@exo.org.uk> | 2013-02-28 17:01:10 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-02-28 17:01:10 +0000 |
commit | e481a7fd383e041cd6be4f262a4dcc40b3e5a744 (patch) | |
tree | 6abd5f1866a3b9b48ed18ed45c21e44cc05c5247 /www/js | |
parent | df7de48f2eb5c4c6699273392296f87af628ea51 (diff) |
add in photo page and navigation to page
also used jquery mobile pageshow/hide events instead of our own
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/app.js | 2 | ||||
-rw-r--r-- | www/js/router.js | 16 | ||||
-rw-r--r-- | www/js/views/around.js | 41 | ||||
-rw-r--r-- | www/js/views/fms.js | 13 | ||||
-rw-r--r-- | www/js/views/home.js | 9 |
5 files changed, 72 insertions, 9 deletions
diff --git a/www/js/app.js b/www/js/app.js index 01c8f03..94ed26a 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -38,7 +38,7 @@ var tpl = { ;(function (FMS, Backbone, _, $) { _.extend(FMS, { templates: [ - 'home', 'around' + 'home', 'around', 'photo' ], initialized: 0, diff --git a/www/js/router.js b/www/js/router.js index 5327a1c..4c7430c 100644 --- a/www/js/router.js +++ b/www/js/router.js @@ -6,7 +6,8 @@ routes: { '': 'home', 'home': 'home', - 'around': 'around' + 'around': 'around', + 'photo': 'photo' }, initialize: function() { @@ -28,17 +29,22 @@ this.changeView(homeView); }, + photo: function(){ + var photoView = new FMS.PhotoView(); + this.changeView(photoView); + }, + changeView: function(view) { console.log( 'change View to ' + view.id ); $(view.el).attr('data-role', 'page'); + if ( view.prev ) { + $(view.el).attr('data-add-back-btn', 'true'); + } view.render(); $('body').append($(view.el)); $.mobile.changePage($(view.el), { changeHash: false }); - if(!_.isNull(this.currentView)) { - this.currentView.destroy(); - } - view.afterDisplay(); + console.log('changed View to ' + view.id); this.currentView = view; } }) diff --git a/www/js/views/around.js b/www/js/views/around.js index 02f7cc0..53c2889 100644 --- a/www/js/views/around.js +++ b/www/js/views/around.js @@ -5,6 +5,12 @@ tag: 'div', id: 'around-page', + events: { + 'pagehide': 'destroy', + 'pageshow': 'afterDisplay', + 'click #mark-here': 'onClickReport' + }, + afterDisplay: function() { this.locate(); }, @@ -45,6 +51,41 @@ this.displayError( STRINGS.location_problem ); } }, + + onClickReport: function() { + var position = this.getCrossHairPosition(); + + var l = new Locate(); + _.extend(l, Backbone.Events); + l.on('failed', this.noMap, this ); + l.on('located', this.goPhoto, this ); + l.check_location( { latitude: position.lat, longitude: position.lon } ); + }, + + goPhoto: function(info) { + //this.model.set('lat', info.coordinates.latitude ); + //this.model.set('lon', info.coordinates.longitude ); + //this.model.set('categories', info.details.category ); + + this.navigate( 'photo' ); + }, + + getCrossHairPosition: function() { + var cross = fixmystreet.map.getControlsByClass( + "OpenLayers.Control.Crosshairs"); + + var position = cross[0].getMapPosition(); + position.transform( + fixmystreet.map.getProjectionObject(), + new OpenLayers.Projection("EPSG:4326") + ); + + return position; + }, + + _destroy: function() { + delete fixmystreet; + } }) }); })(FMS, Backbone, _, $); diff --git a/www/js/views/fms.js b/www/js/views/fms.js index 384d125..848690d 100644 --- a/www/js/views/fms.js +++ b/www/js/views/fms.js @@ -21,6 +21,14 @@ afterDisplay: function() {}, + navigate: function( route, direction ) { + if ( !direction ) { + direction == 'left'; + } + + FMS.router.navigate( route, { trigger: true } ); + }, + onClickButtonPrev: function() { this.navigate( this.prev, 'right' ); }, @@ -33,7 +41,10 @@ alert(msg); }, - destroy: function() { console.log('destory for ' + this.id); this.remove(); } + destroy: function() { console.log('destory for ' + this.id); this._destroy(); this.remove(); }, + + _destroy: function() {} }) }); + _.extend( FMS.FMSView, Backbone.Events ); })(FMS, Backbone, _, $); diff --git a/www/js/views/home.js b/www/js/views/home.js index e29534e..2fc07e6 100644 --- a/www/js/views/home.js +++ b/www/js/views/home.js @@ -5,6 +5,11 @@ tag: 'div', id: 'front-page', + events: { + 'pagehide': 'destroy', + 'pageshow': 'afterDisplay' + }, + afterRender: function() { /* if ( !can_geolocate && ( !navigator.network || !navigator.network.connection ) ) { @@ -27,9 +32,9 @@ if ( navigator && navigator.network && ( navigator.network.connection.type == Connection.NONE || navigator.network.connection.type == Connection.UNKNOWN ) ) { localStorage.offline = 1; - FMS.router.navigate( 'no_connection' ); + this.navigate( 'no_connection' ); } else { - FMS.router.navigate( 'around', { trigger: true } ); + this.navigate( 'around' ); } } }) |