var Unibase;
(function (Unibase) {
let Forms;
(function (Forms) {
let Controls;
(function (Controls) {
class Location {
init(formpropertyid, prop, callback) {
var _id = $(".formValidate:visible").attr("id");
var slt = _id.split('_');
var map11 = $('#locationcontrol_' + formpropertyid);
map11.geocomplete({ details: "form.form_" + slt[1] });
initialize();
function initialize() {
var ac = eval('new google.maps.places.Autocomplete((document.getElementById("Location_Map")), {types: ["geocode"]});');
ac.addListener('place_changed', function () {
var geocoder = new google.maps.Geocoder();
setTimeout(function () {
var address = document.getElementById('Location_latid');
address.value;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
$('#hfLattitude').val(latitude);
$('#hfLongitude').val(longitude);
}
});
}, 1000);
});
}
var instance = Location.Instance();
instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
if (callback != null)
callback();
}
loadControl(containerid, prop) {
var regExpr = "";
var ErrMsg = "";
var Isrequired = prop.IsRequired != true ? 'hidden' : '';
var required = prop.IsRequired != true ? '' : 'required';
const { helpTooltipHtml, helpTextHtml } = Unibase.Platform.Forms.Components.FormViewer.Instance().getControlHelpHtml(prop);
var html = '
' +
'
' +
'' +
'' +
'' +
'Capture Location' +
'Current Location';
$("#" + containerid).html(html);
}
getLocation(formpropertyid) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
$("#hfLattitude").val(position.coords.latitude);
$("#hfLongitude").val(position.coords.longitude);
Unibase.Forms.Controls.Location.Instance().showPosition(formpropertyid, position);
});
}
else {
bootbox.alert("Geolocation is not supported by this browser.");
}
}
showPosition(formpropertyid, position) {
var instance = this;
$("#hfLattitude").val(position.coords.latitude);
$("#hfLongitude").val(position.coords.longitude);
var cityname = instance.getCityNameByLatdLgtd(formpropertyid, position.coords.latitude, position.coords.longitude);
}
getCityNameByLatdLgtd(formpropertyid, latd, lgtd) {
var instance = this;
var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latd + "," + lgtd + "&key=" + _mapsettings.key() + "&sensor=false";
var xhr = instance.createCORSRequest1('Get', url);
if (!xhr) {
bootbox.alert('CORS not supported');
return;
}
xhr.onload = function () {
var text = xhr.responseText;
var json = JSON.parse(text);
var found_city = false;
if (json && json.results.length > 0) {
let formatted_address = json.results[0].formatted_address;
for (var k = 0; k < json.results.length; k++) {
if (json.results[k].address_components) {
for (var i = 0; i < json.results[k].address_components.length; i++) {
if (json.results[k].address_components[i]) {
for (var j = 0; j < json.results[k].address_components[i].types.length; j++) {
if (json.results[k].address_components[i].types[j] == 'locality') {
var city_name = json.results[k].address_components[i].long_name;
$("#locationcontrol_" + formpropertyid).val(formatted_address);
found_city = true;
}
}
}
}
}
}
}
if (found_city == false) {
$("#locationcontrol_" + formpropertyid).val('City not found!');
}
};
xhr.onerror = function () {
bootbox.alert('Woops, there was an error making the request.');
};
xhr.send();
}
meetingControlObj(FormPropertyId) {
var MeetingEntries = new Array();
MeetingEntries.push({
MeetingLatId: $('#hfLattitude').val(),
MeetingLngId: $("#hfLongitude").val(),
CityName: $("#locationcontrol_" + FormPropertyId).val(),
});
return MeetingEntries;
}
loadControlSettings(controlsettingjson, formpropertyid) {
return null;
}
loadPropertySettings(propertysettings, formpropertyid) {
return null;
}
bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
$("#txt_" + formpropertyid).val(propval);
var meetingId = Number(propval);
Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile('apps/communications/meetings/managers/meetingmanager.js', function () {
Bizgaze.Apps.Communications.Meetings.Managers.MeetingManager.Instance().getMeeting(meetingId).then(function (response) {
var data = response.result;
if (data.MeetingLatId != "0" && data.MeetingLngId != "0" && data.CityName != "0") {
$('#hfLattitude').val(data.MeetingLatId);
$("#hfLongitude").val(data.MeetingLngId);
$("#locationcontrol_" + formpropertyid).val(data.CityName);
}
});
});
}
createCORSRequest1(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
}
else {
xhr = null;
}
return xhr;
}
static Instance() {
if (this.instance === undefined) {
this.instance = new Location();
}
return this.instance;
}
}
Controls.Location = Location;
})(Controls = Forms.Controls || (Forms.Controls = {}));
})(Forms = Unibase.Forms || (Unibase.Forms = {}));
})(Unibase || (Unibase = {}));