2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "WECalendarField.h"
23 #include <NGObjWeb/WEClientCapabilities.h>
26 static Class StrClass = Nil;
28 @implementation WECalendarField
31 return [super version] + 0 /* v2 */;
35 NSAssert2([super version] == 2,
36 @"invalid superclass (%@) version %i !",
37 NSStringFromClass([self superclass]), [super version]);
38 StrClass = [NSString class];
41 static NSString *retStrForInt(int i) {
42 // TODO: find out good statics
43 return [[StrClass alloc] initWithFormat:@"%i", i];
45 static NSString *retStr02ForInt(int i) {
46 switch (i) { // TODO: find out a good count ...
59 return [[StrClass alloc] initWithFormat:@"%02i", i];
63 - (id)initWithName:(NSString *)_name
64 associations:(NSDictionary *)_config
65 template:(WOElement *)_subs
67 if ((self = [super initWithName:_name associations: _config template:_subs])) {
68 self->name = OWGetProperty(_config, @"name");
69 self->date = OWGetProperty(_config, @"date");
71 // time field associations
72 self->hour = OWGetProperty(_config, @"hour");
73 self->minute = OWGetProperty(_config, @"minute");
74 self->second = OWGetProperty(_config, @"second");
75 self->useTextField = OWGetProperty(_config, @"useTextField");
76 self->hourInterval = OWGetProperty(_config, @"hourInterval");
77 self->minuteInterval = OWGetProperty(_config, @"minuteInterval");
78 self->secondInterval = OWGetProperty(_config, @"secondInterval");
80 // date field associations
81 self->year = OWGetProperty(_config, @"year");
82 self->month = OWGetProperty(_config, @"month");
83 self->day = OWGetProperty(_config, @"day");
84 self->format = OWGetProperty(_config, @"format");
86 self->template = [_subs retain];
95 /* time field associations */
97 [self->minute release];
98 [self->second release];
99 [self->useTextField release];
100 [self->hourInterval release];
101 [self->minuteInterval release];
102 [self->secondInterval release];
104 /* date field associations */
105 [self->year release];
106 [self->month release];
108 [self->format release];
110 [self->template release];
114 - (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
115 [self _takeValuesFromTimeFieldRequest:_rq inContext:_ctx];
116 [self _takeValuesFromDateFieldRequest:_rq inContext:_ctx];
119 - (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
122 result = [self _invokeActionForTimeFieldRequest:_rq inContext:_ctx];
124 result = [self _invokeActionForDateFieldRequest:_rq inContext:_ctx];
129 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
130 [_response appendContentString:
131 @"<table border='0' cellpadding='0' cellspacing='0'>"
133 @"<td align='left' valign='bottom'>"];
134 [self _appendTimeFieldToResponse:_response inContext:_ctx];
136 [_response appendContentString:
138 @"<td align='left' valign='bottom'>"];
140 [self _appendDateFieldToResponse:_response inContext:_ctx];
142 [_response appendContentString:
148 @end /* WECalendarField */
150 @implementation WECalendarField(WETimeFieldImplementation)
152 /* Private Methodes */
154 - (NSString *)_divIDAndScriptInContext:(WOContext *)_ctx
155 response:(WOResponse *)_response
159 divCount = [[_ctx valueForKey: @"WETimeFieldScript"] intValue];
161 [_response appendContentString:
162 @"<style type=\"text/css\">\n"
164 @"A.DDLlink { width: 23px; font: normal 10pt Arial; color: "
165 @"#6F1537; text-decoration: none; } \n"
166 @"A.DDLlink:hover { color: red; background: #FAE8B8; } \n"
169 [_response appendContentString:
170 @"<script language=\"JavaScript\">\n"
172 @"var DDLlayerCount = 1000;\n"
173 @"function DDLopen(layerObj,el) {\n"
174 @" if (layerObj.style.visibility == 'hidden') {\n"
175 @" layerObj.style.visibility = 'visible';\n"
176 @" layerObj.style.zIndex = DDLlayerCount;\n"
177 @" formObj = DDLformField(el);\n"
178 @" formObj.contentEditable = false;\n"
179 @" DDLlayerCount++;\n"
181 @" } else { layerObj.style.visibility = 'hidden'; }\n"
183 @"function DDLreturn(layerObj,el,value) {\n"
184 @" formObj = DDLformField(el);\n"
185 @" formObj.value = value;\n"
186 @" formObj.contentEditable = true;\n"
187 @" layerObj.style.visibility = 'hidden';\n"
189 @"function DDLformField(el) {\n"
190 @" for (i = 0; i < document.forms.length; i++)\n"
191 @" for (j = 0; j < document.forms[i].elements.length; j++)\n"
192 @" if (document.forms[i].elements[j].name == el)\n"
193 @" return document.forms[i].elements[j];\n"
198 [_ctx takeValue:[NSNumber numberWithInt:(divCount+1)]
199 forKey:@"WETimeFieldScript"];
201 return [StrClass stringWithFormat:@"dropDownDiv%i", divCount];
204 - (void)_appendSelectToResponse:(WOResponse *)_response
205 inContext:(WOContext *)_ctx
206 elementIDComponent:(NSString *)_elementIDComponent
208 selectedIndex:(int)_idx
209 interval:(int)_interval
211 WEClientCapabilities *ccaps;
220 ccaps = [[_ctx request] clientCapabilities];
221 userAgent = [[_ctx request] headerForKey: @"user-agent"];
222 isMSIE = [ccaps isInternetExplorer];
223 elementId = [self elementIdWithSuffix:_elementIDComponent ctx:_ctx];
225 divID = [self _divIDAndScriptInContext:_ctx response:_response];
227 img = WEUriOfResource(@"downstairs.gif", _ctx);
232 [_response appendContentString:@"<input readonly=\"readonly\" name=\""];
233 [_response appendContentString:elementId];
234 [_response appendContentString:@"\" value=\""];
236 s = retStr02ForInt(_idx);
237 [_response appendContentHTMLAttributeValue:s];
240 [_response appendContentString:
241 @"\" type=\"text\" size=\"2\" maxlength=\"2\""];
243 [_response appendContentString:@" style=\"background-color: #FFDAAA;\""];
245 [_response appendContentString:@" /><img border=\"0\" src=\""];
246 [_response appendContentString:img];
247 [_response appendContentString:@"\" onClick=\""];
248 [_response appendContentString:@"javascript:DDLopen("];
249 [_response appendContentString:divID];
250 [_response appendContentString:@",'"];
251 [_response appendContentString:elementId];
252 [_response appendContentString:@"')\" /><br />"];
253 [_response appendContentString:@"<div id=\""];
254 [_response appendContentString:divID];
255 [_response appendContentString:
256 @"\" style=\"position: absolute; overflow: auto; height: 150; width: 47;"
257 @" background: #FFDAAA; border: 1 solid; "
258 @"visibility: hidden; padding: 0 0 0 2;\">"];
261 [_response appendContentString:@"<select name=\""];
262 [_response appendContentString:elementId];
263 [_response appendContentString:@"\">"];
266 for (i = 0; i <= _count; i += _interval) {
267 tmp = retStr02ForInt(i);
271 s = [[StrClass alloc] initWithFormat:
272 @"<a class=\"DDLlink\" href=\"javascript:DDLreturn(%@,'%@','%@')\">%@"
274 divID, elementId, tmp, tmp];
275 [_response appendContentString:s];
279 [_response appendContentString:@"<option value=\""];
280 [_response appendContentString:tmp];
281 [_response appendContentString:@"\""];
282 [_response appendContentString:
283 (i == _idx) ? @" selected=\"selected\"" : @""];
284 [_response appendContentString:@">"];
285 [_response appendContentString:tmp];
286 [_response appendContentString:@"</option>"];
288 [tmp release]; tmp = nil;
292 [_response appendContentString:@"</div>"];
294 [_response appendContentString:@"</select>"];
299 - (void)_takeValuesFromTimeFieldRequest:(WORequest *)_request
300 inContext:(WOContext *)_ctx
309 comp = [_ctx component];
310 tuseTField = self->useTextField
311 ? [[self->useTextField valueInComponent: comp] boolValue]
316 elementId = [self elementIdWithSuffix:@"" ctx:_ctx];
317 if ((formValue = [_request formValueForKey:elementId])) {
320 ta = [formValue componentsSeparatedByString:@":"];
324 if ([self isHourSettable]) {
325 intValue = (idx < cnt) ? [[ta objectAtIndex:idx] intValue] : 0;
326 [self setHour:intValue inComponent:comp];
329 if ([self isMinuteSettable]) {
330 intValue = (idx < cnt) ? [[ta objectAtIndex:idx] intValue] : 0;
331 [self setMinute:intValue inComponent:comp];
334 if ([self isSecondSettable]) {
335 intValue = (idx < cnt) ? [[ta objectAtIndex:idx] intValue] : 0;
336 [self setSecond:intValue inComponent:comp];
341 elementId = [self elementIdWithSuffix:@"hour" ctx:_ctx];
342 if ((formValue = [_request formValueForKey:elementId])) {
343 if ([self isHourSettable])
344 [self setHour:[formValue intValue] inComponent:comp];
347 elementId = [self elementIdWithSuffix:@"minute" ctx:_ctx];
348 if ((formValue = [_request formValueForKey:elementId])) {
349 if ([self isMinuteSettable])
350 [self setMinute:[formValue intValue] inComponent:comp];
353 elementId = [self elementIdWithSuffix:@"second" ctx:_ctx];
354 if ((formValue = [_request formValueForKey:elementId])) {
355 if ([self isSecondSettable])
356 [self setSecond:[formValue intValue] inComponent:comp];
361 [_ctx appendElementIDComponent:@"timeField"];
362 [self->template takeValuesFromRequest:_request inContext:_ctx];
363 [_ctx deleteLastElementIDComponent];
366 - (id)_invokeActionForTimeFieldRequest:(WORequest *)_rq
367 inContext:(WOContext *)_ctx
369 return [self->template invokeActionForRequest:_rq inContext:_ctx];
372 /* generate response */
374 - (void)_appendTimeFieldToResponse:(WOResponse *)_r inContext:(WOContext *)_cx{
375 NSCalendarDate *tdate;
378 int hourInt; // hourInterval
379 int minuteInt; // minuteInterval
380 int secondInt; // secondInterval
383 comp = [_cx component];
384 tdate = [NSCalendarDate calendarDate];
386 hourInt = self->hourInterval
387 ? [self->hourInterval intValueInComponent:comp] : 1;
389 minuteInt = self->minuteInterval
390 ? [self->minuteInterval intValueInComponent:comp] : 1;
392 secondInt = self->secondInterval
393 ? [self->secondInterval intValueInComponent:comp] : 1;
395 tuseTField = self->useTextField
396 ? [self->useTextField boolValueInComponent:comp]
400 [_cx appendElementIDComponent:@"timeField"];
401 [self->template appendToResponse:_r inContext:_cx];
402 [_cx deleteLastElementIDComponent];
404 // all values in one textField
408 // build string of values and @":"
410 h = [self hourInComponent:comp];
411 m = [self minuteInComponent:comp];
412 s = [self secondInComponent:comp];
414 ta = [[NSMutableArray alloc] initWithCapacity: 3];
417 if ([self hasHourInComponent:comp]) {
418 tmp = retStr02ForInt(h);
422 if ([self hasMinuteInComponent:comp]) {
423 tmp = [[StrClass alloc] initWithFormat:fmt, m];
427 if ([self hasSecondInComponent:comp]) {
428 tmp = [[StrClass alloc] initWithFormat:fmt, s];
433 tmp = [ta componentsJoinedByString:@":"];
434 [ta release]; ta = nil;
436 /* append to response */
437 if ([tmp isNotEmpty]) {
438 [_r appendContentString:@"<input type=\"text\" name=\""];
439 [_r appendContentString:[self elementIdWithSuffix:@"" ctx:_cx]];
440 [_r appendContentString:@"\" value=\""];
441 [_r appendContentString:tmp];
442 [_r appendContentString:@"\""];
444 tmp = retStrForInt([tmp length]);
445 [_r appendContentString:@" size=\""];
446 [_r appendContentString:tmp];
447 [_r appendContentString:@"\" maxlength=\""];
448 [_r appendContentString:tmp];
449 [_r appendContentString:@"\""];
452 [_r appendContentString:@" />"];
457 [_r appendContentString:
458 @"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>"];
460 if ([self hasHourInComponent:comp]) {
461 [_r appendContentString:@"<td valign=\"bottom\">"];
462 [self _appendSelectToResponse:_r inContext:_cx
463 elementIDComponent:@"hour"
464 count:23 selectedIndex:[self hourInComponent:comp]
466 [_r appendContentString:@"</td>"];
469 // minute select field
470 if ([self hasMinuteInComponent:comp]) {
471 [_r appendContentString:@"<td valign=\"bottom\">"];
472 [self _appendSelectToResponse:_r inContext:_cx
473 elementIDComponent:@"minute"
474 count:59 selectedIndex:[self minuteInComponent:comp]
476 [_r appendContentString:@"</td>"];
479 // second select field
480 if ([self hasSecondInComponent:comp]) {
481 [_r appendContentString:@"<td valign=\"bottom\">"];
482 [self _appendSelectToResponse:_r inContext:_cx
483 elementIDComponent:@"second"
484 count:59 selectedIndex:[self secondInComponent:comp]
486 [_r appendContentString:@"</td>"];
488 [_r appendContentString:@"</tr></table>"];
490 } /* end of (!tuseTField) */
493 @end /* WECalendarField(WETimeFieldImplementation */
495 @implementation WECalendarField(WEDateFieldImplementation)
497 - (void)_takeValuesFromDateFieldRequest:(WORequest *)_request
498 inContext:(WOContext *)_ctx
501 NSCalendarDate *tdate;
508 comp = [_ctx component];
510 tformat = [self->format stringValueInComponent: comp];
511 if (tformat == nil) tformat = @"%Y-%m-%d";
512 elementId = [self elementIdWithSuffix:@"" ctx:_ctx];
514 if ([self isKindOfClass:[WECalendarField class]]) {
517 t = [[t componentsSeparatedByString:@"%H"] componentsJoinedByString:@""];
518 t = [[t componentsSeparatedByString:@"%M"] componentsJoinedByString:@""];
519 t = [[t componentsSeparatedByString:@"%S"] componentsJoinedByString:@""];
524 tdate = [NSCalendarDate dateWithString:
525 [_request formValueForKey:elementId]
526 calendarFormat: tformat];
528 NSLog(@"WARNING: WEDateField: field value and format do not match!");
531 tyear = [tdate yearOfCommonEra];
532 tmonth = [tdate monthOfYear];
533 tday = [tdate dayOfMonth];
536 if ([self isYearSettable]) [self setYear:tyear inComponent:comp];
537 if ([self isMonthSettable]) [self setMonth:tmonth inComponent:comp];
538 if ([self isDaySettable]) [self setDay:tday inComponent:comp];
541 [_ctx appendElementIDComponent:@"dateField"];
542 [self->template takeValuesFromRequest:_request inContext:_ctx];
543 [_ctx deleteLastElementIDComponent];
546 - (id)_invokeActionForDateFieldRequest:(WORequest *)_request
547 inContext:(WOContext *)_ctx
549 return [self->template invokeActionForRequest:_request inContext:_ctx];
552 - (void)_appendDateFieldToResponse:(WOResponse *)_response
553 inContext:(WOContext *)_ctx
555 WEClientCapabilities *ccaps;
562 NSCalendarDate *tdate;
563 NSString *calendarDivID;
568 ccaps = [[_ctx request] clientCapabilities];
569 comp = [_ctx component];
570 tdate = [NSCalendarDate calendarDate];
571 isMSIE = [ccaps isInternetExplorer];
573 if (![_ctx valueForKey:@"WEDateFieldScriptDone"])
574 [WEDateFieldScript appendWEDateFieldScriptToResponse: _response
576 headBackground: HEAD_BACKGROUND_COLOR
577 headColor: HEAD_COLOR
578 headNavColor: HEAD_NAVIGATION_COLOR
583 tyear = ([self hasYearInComponent:comp])
584 ? [self yearInComponent:comp]
585 : [tdate yearOfCommonEra];
586 tmonth = ([self hasMonthInComponent:comp])
587 ? [self monthInComponent:comp]
588 : [tdate monthOfYear];
589 tday = ([self hasDayInComponent:comp])
590 ? [self dayInComponent:comp]
591 : [tdate dayOfMonth];
592 tformat = self->format
593 ? [self->format stringValueInComponent: comp]
594 : (NSString *)@"%Y-%m-%d";
596 if ([self isKindOfClass:[WECalendarField class]]) {
599 t = [[t componentsSeparatedByString:@"%H"] componentsJoinedByString:@""];
600 t = [[t componentsSeparatedByString:@"%M"] componentsJoinedByString:@""];
601 t = [[t componentsSeparatedByString:@"%S"] componentsJoinedByString:@""];
607 tdate = [NSCalendarDate dateWithYear: tyear
610 hour: 0 minute: 0 second: 0
611 timeZone: [tdate timeZone]];
613 value = [tdate descriptionWithCalendarFormat: tformat];
615 // div id for javascript calendar
616 calendarID = ([_ctx valueForKey: @"WEDateField_DivID"])
617 ? [[_ctx valueForKey: @"WEDateField_DivID"] intValue]
619 calendarDivID = [StrClass stringWithFormat:@"calendarDiv%d", calendarID];
621 [_ctx takeValue:[NSNumber numberWithInt: calendarID]
622 forKey:@"WEDateField_DivID"];
625 [_ctx appendElementIDComponent:@"dateField"];
626 [self->template appendToResponse:_response inContext:_ctx];
627 [_ctx deleteLastElementIDComponent];
629 [_response appendContentString:
630 @"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"];
631 [_response appendContentString:
632 @"<td valign=\"top\" align=\"left\">"];
635 [_response appendContentString:@"<input type=\"text\" name=\""];
636 [_response appendContentString:[self elementIdWithSuffix:@"" ctx:_ctx]];
637 [_response appendContentString:@"\" value=\""];
638 [_response appendContentString:value];
639 [_response appendContentString:@"\" size=\""];
640 [_response appendContentString:
641 [[NSNumber numberWithInt: [value length]] stringValue]];
642 [_response appendContentString:@"\" maxlength=\""];
643 [_response appendContentString:
644 [[NSNumber numberWithInt: [value length]] stringValue]];
645 [_response appendContentString:@"\" />"];
647 /* link to calendar panel */
648 [_response appendContentString: @" <a href=\"javascript:doNothing()\" "];
649 [_response appendContentString: @"onClick=\""];
650 tmp = @"javascript:%@toggleCalendar('%@',%@%@,'%@')";
651 tmp = [[StrClass alloc] initWithFormat: tmp,
652 (isMSIE) ? @"" : @"actPos;", // layer position
653 [self elementIdWithSuffix:@"" ctx:_ctx], // form element
654 (isMSIE) ? @"" : @"document.", calendarDivID, // calendar DIV
655 tformat]; // dateFormat
656 [_response appendContentString: tmp];
658 [_response appendContentString: @"\">"];
661 tmp = WEUriOfResource(@"icon_popupcalendar.gif", _ctx);
664 tmp = [[StrClass alloc] initWithFormat:
665 @"<img border=\"0\" src=\"%@\" />", tmp];
670 [_response appendContentString:tmp];
673 [_response appendContentString: @"</a><br />"];
676 [_response appendContentString: @"<div id=\""];
677 [_response appendContentString: calendarDivID];
678 [_response appendContentString: @"\" style=\"position: absolute; "];
679 [_response appendContentString: @"visibility: "];
680 [_response appendContentString: (isMSIE) ? @"hidden" : @"hide"];
681 [_response appendContentString: @";\"></div>"];
683 [_response appendContentString: @"</td></tr></table>"];
686 @end /* WECalendarField(WEDateFieldImplementation) */
688 @implementation WEDateFieldScript
690 - (id)initWithName:(NSString *)_name
691 associations:(NSDictionary *)_config
692 template: (WOElement *)_subs
694 if ((self = [super initWithName:_name associations: _config template:_subs]))
696 self->headBackground = OWGetProperty(_config, @"headBackground");
697 self->headColor = OWGetProperty(_config, @"headColor");
698 self->headNavColor = OWGetProperty(_config, @"headNavColor");
699 self->labels = OWGetProperty(_config, @"labels");
700 self->useImages = OWGetProperty(_config, @"useImages");
706 [self->useImages release];
707 [self->headBackground release];
708 [self->headColor release];
709 [self->headNavColor release];
710 [self->labels release];
715 + (void)appendWEDateFieldScriptToResponse: (WOResponse *)_response
716 inContext: (WOContext *)_ctx
717 headBackground: (NSString *)_hBack
718 headColor: (NSString *)_hCol
719 headNavColor: (NSString *)_hNav
721 useImages: (BOOL)_useImg
737 if (_hBack == nil) _hBack = HEAD_BACKGROUND_COLOR;
738 if (_hCol == nil) _hCol = HEAD_COLOR;
739 if (_hNav == nil) _hNav = HEAD_NAVIGATION_COLOR;
741 // months and weekdays
742 if (_labels == nil) {
743 NSLog(@"WARNING: WEDateFieldScript: undefined variable 'labels'");
744 tmon = @"var externMonths = false; \n";
745 tweek = @"var externWeekdays = false; \n";
748 tmon = @"var externMonths = new Array("
749 @"\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\","
750 @"\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\"); \n";
751 tmon = [[StrClass alloc] initWithFormat: tmon,
752 [_labels valueForKey: @"January"],
753 [_labels valueForKey: @"February"],
754 [_labels valueForKey: @"March"],
755 [_labels valueForKey: @"April"],
756 [_labels valueForKey: @"May"],
757 [_labels valueForKey: @"June"],
758 [_labels valueForKey: @"July"],
759 [_labels valueForKey: @"August"],
760 [_labels valueForKey: @"September"],
761 [_labels valueForKey: @"October"],
762 [_labels valueForKey: @"November"],
763 [_labels valueForKey: @"December"]
765 tweek = @"var externWeekdays = new Array("
766 @"\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\"); \n";
767 tweek = [[StrClass alloc] initWithFormat: tweek,
768 [_labels valueForKey: @"SundayAbbrev"],
769 [_labels valueForKey: @"MondayAbbrev"],
770 [_labels valueForKey: @"TuesdayAbbrev"],
771 [_labels valueForKey: @"WednesdayAbbrev"],
772 [_labels valueForKey: @"ThursdayAbbrev"],
773 [_labels valueForKey: @"FridayAbbrev"],
774 [_labels valueForKey: @"SaturdayAbbrev"]
778 if (![_ctx valueForKey: @"WEDateFieldScriptDone"]) {
779 tmp = @"<style type='text/css'>\n"
781 @"TD.heading { text-decoration: none; color: black; "
782 @"font: bold 8pt arial, helvetica; } \n "
783 @"A.focusDay { color: blue; text-decoration: none; "
784 @"font: 8pt arial, helvetica; } \n"
785 @"A.focusDay:hover { color:darkred; text-decoration: none; "
786 @"font: 8pt arial, helvetica; } \n"
787 @"A.weekday { color: blue; text-decoration: none; "
788 @"font: 8pt arial, helvetica; } \n"
789 @"A.weekday:hover { color: darkred; font: 8pt arial, helvetica; } \n"
791 @"{ color: %@; text-decoration: none; font: 8pt Arial; }\n"
793 @"{ font: 10pt Arial; color: %@; background-color: %@; } \n"
796 tmp = [StrClass stringWithFormat: tmp, _hNav, _hCol, _hBack];
797 [_response appendContentString: tmp];
799 [_response appendContentString:
800 @"<script language=\"JavaScript\">\n<!--\n"];
801 [_response appendContentString: @"var dateFormat = \"%Y-%m-%d\"; \n"];
802 [_response appendContentString: tmon];
803 [_response appendContentString: tweek];
806 // doppelt haelt wirklich besser
807 firstI = WEUriOfResource(@"first.gif", _ctx);
808 prevI = WEUriOfResource(@"previous.gif", _ctx);
809 todayI = WEUriOfResource(@"non_sorted.gif", _ctx);
810 nextI = WEUriOfResource(@"next.gif", _ctx);
811 lastI = WEUriOfResource(@"last.gif", _ctx);
812 closeI = WEUriOfResource(@"icon_unread.gif", _ctx);
817 timg = @"var %@=new Image(); %@.src='%@';\n"
818 @"var %@=\"<img border='0' name='%@' src='%@' />\";\n";
819 s = [[StrClass alloc] initWithFormat: timg,
820 @"dateFieldFirst", @"dateFieldFirst", firstI,
821 @"dateFieldFirstSRC", @"dateFieldFirstImg", firstI];
822 [_response appendContentString:s];
824 s = [[StrClass alloc] initWithFormat: timg,
825 @"dateFieldPrevious", @"dateFieldPrevious", prevI,
826 @"dateFieldPreviousSRC", @"dateFieldPreviousImg", prevI];
827 [_response appendContentString:s];
829 s = [[StrClass alloc] initWithFormat: timg,
830 @"dateFieldToday", @"dateFieldToday", todayI,
831 @"dateFieldTodaySRC", @"dateFieldTodayImg", todayI];
832 [_response appendContentString:s];
834 s = [[StrClass alloc] initWithFormat: timg,
835 @"dateFieldNext", @"dateFieldNext", nextI,
836 @"dateFieldNextSRC", @"dateFieldNextImg", nextI];
837 [_response appendContentString:s];
839 s = [[StrClass alloc] initWithFormat: timg,
840 @"dateFieldLast", @"dateFieldLast", lastI,
841 @"dateFieldLastSRC", @"dateFieldLastImg", lastI];
842 [_response appendContentString:s];
844 s = [[StrClass alloc] initWithFormat: timg,
845 @"dateFieldClose", @"dateFieldClose", closeI,
846 @"dateFieldCloseSRC", @"dateFieldCloseImg", closeI];
847 [_response appendContentString:s];
849 [_response appendContentString:@"var usesNavImages = true;\n"];
852 [_response appendContentString:@"var dateFieldCloseSRC=\"X\";\n"];
853 [_response appendContentString:@"var dateFieldFirstSRC=\"<<\";\n"];
854 [_response appendContentString:@"var dateFieldPreviousSRC=\"<\";\n"];
855 [_response appendContentString:@"var dateFieldTodaySRC=\"O\";\n"];
856 [_response appendContentString:@"var dateFieldNextSRC=\">\";\n"];
857 [_response appendContentString:@"var dateFieldLastSRC=\">>\";\n"];
858 [_response appendContentString:@"var usesNavImages = false;\n"];
862 #include "calendar.jsm"
864 [_response appendContentString: tmp];
865 [_response appendContentString: @"\n//-->\n</script>"];
867 [_ctx takeValue: [NSNumber numberWithBool: YES]
868 forKey: @"WEDateFieldScriptDone"];
875 - (void)appendToResponse: (WOResponse *)_response
876 inContext: (WOContext *)_ctx
879 comp = [_ctx component];
881 [[self class] appendWEDateFieldScriptToResponse: _response inContext:_ctx
882 headBackground: [self->headBackground stringValueInComponent:comp]
883 headColor: [self->headColor stringValueInComponent:comp]
884 headNavColor: [self->headNavColor stringValueInComponent:comp]
885 labels: [self->labels valueInComponent:comp]
886 useImages: [[self->useImages valueInComponent: comp] boolValue]];
889 @end /* WEDateFieldScript */
891 @implementation WECalendarField(Accessors)
893 - (NSString *)elementIdWithSuffix:(NSString *)_suffix ctx:(WOContext *)_ctx {
894 NSString *prefix = nil;
896 if ((prefix = [self->name stringValueInComponent:[_ctx component]]) == nil)
897 prefix = [_ctx elementID];
899 if ([_suffix isNotEmpty])
900 prefix = [prefix stringByAppendingString:@"_"];
902 return [prefix stringByAppendingString:_suffix];
905 - (void)setSecond:(int)_second inComponent:(WOComponent *)_comp {
907 NSCalendarDate *d = [self->date valueInComponent:_comp];
910 d = [NSCalendarDate dateWithYear:[d yearOfCommonEra]
911 month:[d monthOfYear]
914 minute:[d minuteOfHour]
916 timeZone:[d timeZone]];
918 [self->date setValue:d inComponent:_comp];
921 [self->second setIntValue:_second inComponent:_comp];
924 - (int)secondInComponent:(WOComponent *)_comp {
925 return (self->date != nil)
926 ? [[self->date valueInComponent:_comp] secondOfMinute]
927 : [self->second intValueInComponent:_comp];
930 - (void)setMinute:(int)_minute inComponent:(WOComponent *)_comp {
934 d = [self->date valueInComponent:_comp];
935 d = [NSCalendarDate dateWithYear:[d yearOfCommonEra]
936 month:[d monthOfYear]
940 second:[d secondOfMinute]
941 timeZone:[d timeZone]];
943 [self->date setValue:d inComponent:_comp];
946 [self->minute setIntValue:_minute inComponent:_comp];
949 - (int)minuteInComponent:(WOComponent *)_comp {
950 return (self->date != nil)
951 ? [[self->date valueInComponent:_comp] minuteOfHour]
952 : [self->minute intValueInComponent:_comp];
955 - (void)setHour:(int)_hour inComponent:(WOComponent *)_comp {
957 NSCalendarDate *d = [self->date valueInComponent:_comp];
960 d = [NSCalendarDate dateWithYear:[d yearOfCommonEra]
961 month:[d monthOfYear]
964 minute:[d minuteOfHour]
965 second:[d secondOfMinute]
966 timeZone:[d timeZone]];
968 [self->date setValue:d inComponent:_comp];
971 [self->hour setIntValue:_hour inComponent:_comp];
974 - (int)hourInComponent:(WOComponent *)_comp {
975 return (self->date != nil)
976 ? [[self->date valueInComponent:_comp] hourOfDay]
977 : [self->hour intValueInComponent:_comp];
980 - (void)setDay:(int)_day inComponent:(WOComponent *)_comp {
982 NSCalendarDate *d = [self->date valueInComponent:_comp];
984 d = [NSCalendarDate dateWithYear:[d yearOfCommonEra]
985 month:[d monthOfYear]
988 minute:[d minuteOfHour]
989 second:[d secondOfMinute]
990 timeZone:[d timeZone]];
992 [self->date setValue:d inComponent:_comp];
995 [self->day setIntValue:_day inComponent:_comp];
998 - (int)dayInComponent:(WOComponent *)_comp {
999 return (self->date != nil)
1000 ? [[self->date valueInComponent:_comp] dayOfMonth]
1001 : [self->day intValueInComponent:_comp];
1004 - (void)setMonth:(int)_month inComponent:(WOComponent *)_comp {
1006 NSCalendarDate *d = [self->date valueInComponent:_comp];
1008 d = [NSCalendarDate dateWithYear:[d yearOfCommonEra]
1012 minute:[d minuteOfHour]
1013 second:[d secondOfMinute]
1014 timeZone:[d timeZone]];
1016 [self->date setValue:d inComponent:_comp];
1019 [self->month setIntValue:_month inComponent:_comp];
1022 - (int)monthInComponent:(WOComponent *)_comp {
1023 return (self->date != nil)
1024 ? [[self->date valueInComponent:_comp] monthOfYear]
1025 : [self->month intValueInComponent:_comp];
1028 - (void)setYear:(int)_year inComponent:(WOComponent *)_comp {
1030 NSCalendarDate *d = [self->date valueInComponent:_comp];
1032 d = [NSCalendarDate dateWithYear:_year
1033 month:[d monthOfYear]
1036 minute:[d minuteOfHour]
1037 second:[d secondOfMinute]
1038 timeZone:[d timeZone]];
1040 [self->date setValue:d inComponent:_comp];
1043 [self->year setIntValue:_year inComponent:_comp];
1046 - (int)yearInComponent:(WOComponent *)_comp {
1047 return (self->date != nil)
1048 ? [[self->date valueInComponent:_comp] yearOfCommonEra]
1049 : [self->year intValueInComponent:_comp];
1052 - (BOOL)isSecondSettable {
1053 return (self->date != nil)
1054 ? [self->date isValueSettable] : [self->second isValueSettable];
1057 - (BOOL)isMinuteSettable {
1058 return (self->date != nil)
1059 ? [self->date isValueSettable] : [self->minute isValueSettable];
1062 - (BOOL)isHourSettable {
1063 return (self->date != nil)
1064 ? [self->date isValueSettable] : [self->hour isValueSettable];
1067 - (BOOL)isDaySettable {
1068 return (self->date != nil)
1069 ? [self->date isValueSettable] : [self->day isValueSettable];
1072 - (BOOL)isMonthSettable {
1073 return (self->date != nil)
1074 ? [self->date isValueSettable] : [self->month isValueSettable];
1077 - (BOOL)isYearSettable {
1078 return (self->date != nil)
1079 ? [self->date isValueSettable] : [self->year isValueSettable];
1082 - (BOOL)_chkDateFormatKey:(NSString *)_s inComponent:(WOComponent *)_comp {
1085 if (self->format == nil)
1088 fmt = [self->format stringValueInComponent:_comp];
1089 return ([fmt rangeOfString:_s].length > 0) ? YES : NO;
1092 - (BOOL)hasSecondInComponent:(WOComponent *)_comp {
1094 ? [self _chkDateFormatKey:@"S" inComponent:_comp]
1095 : (self->second != nil ? YES : NO);
1098 - (BOOL)hasMinuteInComponent:(WOComponent *)_comp {
1100 ? [self _chkDateFormatKey:@"M" inComponent:_comp]
1101 : (self->minute != nil ? YES : NO);
1104 - (BOOL)hasHourInComponent:(WOComponent *)_comp {
1106 ? [self _chkDateFormatKey:@"H" inComponent:_comp]
1107 : (self->hour != nil ? YES : NO);
1110 - (BOOL)hasDayInComponent:(WOComponent *)_comp {
1112 ? [self _chkDateFormatKey:@"d" inComponent:_comp]
1113 : (self->day != nil ? YES : NO);
1116 - (BOOL)hasMonthInComponent:(WOComponent *)_comp {
1118 ? [self _chkDateFormatKey:@"m" inComponent:_comp]
1119 : (self->month != nil ? YES : NO);
1122 - (BOOL)hasYearInComponent:(WOComponent *)_comp {
1124 ? [self _chkDateFormatKey:@"Y" inComponent:_comp]
1125 : (self->year != nil ? YES : NO);
1128 @end /* WECalendarField */