1
1
/**
2
- *********************************************************************************
3
- * Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
4
- * www.coldbox.org | www.luismajano.com | www.ortussolutions.com
5
- ********************************************************************************
6
- */
7
- component {
2
+ *********************************************************************************
3
+ * Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
4
+ * www.coldbox.org | www.luismajano.com | www.ortussolutions.com
5
+ ********************************************************************************
6
+ */
7
+ component {
8
8
9
9
// Module Properties
10
- this .title = " validation" ;
11
- this .author = " Luis Majano" ;
12
- this .webURL = " http://www.ortussolutions.com" ;
13
- this .description = " This module provides server-side validation to ColdBox applications" ;
14
- this .
version = " @build.version@[email protected] @" ;
10
+ this .title = " validation" ;
11
+ this .author = " Luis Majano" ;
12
+ this .webURL = " http://www.ortussolutions.com" ;
13
+ this .description = " This module provides server-side validation to ColdBox applications" ;
14
+ this .
version = " @build.version@[email protected] @" ;
15
15
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
16
- this .viewParentLookup = true ;
16
+ this .viewParentLookup = true ;
17
17
// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
18
- this .layoutParentLookup = true ;
18
+ this .layoutParentLookup = true ;
19
19
// Model Namespace
20
- this .modelNamespace = " cbvalidation" ;
20
+ this .modelNamespace = " cbvalidation" ;
21
21
// CF Mapping
22
- this .cfmapping = " cbvalidation" ;
22
+ this .cfmapping = " cbvalidation" ;
23
23
// Auto-map models
24
- this .autoMapModels = true ;
24
+ this .autoMapModels = true ;
25
25
// Module Dependencies That Must Be Loaded First, use internal names or aliases
26
- this .dependencies = [ " cbi18n" ];
26
+ this .dependencies = [ " cbi18n" ];
27
27
// ColdBox Static path to validation manager
28
28
this .COLDBOX_VALIDATION_MANAGER = " cbvalidation.models.ValidationManager" ;
29
29
30
30
/**
31
- * Configure module
32
- */
31
+ * Configure module
32
+ */
33
33
function configure (){
34
34
// Mixin our own methods on handlers, interceptors and views via the ColdBox UDF Library File setting
35
- arrayAppend ( controller .getSetting ( " ApplicationHelper" ), " #moduleMapping #/models/Mixins.cfm" );
35
+ arrayAppend (
36
+ controller .getSetting ( " ApplicationHelper" ),
37
+ " #moduleMapping #/models/Mixins.cfm"
38
+ );
36
39
}
37
40
38
41
/**
39
- * Fired when the module is registered and activated.
40
- */
42
+ * Fired when the module is registered and activated.
43
+ */
41
44
function onLoad (){
42
45
var configSettings = controller .getConfigSettings ();
43
46
// parse parent settings
44
47
parseParentSettings ();
45
48
// Did you change the validation manager?
46
- if ( configSettings .validation .manager ! = this .COLDBOX_VALIDATION_MANAGER ){
47
- binder .map ( alias = " validationManager@cbvalidation" , force = true )
49
+ if ( configSettings .validation .manager ! = this .COLDBOX_VALIDATION_MANAGER ) {
50
+ binder
51
+ .map (
52
+ alias = " validationManager@cbvalidation" ,
53
+ force = true
54
+ )
48
55
.to ( configSettings .validation .manager )
49
56
.asSingleton ();
50
57
}
51
58
// setup shared constraints
52
- wirebox .getInstance ( " validationManager@cbvalidation" )
59
+ wirebox
60
+ .getInstance ( " validationManager@cbvalidation" )
53
61
.setSharedConstraints ( configSettings .validation .sharedConstraints );
54
62
}
55
63
56
64
/**
57
- * Fired when the module is unregistered and unloaded
58
- */
65
+ * Fired when the module is unregistered and unloaded
66
+ */
59
67
function onUnload (){
60
68
var appHelperArray = controller .getSetting ( " ApplicationHelper" );
61
- var mixinToRemove = " #moduleMapping #/models/Mixins.cfm" ;
62
- var mixinIndex = arrayFindNoCase ( appHelperArray , mixinToRemove );
63
-
69
+ var mixinToRemove = " #moduleMapping #/models/Mixins.cfm" ;
70
+ var mixinIndex = arrayFindNoCase ( appHelperArray , mixinToRemove );
71
+
64
72
// If the mixin is in the array
65
- if ( mixinIndex ) {
73
+ if ( mixinIndex ) {
66
74
// Remove it
67
75
arrayDeleteAt ( appHelperArray , mixinIndex );
68
76
// Arrays passed by value in Adobe CF
@@ -71,13 +79,13 @@ component{
71
79
}
72
80
73
81
/**
74
- * Prepare settings and returns true if using i18n else false.
75
- */
82
+ * Prepare settings and returns true if using i18n else false.
83
+ */
76
84
private function parseParentSettings (){
77
85
/**
78
- Sample:
86
+ Sample :
79
87
validation = {
80
- manager = "class path" // if overriding
88
+ manager = "class path" // if overriding
81
89
sharedConstraints = {
82
90
name = {
83
91
field = { constraints here }
@@ -87,23 +95,31 @@ component{
87
95
}
88
96
*/
89
97
// Read parent application config
90
- var oConfig = controller .getSetting ( " ColdBoxConfig" );
91
- var validationDSL = oConfig .getPropertyMixin ( " validation" , " variables" , structnew () );
92
- var configStruct = controller .getConfigSettings ();
98
+ var oConfig = controller .getSetting ( " ColdBoxConfig" );
99
+ var validationDSL = oConfig .getPropertyMixin (
100
+ " validation" ,
101
+ " variables" ,
102
+ structNew ()
103
+ );
104
+ var configStruct = controller .getConfigSettings ();
93
105
94
106
// Default Config Structure
95
107
configStruct .validation = {
96
- manager = this .COLDBOX_VALIDATION_MANAGER ,
97
- sharedConstraints = {}
108
+ manager : this .COLDBOX_VALIDATION_MANAGER ,
109
+ sharedConstraints : {}
98
110
};
99
111
100
112
// manager
101
- if ( structKeyExists ( validationDSL , " manager" ) ){
113
+ if ( structKeyExists ( validationDSL , " manager" ) ) {
102
114
configStruct .validation .manager = validationDSL .manager ;
103
115
}
104
116
// shared constraints
105
- if ( structKeyExists ( validationDSL , " sharedConstraints" ) ){
106
- structAppend ( configStruct .validation .sharedConstraints , validationDSL .sharedConstraints , true );
117
+ if ( structKeyExists ( validationDSL , " sharedConstraints" ) ) {
118
+ structAppend (
119
+ configStruct .validation .sharedConstraints ,
120
+ validationDSL .sharedConstraints ,
121
+ true
122
+ );
107
123
}
108
124
}
109
125
0 commit comments