Skip to content

Commit

Permalink
feat(Desk): fetch geolocation btn in Employee Checkin form
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed May 29, 2024
1 parent 239e1a4 commit ced4969
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
52 changes: 50 additions & 2 deletions hrms/hr/doctype/employee_checkin/employee_checkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,54 @@
// For license information, please see license.txt

frappe.ui.form.on("Employee Checkin", {
// setup: (frm) => {
// }
refresh: async (_frm) => {
const allow_geolocation_tracking = await frappe.db.get_single_value(
"HR Settings",
"allow_geolocation_tracking",
);

if (!allow_geolocation_tracking) {
hide_field(["fetch_geolocation", "latitude", "longitude", "geolocation"]);
return;
}
},

fetch_geolocation: async (frm) => {
if (!navigator.geolocation) {
frappe.msgprint({
message: __("Geolocation is not supported by your current browser"),
title: __("Geolocation Error"),
indicator: "red",
});
hide_field(["geolocation"]);
return;
}

frappe.dom.freeze(__("Fetching your geolocation") + "...");

navigator.geolocation.getCurrentPosition(
async (position) => {
frm.set_value({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
});

await frm.call("set_geolocation_from_coordinates");
frappe.dom.unfreeze();
},
(error) => {
frappe.dom.unfreeze();

let msg = __("Unable to retrieve your location") + "<br><br>";
if (error) {
msg += __("ERROR({0}): {1}", [error.code, error.message]);
}
frappe.msgprint({
message: msg,
title: __("Geolocation Error"),
indicator: "red",
});
},
);
},
});
11 changes: 9 additions & 2 deletions hrms/hr/doctype/employee_checkin/employee_checkin.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"column_break_yqpi",
"longitude",
"section_break_ksbo",
"fetch_geolocation",
"geolocation",
"shift_timings_section",
"shift_start",
Expand Down Expand Up @@ -124,7 +125,8 @@
{
"fieldname": "geolocation",
"fieldtype": "Geolocation",
"label": "Geolocation"
"label": "Geolocation",
"read_only": 1
},
{
"fieldname": "shift_timings_section",
Expand Down Expand Up @@ -157,10 +159,15 @@
"fieldname": "section_break_ksbo",
"fieldtype": "Section Break",
"hide_border": 1
},
{
"fieldname": "fetch_geolocation",
"fieldtype": "Button",
"label": "Fetch Geolocation"
}
],
"links": [],
"modified": "2024-05-29 20:09:19.489203",
"modified": "2024-05-29 21:19:11.550766",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Checkin",
Expand Down
1 change: 1 addition & 0 deletions hrms/hr/doctype/employee_checkin/employee_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def fetch_shift(self):
else:
self.shift = None

@frappe.whitelist()
def set_geolocation_from_coordinates(self):
if not (self.latitude and self.longitude):
return
Expand Down

0 comments on commit ced4969

Please sign in to comment.