I have finally gotten around to making an initial patch for startdate, woo!

Some things remain:
1. Initially closing the poll if startdate > time().
2. Opening the poll when (time() + runtime) > startdate > time().
3. Automatically switching to jscalendar if jstools is enabled.
4. Decide on the best UI for disabling the starttime form: disable the form elements or just hide it (both are implemented in the jQuery).

Any thoughts on it so far?

Comments

ChrisKennedy’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new8.08 KB

Okay #1 and #2 should be fixed. #3 is postponed until jscalendar & jstools are ported to 5.0.

One other issue is how the startdate and/or runtime should be displayed in the poll itself.

ChrisKennedy’s picture

StatusFileSize
new8.06 KB

Minor formatting changes to advpoll_update().

ChrisKennedy’s picture

Most recent patch committed - http://drupal.org/cvs?commit=46523

anders.fajerson’s picture

Haven't had a chance to look at this patch yet. But I stumbled upon a Drupal 5 version of jscalender in this thread: http://drupal.org/node/81691.

Also mentioned there is the jQuery version which I first had in mind, http://kelvinluck.com/assets/jquery/datePicker/.
That together with the jQuery time picker plugin might be interesting, http://www.texotela.co.uk/code/jquery/timepicker/.

anders.fajerson’s picture

StatusFileSize
new5.51 KB

Ok, I looked at the code, here are some comments:

1. $form['settings']['startdatejs'] can't be right?

2. I don't understand "/// Open polls with a startdate that is in the past but that need to be opened".

3. I prefer not to linebreak just to be < 80 characters, e.g line 288 and 819.

4. Using just a class with jQuery as in $(".edit-settings-startdate") makes it really slow as it has to go through the whole DOM - an id is a better option here.

5. We really have to be careful not filling up the settings box with too many options, already now I think it's too much. I have some ideas how I want the date functionality to work, to make it more concise (see below). But this is a difficult one. Just see how the settings box in Decisions look like.

7. I've attached a screenshot from google calendar, which I think could be a good start. Also see my previous post for jQuery plugins, they can be used here.

8. Finally, I think that maybe this patch could have staid a litter bit longer in the issue queue - not that it's so bad though. But it's a little bit sketchy and I don't mind reviewing/improving patches. I can see why you wanted this in quick though, as I have been bugging you about it :)

ChrisKennedy’s picture

1. That part was to store the timestamp for eventual use in jsCalendar. I'll take it out in the meantime.

2. How about this: "// Open polls with a startdate that is in the past but that are currently closed"?

3. This is a personal preference - but if there's a drupal standard let me know. I tried some searches and couldn't find anything.

4. Agreed, good point.

5. I agree, which is why the startdate fields are hidden unless the user wants to specify them. Condensing multiple fields into a single line will be kind of a pain with formapi but I'll see what I can do.

