Opened 9 years ago

Closed 7 years ago

Last modified 7 years ago

#25006 closed New feature (fixed)

Allow for custom Time shortcut in DateTimeShortCuts.js

Reported by: Ramez Issac Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: desecho@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The Time shortcut is an amazing add-on , yet it's kinda frustrating if the pre-defined shortcuts doesn't fit the field/the model or end user most used times.
Shortcut times are: Now, 00:00 , 6 a.m. and noon, ..not very handy for night fun activities i might say :-D

I managed to add this functionality through a javascript var that gets a check for existence when creating the shortcut html elements ;
if found: loop through it & get shortcut 'Name' and 'hour' difference,
Else: is the default behavior & times.

I want to hear your opinion on the most 'django' way to go about it in order to make a pull request.

Also, I apologize in advance if duplicated. (I honestly searched and couldn't find it)

Regards;

Change History (13)

comment:1 by Tim Graham, 9 years ago

Stackoverflow has some ideas. Admittedly, none of these look particularly robust such that we could recommend them in our docs.

I don't know that spending a lot of time trying to make it more customizable is worthwhile (can't think of an easy way), but I think an easy win for now would be to add 6pm to the list of choices so at least we're consistent with having options for every 6 hours.

I think the best long-term solution would be to switch to HTML5 input="time" and use the widgets provided by browsers. As of now, we are missing IE and Firefox support according to w3schools.

comment:2 by Ramez Issac, 9 years ago

I'm with you that it's not a big a deal, and hacks do exsits
However, enhancing this might not be that hard, and most probably it's gonna stay with us when the html5 comes too.

What do you think about this way...

We add a new default in the DateTimeShortCut var, it use would look like this

DateTimeShortcuts['defaultTimes'] = {
    'all':[{ name : '8PM', hours:20} ,{ name : '10 PM', hours:22}], 
    //special id, can make it _all_ to be get fancy
    //the default for all time fields , If not present we fall back to the django default
    'id_pub_date':[{ name : '11AM', hours:11} ,{ name : '11PM', hours:23}],
    'id_release_date':function(inp){
        //Go Nuts ! :-)
    }
};

?

Kind Regards;

comment:3 by Tim Graham, 9 years ago

I'm not too familiar with that code. If it's not much work could you implement your suggestion and send a pull request so I can better understand it?

comment:4 by Tim Graham, 9 years ago

Has patch: set
Triage Stage: UnreviewedAccepted

In the meantime, here's a pull request to add the 6 p.m. option I suggested.

comment:5 by Markus Holtermann, 9 years ago

Triage Stage: AcceptedReady for checkin

The "6 p.m." PR is ready-for-commit.

comment:6 by Tim Graham <timograham@…>, 9 years ago

In 7f155a0:

Refs #25006 -- Added a '6 p.m.' option to the admin's time picker.

comment:7 by Tim Graham, 9 years ago

Has patch: unset
Triage Stage: Ready for checkinAccepted

comment:8 by Anton Samarchyan, 8 years ago

Cc: desecho@… added
Has patch: set
Version: 1.8master

Added PR

The list of hours can be overridden for each field in javascript like this:
DateTimeShortcuts.clockHours.name = [

['3 a.m.', 3]

]

where name is the name attribute of the input tag.

Version 0, edited 8 years ago by Anton Samarchyan (next)

comment:9 by Tim Graham, 8 years ago

Needs tests: set

comment:10 by Anton Samarchyan, 8 years ago

Needs tests: unset

comment:11 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 385cf70:

Fixed #25006 -- Allowed custom time shortcuts in admin's time picker.

comment:12 by Claude Paroz <claude@…>, 7 years ago

In fe000ab:

Refs #25006 -- Marked again admin time picker shortcuts for translation

comment:13 by Claude Paroz <claude@…>, 7 years ago

In 9907f8a5:

[2.0.x] Refs #25006 -- Marked again admin time picker shortcuts for translation

Backport of fe000ab18d2571394868882865907e92aabbda0a from master.

Note: See TracTickets for help on using tickets.
Back to Top