PageRenderTime 43ms CodeModel.GetById 33ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/wheels/view/formsdate.cfm

http://cfwheels.googlecode.com/
ColdFusion | 271 lines | 254 code | 17 blank | 0 comment | 54 complexity | 54aafc8ab602f24b3822fa402dc0b14b MD5 | raw file
  1<cffunction name="$yearSelectTag" returntype="string" access="public" output="false">
  2	<cfargument name="startYear" type="numeric" required="true">
  3	<cfargument name="endYear" type="numeric" required="true">
  4	<cfscript>
  5		if (Structkeyexists(arguments, "value") && Val(arguments.value))
  6		{
  7			if (arguments.value < arguments.startYear && arguments.endYear > arguments.startYear)
  8				arguments.startYear = arguments.value;
  9			else if(arguments.value < arguments.endYear && arguments.endYear < arguments.startYear)
 10				arguments.endYear = arguments.value;
 11		}
 12		arguments.$loopFrom = arguments.startYear;
 13		arguments.$loopTo = arguments.endYear;
 14		arguments.$type = "year";
 15		arguments.$step = 1;
 16		StructDelete(arguments, "startYear");
 17		StructDelete(arguments, "endYear");
 18	</cfscript>
 19	<cfreturn $yearMonthHourMinuteSecondSelectTag(argumentCollection=arguments)>
 20</cffunction>
 21
 22<cffunction name="$monthSelectTag" returntype="string" access="public" output="false">
 23	<cfargument name="monthDisplay" type="string" required="true">
 24	<cfscript>
 25		arguments.$loopFrom = 1;
 26		arguments.$loopTo = 12;
 27		arguments.$type = "month";
 28		arguments.$step = 1;
 29		if (arguments.monthDisplay == "abbreviations")
 30			arguments.$optionNames = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
 31		else if (arguments.monthDisplay == "names")
 32			arguments.$optionNames = "January,February,March,April,May,June,July,August,September,October,November,December";
 33		StructDelete(arguments, "monthDisplay");
 34	</cfscript>
 35	<cfreturn $yearMonthHourMinuteSecondSelectTag(argumentCollection=arguments)>
 36</cffunction>
 37
 38<cffunction name="$daySelectTag" returntype="string" access="public" output="false">
 39	<cfscript>
 40		arguments.$loopFrom = 1;
 41		arguments.$loopTo = 31;
 42		arguments.$type = "day";
 43		arguments.$step = 1;
 44	</cfscript>
 45	<cfreturn $yearMonthHourMinuteSecondSelectTag(argumentCollection=arguments)>
 46</cffunction>
 47
 48<cffunction name="$hourSelectTag" returntype="string" access="public" output="false">
 49	<cfscript>
 50		arguments.$loopFrom = 0;
 51		arguments.$loopTo = 23;
 52		arguments.$type = "hour";
 53		arguments.$step = 1;
 54		if (arguments.twelveHour)
 55		{
 56			arguments.$loopFrom = 1;
 57			arguments.$loopTo = 12;
 58		}
 59	</cfscript>
 60	<cfreturn $yearMonthHourMinuteSecondSelectTag(argumentCollection=arguments)>
 61</cffunction>
 62
 63<cffunction name="$minuteSelectTag" returntype="string" access="public" output="false">
 64	<cfargument name="minuteStep" type="numeric" required="true">
 65	<cfscript>
 66		arguments.$loopFrom = 0;
 67		arguments.$loopTo = 59;
 68		arguments.$type = "minute";
 69		arguments.$step = arguments.minuteStep;
 70		StructDelete(arguments, "minuteStep");
 71	</cfscript>
 72	<cfreturn $yearMonthHourMinuteSecondSelectTag(argumentCollection=arguments)>
 73</cffunction>
 74
 75<cffunction name="$secondSelectTag" returntype="string" access="public" output="false">
 76	<cfscript>
 77		arguments.$loopFrom = 0;
 78		arguments.$loopTo = 59;
 79		arguments.$type = "second";
 80		arguments.$step = 1;
 81	</cfscript>
 82	<cfreturn $yearMonthHourMinuteSecondSelectTag(argumentCollection=arguments)>
 83</cffunction>
 84
 85<cffunction name="$dateOrTimeSelect" returntype="string" access="public" output="false">
 86	<cfargument name="objectName" type="any" required="true">
 87	<cfargument name="property" type="string" required="true">
 88	<cfargument name="$functionName" type="string" required="true">
 89	<cfargument name="combine" type="boolean" required="false" default="true">
 90	<cfargument name="twelveHour" type="boolean" required="false" default="false">
 91	<cfscript>
 92		var loc = {};
 93		loc.combine = arguments.combine;
 94		StructDelete(arguments, "combine", false);
 95		loc.name = $tagName(arguments.objectName, arguments.property);
 96		arguments.$id = $tagId(arguments.objectName, arguments.property);
 97
 98		// in order to support 12-hour format, we have to enforce some rules
 99		// if arguments.twelveHour is true, then order MUST contain ampm