7. Yeah, this is what it can look like once jsCalendar works. I've tried the 5.0 version but it doesn't seem to work for me (probably because jstools.module isn't converted to 5.0 either).

8. You're right. My reasoning for committing early included:
a. It was functional.
b. We had agreed that the UI could be evolved over time.
c. I should have finished this a few weeks ago.
d. I wanted to work on other issues (ajax, postgres) and keeping the patches separate can be tough.

I should wait at least 24 hours to give you time to comment though. I'll try to be better about this in the future.

ChrisKennedy’s picture

StatusFileSize
new2.72 KB

Okay here's a patch that fixes #1, #2, and #4.

ChrisKennedy’s picture

StatusFileSize
new2.76 KB

Tweaked advpoll_cron() comment.

anders.fajerson’s picture

I think I understand what the "Open polls with a startdate in the past" code does, but won't it mean that old polls that has been manually closed will be re-opened?

Also, have you been thinking of implementing time? I first thought that you were going to add a field similar to "Authored by" which is really cumbersome to edit, but that we can later improve with some js. I didn't know about the date field though, but in general i think those select boxes are quite bad UI-wise. So my suggestion is to skip the checkbox ("use startdate") and the date select boxes in favour for a pre-filled texfield, similar to "Authored by". Thoughts on that?

anders.fajerson’s picture

My original mockup, http://drupal.org/files/issues/decision_startdate.png (I'd forgot about that) in http://drupal.org/node/88217 can illustrate my suggestion.

ChrisKennedy’s picture

#1 Yes, if they have specified a startdate and their duration is unlimited. Any suggestions on how to deal with this?

#2 Yes, time should be implemented eventually, although with cron typically running on an hourly basis there isn't really a need to include seconds in the timestamp, and minutes are only useful if you know the exact minute that cron is scheduled to run on your server.

My reason for including the checkbox is so that the fields can default to the current time, but that users aren't forced to use the starttime. I can't think of a better way to make it optional without such a toggle.

I got a chance to check out the datePicker and timePicker that you referenced earlier, and those look quite effective. I think it will be best to implement the google calendar type of UI and switch duration to an endate. The problem with a duration select is that we can only supply a finite number of options, but users should have access to more fine grained timing control (e.g. they can't have the poll open for 3, 5, 6, or < 1 days).

Also, we should automatically use the user's timezone.

anders.fajerson’s picture

Do we really need to be rely on cron? If we could check to see if a vote is opened with some php logic instead, then "status" in the database could be used only for the manual setting. This would solve both #1 and #2.

I did play with the two plugins. They are not really ready yet. The datePicker paging is a bit slow and timePicker has some display issues and the implementation is not that good, it's a quite simple module though so it should be easy to fix. There won't be any problems to style the FormAPI the way we wan't it though, which you mentioned before.

anders.fajerson’s picture

I missed to comment some things:

I the statdate field is pre-filled with the current time as the "Authered by" field, isn't it the same thing as optional?

I should have pointed out earlier that I also favour an end date, the google calendar way is quite optimal me thinks. If you try google calendar you will also see an "all day" checkbox - we could have the exact same thing but for "unlimited".

ChrisKennedy’s picture

Dynamically calculating the active/closed status of a poll is an interesting suggestion. The first area where it would be a problem is in db queries, and advpoll_block() is the only place where that comes up.

The main problem then is to determine when a poll was manually opened or closed, especially when it conflicts with the dynamic status. Right now the status defaults to "active", but if the startdate is in the future it is converted to closed when the edit form is submitted. Even if it is manually changed by the user to closed, when the startdate does come up, advpoll should theoretically open the poll, but can't since the user manually closed it.

Do we need a third status, "dynamic", set as the default to determine the status at runtime based on starttime && duration? I'm not sure how this will affect Views integration either, because we probably need to let users include status as an argument in their Views.

anders.fajerson’s picture

No, my point was that we don't need a third status. If it's done correctly we don't need to store this in the database, the information is already there (startdate and (soon) enddate). The status active/closed is just an feature to give the user the possibility to easely close the poll without changing the dates - thus this just overrides the date checking. In a sense this feature could be removed, if we think the user is smart enough to set an endate that has passed to close a poll.

In Views to list active or closed polls you just use an argument that compares the today's date to the startdate and/or enddate. Without looking at Views I'm pretty shure this is already possible to do for e.g. "Authored by".

Isn't this done all the time in Drupal - comparing dates in the database to the current date? This isn't really any different, right?

anders.fajerson’s picture

Title: Startdate at long last! » Possibility to define start-date (and end-date)
Version: master » 5.x-1.x-dev
Status: Reviewed & tested by the community » Needs work

Just a sidenote: I saw that Views use the textfield+jscalendar approach as date UI. I still favour a textfield instead of selects, it will also be easier for me to use as a base for a potential jQuery solution.

ChrisKennedy’s picture

Status: Needs work » Needs review
StatusFileSize
new11.01 KB

Alright here is a stab at changing runtime/duration to enddate and conversion of the widgets to textfields.

ChrisKennedy’s picture

StatusFileSize
new11.11 KB

Oops, I missed one change.

anders.fajerson’s picture

StatusFileSize
new11.11 KB

Attaching a patch which adds a missing parenthesis in advpoll_update_2().

We have to decide how to treat the status option. I'm leaning towards only a close option, and making it an "close poll" checkbox instead which overrides the duration. That might be more intuitive. Now it's not really clear what happens if the status is set on active and the startdate for example i set in the future. Before this patch the status was changed to closed in that situation, but that doesn't happen with this patch.

Will it be possible to ditch cron as discussed before?

ChrisKennedy’s picture

Ah thanks, I guess I forgot to check that the postgres code was syntactically correct.

Using a checkbox for closed seems like it might work. I'll add that to the patch in the next day or two and see about ditching cron.

Does the current functionality/implementation look okay?

anders.fajerson’s picture

As said before I like the textfield implementation as it gives us more freedom to improve the UI with js.

We have to make sure that it's obvious when a poll is opened or not. Hopefully the close checkbox will fix that.

Something that could help here and also clean up the UI as most users will not set a duration is to hide the start/endate when it's not defined, similar to how it was done before with the "Use start date" checkbox. An idea is to do this strictly with js (when the back-end is solid). An empty stardate in the db tells us that no startdate is set, i.e no default startdate i saved when the node is created.

Some comments on the current code:
* Endate doesn't have a time (maxlength = 10).
* A default endate is saved, it should be empty if not explicitly entered.
* endate has '#attributes' => array('class' => 'jscalendar') but not startdate

Great work as always!

ChrisKennedy’s picture

Status: Needs review » Needs work
StatusFileSize
new11.8 KB

Here is an update with all of the minor bugs fixed.

I'm still not sure about the best way to integrate manual active/closed settings with startdate/enddate.

I'm starting to think that a button is the best idea, with this functionality:

  1. If the poll is currently open display "Close poll".
    • Set the enddate to time().
  2. If the poll is currently closed display "Open poll".
  • If the startdate is in the future, set the startdate to time().
  • If the startddate is in the past, remove the enddate (i.e. it is now opened indefinitely).

Or would that end up being confusing to the user? Keeping startdate/enddate optional and integrating it into a manual active/closed option is pretty tough.

Also, I should note that with this last patch series startdate is always set. I can't remember if I did this to simplify the update handling, UI, or cron queries. I need to think about that decision some more.

ChrisKennedy’s picture

I forgot to mention that in this patch I restored the automatic active/closed based on the startdate/enddate, and removed the UI to manually set active/closed status.

anders.fajerson’s picture

"Keeping startdate/enddate optional and integrating it into a manual active/closed option is pretty tough."

To me it seems like this is just a matter of a helper function with a couple of if statements; i.e first check if the current time is within the set duration (if set) and if so, check if the poll is set to be opened. What have I missed?

The problem with *only* using the startdate/endate is that you miss the possibility to close a poll temporary that has a set duration. And I think it might be confusing to the user why we "mess up" the duration. UI wise I'm also a bit skeptical to more buttons.

anders.fajerson’s picture

StatusFileSize
new10.32 KB

Trying to move this forward.

* Still 3 database fields: enddate, startdate and active
* No cron, instead a helper function _advpoll_is_active($node) that checks if the poll is open, ie if today() > startdate and today() < enddate. It also checks that active == 1, if not the poll is always closed.
* The status option (which sets active status as before) is now a checkbox: "Close poll".
* Startdate and enddate can be empty.

I haven't dealt with the database things like the block and the polls page. Also, this patch is only ready for binary options. I just want an agreement on the implementation first.

ChrisKennedy’s picture

I need to look at this. (Bump)

anders.fajerson’s picture

StatusFileSize
new15.81 KB

Re-rolled.

1. Added back and improved the update path lost in previous patch.
2. Change order so endddate comes after startdate in queries etc
3. Added support for default duration.

ChrisKennedy’s picture

Really quick visual inspecton: saw a spacing error at "$default_enddate = format_date(" and some errors at _advpoll_is_active(). Might as well capitalize the "int" in the mysql update code too. Full test to come soon.

anders.fajerson’s picture

Lowercase "int" seems to be used in core.

Todo:
* Display that a poll is closed (now it only displays that you are not eligable)

JavaScript (could wait):
* Some kind of checkbox(es) to show/hide dates.
* Always hide dates if "Close poll" is checked.
* Some kind of picker would still be nice, I don't know if the community has settled on one yet. Or we roll our own solution (http://labs.perifer.se/timedatepicker)

anders.fajerson’s picture

StatusFileSize
new15.8 KB

* Give default startdate same treatment as default enddate
* Removed extra space

anders.fajerson’s picture

I think I was wrong when in #29 when I said that "it only displays that you are not eligable". Or it was probably a bug. The current behavior is that the result is shown if the poll is not active. So we were wrong in http://drupal.org/node/143194, right? (We show the form even if they are not eligable, but no date support in that patch). Messy.

* Corrected _advpoll_is_active()
* Changed [setting][active] to [setting][close] at it makes it more obvious what we are doing there and made it work again

Maybe the best plan is the to re-open http://drupal.org/node/143194 when this gets in.

anders.fajerson’s picture

StatusFileSize
new17.82 KB

And the patch. I forgot to mention that I've added a check in _validate(), it's no used yet as explained above, but is useful when we fix http://drupal.org/node/143194 .

anders.fajerson’s picture

Status: Needs work » Needs review
StatusFileSize
new23.42 KB

1. _advpoll_is_active() can now optionally return $status ('closed', 'pending', 'passed' or 'open'). Could need some doxygen.

2. Pending polls (startdate in the future) now renders the voting form with a message: "This poll opens in X days".

3. I removed the vote button instead of disabling it. I think it's better usability wise. Try it!

Sidenote: As both _voting_form() and _validate() are getting increasingly powerful more and more code are also identical in binary.inc and ranking.inc. We might benefit from trying to put that in some shared functions.

anders.fajerson’s picture

StatusFileSize
new23.55 KB

Re-rolled.

ChrisKennedy’s picture

This is awesome. I think it's very close to finished. I have a few thoughts (some are independent of this patch):

* Show the date format in the start/end descriptions ala the "Authored on" field. We'll probably want to hide them via jQuery eventually.

* If the poll's end date has passed but no votes has recorded it says "No votes have been recorded for this poll" without actually displaying the choices in the poll. I guess this should be fixed in a separate patch though.

* If the poll's end date has passed, I think it should say, "Poll ended on YYYY-MM-DD" or something to that effect.

* For pending polls maybe we should specifically display the date and time they open - better usability imo (i.e. calculating when exactly 17 days in the future will be is annoying). Also, caching for anonymous users will mess up the "opens in X mins" style. Or, maybe we can display the exact time unless the user is anonymous & normal or aggressive caching is enabled? It would be kinda cool to eventually update the exact time dynamically and refresh the page when it starts. Or maybe I'm making this too complicated.

* Separately, it really seems like poor usability to show the radio/input/select elements if the user can't vote yet. I realize this is a separate issue, but as long as I'm reviewing it I want to mention this. We need to change this to display the choices without form elements and show if the user is eligible or not.

* It might be good to display a validation error if the enddate is before the start date.

* Minor: need an extra space at the IF in theme_advpoll_voting_binary_form

ChrisKennedy’s picture

Title: Possibility to define start-date (and end-date) » Refactor date handling

Let's change to a better title too.

anders.fajerson’s picture

Title: Refactor date handling » Possibility to define start-date (and end-date)
StatusFileSize
new24.5 KB

Thanks!

1. Shows the format
2. Validates dates (valid and endate before startdate)
3. Changed "in X minutes" to the actual date. Good catch!
4. Fixed spacing error.

The other stuff (usability improvements) feels like they can go in later(?).

I've been thinking on how we should use this new data more to improve usablity. Most of it I feel should go in a theme function, but we don't have a good one to put them in. Hopefully in Drupal 6 we can provide our own node-advpoll_binary.tpl.php, I think that might be the best option.

anders.fajerson’s picture

Title: Possibility to define start-date (and end-date) » Refactor date handling

Refresh...

ChrisKennedy’s picture

Just needs the format_interval/format_date change for ranking polls.

anders.fajerson’s picture

StatusFileSize
new24.48 KB

Added.

ChrisKennedy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Yay. Thanks for pushing forward on this.

anders.fajerson’s picture

Status: Reviewed & tested by the community » Fixed

http://drupal.org/node/100098. I wanted to write a more inspiring commit message, but I was too tired. This is really great though.

anders.fajerson’s picture

Yep, tired. This one it is: http://drupal.org/cvs?commit=79661

anders.fajerson’s picture

On the date interval/cache issue: I remembered Typo (http://blog.typosphere.org) had a solution to this: The date is rendered in the html and then JavaScript is used to calculate the interval, thus working around the cache problem. Maybe even something for core Drupal.

Anonymous’s picture

Status: Fixed » Closed (fixed)