Drupal : Three simple steps to adding ajax to your drupal forms/pages

If you need a simple content refresh system, let me show you an example of a simple (yet powerful) implementation.

Step 1
Download a the lightweight ajax library from ImpliedByDesign, and copy it to a directory called “ajax” in your module directory.

Step 2
Add the following two functions to your drupal module

function printAjaxJs() {
   drupal_add_js(drupal_get_path('module', 'myModule').'/ajax/ajax.js');
}
function printAjaxFunction($function,$page) {
  $output.='function '.$function.'(div_id,content_id) {';
  $output.='subject_id = div_id;';
  $output.='content = document.getElementById(content_id).value;';
  $output.='http.open("GET", "'.$page.'" + content, true);';
  $output.='http.onreadystatechange = handleHttpResponse;';
  $output.='http.send(null);';  $output.='}';
  drupal_add_js($output,'inline');
}   

Step 3
Ajaxfy your forms/pages

  printAjaxJs();
  $function="showContent";
  printAjaxFunction($function,"/show/content/");
  $script=$function."('updated-field','edit-myselect')";
  $form['myForm']['mySelect'] = array(
  '#type' => 'select',
  '#title' => t('Formation Select'),
  '#default_value' => $fdefault,
  '#options' => $foptions,
  '#prefix' => '
', '#suffix' => '
The output of /show/content/*value* will be updated here.
', );

Setting up “auto-update” on your system thru command line

Below you can find a ‘howto’ on setting up an automated update system for your ubuntu system. In essence we’ll be setting up the whole aptitude mechanism thru cron.

WARNING : This may cause unexpected results due to unknown updates.

Open up the crontab as root

kvaes@ubuntu:~$ sudo crontab -e

Add the following line to your crontab

0 0 * * * aptitude -y update && aptitude -y upgrade && aptitude -y dist-upgrade && aptitude -y autoclean

Sidenote: If you prefer the gui, check the following article. It won’t do exactly the same, but it might give you a better feeling… 😉

Resetting permissions for drupal

For some odd reason, after testing out some modules I was given an access denied on all content for non-admin users. If you would get such a thing, and are at the end of the road with your options, try the following commands:

INSERT INTO users (uid, name, mail) VALUES (‘0’, ”, ”);
INSERT INTO users_roles (uid, rid) VALUES (0, 1);
INSERT INTO node_access VALUES (0, 0, ‘all’, 1, 0, 0);

It will either return ‘duplicate entry’ warning (ignore this) or -maybe- fix your problem…

OWA Most Popular – version 0.5

This version contains a bugfix and the new “PostOnly”-feature. By selecting this feature, you won’t be pestered by non-posts in your listing. Examples here are the “Flavicon” & the “Homepage”.

Have fun with the release. Suggestions are always welcome!

IT Departments, dare to innovate!

Scenery
Wich companies come to mind if you would be presented with the following question:

What’s the difference between the new companies that stand out, and those who just populate the economic landscape as scenery?

Let’s take the “almighty google”. It started out as an idea of two Stanford University students. Its corporate philosophy includes statements such as “Don’t be evil”, and “Work should be challenging and the challenge should be fun”. I guess that isn’t something you see in every company. The competition for competence is fiercely high in Silicon Valley, and yet they win a lot of brainpower due to their company mentality. Note that I don’t want to sell google as heaven on earth, but I just want to sketch a certain starting point.

The human factor Continue reading “IT Departments, dare to innovate!”

Realizing the position of an IT department within the company

The Landscape
Imagine the structure of a somewhat reasonably sized company. You’ve got the purchasing, sales, accountancy, production,… the IT department. All departments depend on each other to get the global job done. It’s the job of IT, to make sure that the other departments can do their job efficiently, according to the information technology/resources available.

Strangely enough, not all IT departments realize that they are actually working FOR their company. They are aware that they work within a company. It’s not merely about maintaining the infrastructure, and doing end-user support. It’s about providing the service of increasing efficiency for every department!

The “end-user”
Everyone’s read them, the jokes about the everlasting moron end-users who don’t have a clue what the hell they are doing. I have to admit, I like to read those as well. But if you look past the fun-factor of them, and to the company impact of the situation, what do you see? You should see a part of the company engine, that’s malfunctioning! So why is this person malfunctioning? Did we provide the means for this person to do his/her job without any hassle? Continue reading “Realizing the position of an IT department within the company”

WordPress widget : Most popular posts

I wanted a “Most popular post” section on my blog, but after some bad experiences with “Popularity Contest” (by Alex King) I decided to write my own. As I already had a statistical mechanism that provided me with the data (namely OWA), it was a no-brainer to write a small plugin that would use the data gathered by OWA. So after a bit of coding, a bit of testing, and polishing… it was done. You can find the script (with some installation help) here. If you have any feedback about it, let me know!