Ryan Vikander's Development Blog - ColdMVChttp://blog.ryanvikander.com/index.cfm
Development blog that may contain but not limited to entries about Coldfusion, Javascript, Flex, and life. Maybe a splash of video games as well.en-usWed, 19 Dec 2018 06:19:05 -0600Thu, 15 Jul 2010 18:00:00 -0600BlogCFChttp://blogs.law.harvard.edu/tech/rssr.vikander@gmail.comr.vikander@gmail.comr.vikander@gmail.comnoModal Helper for ColdMVChttp://blog.ryanvikander.com/index.cfm/2010/7/15/Modal-Helper-for-ColdMVC
So during my spare time I have been working on a wedding site for myself and its written in a coworker's Coldfusion framework ColdMVC. Within learning the language I decided I was going to create my own custom helper for a modal window. I went with the jQuery modal library jQModal. The way I created the helper you can use whatever modal window library you want this is just one that I like. But anyways enough with that let's look at some code.
So a typical ColdMVC directory will look like this. Inside I have a Helpers folder. This folder is where you will put your CFCs that contain your helper functions. I do believe you can override the built in functions if they are the same name and function name? I am not positive but I can find out.
<img src="http://www.ryanvikander.com/images/directory.jpg" />
My modal CFC contains one function called display and this is where you would put your HTML to render your modal window. Since I went with jQModal I have had to add some certain classes that only pertain to that library. Your function might be different.
<code><cffunction name="Display" returntype="any">
<cfargument name="ID" required="true" />
<cfargument name="URL" required="false" default="" />
<cfargument name="Content" required="false" default="" />
<cfargument name="Label" required="false" default="" />
<cfargument name="Title" required="false" default="Modal Window" />
<cfargument name="Loading" required="false" default="" />
<cfset var html = "" />
<cfsavecontent variable="html">
<cfoutput>
<script type="text/javascript">
$(document).ready(function() {
$('###arguments.ID#').jqm({
modal: true,
trigger: 'a.modal_link#arguments.ID#'
<cfif arguments.URL NEQ "">
,ajax: '#arguments.URL#'
,ajaxText: "#arguments.Loading#"
</cfif>
});
});
</script>
<div id="#arguments.ID#" class="jqmWindow">
<div class="modal_title">#arguments.title# <div class="floatright text_right"><a href="##" class="jqmClose">Close</a></div></div>
<div class="text_left">
<div class="modal_content content">
#arguments.Content#
</div>
</div>
</div>
<a href="##" class="modal_link#arguments.ID#">#arguments.label#</a>
</cfoutput>
</cfsavecontent>
<cfreturn html>
</cffunction>
</code>
The function itself accepts an ID which is required and must be unique. This is for the fact that if you want to have multiple modal windows on your page we need them to be unique. The URL argument is used if you are doing an AJAX call. This will do a refresh every time you make a call to the modal window. The content argument is used if you want to send in content to the window by using cfsavecontent and passing the variable to the function. The label argument is used for the link. This can be modified if you want to do something different to display for the user to trigger the modal window. Title is the title of the argument. By default the window will just say "Modal Window" this is incase I forgot to include a title of course you don't HAVE to have a title, but I like it. Loading is just some HTML that I display for the AJAX calls so the user just doesn't see a blank window.
So that's the function now how do we use it? Well there are two ways I use the modal window. Well there is two different ways you can use it. First is if you want to take some content and pass it to the modal window. Here is how I do that:
<code>
<cfsavecontent variable="text">
Hello World!
</cfsavecontent>
<cfoutput>
#$.modal.display(label="Click Me", Content=text, id="displaycontent", title="How We Met")#
</cfoutput>
</code>
Now if you are not familiar with ColdMVC I suggest visiting: <a href="http://bears-eat-beets.blogspot.com/" target="_blank">Tony Nelson's blog</a> and read up on some of his posts explaining the ins and outs on the framework. But just for this blog I will explain that $ replaces the helper scope inside ColdMVC so you don't have to type out helpers every time. That's one way I call the modal helper. The next way is by making an AJAX request.
This way is a bit more trickier:
<code>
#$.modal.display(ID="loginWindow", URL="#linkTo({controller='wedding',action='loginform'},'currentView=#cgi.path_info#')#",label="Login", loading="<div class='text_left'>Loading<marquee style='width: 1.5em;'>.....</marquee>")#
</code>
The first thing I do is use the built in ColdMVC linkTo() function to link to my controller and pass the action of loginform. Again, ColdMVC is going to know how to use that and render the correct view. The only other thing different is I pass in some HTML for loading so I can display loading to the user while the page loads. *note my best use of the marquee tag ;)* And that's pretty much it. I have some custom css for displaying the modal window and it comes out looking like this:
Example of non AJAX modal:
<img src="http://www.ryanvikander.com/images/demo1.jpg" />
Example of AJAX modal:
<img src="http://www.ryanvikander.com/images/demo2.jpg" />
Note I am in no way the best designer. I am sure someone could design a better window. I am up for suggestions.
Also here is a link to the jQuery plugin I used <a href="http://dev.iceburg.net/jquery/jqModal/" target="_blank">jQModal</a>
ColdfusionColdMVCThu, 15 Jul 2010 18:00:00 -0600http://blog.ryanvikander.com/index.cfm/2010/7/15/Modal-Helper-for-ColdMVC