Posts tagged: jquery

Reading Schedule Generator

Or: some stuff I worked on over break.

This is a small solution to (some would say) an even smaller problem: I used to ignominiously return unread books to the library, and face new issues of magazines after having only read a few items in the previous one. My to-be-read pile was only getting taller.

I found I was able to read more “reliably” if I had a specific daily page goal for each item. Somehow having an “official” schedule helped me overcome my affliction.

I’ve been doing this for a few years, and have written code to help out. (Certainly there must be a name for the psychological quirk that compels me to “write code to help out”. Let me know if you come across it.)  What follows is my current “solution”: a CGI-backed web form that accepts the schedule parameters for a single reading item (book or magazine) and generates a small HTML calendar schedule that I can print from a web browser, cut out, and use as a bookmark for the item.

This seems conceptually easy, if not trivial, so I imagine similar code is “out there somewhere”, but cursory Googling didn’t turn up anything.

Anyway: the finished product appears like this (specific example is the book Freedom™ by Daniel Suarez):(Not that I recommend this book: it's pretty bad so far.)

Yes, cut on the dotted line. So my goal for today (January 6) is to get up to (or past) page 127. And I should be finished in a couple weeks.

Now I’m not psycho about this: it’s OK to get ahead of the goals if the material is compelling and I have the time. It’s also OK to fall behind if there’s just too much other stuff going on. (However, in my experience, just knowing that I’ve “fallen behind” is just enough motivation to carve out some extra time to catch up later.)

Enough for the mechanics, on to the code. For a long time I ran a Perl script from the command line to generate an HTML schedule as a static file, which I would then open/print in a browser. But over break I decided that it would be (slightly) more flexible to do the whole thing from the browser, using an HTML form to get the schedule parameters, calling a CGI backend to display the result.

The form is here (hosted on my workstation). What it looks like:

It’s a very rudimentary form, with few bells or whistles. Well, OK, one bell: the Javascript jQuery UI datepicker widget for getting the schedule’s start and end dates. I didn’t know nothin’ about jQuery before I did this. (And I only know slightly more now; if you examine the source code for the form, it’s not very complicated.)

So you fill out the form. Using our example (and showing the datepicker in action):

… hit the submit button and the resulting page should produce the appropriate schedule. (I’m pretty sure it would work for you if you want to try it.)

The real work is performed by the Perl CGI script, which relies heavily on the smarts contained in the CGI, Date::Manip, and HTML::Template modules. (What’s left: some date arithmetic that’s only tricky if you’ve done it wrong a few times. I think it handles edge cases and DST changes correctly, although I haven’t checked lately.)  If you’d like to look at the script, the plain-Perl file is here, and the html-prettyprinted version is here. The HTML template used by the script is also important and that’s here.

jQuery is(), not(), and ! is()

jQuery lovers: this little distinction got me this morning, even though I should know it already. I’d explain it here, but the linked article does a fine job.

Addendum: is it still worth using a JS abstraction library like jQuery? Yes.

Table Sorting On The Client Side

The love affair with jQuery continues…

In one project, I got cute and filtered a table based on a checkbox that read ‘mine only’. When checked, the user would only see rows for the cases assigned to them. It is even checked by default.

However, when column sorting was requested on that same table, I realized my usual server-side sorting routine would not suffice, as it would not remember the ‘mine only’ selection without something fancier the parameterized links on the column headers.

Lost you yet? Sorry… just check out tablesorter, a jQuery plugin that allows you to sort columns without a server call, maintaining state on the client side.

It even does secondary column sorting. And no page refresh for the user?

Yum. So good.

I Love jQuery So Much

Using jQuery excites me so, I get that ‘too much coffee’ feeling.

Then again, I’ve also had too much coffee.

Stay tuned for a more controlled experiment.

Data Sanitization with jQuery Validation Plugin

jQuery is a JavaScript Library that simplifies the creation of dynamic HTML documents that work for every browser. It allows for user generated plugins to extended functionality.

One useful jQuery Plugin is Validation. This Plugin allows you to quickly and easily check to ensure that the values entered into a form by the user are accurate. This functionality helps improves the usability of a webform and the accuracy of the data collected by giving the user feed back as they are entering data. Read more »

Panorama theme by Themocracy