Archive for October, 2009

escaping text input for urls in javascript

Posted in javascript on October 29th, 2009 by paul – Be the first to comment

If you need to make sure that some text entered into a text field can be sent as part of a uri, say in an ajax call as a parameter, then the built in javascript function encodeURIComponent() seems to work well.

Reference here.

Working with json from rails

Posted in Uncategorized on October 28th, 2009 by paul – Be the first to comment

If we have an array called users which contains a number of User objects sent from our rails app, then looping through this array gives us access to each user object.

for (var i = 0;i<users.length;i++) {
   var user = users[i];
   alert(user.user.name);  //This gives us the name property of the object.
 }

Note that each object in the array is preceeded by the name of the class, hence the double user. syntax.

jquery Boxy close popup

Posted in Uncategorized on October 27th, 2009 by paul – 2 Comments

I use the rather excellent Boxy plugin to do some modal style popups.

If you want to close the popup programatically from within the popup, say from a cancel button, you can do it like so…

<input type=button value="Cancel" onClick="cancel_button(this);">
function cancel_button(popup){
 if(confirm("All changes will be lost")){
  Boxy.get(popup).hide();
 }
}

sorting dynamic tables with jquery and tablesorter

Posted in jquery on October 27th, 2009 by paul – 1 Comment

I have a page in an application where the user can move names from one column (table) to another.

I have a bunch of js that removes the selected row from table a and adds it to table b.

Everytime I change one of the tables I want to sort the tables.

The syntax is below, if only for my own reference as it took me ages to get it just right. I need to write a custom sorter as I need to sort on the second word (i.e. surname). But anyway, the following is in a function that gets called when a row is moved between tables…

function sort_table(table){
   $(table).tablesorter();
   $(table).trigger("update");
   var sorting = [[0,0]];
   // sort on the first column
   $(table).trigger("sorton",[sorting]);
}

There’s nothing particularily novel here, all available around the net. The call to

$(table).trigger("update");

is there as I found that when I moved a row over to the right column and then sorted the left column the row appeared to be still in that table. This is because tablesorter uses a cache of some sort. Calling .trigger(“update”) forces it to rebuild the cache. Or something like that…

problems updating ssl certificate on cpanel

Posted in cpanel on October 14th, 2009 by paul – Be the first to comment

Today I had to install a renewed ssl cert for a client on their cpanel server.

cPanel has a pretty good interface for managing ssl certs, but it doesn’t always go to plan (so, perhaps not so good…).

I logged in to the clients cpanel account and installed the new certificate (the contents of the .crt file).

On submitting this, everything appeared to work ok, but the website was still showing the expired certificate. So the new certificate was being installed but apache was still using the old one.

After much head scratching I tried doing the install via WHM, i.e. the ‘root’ user interface.

I used the “Install a SSL Certificate and Setup the Domain” page. I pasted in the ssl cert, and this meant WHM autimatically picked up the domain, the key and ca bundle. Submitting this form seemed to work, i.e. apache started serving up the correct certificate.

Bit of a pain…