From 2ce617cb7e9e93239a5259d073655c006569e35f Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 10 Aug 2016 11:11:18 -0300 Subject: [PATCH] Improve geolocation button --- .../message/messageBox.coffee | 89 ++++++++++--------- .../message/messageBox.html | 24 ++--- 2 files changed, 58 insertions(+), 55 deletions(-) diff --git a/packages/rocketchat-ui-message/message/messageBox.coffee b/packages/rocketchat-ui-message/message/messageBox.coffee index 0d03f3de263..e09a2238df2 100644 --- a/packages/rocketchat-ui-message/message/messageBox.coffee +++ b/packages/rocketchat-ui-message/message/messageBox.coffee @@ -80,11 +80,7 @@ Template.messageBox.helpers return 'show-send' showLocation: -> - if Geolocation.error() - console.log("Geolocation is not supported by this browser."); - return false - - return Template.instance().showLocationButton.get() + return Template.instance().location.get() isnt false notSubscribedTpl: -> return RocketChat.roomTypes.getNotSubscribedTpl @_id @@ -165,40 +161,35 @@ Template.messageBox.events 'click .message-form .icon-location.location': (event, instance) -> roomId = @_id - if instance.showLocationButton - - userGeoLocation = new ReactiveVar null - - Tracker.autorun (computation) -> - - userGeoLocation.set(Geolocation.latLng()) - - if userGeoLocation.get() - computation.stop() - - latitude = userGeoLocation.get().lat - longitude = userGeoLocation.get().lng - - text = '
' - - swal - title: t('Share_Location_Title') - text: text - showCancelButton: true - closeOnConfirm: true - closeOnCancel: true - html: true - , (isConfirm) -> - - if isConfirm isnt true - return + position = instance.location.get() + + latitude = position.coords.latitude + longitude = position.coords.longitude + + text = """ +
+ +
+ """ + + swal + title: t('Share_Location_Title') + text: text + showCancelButton: true + closeOnConfirm: true + closeOnCancel: true + html: true + , (isConfirm) -> + if isConfirm isnt true + return - Meteor.call "sendMessage", { - _id: Random.id() - rid: roomId - msg: "" - location: { 'type': 'Point', 'coordinates': [ longitude, latitude ]} - } + Meteor.call "sendMessage", + _id: Random.id() + rid: roomId + msg: "" + location: + type: 'Point' + coordinates: [ longitude, latitude ] 'click .message-form .mic': (e, t) -> @@ -245,8 +236,7 @@ Template.messageBox.onCreated -> @isMessageFieldEmpty = new ReactiveVar true @showMicButton = new ReactiveVar false @showVideoRec = new ReactiveVar false - @showLocationButton = new ReactiveVar false - @googleMapsKey = new ReactiveVar false + @location = new ReactiveVar false @autorun => videoRegex = /video\/webm/i @@ -263,8 +253,19 @@ Template.messageBox.onCreated -> else @showMicButton.set false - if RocketChat.settings.get('MapView_Enabled') and RocketChat.settings.get('MapView_GMapsAPIKey')?.length - @showLocationButton.set true - @googleMapsKey.set RocketChat.settings.get('MapView_GMapsAPIKey') + if RocketChat.settings.get('MapView_Enabled') and RocketChat.settings.get('MapView_GMapsAPIKey')?.length and navigator.geolocation?.getCurrentPosition? + success = (position) => + @location.set position + + error = (error) => + console.log 'Error getting your geolocation', error + @location.set false + + options = + enableHighAccuracy: true + maximumAge: 0 + timeout: 10000 + + navigator.geolocation.watchPosition success, error else - @showLocationButton.set false + @location.set false diff --git a/packages/rocketchat-ui-message/message/messageBox.html b/packages/rocketchat-ui-message/message/messageBox.html index 8d57630bb64..5b1edeb2391 100644 --- a/packages/rocketchat-ui-message/message/messageBox.html +++ b/packages/rocketchat-ui-message/message/messageBox.html @@ -7,13 +7,6 @@ - - {{#if showLocation}} -
- -
- {{/if}} - {{#if showSandstorm}}
@@ -28,6 +21,13 @@
+ {{#unless showSend}} + {{#if showLocation}} +
+ +
+ {{/if}} + {{/unless}}
@@ -39,11 +39,13 @@
-
-
- + {{#unless showSend}} +
+
+ +
-
+ {{/unless}}
{{#with usersTyping}}