100		// if the order contains ampm, then arguments.twelveHour MUST be true
101		if (arguments.twelveHour || ListFindNoCase(arguments.order, "ampm"))
102		{
103			arguments.twelveHour = true;
104			if (!ListFindNoCase(arguments.order, "ampm"))
105			{
106				arguments.order = ListAppend(arguments.order, "ampm");
107			}
108		}
109
110		loc.value = $formValue(argumentCollection=arguments);
111		loc.returnValue = "";
112		loc.firstDone = false;
113		loc.iEnd = ListLen(arguments.order);
114		for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
115		{
116			loc.item = ListGetAt(arguments.order, loc.i);
117			loc.marker = "($" & loc.item & ")";
118			if(!loc.combine)
119			{
120				loc.name = $tagName(arguments.objectName, "#arguments.property#-#loc.item#");
121				loc.marker = "";
122			}
123			arguments.name = loc.name & loc.marker;
124			arguments.value = loc.value;
125			if (Isdate(loc.value))
126			{
127				if (arguments.twelveHour)
128				{
129					if (loc.item IS "hour")
130					{
131						arguments.value = TimeFormat(loc.value, 'h');
132					}
133					else if (loc.item IS "ampm")
134					{
135						arguments.value = TimeFormat(loc.value, 'tt');
136					}
137				}
138				else
139				{
140					arguments.value = Evaluate("#loc.item#(loc.value)");
141				}
142			}
143
144			if (loc.firstDone)
145				loc.returnValue = loc.returnValue & arguments.separator;
146			loc.returnValue = loc.returnValue & Evaluate("$#loc.item#SelectTag(argumentCollection=arguments)");
147			loc.firstDone = true;
148		}
149	</cfscript>
150	<cfreturn loc.returnValue>
151</cffunction>
152
153<cffunction name="$yearMonthHourMinuteSecondSelectTag" returntype="string" access="public" output="false">
154	<cfargument name="name" type="string" required="true">
155	<cfargument name="value" type="string" required="true">
156	<cfargument name="includeBlank" type="any" required="true">
157	<cfargument name="label" type="string" required="true">
158	<cfargument name="labelPlacement" type="string" required="true">
159	<cfargument name="prepend" type="string" required="true">
160	<cfargument name="append" type="string" required="true">
161	<cfargument name="prependToLabel" type="string" required="true">
162	<cfargument name="appendToLabel" type="string" required="true">
163	<cfargument name="errorElement" type="string" required="false" default="">
164	<cfargument name="errorClass" type="string" required="false" default="">
165	<cfargument name="$type" type="string" required="true">
166	<cfargument name="$loopFrom" type="numeric" required="true">
167	<cfargument name="$loopTo" type="numeric" required="true">
168	<cfargument name="$id" type="string" required="true">
169	<cfargument name="$step" type="numeric" required="true">
170	<cfargument name="$optionNames" type="string" required="false" default="">
171	<cfargument name="twelveHour" type="boolean" required="false" default="false">
172	<cfscript>
173		var loc = {};
174		loc.optionContent = "";
175		// only set the default value if the value is blank and includeBlank is false
176		if (!Len(arguments.value) && (IsBoolean(arguments.includeBlank) && !arguments.includeBlank))
177			if (arguments.twelveHour && arguments.$type IS "hour")
178				arguments.value = TimeFormat(Now(), 'h');
179			else
180				arguments.value = Evaluate("#arguments.$type#(Now())");
181		if (StructKeyExists(arguments, "order") && ListLen(arguments.order) > 1 && ListLen(arguments.label) > 1)
182			arguments.label = ListGetAt(arguments.label, ListFindNoCase(arguments.order, arguments.$type));
183		if (!StructKeyExists(arguments, "id"))
184			arguments.id = arguments.$id & "-" & arguments.$type;
185		loc.before = $formBeforeElement(argumentCollection=arguments);
186		loc.after = $formAfterElement(argumentCollection=arguments);
187		loc.content = "";
188		if (!IsBoolean(arguments.includeBlank) || arguments.includeBlank)
189		{
190			loc.args = {};
191			loc.args.value = "";
192			if(!Len(arguments.value))
193				loc.args.selected = "selected";
194			if (!IsBoolean(arguments.includeBlank))
195				loc.optionContent = arguments.includeBlank;
196			loc.content = loc.content & $element(name="option", content=loc.optionContent, attributes=loc.args);
197		}
198
199		if(arguments.$loopFrom < arguments.$loopTo)
200		{
201			for (loc.i=arguments.$loopFrom; loc.i <= arguments.$loopTo; loc.i=loc.i+arguments.$step)
202			{
203				loc.args = Duplicate(arguments);
204				loc.args.counter = loc.i;
205				loc.args.optionContent = loc.optionContent;
206				loc.content = loc.content & $yearMonthHourMinuteSecondSelectTagContent(argumentCollection=loc.args);
207			}
208		}
209		else
210		{
211			for (loc.i=arguments.$loopFrom; loc.i >= arguments.$loopTo; loc.i=loc.i-arguments.$step)
212			{
213				loc.args = Duplicate(arguments);
214				loc.args.counter = loc.i;
215				loc.args.optionContent = loc.optionContent;
216				loc.content = loc.content & $yearMonthHourMinuteSecondSelectTagContent(argumentCollection=loc.args);
217			}
218		}
219		loc.returnValue = loc.before & $element(name="select", skip="objectName,property,label,labelPlacement,prepend,append,prependToLabel,appendToLabel,errorElement,errorClass,value,includeBlank,order,separator,startYear,endYear,monthDisplay,dateSeparator,dateOrder,timeSeparator,timeOrder,minuteStep,association,position,twelveHour", skipStartingWith="label", content=loc.content, attributes=arguments) & loc.after;
220	</cfscript>
221	<cfreturn loc.returnValue>
222</cffunction>
223
224<cffunction name="$yearMonthHourMinuteSecondSelectTagContent">
225	<cfscript>
226		var loc = {};
227		loc.args = {};
228		loc.args.value = arguments.counter;
229		if (arguments.value == arguments.counter)
230			loc.args.selected = "selected";
231		if (Len(arguments.$optionNames))
232			arguments.optionContent = ListGetAt(arguments.$optionNames, arguments.counter);
233		else
234			arguments.optionContent = arguments.counter;
235		if (arguments.$type == "minute" || arguments.$type == "second")
236			arguments.optionContent = NumberFormat(arguments.optionContent, "09");
237	</cfscript>
238	<cfreturn $element(name="option", content=arguments.optionContent, attributes=loc.args)>
239</cffunction>
240
241<cffunction name="$ampmSelectTag" returntype="string" access="public" output="false">
242	<cfargument name="name" type="string" required="true">
243	<cfargument name="value" type="string" required="true">
244	<cfargument name="$id" type="string" required="true">
245	<cfscript>
246		var loc = {};
247		loc.options = "AM,PM";
248		loc.optionContent = "";
249		if (!Len(arguments.value))
250			arguments.value = TimeFormat(Now(), 'tt');
251		if (!StructKeyExists(arguments, "id"))
252			arguments.id = arguments.$id & "-ampm";
253		loc.content = "";
254
255		loc.iEnd = ListLen(loc.options);
256		for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
257		{
258			loc.option = ListGetAt(loc.options, loc.i);
259
260			loc.args = {};
261			loc.args.value = loc.option;
262			if (arguments.value IS loc.option)
263				loc.args.selected = "selected";
264
265			loc.content = loc.content & $element(name="option", content=loc.option, attributes=loc.args);
266		}
267
268		loc.returnValue = $element(name="select", skip="objectName,property,label,labelPlacement,prepend,append,prependToLabel,appendToLabel,errorElement,errorClass,value,includeBlank,order,separator,startYear,endYear,monthDisplay,dateSeparator,dateOrder,timeSeparator,timeOrder,minuteStep,association,position,twelveHour", skipStartingWith="label", content=loc.content, attributes=arguments);
269	</cfscript>
270	<cfreturn loc.returnValue>
271</cffunction>