Built files from Bizgaze WebServer
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

location.component.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. var Unibase;
  2. (function (Unibase) {
  3. let Forms;
  4. (function (Forms) {
  5. let Controls;
  6. (function (Controls) {
  7. class Location {
  8. init(formpropertyid, prop, callback) {
  9. var _id = $(".formValidate:visible").attr("id");
  10. var slt = _id.split('_');
  11. var map11 = $('#locationcontrol_' + formpropertyid);
  12. map11.geocomplete({ details: "form.form_" + slt[1] });
  13. initialize();
  14. function initialize() {
  15. var ac = eval('new google.maps.places.Autocomplete((document.getElementById("Location_Map")), {types: ["geocode"]});');
  16. ac.addListener('place_changed', function () {
  17. var geocoder = new google.maps.Geocoder();
  18. setTimeout(function () {
  19. var address = document.getElementById('Location_latid');
  20. address.value;
  21. geocoder.geocode({ 'address': address }, function (results, status) {
  22. if (status == google.maps.GeocoderStatus.OK) {
  23. var latitude = results[0].geometry.location.lat();
  24. var longitude = results[0].geometry.location.lng();
  25. $('#hfLattitude').val(latitude);
  26. $('#hfLongitude').val(longitude);
  27. }
  28. });
  29. }, 1000);
  30. });
  31. }
  32. var instance = Location.Instance();
  33. instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
  34. instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
  35. if (callback != null)
  36. callback();
  37. }
  38. loadControl(containerid, prop) {
  39. var regExpr = "";
  40. var ErrMsg = "";
  41. var Isrequired = prop.IsRequired != true ? 'hidden' : '';
  42. var required = prop.IsRequired != true ? '' : 'required';
  43. const { helpTooltipHtml, helpTextHtml } = Unibase.Platform.Forms.Components.FormViewer.Instance().getControlHelpHtml(prop);
  44. 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">' +
  45. '<span class="input-group-addon bg-white no-border mt-10"><i class="text-success fa fa-map-marker pull-left"></i></span>' +
  46. '<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 + '"> ' +
  47. '<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>' +
  48. '<input type="hidden" id="hfId" value=""><label for="Validation" id="lblValidation_' + prop.DocPropertyName + '"></label><input type="hidden" id="hfFormPropertyId" value=""></div></div>' +
  49. '<div class="col-sm-2 mt-25 hidden" style="padding:0px">' +
  50. '<a href="javascript:;" class="btn btn-success mb-1" onclick="_bizgaze_control_Location.getLocation()">Capture Location</a>' +
  51. '<button type="button" class="btn btn-success hidden" onclick="_bizgaze_control_Location.getMobileLocation()">Capture Location</button>' +
  52. '</div></div>' +
  53. '<input type="hidden" id="hfLattitude" name="lat" value="">' +
  54. '<input type ="hidden" id = "hfLongitude" name = "lng" value = "" >' +
  55. '<input type="hidden" id="hdn_locationcontrol" class="value-control" value="Unibase.Forms.Controls.Location.Instance().meetingControlObj(' + prop.FormPropertyId + ')">' +
  56. '<a href="javascript:;" class="btn btn-default input-group-addon hidden" onclick="_bizgaze_control_Location.getLocation()">Capture Location</a>' +
  57. '<a href="javascript:;" class="btn btn-primary hidden input-group-addon" onclick="_bizgaze_control_Location.getMobileLocation()">Current Location</a>';
  58. $("#" + containerid).html(html);
  59. }
  60. getLocation(formpropertyid) {
  61. if (navigator.geolocation) {
  62. navigator.geolocation.getCurrentPosition(function (position) {
  63. $("#hfLattitude").val(position.coords.latitude);
  64. $("#hfLongitude").val(position.coords.longitude);
  65. Unibase.Forms.Controls.Location.Instance().showPosition(formpropertyid, position);
  66. });
  67. }
  68. else {
  69. bootbox.alert("Geolocation is not supported by this browser.");
  70. }
  71. }
  72. showPosition(formpropertyid, position) {
  73. var instance = this;
  74. $("#hfLattitude").val(position.coords.latitude);
  75. $("#hfLongitude").val(position.coords.longitude);
  76. var cityname = instance.getCityNameByLatdLgtd(formpropertyid, position.coords.latitude, position.coords.longitude);
  77. }
  78. getCityNameByLatdLgtd(formpropertyid, latd, lgtd) {
  79. var instance = this;
  80. var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latd + "," + lgtd + "&key=" + _mapsettings.key() + "&sensor=false";
  81. var xhr = instance.createCORSRequest1('Get', url);
  82. if (!xhr) {
  83. bootbox.alert('CORS not supported');
  84. return;
  85. }
  86. xhr.onload = function () {
  87. var text = xhr.responseText;
  88. var json = JSON.parse(text);
  89. var found_city = false;
  90. if (json && json.results.length > 0) {
  91. let formatted_address = json.results[0].formatted_address;
  92. for (var k = 0; k < json.results.length; k++) {
  93. if (json.results[k].address_components) {
  94. for (var i = 0; i < json.results[k].address_components.length; i++) {
  95. if (json.results[k].address_components[i]) {
  96. for (var j = 0; j < json.results[k].address_components[i].types.length; j++) {
  97. if (json.results[k].address_components[i].types[j] == 'locality') {
  98. var city_name = json.results[k].address_components[i].long_name;
  99. $("#locationcontrol_" + formpropertyid).val(formatted_address);
  100. found_city = true;
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. if (found_city == false) {
  109. $("#locationcontrol_" + formpropertyid).val('City not found!');
  110. }
  111. };
  112. xhr.onerror = function () {
  113. bootbox.alert('Woops, there was an error making the request.');
  114. };
  115. xhr.send();
  116. }
  117. meetingControlObj(FormPropertyId) {
  118. var MeetingEntries = new Array();
  119. MeetingEntries.push({
  120. MeetingLatId: $('#hfLattitude').val(),
  121. MeetingLngId: $("#hfLongitude").val(),
  122. CityName: $("#locationcontrol_" + FormPropertyId).val(),
  123. });
  124. return MeetingEntries;
  125. }
  126. loadControlSettings(controlsettingjson, formpropertyid) {
  127. return null;
  128. }
  129. loadPropertySettings(propertysettings, formpropertyid) {
  130. return null;
  131. }
  132. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  133. $("#txt_" + formpropertyid).val(propval);
  134. var meetingId = Number(propval);
  135. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile('apps/communications/meetings/managers/meetingmanager.js', function () {
  136. Bizgaze.Apps.Communications.Meetings.Managers.MeetingManager.Instance().getMeeting(meetingId).then(function (response) {
  137. var data = response.result;
  138. if (data.MeetingLatId != "0" && data.MeetingLngId != "0" && data.CityName != "0") {
  139. $('#hfLattitude').val(data.MeetingLatId);
  140. $("#hfLongitude").val(data.MeetingLngId);
  141. $("#locationcontrol_" + formpropertyid).val(data.CityName);
  142. }
  143. });
  144. });
  145. }
  146. createCORSRequest1(method, url) {
  147. var xhr = new XMLHttpRequest();
  148. if ("withCredentials" in xhr) {
  149. xhr.open(method, url, true);
  150. }
  151. else {
  152. xhr = null;
  153. }
  154. return xhr;
  155. }
  156. static Instance() {
  157. if (this.instance === undefined) {
  158. this.instance = new Location();
  159. }
  160. return this.instance;
  161. }
  162. }
  163. Controls.Location = Location;
  164. })(Controls = Forms.Controls || (Forms.Controls = {}));
  165. })(Forms = Unibase.Forms || (Unibase.Forms = {}));
  166. })(Unibase || (Unibase = {}));