Archive for March, 2008

Javascript Popup with graceful fallback

Wednesday, March 26th, 2008

I’ve struggled with popups for some time now. I’ve never really found a good way to handle popping up a new window when clicking a link. Sure, there is the target=”_blank” method but I’ve heard that in XHTML1.0 that is not actually valid. That tells me that browsers can still handle this but might not sometime in the future (or it might end up being included in some kind of quirks rendering mode in the future). A standard Javascript popup is another option but is too easily disabled.

This method will actually do both by creating an event handler.

(more…)

dmFlash Technique

Wednesday, March 19th, 2008

I’ve had some requests that I blog a dmFlash technique that I use in both version 3 and verion 4 of Farcry. This sounds much more glamourous than it actually is. I really just use a container with a handpicked rule but here are the details you will need to use this for yourself:

(more…)

Custom contentObjectGet Widget

Monday, March 17th, 2008

Something about Farcry has bothered me for a while. It is difficult to link to content programatically, especially if you have a navigation node with multiple content items under it. For example, I have an application that I was writing which contained a calendar and a registration piece. Each was a separate dmInclude under the same dmNavigation node. So, how do I create a “Register Now” button from the calendar to the registration piece programmatically? Sure, I could hard-code the objectID but that just wasn’t cutting it for this. Sure, it would work, but would be easily broken. If the registration piece was ever deleted and re-created, there would be a new UUID for it and the user would not be able to recover the functionality without editing code or the database record. So, I came up with a better solution…

(more…)

MS SQL IF EXISTS Technique

Thursday, March 13th, 2008

I’ll be the first to admit that I’m not the greatest when it comes to database design, optimization, even query code when it comes right down to it. Sure, I can do the standard CRUD things withough a problem but really digging into a database is not my cup of tea. So, when I came up with something actually usable, I had to post it :) So, on with the shameless self-promotion…

So, I am using an IF EXISTS … ELSE block for an INSERT/UPDATE query and was having an issue with the message handler. Yeah, I could have added some additional ColdFusion logic, but who wants to do that??? I thought, It’d be really great if the query would give me back the results of what action was actually taken. So, Here’s the original query:

<cfquery name="addUpdate" datasource="#application.CaseInfoDsn#">
	IF EXISTS (		SELECT 	AreaCode
					FROM 	area_codes
					WHERE 	AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.originalAreaCode#">
			  		OR		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.AreaCode#">	)
		BEGIN
			UPDATE 	area_codes
			SET		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.AreaCode)#">,
					State_Region = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.State_Region)#">,
					Description = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.Description)#">
			WHERE 	AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.originalAreaCode#">
			OR		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.AreaCode#">

		END
	ELSE
		BEGIN
			INSERT
			INTO 	area_codes
					(
						AreaCode,
						State_Region,
						Description
					)
			VALUES
					(
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.AreaCode)#">,
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.State_Region)#">,
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.Description)#">
					)

		END
</cfquery>

And Here’s my addition:

<cfquery name="addUpdate" datasource="#application.CaseInfoDsn#">
	IF EXISTS (		SELECT 	AreaCode
					FROM 	area_codes
					WHERE 	AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.originalAreaCode#">
			  		OR		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.AreaCode#">	)
		BEGIN
			UPDATE 	area_codes
			SET		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.AreaCode)#">,
					State_Region = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.State_Region)#">,
					Description = <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.Description)#">
			WHERE 	AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.originalAreaCode#">
			OR		AreaCode = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.AreaCode#">

			SELECT	TOP 1 'upd' AS actionTaken
			FROM	area_codes
		END
	ELSE
		BEGIN
			INSERT
			INTO 	area_codes
					(
						AreaCode,
						State_Region,
						Description
					)
			VALUES
					(
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.AreaCode)#">,
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.State_Region)#">,
						<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(form.Description)#">
					)

			SELECT	TOP 1 'ins' AS actionTaken
			FROM	area_codes
		END
</cfquery>

After each action (Insert or Update) I select a random string with a random alias which I can then use for my message handler. Hopefully someone else out there thinks this is cool because I sure do :)