123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- 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 = '<style type="text/css">.pac-container{z-index:1100 !important;}</style><div class="row"><div class="div_map_meeting hidden" ></div><div class="col-sm-12"><label for="lbl" id="lbl_' + prop.DocPropertyName + '" class="text-secondary" style="margin-bottom:0px;">' + helpTooltipHtml + '<span class="label-name">' + prop.LabelName + '</span><span class="text-danger ' + Isrequired + '" id="spnIsRequired_' + prop.DocPropertyId + '"> *</span></label><div class="input-group floating-label-form-group floating-label-form-group-with-value border-left-0" style="padding-left:0px">' +
- '<span class="input-group-addon bg-white no-border mt-10"><i class="text-success fa fa-map-marker pull-left"></i></span>' +
- '<input type="text" id="locationcontrol_' + prop.UniqueId + '" class="form-control ' + required + '" data-isdefault="' + prop.IsDefault + '" data-propdoctypename="' + prop.DocTypeName + '" data-required="' + prop.IsRequired + '" data-regularexp="' + regExpr + '" data-validatemsg="' + ErrMsg + '" placeholder="' + prop.Placeholder + '" data-placeholder="' + prop.Placeholder + '" data-label="' + prop.LabelName + '"> ' +
- '<a href="javascript:;" style="font-size: 14px;" class="btn btn-success mb-1" onclick="Unibase.Forms.Controls.Location.Instance().getLocation(' + prop.FormPropertyId + ')">Capture Location</a>' +
- '<input type="hidden" id="hfId" value=""><label for="Validation" id="lblValidation_' + prop.DocPropertyName + '"></label><input type="hidden" id="hfFormPropertyId" value=""></div></div>' +
- '<div class="col-sm-2 mt-25 hidden" style="padding:0px">' +
- '<a href="javascript:;" class="btn btn-success mb-1" onclick="_bizgaze_control_Location.getLocation()">Capture Location</a>' +
- '<button type="button" class="btn btn-success hidden" onclick="_bizgaze_control_Location.getMobileLocation()">Capture Location</button>' +
- '</div></div>' +
- '<input type="hidden" id="hfLattitude" name="lat" value="">' +
- '<input type ="hidden" id = "hfLongitude" name = "lng" value = "" >' +
- '<input type="hidden" id="hdn_locationcontrol" class="value-control" value="Unibase.Forms.Controls.Location.Instance().meetingControlObj(' + prop.FormPropertyId + ')">' +
- '<a href="javascript:;" class="btn btn-default input-group-addon hidden" onclick="_bizgaze_control_Location.getLocation()">Capture Location</a>' +
- '<a href="javascript:;" class="btn btn-primary hidden input-group-addon" onclick="_bizgaze_control_Location.getMobileLocation()">Current Location</a>';
- $("#" + 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 = {}));
|