"Fossies" - the Fresh Open Source Software Archive

Member "opengroupware-5.5rc3/WebUI/Common/BaseUI/SkyWeekOfYearPopUp.m" (5 Dec 2015, 5532 Bytes) of package /linux/privat/opengroupware-5.5rc3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Matlab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "SkyWeekOfYearPopUp.m" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.5rc2_vs_5.5rc3.

    1 /*
    2   Copyright (C) 2000-2005 SKYRIX Software AG
    3 
    4   This file is part of OpenGroupware.org.
    5 
    6   OGo 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
    9   later version.
   10 
   11   OGo 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.
   15 
   16   You should have received a copy of the GNU Lesser General Public
   17   License along with OGo; see the file COPYING.  If not, write to the
   18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   19   02111-1307, USA.
   20 */
   21 
   22 #include <OGoFoundation/OGoComponent.h>
   23 
   24 @class NSCalendarDate, NSTimeZone;
   25 
   26 /*
   27   a component to generate a PopUp for week-of-year-selection as used in the
   28   scheduler page.
   29 
   30   Input-Parameters:
   31 
   32     timeZone  - required timeZone
   33     year      - year as an integer, eg '2000'
   34   
   35   Output-Parameters:
   36     
   37     weekStart - an NSCalendarDate of the monday of the selected week
   38 */
   39 
   40 @interface SkyWeekOfYearPopUp : OGoComponent
   41 {
   42   NSCalendarDate *firstMonday;
   43   short          lastWeek;
   44   id             item;
   45 }
   46 @end
   47 
   48 #include "common.h"
   49 
   50 @implementation SkyWeekOfYearPopUp
   51 
   52 - (BOOL)synchronizesVariablesWithBindings {
   53   return NO;
   54 }
   55 
   56 - (void)dealloc {
   57   RELEASE(self->firstMonday);
   58   RELEASE(self->item);
   59   [super dealloc];
   60 }
   61 
   62 /* accessors */
   63 
   64 - (void)setItem:(id)_item {
   65   ASSIGN(self->item, _item);
   66 }
   67 - (id)item {
   68   return self->item;
   69 }
   70 
   71 - (NSCalendarDate *)itemDate {
   72   int dayOffset;
   73 
   74   dayOffset = [self->item intValue] - 1;
   75   dayOffset *= 7;
   76   
   77   return [self->firstMonday dateByAddingYears:0 months:0 days:dayOffset];
   78 }
   79 
   80 - (NSString *)itemLabel {
   81   NSCalendarDate *date;
   82   static int showYear = -1;
   83   NSInteger weekOfYear, year;
   84   
   85   if (showYear == -1) {
   86     showYear = [[NSUserDefaults standardUserDefaults]
   87                                 boolForKey:@"SkyWeekOfYearPopUp_showYear"]
   88       ? 1 :0;
   89   }
   90   
   91   date       = [self itemDate];
   92   year       = [date yearOfCommonEra];
   93   weekOfYear = [date weekOfYear];
   94   
   95   if ([self->item intValue] == 1) {
   96     short woy, nowy;
   97     
   98     woy  = [date weekOfYear];
   99     nowy = [date numberOfWeeksInYear];
  100     
  101     if (woy > nowy)
  102       year++;
  103   }
  104   
  105   if (showYear) {
  106     return [NSString stringWithFormat:@"%@: %04"PRIiPTR"-%02i (%02"PRIiPTR"-%02"PRIiPTR")",
  107                        [[self labels] valueForKey:@"week"],
  108                        year,
  109                        [self->item intValue],
  110                        [date monthOfYear],
  111                        [date dayOfMonth]];
  112   }
  113   else {
  114     return [NSString stringWithFormat:@"%@: %02i (%02"PRIiPTR"-%02"PRIiPTR")",
  115                        [[self labels] valueForKey:@"week"],
  116                        [self->item intValue],
  117                        [date monthOfYear],
  118                        [date dayOfMonth]];
  119   }
  120 }
  121 
  122 - (NSTimeZone *)timeZone {
  123   NSTimeZone *tz;
  124   
  125   if ((tz = [self valueForBinding:@"timeZone"])) {
  126     //NSLog(@"TZ BINDING: %@", tz);
  127     return tz;
  128   }
  129   
  130   //NSLog(@"TZ from session: %@", [(id)[self session] timeZone]);
  131   return [(id)[self session] timeZone];
  132 }
  133 
  134 - (void)setWeekStart:(id)_weekStart {
  135   if (_weekStart) {
  136     [self setItem:_weekStart];
  137     [self setValue:[self itemDate] forBinding:@"weekStart"];
  138   }
  139 }
  140 - (id)weekStart {
  141   NSCalendarDate *weekStart;
  142   int woy;
  143 
  144   weekStart = [self valueForBinding:@"weekStart"];
  145   woy = [weekStart weekOfYear];
  146 
  147   if ([weekStart yearOfCommonEra] !=
  148       [[self valueForBinding:@"year"] intValue]) {
  149     // --> weekStart is monday --> must be first week of year !!"
  150     woy = 1;
  151   }
  152   return [NSNumber numberWithInt:woy];
  153 }
  154 
  155 /* being the list */
  156 
  157 - (unsigned int)count {
  158   return self->lastWeek;
  159 }
  160 - (id)objectAtIndex:(unsigned int)_idx {
  161   NSAssert(self->firstMonday, @"missing firstmonday ..");
  162   return [NSNumber numberWithInt:_idx + 1];
  163 #if 0
  164   return [self->firstMonday dateByAddingYears:0
  165                             months:0
  166                             days:(7 * (_idx))];
  167 #endif
  168 }
  169 
  170 /* notifications */
  171 
  172 - (void)reconfigure {
  173   NSCalendarDate *dateInYear;
  174   id         year, tmp;
  175   
  176   year = [self valueForBinding:@"year"];
  177 
  178   //  NSLog(@"Binding value of year is:%@",year);
  179   
  180   if (year) {
  181     dateInYear = [NSCalendarDate dateWithYear:[year intValue] month:6 day:1
  182                                  hour:0 minute:0 second:0
  183                                  timeZone:[self timeZone]];
  184   }
  185   else {
  186 #if 0
  187     NSLog(@"MISSING YEAR BINDING ..");
  188 #endif
  189     dateInYear = [NSCalendarDate calendarDate];
  190     [dateInYear setTimeZone:[self timeZone]];
  191   }
  192   
  193   RELEASE(self->firstMonday); self->firstMonday = nil;
  194   self->firstMonday =
  195     [[dateInYear firstMondayAndLastWeekInYear:&(self->lastWeek)] copy];
  196   
  197   tmp = [self valueForBinding:@"weekStart"];
  198   if ([tmp weekOfYear] > self->lastWeek) self->lastWeek = [tmp weekOfYear];
  199   //NSLog(@"WEEK START: %i - %@", [tmp weekOfYear], tmp);
  200   //if (tmp) [self setWeekStart:[NSNumber numberWithInt:[tmp weekOfYear]]];
  201 
  202 #if 0
  203   NSLog(@"monday=%@, #weeks: %i", self->firstMonday, (int)self->lastWeek);
  204 #endif
  205 }
  206 
  207 - (void)syncAwake {
  208   [super syncAwake];
  209   [self reconfigure];
  210 }
  211 
  212 - (void)sleep {
  213   [self setItem:nil];
  214   [super sleep];
  215 }
  216 
  217 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
  218   [self reconfigure];
  219   [super appendToResponse:_response inContext:_ctx];
  220 }
  221 
  222 @end /* SkyWeekOfYearPopUp */