Update of /cvsroot/modus/org/bacfug/modus/fields
In directory sc8-pr-cvs1:/tmp/cvs-serv5475/fields
Modified Files:
basefield.cfc basefile.cfc hidden.cfc longtext.cfc text.cfc
webimage.cfc yesno.cfc
Log Message:
Whoops, these were the old files - pardon my CVS skills. The new files are now there.
Index: basefield.cfc
===================================================================
RCS file: /cvsroot/modus/org/bacfug/modus/fields/basefield.cfc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** basefield.cfc 3 Oct 2002 05:42:22 -0000 1.7
--- basefield.cfc 9 Jan 2003 01:53:39 -0000 1.8
***************
*** 2,115 ****
<cfparam name="instance" default="#structNew()#">
<cffunction name="init" access="public" output="no" returnType="org.bacfug.modus.fields.baseField" hint="initialize this instance, creating the instance variables">
- <cfargument name="defaultValue" required="no" default="">
<cfscript>
- //the label is blank by default
- instance.label = "";
- //instance to hold the error
- instance.errors = arrayNew(1);
- //instane rules
- instance.rules = "";
- //instance metaData
- instance.metaData = getMetaData(this);
- //the name is whatever the name in the meta data is
- instance.name = instance.metaData.name;
- //the default value
- instance.defaultValue = arguments.defaultValue;
- //the value is blank by default
- setValue(instance.defaultValue);
//if necessary, create a form field factory
! if(NOT isDefined("server.modus.formFieldFactory")){
! server.modus.formFieldFactory = createObject("component","org.bacfug.modus.form.formFieldFactory").init();
}
//set the form field factory to this instance
! //instance.formFieldFactory = server.modus.formFieldFactory;
! instance.formFieldFactory = createObject("component","org.bacfug.modus.form.formFieldFactory").init();
</cfscript>
<cfreturn this>
</cffunction>
!
! <!--- a way to set the label --->
! <cffunction name="setLabel" access="public" output="no" returnType="void" hint="sets the value of the label">
! <cfargument name="label" required="yes">
! <cfset instance.label = arguments.label>
! </cffunction>
! <!--- a way to get the label --->
! <cffunction name="getLabel" access="public" output="no" returnType="string" hint="get the value of the label">
! <cfreturn instance.label>
! </cffunction>
! <!--- a method for setting the value --->
! <cffunction name="setValue" access="public" output="no" returnType="void" hint="sets the value of the instance value -- also validates internally to set the error state">
<cfargument name="value" required="yes">
! <cfscript>
! instance.value = arguments.value;
! validate();
! </cfscript>
! </cffunction>
! <!--- a method to get the type of CFC --->
! <cffunction name="getType" access="public" output="no" returnType="string" hint="get the type of field (based on the name key in the metaData">
! <cfreturn instance.metaData["NAME"]>
! </cffunction>
! <!--- a method to get the value --->
! <cffunction name="getValue" access="public" output="no" returnType="any" hint="get whatever the value of this instance is">
! <cfreturn instance.value>
! </cffunction>
! <!--- a method to get the name --->
! <cffunction name="getName" access="public" output="no" returnType="string" hint="get the name assigned to this instance">
! <cfreturn instance.name>
</cffunction>
<!--- to render it by default, just spit it out --->
! <cffunction name="toHTML" access="public" output="no" returnType="string" hint="renders the value to HTML.">
! <cfreturn toString(instance.value)>
</cffunction>
<!--- render a form field --->
<cffunction name="toFormField" access="public" output="no" returnType="string" hint="returns a simple text form widget. Typically overridden in any implementation of a field">
! <cfreturn instance.formFieldFactory.makeText(getName(),getValue())>
! </cffunction>
! <!--- a method the package can use to set the attributes of this field with a short-hand --->
! <cffunction name="setAttributes" access="public" returnType="void" output="no" hint="a convenience method. given a struct, sets private data members (instance variables) to the value in the struct, overriding any existing values.">
! <cfargument name="attributesToAdd" required="yes" type="struct" output="no">
! <!--- an iterator --->
! <cfset structAppend(instance,attributesToAdd,true)>
! </cffunction>
! <!--- a method to validate --->
! <cffunction name="validate" access="package" output="no" returnType="void" hint="runs through any rules and sets the error state and adds any error messages necessary">
! <cfset var ruleArray = listToArray(instance.rules)>
! <cfset var ii = 1>
! <cfset var ruleToRun = "">
! <cfscript>
! for(ii = 1; ii LTE arrayLen(ruleArray); ii = ii + 1){
! ruleToRun = createObject("component",ruleArray[ii]).init();
! //if it's not OK, add an error
! if(NOT ruleToRun.isOK(instance.value)){
! addError(newError(ruleArray[ii],ruleToRun.errorMessage(getLabel(),getValue())));
! }
! }
! </cfscript>
! </cffunction>
! <!--- a method to get the errors --->
! <cffunction name="getErrors" access="public" returntype="array" output="no" hint="returns an array of fieldError objects">
! <cfreturn instance.errors>
! </cffunction>
! <!--- a method to return a boolean to know if there are any errors --->
! <cffunction name="hasErrors" access="public" returnType="boolean" output="no" hint="returns a boolean value for whether any errors exist for this instance">
! <cfreturn yesNoFormat(arrayLen(getErrors()))>
! </cffunction>
! <!--- a method to add an error --->
! <cffunction name="addError" access="package" output="no" hint="internal method to add an error to this instance">
! <cfargument name="error" required="yes" type="org.bacfug.modus.errors.fieldError">
! <cfscript>
! arrayAppend(instance.errors,arguments.error);
! </cfscript>
! </cffunction>
! <!--- a method to create an error --->
! <cffunction name="newError" access="package" output="no" returnType="org.bacfug.modus.errors.fieldError" hint="generates an error object, used primarily inside of addError()">
! <cfargument name="type" required="no" default="modus.field">
! <cfargument name="message" required="no" default="A general error occurred in #instance.name#">
! <cfargument name="detail" required="no" default="#arguments.message#">
! <cfset var error = createObject("component","org.bacfug.modus.errors.fieldError")>
! <cfscript>
! error.init(arguments.message,arguments.type,arguments.detail);
! </cfscript>
! <cfreturn error>
</cffunction>
</cfcomponent>
--- 2,30 ----
<cfparam name="instance" default="#structNew()#">
<cffunction name="init" access="public" output="no" returnType="org.bacfug.modus.fields.baseField" hint="initialize this instance, creating the instance variables">
<cfscript>
//if necessary, create a form field factory
! if(NOT isDefined("server._modus.core.formFieldFactory")){
! server._modus.core.formFieldFactory = createObject("component","org.bacfug.modus.rendering.form.formFieldFactory").init();
}
//set the form field factory to this instance
! instance.formFieldFactory = server._modus.core.formFieldFactory;
</cfscript>
<cfreturn this>
</cffunction>
! <cffunction name="setValue" access="public" output="no" returnType="string" hint="default implementation returns the value sent. Children may override this method for more complicated form fields, e.g.:file uploads">
<cfargument name="value" required="yes">
! <cfreturn arguments.value>
</cffunction>
<!--- to render it by default, just spit it out --->
! <cffunction name="renderField" access="public" output="no" returnType="string" hint="renders the value to a simple string.">
! <cfargument name="name" type="string" required="Yes">
! <cfargument name="value" required="Yes">
! <cfreturn toString(arguments.value)>
</cffunction>
<!--- render a form field --->
<cffunction name="toFormField" access="public" output="no" returnType="string" hint="returns a simple text form widget. Typically overridden in any implementation of a field">
! <cfargument name="name" type="string" required="Yes">
! <cfargument name="value" required="Yes">
! <cfreturn instance.formFieldFactory.makeText(arguments.name,arguments.value)>
</cffunction>
</cfcomponent>
Index: basefile.cfc
===================================================================
RCS file: /cvsroot/modus/org/bacfug/modus/fields/basefile.cfc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** basefile.cfc 3 Sep 2002 23:47:37 -0000 1.4
--- basefile.cfc 9 Jan 2003 01:53:39 -0000 1.5
***************
*** 1,40 ****
! <cfcomponent extends="org.bacfug.modus.fields.baseField" displayname="baseFile" hint="The base field for a file. Typically, this would not be used by itself, but extended by specific types of files -- that is primarily because each type of file (image, flash, doc) will want to define a different toHTML() method.">
<cfparam name="instance.directory" default="#expandPath("/")#">
! <!--- override the toFormField method to make a TEXTAREA --->
<cffunction name="toFormField" access="public" output="no" returntype="string">
! <cfreturn instance.formFieldFactory.makeFile(getName())>
</cffunction>
<!--- a method for setting the value --->
! <cffunction name="setValue" access="public" output="no" returnType="void">
<cfargument name="value" required="yes">
<!--- if there is a form element with this name and it has the same value of as the arguments.value then we assume we're trying to upload the file --->
! <cfif structKeyExists(form,getName()) AND len(trim(form[getName()])) AND arguments.value is form[getName()]>
<!--- try the upload of the file --->
! <cffile action="upload" fileField="#getName()#" destination="#getDirectory()#" nameconflict="MAKEUNIQUE">
! <cfscript>
! //set the instance.value to the full path to the file
! instance.value = getDirectory() & file.serverFile;
//validate the upload, if it returns false, delete the file and blank out the value
! if(NOT fileValidate(argumentCollection=file)){
! deleteFile();
}
</cfscript>
<!--- if the form field is there, but it is blank and the arguments.value is the same, then just set the instance.value to whatever the value already is --->
! <cfelseif structKeyExists(form,getName()) AND NOT len(trim(form[getName()])) AND arguments.value is form[getName()]>
! <cfscript>
! instance.value = getValue();
! </cfscript>
! <!--- if we're not uploading the file, then the value is just the value --->
<cfelse>
! <cfscript>
! instance.value = arguments.value;
! </cfscript>
</cfif>
- <cfscript>
- validate();
- </cfscript>
</cffunction>
--- 1,35 ----
! <cfcomponent extends="org.bacfug.modus.fields.baseField" displayname="baseFile" hint="The base field for a file. Typically, this would not be used by itself, but extended by specific types of files -- that is primarily because each type of file (image, flash, doc) will want to define a different renderField() method.">
<cfparam name="instance.directory" default="#expandPath("/")#">
! <!--- override the toFormField method to make a File Upload Field --->
<cffunction name="toFormField" access="public" output="no" returntype="string">
! <cfargument name="name" type="string" required="Yes">
! <cfreturn instance.formFieldFactory.makeFile(arguments.name)>
</cffunction>
<!--- a method for setting the value --->
! <cffunction name="setValue" access="public" output="no" returnType="string">
<cfargument name="value" required="yes">
+ <cfargument name="name" type="string" required="Yes">
<!--- if there is a form element with this name and it has the same value of as the arguments.value then we assume we're trying to upload the file --->
! <cfif len(arguments.value)>
<!--- try the upload of the file --->
! <cffile action="upload" fileField="#arguments.name#" destination="C:\" nameconflict="MAKEUNIQUE">
!
! <cfscript>
//validate the upload, if it returns false, delete the file and blank out the value
! if(NOT fileValidate(argumentCollection=cffile)){
! deleteFile(arguments.value);
}
+ return getDirectory() & file.serverFile;
</cfscript>
<!--- if the form field is there, but it is blank and the arguments.value is the same, then just set the instance.value to whatever the value already is --->
! <cfelseif structKeyExists(form,arguments.name) AND NOT len(trim(form[arguments.name])) AND arguments.value is form[arguments.name]>
! <cfreturn "">
! <!--- if we're not uploading the file, then the value is blank --->
<cfelse>
! <cfreturn "">
</cfif>
</cffunction>
***************
*** 59,65 ****
<!--- a method for getting the web root relative path to this file (if possible) --->
<cffunction name="getWebRootRelativePath" access="public" output="no" returnType="string">
<cfset var webRootAbsolutePath = expandPath("/")>
<cfset var webRootRelativePath = "">
! <cfset var thisPath = getValue()>
<cfset var webInfPath = webRootAbsolutePath & "WEB-INF">
<cfscript>
--- 54,61 ----
<!--- a method for getting the web root relative path to this file (if possible) --->
<cffunction name="getWebRootRelativePath" access="public" output="no" returnType="string">
+ <cfargument name="value" type="string" required="Yes">
<cfset var webRootAbsolutePath = expandPath("/")>
<cfset var webRootRelativePath = "">
! <cfset var thisPath = arguments.value>
<cfset var webInfPath = webRootAbsolutePath & "WEB-INF">
<cfscript>
***************
*** 79,86 ****
<!--- a method to delete the file --->
<cffunction name="deleteFile" access="public" output="no" returnType="void">
! <cfset var thisPath = getValue()>
<!--- if there is a path, and it exists, delete the file --->
! <cfif len(trim(thisPath)) AND fileExists(thisPath)>
! <cffile action="delete" file="#getValue()#">
</cfif>
<cfscript>
--- 75,82 ----
<!--- a method to delete the file --->
<cffunction name="deleteFile" access="public" output="no" returnType="void">
! <cfargument name="value" type="string" required="Yes">
<!--- if there is a path, and it exists, delete the file --->
! <cfif len(trim(arguments.value)) AND fileExists(arguments.value)>
! <cffile action="delete" file="#arguments.value#">
</cfif>
<cfscript>
***************
*** 89,93 ****
</cfscript>
</cffunction>
! <cffunction name="toHTML" access="public" output="no">
<cfreturn "BBBB" & toString(instance.value)>
</cffunction>
--- 85,89 ----
</cfscript>
</cffunction>
! <cffunction name="renderField" access="public" output="no">
<cfreturn "BBBB" & toString(instance.value)>
</cffunction>
Index: hidden.cfc
===================================================================
RCS file: /cvsroot/modus/org/bacfug/modus/fields/hidden.cfc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** hidden.cfc 24 Oct 2002 00:56:47 -0000 1.1
--- hidden.cfc 9 Jan 2003 01:53:39 -0000 1.2
***************
*** 2,6 ****
<!--- override the toFormField method to make a hidden field --->
<cffunction name="toFormField" access="public" output="no" hint="returns a simple hidden form widget" returnType="string">
! <cfreturn instance.formFieldFactory.makeHidden(getName(),getValue())>
</cffunction>
</cfcomponent>
--- 2,8 ----
<!--- override the toFormField method to make a hidden field --->
<cffunction name="toFormField" access="public" output="no" hint="returns a simple hidden form widget" returnType="string">
! <cfargument name="name" type="string" required="Yes">
! <cfargument name="value" required="Yes">
! <cfreturn instance.formFieldFactory.makeHidden(arguments.name,arguments.value)>
</cffunction>
</cfcomponent>
Index: longtext.cfc
===================================================================
RCS file: /cvsroot/modus/org/bacfug/modus/fields/longtext.cfc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** longtext.cfc 3 Sep 2002 22:29:05 -0000 1.3
--- longtext.cfc 9 Jan 2003 01:53:39 -0000 1.4
***************
*** 3,7 ****
<!--- override the toFormField method to make a TEXTAREA --->
<cffunction name="toFormField" access="public" output="no" returnType="string" hint="returns a textarea form widget">
! <cfreturn instance.formFieldFactory.makeTextArea(getName(),getValue())>
</cffunction>
</cfcomponent>
--- 3,9 ----
<!--- override the toFormField method to make a TEXTAREA --->
<cffunction name="toFormField" access="public" output="no" returnType="string" hint="returns a textarea form widget">
! <cfargument name="name" type="string" required="Yes">
! <cfargument name="value" required="Yes">
! <cfreturn instance.formFieldFactory.makeTextArea(arguments.name,arguments.value)>
</cffunction>
</cfcomponent>
Index: text.cfc
===================================================================
RCS file: /cvsroot/modus/org/bacfug/modus/fields/text.cfc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** text.cfc 3 Sep 2002 22:29:05 -0000 1.3
--- text.cfc 9 Jan 2003 01:53:39 -0000 1.4
***************
*** 2,6 ****
<!--- override the toFormField method to make a TEXTAREA --->
<cffunction name="toFormField" access="public" output="no" hint="returns a simple text form widget" returnType="string">
! <cfreturn instance.formFieldFactory.makeText(getName(),getValue())>
</cffunction>
</cfcomponent>
--- 2,8 ----
<!--- override the toFormField method to make a TEXTAREA --->
<cffunction name="toFormField" access="public" output="no" hint="returns a simple text form widget" returnType="string">
! <cfargument name="name" type="string" required="Yes">
! <cfargument name="value" required="Yes">
! <cfreturn instance.formFieldFactory.makeText(arguments.name,arguments.value)>
</cffunction>
</cfcomponent>
Index: webimage.cfc
===================================================================
RCS file: /cvsroot/modus/org/bacfug/modus/fields/webimage.cfc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** webimage.cfc 3 Sep 2002 00:33:20 -0000 1.2
--- webimage.cfc 9 Jan 2003 01:53:39 -0000 1.3
***************
*** 1,6 ****
<cfcomponent extends="org.bacfug.modus.fields.baseFile" displayname="webImage" hint="The field for a web image">
! <!--- toHTML() should show an image tag if we can get a web root relative path --->
! <cffunction name="toHTML" access="public" output="no" returnType="string" hint="Draws an IMG tag if a web root relative path can be determined">
! <cfset var imgPath = getWebRootRelativePath()>
<cfif len(trim(imgPath))>
<cfreturn "<img src=""" & imgPath & """ border=""0"">">
--- 1,8 ----
<cfcomponent extends="org.bacfug.modus.fields.baseFile" displayname="webImage" hint="The field for a web image">
! <!--- renderField() should show an image tag if we can get a web root relative path --->
! <cffunction name="renderField" access="public" output="no" returnType="string" hint="Draws an IMG tag if a web root relative path can be determined">
! <cfargument name="name" type="string">
! <cfargument name="value" type="string" required="Yes">
! <cfset var imgPath = getWebRootRelativePath(arguments.value)>
<cfif len(trim(imgPath))>
<cfreturn "<img src=""" & imgPath & """ border=""0"">">
Index: yesno.cfc
===================================================================
RCS file: /cvsroot/modus/org/bacfug/modus/fields/yesno.cfc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** yesno.cfc 3 Sep 2002 22:29:05 -0000 1.5
--- yesno.cfc 9 Jan 2003 01:53:39 -0000 1.6
***************
*** 2,10 ****
<!--- override the toFormField method to make a TEXTAREA --->
<cffunction name="toFormField" access="public" output="no" returnType="string" hint="Renders two radio buttons with values ""yes"" and ""no""">
! <cfreturn instance.formFieldFactory.makeRadio(getName(),"yes",getValue())
&
" Yes"
&
! instance.formFieldFactory.makeRadio(getName(),"no",getValue())
&
" No">
--- 2,12 ----
<!--- override the toFormField method to make a TEXTAREA --->
<cffunction name="toFormField" access="public" output="no" returnType="string" hint="Renders two radio buttons with values ""yes"" and ""no""">
! <cfargument name="name" type="string" required="Yes">
! <cfargument name="value" required="Yes">
! <cfreturn instance.formFieldFactory.makeRadio(arguments.name,1,arguments.value)
&
" Yes"
&
! instance.formFieldFactory.makeRadio(arguments.name,0,arguments.value)
&
" No">
|