Built files from Bizgaze WebServer
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

geofencingmap.js 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. var Bizgaze;
  2. (function (Bizgaze) {
  3. let Apps;
  4. (function (Apps) {
  5. let Hrms;
  6. (function (Hrms) {
  7. let Controls;
  8. (function (Controls) {
  9. class geofencingmap extends Unibase.Platform.Core.BaseComponent {
  10. init(formpropertyid, prop, callback) {
  11. var _id = $(".formValidate:visible").attr("id");
  12. var slt = _id.split('_');
  13. var map11 = $('#locationcontrol_' + formpropertyid);
  14. map11.geocomplete({ details: "form.form_" + slt[1] });
  15. var instance = this;
  16. instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
  17. instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
  18. }
  19. loadControl(containerid, prop) {
  20. var html = '<div id="GeofencingMap" class="text-center b-a" style="height: 250px"></div>' +
  21. '<div class="coordinates"><span id="lbl_coordinates"></span></div><input type="hidden" id="hfLattitude" name="lat" value="">' +
  22. '<input type ="hidden" id = "hfLongitude" name = "lng" value = "" >';
  23. $("#" + containerid).html(html);
  24. var latd = 0;
  25. var lgtd = 0;
  26. $('#hfLattitude').val(latd);
  27. $('#hfLongitude').val(lgtd);
  28. $("#lbl_coordinates").html("latd : " + latd + ", lgtd : " + lgtd);
  29. Bizgaze.Apps.Hrms.Controls.geofencingmap.Instance().loadMap(latd, lgtd, prop.FormPropertyId);
  30. }
  31. loadMap(latd, lgtd, formpropertyid) {
  32. var instance = this;
  33. var myLatlng = new google.maps.LatLng(latd, lgtd);
  34. var mapOptions = {
  35. zoom: 15,
  36. center: myLatlng,
  37. draggable: true,
  38. };
  39. let radius = Number($("#div_radius").find(".number_radius").val());
  40. var myCity = new google.maps.Circle({
  41. center: myLatlng,
  42. radius: radius,
  43. strokeColor: "#87C1FF",
  44. strokeOpacity: 0.8,
  45. strokeWeight: 2,
  46. fillColor: "#87C1FF",
  47. fillOpacity: 0.4
  48. });
  49. var map = new google.maps.Map(document.getElementById("GeofencingMap"), mapOptions);
  50. myCity.setMap(map);
  51. var marker = new google.maps.Marker({
  52. position: myLatlng,
  53. title: "",
  54. });
  55. marker.setMap(map);
  56. var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latd + "," + lgtd + "&key=" + _mapsettings.key() + "&sensor=false";
  57. var xhr = Bizgaze.Apps.Hrms.Controls.geofencingmap.Instance().createCORSRequest2('Get', url);
  58. if (!xhr) {
  59. bootbox.alert('CORS not supported');
  60. return;
  61. }
  62. xhr.onload = function () {
  63. var text = xhr.responseText;
  64. var json = JSON.parse(text);
  65. instance.addressData = [];
  66. instance.addressData = json.results;
  67. $("#locationcontrol_" + formpropertyid).val(json.results[0].formatted_address);
  68. };
  69. xhr.onerror = function () {
  70. bootbox.alert('Woops, there was an error making the request.');
  71. };
  72. }
  73. getLocation(formpropertyid) {
  74. var ContactAddressId = Number($("#hf_AutocompleteId").val());
  75. var latitude = 0;
  76. var longitude = 0;
  77. this.fileCacheHelper.addCacheFiles(["apps/crm/contacts/managers/contactmanager.js"]);
  78. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressById(ContactAddressId).then(function (response) {
  79. latitude = response.result.AddrLatd;
  80. longitude = response.result.AddrLgtd;
  81. if (latitude == 0 || longitude == 0 || latitude == null || longitude == null) {
  82. MessageHelper.Instance().showError("You are Selected Branch Geo Tagging is not Enabled longitude : " + longitude + " , latitude : " + latitude, 'div_ErrorMessage_' + $('#' + Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId()).find('#hf_FormId').val());
  83. }
  84. $("#div_latitude").find(".number_latitude").val(+latitude);
  85. $("#div_longitude").find(".number_longitude").val(+longitude);
  86. $("#lbl_coordinates").html("latd : " + latitude + ", lgtd : " + longitude);
  87. Bizgaze.Apps.Hrms.Controls.geofencingmap.Instance().loadMap(latitude, longitude, formpropertyid);
  88. });
  89. }
  90. createCORSRequest2(method, url) {
  91. let XDomainRequest;
  92. var xhr = new XMLHttpRequest();
  93. if ("withCredentials" in xhr) {
  94. xhr.open(method, url, true);
  95. }
  96. else if (typeof XDomainRequest != "undefined") {
  97. xhr = new XDomainRequest();
  98. xhr.open(method, url);
  99. }
  100. else {
  101. xhr = null;
  102. }
  103. return xhr;
  104. }
  105. loadControlSettings(controlsettingjson, formpropertyid) {
  106. return null;
  107. }
  108. loadPropertySettings(propertysettings, formpropertyid) {
  109. return null;
  110. }
  111. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  112. return null;
  113. }
  114. static Instance() {
  115. if (this.instance === undefined) {
  116. this.instance = new geofencingmap();
  117. }
  118. return this.instance;
  119. }
  120. }
  121. Controls.geofencingmap = geofencingmap;
  122. })(Controls = Hrms.Controls || (Hrms.Controls = {}));
  123. })(Hrms = Apps.Hrms || (Apps.Hrms = {}));
  124. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  125. })(Bizgaze || (Bizgaze = {}));