Skip to content

Instantly share code, notes, and snippets.

@nastanford
Last active August 29, 2015 13:55
Show Gist options
  • Save nastanford/8775726 to your computer and use it in GitHub Desktop.
Save nastanford/8775726 to your computer and use it in GitHub Desktop.
ColdFusion Art Gallery ColdBox Lesson 3
<!--- All methods in this helper will be available in all handlers,plugins,views & layouts --->
<cfscript>
// Alternating Row (classes, bgcolor, or any other alternating row useage)
// example: alternatingRow(TheCurrentRowCount,EvenRowText,OddRowText)
function alternatingRow(currentRow,evenRow,oddRow) {
var returnVar = IIF(currentRow Mod 2, DE(evenrow), DE(oddrow));
return returnVar;
}
</cfscript>
/**
* @accessors true
* @output "no"
*/
component displayname="Artist" hint="Artist"
{
property name="artistid" type="numeric" displayname="ArtistID" hint="ArtistID";
property name="firstname" type="string" displayname="First Name" hint="First Name";
property name="lastname" type="string" displayname="Last Name" hint="Last Name";
property name="address" type="string" displayname="Address" hint="Address";
property name="postalcode" type="numeric" displayname="Postal Code" hint="Postal Code";
property name="email" type="string" displayname="Email" hint="Email";
property name="phone" type="numeric" displayname="Phone" hint="Phone";
property name="fax" type="numeric" displayname="Fax" hint="Fax";
property name="thepassword" type="string" displayname="Password" hint="Password" default="Password";
}
<div align="center">
<h1>Artist List</h1>
</div>
<p>
<table align="center" border="0" cellpadding="3" cellspacing="0" class="dspTable">
<tr class="dspTableBar">
<td>
First
</td>
<td>
Last
</td>
<td>
Email
</td>
<td>
Phone
</td>
</tr>
<cfoutput query="rc.artistList">
<tr class="#alternatingRow(currentRow,'altColor1','altColor2')#">
<td>
#Firstname#
</td>
<td>
#Lastname#
</td>
<td>
<a href="mailto:#Email#">#Email#</a>
</td>
<td>
#Phone#
</td>
</tr>
</cfoutput>
<table>
</p>
/**
* @accessors true
* @output "no"
*/
component displayname="Artist Service" hint="Artist Service"
{
// getAllArtists
function getAllArtists() {
var qry="";
// Query and Get Resutls
qry = new Query(datasource="cfartgallery", sql="select * from app.artists").execute().getResult();
// Return Query
return qry;
}
}
<cfoutput>
#html.doctype()#
<html lang="en">
<head>
<meta charset="utf-8">
<title>ColdFusion Art Gallery ColdBox</title>
<!---Base URL --->
<base href="#getSetting("HTMLBaseURL")#" />
<LINK href="#getSetting("HTMLBaseURL")#includes/styles/default.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>ColdFusion Art Gallery</header>
<div class="navbar">#renderView('common/navMain')#</div>
<div class="container">#renderView()#</div>
<footer class="footer">
<div align="center">
&copy; Copyright #year(now())# - CFTipsPlus.com
</div>
</footer>
</body>
</html>
</cfoutput>
/* ---------------------------------------- */
/* Default Styles */
/* ---------------------------------------- */
body {
font-family:arial,Arial, Helvetica, sans-serif;
margin:0;
}
header {
background-color:#336699;
color:#FFFFFF;
font-family:Lucida Grande;
font-size:2em;
font-style:italic;
text-shadow: 3px 3px 3px rgba(0, 0, 0, 1);
padding:10px 0 10px 10px;
}
footer {
background-color:#000000;
color:#FFFFFF;
font-size:.7em;
padding:5px 0 5px 0;
}
/* ---------------------------------------- */
/* Table Display */
/* ---------------------------------------- */
.dspTable {
border:1px solid #000000;
}
.dspTableBar {
color:#FFFFFF;
background-color:#336699;
}
/* ---------------------------------------- */
/* Alternating Colors */
/* ---------------------------------------- */
.altColor1{
color:#000000;
background-color:#ffffff;
}
.altColor2{
color:#000000;
background-color:#dddddd;
}
/* ---------------------------------------- */
/* Main Navigation Bar */
/* ---------------------------------------- */
.navbar {
background-color:#000000;
color:#FFFFFF;
font-size:.8em;
padding:5px 0 5px 0;
}
.navbar a {
color:#FFFFFF;
text-decoration:none;
padding:5px 0 5px 10px;
}
.navSelected a {
background-color:#ffff00;
}
.navbar a:hover
{
color:#FFFFFF;
text-decoration:underline;
}
/**
* Artist
*/
component{
// OPTIONAL HANDLER PROPERTIES
this.prehandler_only = "";
this.prehandler_except = "";
this.posthandler_only = "";
this.posthandler_except = "";
this.aroundHandler_only = "";
this.aroundHandler_except = "";
// REST Allowed HTTP Methods Ex: this.allowedMethods = {delete='POST,DELETE',index='GET'}
this.allowedMethods = {};
function preHandler(event,action,eventArguments){
}
function postHandler(event,action,eventArguments){
}
/*
function aroundHandler(event,targetAction,eventArguments){
// executed targeted action
arguments.targetAction(event);
}
*/
function onMissingAction(event,missingAction,eventArguments){
}
function onError(event,faultAction,exception,eventArguments){
}
function index(event){
// Get the list of artist.
rc.artistList = getModel("artist.artistService").getAllArtists();
event.setView("artist/index");
}
}
/**
* Home
*/
component{
// OPTIONAL HANDLER PROPERTIES
this.prehandler_only = "";
this.prehandler_except = "";
this.posthandler_only = "";
this.posthandler_except = "";
this.aroundHandler_only = "";
this.aroundHandler_except = "";
// REST Allowed HTTP Methods Ex: this.allowedMethods = {delete='POST,DELETE',index='GET'}
this.allowedMethods = {};
function preHandler(event,action,eventArguments){
}
function postHandler(event,action,eventArguments){
}
/*
function aroundHandler(event,targetAction,eventArguments){
// executed targeted action
arguments.targetAction(event);
}
*/
function onMissingAction(event,missingAction,eventArguments){
}
function onError(event,faultAction,exception,eventArguments){
}
function index(event){
event.setView("home/index");
}
}
<div align="center">
<p>
Beginner ColdFusion -
ColdBox Art Gallery -
Lesson 3
Example Site
</p>
</div>
<cfoutput>
<a href="#event.buildLink('home.index')#">Home</a> |
<a href="#event.buildLink('artist.index')#">Artists</a>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment