Please provide enough information so that others can review your pull request:
Many users of Quickbooks are used to the shortcuts included with their date inputs. This extends the previously implemented T
shortcut functionality,
Explain the details for making this change. What existing problem does the pull request solve?
Quickbooks users will enjoy familiarity as they browse through reports. Frappe already incorporates many shortcuts, so this change would enrich snappy experience. The following hotkeys were added in addition to T
:
W
- First Day of the W eek
K
- Last Day of the Wee k
M
- First Day of the M onth
H
- Last Day of the Mont h
Y
- First Day of the Y ear
R
- Last Day of the Yea r
+
- Next day
-
- Previous day
A light hotkey framework was built within the ControlDate
class to improve readability and minimize redundancy. Event dispatching and event handler registration is commented in the code as well as this PR. In short, the hotkeys
class object in ControlDate
specify event handlers for different Key Codes and different fieldtypes
. Event handlers can be reused as seen in the example below.
A hotkeys
class Object has been added with the following format:
hotkeys = {
// // <keycode explanatory comment>
// <keyCode>: {
// '<fieldtype>': function(control_instance) { ... }
// OR
// '<fieldtype>': '<other set fieldtype>'
// },
//
// OR
//
// // <keycode explanatory comment>
// <keyCode>: <other set keyCode>,
//
// 84 === 't' - (t)oday
84: {
'Date': function(control) {
control.set_value(frappe.datetime.nowdate());
},
'Datetime': function(control) {
control.set_value(frappe.datetime.now_datetime());
},
'Time': function(control) {
control.set_value(frappe.datetime.now_time());
}
},
//
// ...
//
// Reusability example:
//
// 109 === numpad '-' - Previous Day
109: {
'Date': function(control) {
control.set_value(frappe.datetime.subtract_days(control.get_value(), 1));
},
'Datetime': 'Date', // reuse the already defined handler for fieldtype 'Date'
},
// 173 === '-'
173: 109, // reuse the already defined handler for key 109 (or numpad '-')
};
This is a drop-in replacement for set_t_for_today()
In order to provide some of the functionality, the datetime
module needed to be further specialized to avoid implementing momentjs
within the control. No breaking changes are part of this; In short, more specific *_start
and *_end
methods were added, specifying *_start_of
(e.g. month_end_of
). Previously implemented methods call *_start_of
with a null parameter, just as if moment()
was called as before.
Screenshots/GIFs
inactive