PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/view/formsdate.cfm

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