Monday, February 16, 2009

How to dynamically change the onclick handler

More related to just web development in general, but sometimes you might need to change the onclick event handler of an element. This can be a little tricky, but I find the best way to do this is:


element.onclick = function() {this_is_my_function($param)}


The tricky part is that the value of the onclick is a reference to the function and not the function itself. So if you simply put:

element.onclick = this_is_my_function($param)


It would actually fail. You need to wrap this under another function, hence the original code where the function() calls the this_is_my_function().

Setting the access to the templates_c

The templates_c folder is location of where the smarty tag templates are compiled to. And these templates are used to display the Xataface application. So it's important that end-users are able to read from this folder so that they are use the application. To properly set this up, the templates_c folder should have the 755 permissions:

chmod 755 templates_c


This basically means that everyone has read and execute access. And also that the owner has write access to the file/folder.

You then need to explicitly set the permissions for the user 'apache' because end users will be under that username when viewing the application. To do this:

setfacl -m user:apache:rwx,mask:rwx templates_c


After that end-users should have no problem viewing the application!

Friday, February 6, 2009

How to change the label of the save button?

Recently ran into an interesting request on how to change the label of the save button on the edit form to something else. While I don't believe there is a direct way to do this in Xataface, you can utilize a little workaround with the feature of "internationalization" of Xataface to get this to work.

How you can do this is:

  1. Create a 'lang' folder in the delegate folder of your class you wish to change the edit form form

  2. Inside that folder, create an en.ini file.

  3. Then add this line:
    save_button_label="Submit"

    What this does is it overrides the label and causes it to say Submit.



The real function of this feature is to actually allow the display of that label to differ depending on the language chosen. In our case, we just override the original label for english (ie. en) and volia!

A nice little work around hey?