Skip to content

Commit

Permalink
Converted validation sample
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw429s committed Jan 21, 2015
1 parent 55da57b commit 9e537ce
Show file tree
Hide file tree
Showing 152 changed files with 25,063 additions and 157 deletions.
11 changes: 7 additions & 4 deletions applications/Validation/Application.cfc
@@ -1,7 +1,7 @@
/**
* Validation Sample
*/
component extends="coldbox.system.Coldbox" {
component extends="coldbox.system.Bootstrap" {

// Application properties
this.name = "Validation Sample" & hash(getCurrentTemplatePath());
Expand All @@ -17,18 +17,21 @@ component extends="coldbox.system.Coldbox" {

// fix for nested orm apps in Mac OS
this.mappings["/validationSample"] = COLDBOX_APP_ROOT_PATH;
root = GetDirectoryFromPath( GetBaseTemplatePath() );
this.mappings["/models"] = root & "models\";
this.mappings["/cborm"] = root & "modules\cborm";

// ORM SETTINGS
this.ormEnabled = true;
this.datasource = "validationSample";
this.ormSettings = {
dbcreate = "dropcreate",
cfclocation = "model",
dbcreate = "update",
cfclocation="models",
flushAtRequestEnd = false,
autoManageSession = false,
logsql = true,
eventHandling = true,
eventHandler = "coldbox.system.orm.hibernate.WBEventHandler"
eventHandler = "cborm.models.EventHandler"
};

public boolean function onApplicationStart() output=false {
Expand Down
14 changes: 14 additions & 0 deletions applications/Validation/box.json
@@ -0,0 +1,14 @@
{
"dependencies":{
"cbvalidation":"1.0.0",
"cborm":"1.0.0",
"cbmessagebox":"1.0.0",
"cbi18n":"1.0.0"
},
"installPaths":{
"cbvalidation":"modules\\cbvalidation",
"cborm":"modules\\cborm",
"cbmessagebox":"modules\\cbmessagebox",
"cbi18n":"modules\\cbi18n"
}
}
196 changes: 78 additions & 118 deletions applications/Validation/config/Coldbox.cfc
@@ -1,119 +1,79 @@
<cfcomponent output="false" hint="My App Configuration">
<cfscript>
/**
structures to create for configuration
- coldbox
- settings
- conventions
- environments
- ioc
- models DEPRECATED use wirebox instead
- wirebox
- debugger
- mailSettings
- i18n
- webservices
- datasources
- layoutSettings
- layouts
- cacheEngine
- interceptorSettings
- interceptors
- modules
Available objects in variable scope
- controller
- logBoxConfig
- appMapping (auto calculated by ColdBox)
Required Methods
- configure() : The method ColdBox calls to configure the application.
Optional Methods
- detectEnvironment() : If declared the framework will call it and it must return the name of the environment you are on.
- {environment}() : The name of the environment found and called by the framework.
*/

// Configure ColdBox Application
function configure(){

// coldbox directives
coldbox = {
//Application Setup
appName = "Validation Sample",

//Development Settings
debugMode = false,
debugPassword = "",
reinitPassword = "",
handlersIndexAutoReload = true,

//Implicit Events
defaultEvent = "dashboard.index",
requestStartHandler = "",
requestEndHandler = "",
applicationStartHandler = "",
applicationEndHandler = "",
sessionStartHandler = "",
sessionEndHandler = "",
missingTemplateHandler = "",

//Error/Exception Handling
exceptionHandler = "",
onInvalidEvent = "",
customErrorTemplate = "",

//Application Aspects
handlerCaching = false,
eventCaching = false
};

// global settings - if you wanted to you could move these to environment specific settings
settings = {
};

// environment settings, create a detectEnvironment() method to detect it yourself.
// create a function with the name of the environment so it can be executed if that environment is detected
// the value of the environment is a list of regex patterns to match the cgi.http_host.
environments = {
development = "^cf9.,^railo."
};

//i18n & Localization
i18n = {
defaultResourceBundle = "includes/i18n/main",
defaultLocale = "en_US",
localeStorage = "cookie",
unknownTranslation = "**NOT FOUND**"
};

//Layout Settings
layoutSettings = {
defaultLayout = "Layout.Main.cfm"
};

//Register interceptors as an array, we need order
interceptors = [
//SES
{class="coldbox.system.interceptors.SES"}
];

// validation
validation = {
sharedConstraints = {
userForm = {
username = {required=true, size="3..20"},
password = {required=true, size="6..20"}
component {

// Configure ColdBox Application
function configure(){

// coldbox directives
coldbox = {
//Application Setup
appName = "Validation Sample",

//Development Settings
debugMode = false,
debugPassword = "",
reinitPassword = "",
handlersIndexAutoReload = true,

//Implicit Events
defaultEvent = "dashboard.index",
requestStartHandler = "",
requestEndHandler = "",
applicationStartHandler = "",
applicationEndHandler = "",
sessionStartHandler = "",
sessionEndHandler = "",
missingTemplateHandler = "",

//Error/Exception Handling
exceptionHandler = "",
onInvalidEvent = "",
customErrorTemplate = "/coldbox/system/includes/BugReport.cfm",

//Application Aspects
handlerCaching = false,
eventCaching = false
};

// global settings - if you wanted to you could move these to environment specific settings
settings = {
};

// environment settings, create a detectEnvironment() method to detect it yourself.
// create a function with the name of the environment so it can be executed if that environment is detected
// the value of the environment is a list of regex patterns to match the cgi.http_host.
environments = {
development = "^cf9.,^railo."
};

//i18n & Localization
i18n = {
defaultResourceBundle = "includes/i18n/main",
defaultLocale = "en_US",
localeStorage = "cookie",
unknownTranslation = "**NOT FOUND**"
};


//Register interceptors as an array, we need order
interceptors = [
//SES
{class="coldbox.system.interceptors.SES"}
];

// validation
validation = {
sharedConstraints = {
userForm = {
username = {required=true, size="3..20"},
password = {required=true, size="6..20"}
}
}
}
};

}

function development(){
//wirebox.singletonReload = true;
}

</cfscript>
</cfcomponent>
};

}

function development(){
//wirebox.singletonReload = true;
}

}
2 changes: 1 addition & 1 deletion applications/Validation/config/WireBox.cfc
Expand Up @@ -51,7 +51,7 @@ Description :
};

// Map Bindings below
mapDirectory( getAppMapping() & ".model" );
mapDirectory( "/models" );

}
</cfscript>
Expand Down
4 changes: 2 additions & 2 deletions applications/Validation/handlers/Category.cfc
@@ -1,7 +1,7 @@
component { property name="categoryService" inject; public void function index(event,rc,prc){ setNextEvent("category/list");
component { property name="MessageBox" inject="MessageBox@cbMessageBox"; property name="categoryService" inject="categoryService"; public void function index(event,rc,prc){ setNextEvent("category/list");
} public void function list(event,rc){ rc.categories = categoryService.list(asquery=false); event.setView("category/categories");
} public void function edit(event,rc){ if( !structKeyExists(rc,"category") ){ rc.category = categoryService.get( event.getValue('category_id','') );
} event.setView("category/category");
} function save(event,rc){ // populate the model with all the properties rc.category = populateModel( model=categoryService.get(rc.category_id) ); // validation var result = validateModel(rc.category); if( !result.hasErrors() ){ // validation found no errors, persist the data categoryService.save(rc.category); getPlugin("MessageBox").setMessage("info","Category saved!"); setNextEvent('category/list'); } else { getPlugin("MessageBox").setMessage(type="error",messageArray=result.getAllErrors()); setNextEvent(event='category/edit',persist="category");
} function save(event,rc){ // populate the model with all the properties rc.category = populateModel( model=categoryService.get(rc.category_id) ); // validation var result = validateModel(rc.category); if( !result.hasErrors() ){ // validation found no errors, persist the data categoryService.save(rc.category); MessageBox.setMessage("info","Category saved!"); setNextEvent('category/list'); } else { MessageBox.setMessage(type="error",messageArray=result.getAllErrors()); setNextEvent(event='category/edit',persist="category");
}
}}
Expand Down
4 changes: 2 additions & 2 deletions applications/Validation/handlers/Product.cfc
@@ -1,5 +1,5 @@
component { property name="productService" inject; property name="categoryService" inject; public void function index(event,rc,prc){ setNextEvent("product/list");
component { property name="MessageBox" inject="MessageBox@cbMessageBox"; property name="productService" inject="productService"; property name="categoryService" inject="categoryService"; public void function index(event,rc,prc){ setNextEvent("product/list");
} public void function list(event,rc){ rc.products = productService.list(asquery=false); event.setView("product/products");
} public void function edit(event,rc){ if( !structKeyExists(rc,"product")){ rc.product = productService.get( event.getValue('product_id','') );
} rc.categories = categoryService.list(asquery=false); event.setView("product/product"); } public void function save(event,rc){ // populate the model with all the properties rc.product = populateModel( model=productService.get(rc.product_id) ); if( structKeyExists(rc,"categories") ){ rc.product.setCategories( categoryService.loadById(rc.categories) );
} // validation var result = validateModel(rc.product); if( !result.hasErrors() ){ // validation found no errors, persist the data productService.save(rc.product); getPlugin("MessageBox").setMessage("info","Product saved!"); setNextEvent('product/list'); } else { getPlugin("MessageBox").setMessage(type="error",messageArray=result.getAllErrors()); setNextEvent(event='product/edit',persist="product"); } } }
} // validation var result = validateModel(rc.product); if( !result.hasErrors() ){ // validation found no errors, persist the data productService.save(rc.product); MessageBox.setMessage("info","Product saved!"); setNextEvent('product/list'); } else { MessageBox.setMessage(type="error",messageArray=result.getAllErrors()); setNextEvent(event='product/edit',persist="product"); } } }
Expand Down
4 changes: 2 additions & 2 deletions applications/Validation/handlers/User.cfc
@@ -1,3 +1,3 @@
component { property name="validationService" inject; public void function index(event,rc,prc){ event.setView("user/index");
component { property name="MessageBox" inject="MessageBox@cbMessageBox"; property name="validationService" inject="validationService"; public void function index(event,rc,prc){ event.setView("user/index");
} public void function save(event,rc){ var constraints = { username = {required=true, size="6..20"}, password = {required=true, size="6..20"}
}; // validation //var result = validateModel(target=rc, constraints=constraints); //var result = validateModel(target=rc, constraints="userForm"); var result = validateModel(target=rc, constraints=validationService.getUserForm()); if( !result.hasErrors() ){ getPlugin("MessageBox").setMessage("info","User Info Validated!"); setNextEvent('user'); } else { getPlugin("MessageBox").setMessage(type="error",messageArray=result.getAllErrors()); index(event,rc,prc); return; } }}
}; // validation var result = validateModel(target=rc, constraints=validationService.getUserForm()); if( !result.hasErrors() ){ MessageBox.setMessage("info","User Info Validated!"); setNextEvent('user'); } else { MessageBox.setMessage(type="error",messageArray=result.getAllErrors()); index(event,rc,prc); return; } }}
Expand Down
9 changes: 9 additions & 0 deletions applications/Validation/install/readme.txt
@@ -0,0 +1,9 @@
This is a simple ORM application that uses the cbvalidation module

To install:

- Create an empty database called validationSample
- Create a data source called "validationSample" in the CF Admin that points to it
- Run the app.

The database tables should be created the first time it is run. Try managing the data in the app to test the validation rules.
1 change: 0 additions & 1 deletion applications/Validation/layouts/Layout.Main.cfm

This file was deleted.

1 change: 1 addition & 0 deletions applications/Validation/layouts/Main.cfm
@@ -0,0 +1 @@
<cfset baseURL = replaceNoCase( getSetting("sesBaseURL"), 'index.cfm', '')><cfset handler = event.getCurrentHandler()><cfoutput><!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>ColdBox Sample App using Validation</title> <!-- Le HTML5 shim, for IE6-8 support of HTML elements --> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link href="#baseURL#/includes/css/bootstrap-1.2.0.min.css" rel="stylesheet" type="text/css"> <link href="#baseURL#/includes/css/stylesheet.css" type="text/css" rel="stylesheet" > <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script type="text/javascript" src="#baseURL#/includes/js/jquery.tablesorter.min.js"></script></head><body> <div class="container"> <div class="content-wrapper"> <div class="row"> <div id="header" class="span15 columns"> <h1>ColdBox Validation Catalog</h1> <ul class="tabs"> <li class="<cfif handler EQ 'dashboard'>active</cfif>"><a href="#event.buildLink('dashboard')#">Home</a></li> <li class="<cfif handler EQ 'category'>active</cfif>"><a href="#event.buildLink('category')#">Categories</a></li> <li class="<cfif handler EQ 'product'>active</cfif>"><a href="#event.buildLink('product')#">Products</a></li> <li class="<cfif handler EQ 'user'>active</cfif>"><a href="#event.buildLink('user')#">User Form</a></li> </ul> </div> </div> <div class="row"> <div class="span15 columns"> #renderView()# </div> </div> </div> </div></body></html></cfoutput>
Expand Down
30 changes: 15 additions & 15 deletions ...ns/Validation/model/ValidationService.cfc → ...s/Validation/models/ValidationService.cfc 100755 → 100644
@@ -1,17 +1,17 @@
/**
* I am a new Model Object
*/
component singleton{

validationService function init(){
return this;
}

struct function getUserForm(){
return {
username = {required=true, size="5..10"},
password = {required=true, size="5..10"}
/**
* I am a new Model Object
*/
component singleton{

validationService function init(){
return this;
}

struct function getUserForm(){
return {
username = {required=true, size="5..10"},
password = {required=true, size="5..10"}
};
}

}

}
Expand Up @@ -5,7 +5,7 @@
property name="name";
property name="sort" ormtype="int";

property name="products" fieldtype="many-to-many" cfc="validationSample.model.product.Product" linktable="product_categories"
property name="products" fieldtype="many-to-many" cfc="validationSample.models.product.Product" linktable="product_categories"
fkcolumn="category_id" inversejoincolumn="product_id" lazy="true" cascade="all" singularname="product" inverse="true";

// object constraints
Expand Down
@@ -1,4 +1,4 @@
component extends="coldbox.system.orm.hibernate.VirtualEntityService" {
component extends="cborm.models.VirtualEntityService" {

public CategoryService function init(){
super.init(entityName="Category");
Expand Down
Expand Up @@ -3,7 +3,7 @@
property name="id" column="product_id" fieldtype="id" generator="native";
property name="name";
property name="description" ormtype="text";
property name="categories" fieldtype="many-to-many" cfc="validationSample.model.category.Category" linktable="product_categories"
property name="categories" fieldtype="many-to-many" cfc="validationSample.models.category.Category" linktable="product_categories"
fkcolumn="product_id" inversejoincolumn="category_id" lazy="true" cascade="all" singularname="category";

// object constraints
Expand Down
@@ -1,4 +1,4 @@
component extends="coldbox.system.orm.hibernate.VirtualEntityService" {
component extends="cborm.models.VirtualEntityService" {

public ProductService function init(){
super.init(entityName="Product");
Expand Down

0 comments on commit 9e537ce

Please sign in to comment.