University of Oregon

Dynamic link destinations

I have an old Drupal 5 site that I inherited and I wanted to find or create users account quickly from committee lists. The site is built in such a way that the committee member data is stored in text fields and not node references. So when I’m notified that a committee group site is ready I have to check each member to see if they have an account or not. Then edit or create the user and add permissions to view the new group… This was getting old… and yes… this site should be ported to Drupal 7; but since there is funding for a 3rd party replacement of this web application, spending money/time on the conversion isn’t in my short term plans. Making administration more efficient is… So I wrote some javascript to do a quick look up of each committee member and determine if their account exists. If so, load the user page. If not, create the user and trigger a script that generates a new password. Here’s a quick look at the committee member table layout: Committee member table layout I click this link: Committee member link which triggers the script to check the committee members. Here’s the script:
<a href="#">0){
		iterator = Number(iterator);
		if(linkArray.length &gt;= iterator){
			thisEmail = '';
			thisEmail = linkArray[iterator].toString().replace('mailto:','');
			thisLink = '';
			thisLink = '/vpfa-searches/search-test/users/'+thisEmail.replace('@uoregon.edu','');

			checkLink(thisEmail, thisLink, iterator);
		}
	}
}

function checkLink(thisEmail, thisLink, iterator){
	iterator = Number(iterator);
  getUrlStatus(thisLink, thisEmail, function(status) {
    //alert(status);
    if(status != '404'){
      window.open(thisLink);
    }else{
      /*
       If page has a h2.title of Contact Information then it's a search committee page.
       Capture name and tax id and append link
      */
      committeeName='';
      committeeHeader='Contact Information';
      if($('h2.title:contains('+committeeHeader+')').length&gt;0){
        if($('.breadcrumb a:last').text()!=='Home'){
          committeeName = $('.breadcrumb a:nth-child(2n)').text();
        }else{
          committeeName = $('h1.title').text();
        }
      }
      window.open(encodeURI('/vpfa-searches/search-test/admin/user/user/create?genEmail='+thisEmail+'&amp;genRole='+committeeName));
    }
    triggerCheckLink(iterator+1);
  });
}
triggerCheckLink('0'); return false;"&gt;Open all Committee Members</a>
All of the js is in the link itself. Initially I had an external script for the ajax call back telling me the status of the link before acting on it, but it works in the link as well. Allow me to explain the code a bit; first off, I use jQuery to capture all the committee member email addresses. Then I layout my functions and trigger the first link check. The link check function “checklink()” calls the getUrlStatus ajax function which uses a callback. The callback returns the page status. I wait for that status and then proceed accordingly. 404′s get the ‘create user’ page and everything else is sent to the user page. In D6 or D7 I probably would have added a view to do this but I’m trying not to add much more server-side code to this old site. I mentioned above that once on the create user page, I generate a new password and assign the user role. To do that I pass the user email and committee name to the create user page. You may have noticed that I dig through the breadcrumbs to get the ‘committeeName’. Again views would make this easier but that’s how it goes. I’ll describe the user creation script some other time.

Added a new form to facilitate creating new user accounts in vpfa-searches

We have a Drupal 5 site we use for users to collaborate on job searches and adding users is a bit of a chore. When I was asked to add 10 users today I wasn’t looking forward to it. Redundant, monotonous and repetitive; the trifecta that is my arch-nemesis. So I created a javascript that populates the form from an email address and creates a random password. (more…)