Skip to content

Commit

Permalink
For #152 - implemented 'send by sms' function, hide 'send by sms' lin…
Browse files Browse the repository at this point in the history
…k on iOS devices
  • Loading branch information
vitalidze committed May 15, 2015
1 parent 1e64df3 commit 24cdd58
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 57 deletions.
78 changes: 65 additions & 13 deletions src/main/webapp/m/js/i18n/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ var i18n = {
address: 'Address',
follow: 'Follow',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
bg: {
_name_: 'Български',
Expand Down Expand Up @@ -57,7 +61,11 @@ var i18n = {
address: 'Адрес',
follow: 'Следвай',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
de: {
_name_: 'German',
Expand Down Expand Up @@ -87,7 +95,11 @@ var i18n = {
address: 'Adresse',
follow: 'Folgen',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
es: {
_name_: 'Spanish',
Expand Down Expand Up @@ -117,7 +129,11 @@ var i18n = {
address: 'Dirección',
follow: 'Seguir',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
hu: {
_name_: 'Hungarian',
Expand Down Expand Up @@ -147,7 +163,11 @@ var i18n = {
address: 'Cím',
follow: 'Követés',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
it: {
_name_: 'Italian',
Expand Down Expand Up @@ -177,7 +197,11 @@ var i18n = {
address: 'Indirizzo',
follow: 'Segui',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
lt: {
_name_: 'Latvian',
Expand Down Expand Up @@ -207,7 +231,11 @@ var i18n = {
address: 'Adresas',
follow: 'Centruoti',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
nl: {
_name_: 'Danish',
Expand Down Expand Up @@ -237,7 +265,11 @@ var i18n = {
address: 'Adres',
follow: 'Volgen',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
pl: {
_name_: 'Polish',
Expand Down Expand Up @@ -267,7 +299,11 @@ var i18n = {
address: 'Adres',
follow: 'Obserwuj',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
pt_PT: {
_name_: 'Portuguese',
Expand Down Expand Up @@ -297,7 +333,11 @@ var i18n = {
address: 'Morada',
follow: 'Seguir',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
ru: {
_name_: 'Russian',
Expand Down Expand Up @@ -327,7 +367,11 @@ var i18n = {
address: 'Адрес',
follow: 'Отслеживать',
stop_following: 'Прекратить отслеживание',
geo_fence: 'Геозона'
geo_fence: 'Геозона',
send_location_by_email: 'Отправить по эл. почте',
send_location_url_by_email: 'Отправить ссылку по эл. почте',
send_location_by_sms: 'Отправить по SMS',
send_location_url_by_sms: 'Отправить ссылку по SMS'
},
tl: {
_name_: 'Tagalog',
Expand Down Expand Up @@ -357,7 +401,11 @@ var i18n = {
address: 'Address',
follow: 'Sundin',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
},
sv_SE: {
_name_: 'Svenska',
Expand Down Expand Up @@ -387,6 +435,10 @@ var i18n = {
address: 'Adress',
follow: 'F\u00f6lj',
stop_following: 'Stop following',
geo_fence: 'Geo-fence'
geo_fence: 'Geo-fence',
send_location_by_email: 'Send location by Email',
send_location_url_by_email: 'Send location URL by Email',
send_location_by_sms: 'Send location by SMS',
send_location_url_by_sms: 'Send location URL by SMS'
}
};
94 changes: 50 additions & 44 deletions src/main/webapp/m/js/traccar-mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,56 +497,57 @@ function drawDeviceDetails(deviceId, position) {
drawDeviceDetails(deviceId, position);
});

// register 'send by email' function
$$('#device-' + deviceId + '-send-email').on('click', function () {
var target = this;
var drawSubject = function() {
for (var i = 0; i < appState.devices.length; i++) {
if (appState.devices[i].id == deviceId) {
return appState.devices[i].name;
}
}
return "";
};
var drawCoordinatesText = function() {
var p = appState.latestPositions[deviceId];
var text =
i18n.time + ': ' + formatDate(p.time) + '\n' +
i18n.latitude + ': ' + formatDouble(p.latitude, 4) + '\n' +
i18n.longitude + ': ' + formatDouble(p.longitude, 4) + '\n' +
i18n.speed + ': ' + formatSpeed(p.speed) + '\n' +
i18n.course + ': ' + formatDouble(p.course, 2) + '\n';
if (p.address != undefined && p.address != null) {
text += i18n.address + ': ' + p.address + '\n';
var drawSubject = function() {
for (var i = 0; i < appState.devices.length; i++) {
if (appState.devices[i].id == deviceId) {
return appState.devices[i].name;
}
var other = parseOther(p);
if (other != undefined && other != null) {
for (var k in other) {
text += k + ': ' + other[k] + '\n';
}
}
return "";
};
var drawCoordinatesText = function() {
var p = appState.latestPositions[deviceId];
var text =
i18n.time + ': ' + formatDate(p.time) + '\n' +
i18n.latitude + ': ' + formatDouble(p.latitude, 4) + '\n' +
i18n.longitude + ': ' + formatDouble(p.longitude, 4) + '\n' +
i18n.speed + ': ' + formatSpeed(p.speed) + '\n' +
i18n.course + ': ' + formatDouble(p.course, 2) + '\n';
if (p.address != undefined && p.address != null) {
text += i18n.address + ': ' + p.address + '\n';
}
var other = parseOther(p);
if (other != undefined && other != null) {
for (var k in other) {
text += k + ': ' + other[k] + '\n';
}
if (p.geoFences != undefined && p.geoFences != null) {
for (var i = 0; i < p.geoFences.length; i++) {
text += i18n.geo_fence + ': ' + p.geoFences[i].name + '\n';
}
}
if (p.geoFences != undefined && p.geoFences != null) {
for (var i = 0; i < p.geoFences.length; i++) {
text += i18n.geo_fence + ': ' + p.geoFences[i].name + '\n';
}
return text;
};
var drawURL = function() {
var p = appState.latestPositions[deviceId];
return 'http://www.openstreetmap.org/?mlat=' + p.latitude + '&mlon=' + p.longitude;
};
}
return text;
};
var drawURL = function() {
var p = appState.latestPositions[deviceId];
return 'http://www.openstreetmap.org/?mlat=' + p.latitude + '&mlon=' + p.longitude;
};

// register 'send by email' function
$$('#device-' + deviceId + '-send-email').on('click', function () {
var target = this;
var buttons = [
{
text: 'Send coordinates',
text: i18n.send_location_by_email,
onClick: function () {
window.open('mailto:?subject=' + encodeURIComponent(drawSubject()) + '&body=' + encodeURIComponent(drawCoordinatesText()), '_blank');
window.location = 'mailto:?subject=' + encodeURIComponent(drawSubject()) + '&body=' + encodeURIComponent(drawCoordinatesText());
}
},
{
text: 'Send location URL',
text: i18n.send_location_url_by_email,
onClick: function () {
window.open('mailto:?subject=' + encodeURIComponent(drawSubject()) + '&body=' + encodeURIComponent(drawURL()), '_blank');
window.location = 'mailto:?subject=' + encodeURIComponent(drawSubject()) + '&body=' + encodeURIComponent(drawURL());
}
}
];
Expand All @@ -558,20 +559,25 @@ function drawDeviceDetails(deviceId, position) {
var target = this;
var buttons = [
{
text: 'Send coordinates',
text: i18n.send_location_by_sms,
onClick: function () {
myApp.alert('Button1 clicked');
window.location = 'sms:?body=' + encodeURIComponent(drawCoordinatesText());
}
},
{
text: 'Send location URL',
text: i18n.send_location_url_by_sms,
onClick: function () {
myApp.alert('Button2 clicked');
window.location = 'sms:?body=' + encodeURIComponent(drawURL());
}
}
];
myApp.actions(target, buttons);
});

// hide 'send by sms' on ios devices since 'body' is not supported in sms URLs there
if (myApp.device.ios) {
$$('#device-' + deviceId + '-send-sms').hide();
}
}
}
}
Expand Down

0 comments on commit 24cdd58

Please sign in to comment.