db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davi...@apache.org
Subject svn commit: r483157 - in /db/derby/code/trunk/java/demo/localcal: ./ README src/CalendarController.java src/index.html src/localcal.js
Date Wed, 06 Dec 2006 17:34:46 GMT
Author: davidvc
Date: Wed Dec  6 09:34:43 2006
New Revision: 483157

URL: http://svn.apache.org/viewvc?view=rev&rev=483157
Log:
Fixed this so that you can change the user and the calendar, making
this more easily "demoable" without having to change code.  Also
fixed svn:ignore properties for stuff we don't want to check in.

Modified:
    db/derby/code/trunk/java/demo/localcal/   (props changed)
    db/derby/code/trunk/java/demo/localcal/README
    db/derby/code/trunk/java/demo/localcal/src/CalendarController.java
    db/derby/code/trunk/java/demo/localcal/src/index.html
    db/derby/code/trunk/java/demo/localcal/src/localcal.js

Propchange: db/derby/code/trunk/java/demo/localcal/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Dec  6 09:34:43 2006
@@ -1,2 +1,3 @@
 dist
 classes
+lib

Modified: db/derby/code/trunk/java/demo/localcal/README
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/localcal/README?view=diff&rev=483157&r1=483156&r2=483157
==============================================================================
--- db/derby/code/trunk/java/demo/localcal/README (original)
+++ db/derby/code/trunk/java/demo/localcal/README Wed Dec  6 09:34:43 2006
@@ -101,63 +101,25 @@
 
 
 3. BUILDING
-
 3.1 SET KEYSTORE PROPERTIES IN BUILD.XML
 Edit build.xml and set the keystore.alias and keystore.password
 values to match the ones you used above when signing the jar files.
 This is used to automatically sign the LocalCalendar jar file each
 time we build it.
 
-3.2 SET THE CALENDAR ID
-
-The calendar id uniquely identifies the calendar you want
-to work with.  Currently it is set to a test calendar that is
-owned by David Van Couvering.  You are free to use this, it is
-available to all, but you can also create your own calendar.  Here
-are the steps:
+3.2 SET UP A CALENDAR
+If you want you can use the default calendar for the Google Calendar
+user localcal@gmail.com, password "synchronize."  But be aware that
+others may be using this same calendar at the same time.  The alternative
+is to create your own Google Calendar account (if you don't have one
+already) and use that.
 
 3.2.1 Create a calendar
-Make sure it is set to be publicly available to all.  If you want
-to make it private, read the instructions for Google Calendar and
-the Google Calendar API for how to do this.
-
-3.2.2 Get the id
-On the left hand pane of your Google Calendar page is the list of
-calendars you have created.  Click on the down-arrow for the
-one you want to use in LocalCalendar and choose "Calendar Settings"
-
-On the settings page, click on the orange [XML] box for calendar
-address.  You'll get a long URI of the form
-
-http://www.google.com/calendar/feeds/<id>@group.calendar.google.com/public/basic
-
-(unless you're using your default calendar, in which case it will be
-of the form
-
-http://www.google.com/calendar/feeds/<your-email-address>/public/basic)
-
-Your calendar id is either <id>@group.calendar.google.com or
-<your-email-address>.  
-
-3.2.3 Set the id in LocalCalendar
-Set the variable derbycal.calid in src/localcal.js to be your
-calendar id.
-
-3.3 SET THE DATE RANGE IN LOCALCALENDAR
-The date range used by LocalCalendar is currently hardcoded.  If you're
-interested, please feel free to make this dynamically settable by the
-user.  But I didn't get around to doing that.
-
-To change the date range, edit src/localcal.js and modify the
-array derbycal.days to match the dates you're interested in.
-
-3.4 CHANGE THE TITLE
-If you want, you can change the title to match what your calendar
-is about.  Edit src/index.html and change the <h1> tag with the
-id "loginHeader" and also the <h1> tag just underneat the <div>
-with id "main-div".
+Create a Google Mail account and then go to http://calendar.google.com
+to set up a calendar.  You can create multiple calendars, but 
+LocalCalendar only works with your default calendar.
 
-3.4 BUILD
+3.3 BUILD
 To build, simply run "ant" in the top-level directory.  This will
 build the source, create and sign a jar file, and put this as well
 as all other needed resources into the dist directory.
@@ -167,9 +129,14 @@
 
 Bring up Firefox and point it to <path-to-localcal>/dist/index.html.
 
-LocalCalendar shows a week's worth of events.  Each event is an 
-all-day event.  I didn't try to mess around with event times, this
-was more HTML and JavaScript than I was willing to write.
+LocalCalendar shows a week's worth of events.  You can change the
+week by changing the start date at the top.  The application will
+automatically pick the next Sunday from the date you enter as the
+starting date.  The default is the next Sunday from today.
+
+Each event is an all-day event.  I didn't try to mess around with 
+event times, this was more HTML and JavaScript than I was willing 
+to write.
 
 To play around with LocalCalendar's capabilities, try the following.
 To find bugs, try almost anything else :)

Modified: db/derby/code/trunk/java/demo/localcal/src/CalendarController.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/localcal/src/CalendarController.java?view=diff&rev=483157&r1=483156&r2=483157
==============================================================================
--- db/derby/code/trunk/java/demo/localcal/src/CalendarController.java (original)
+++ db/derby/code/trunk/java/demo/localcal/src/CalendarController.java Wed Dec  6 09:34:43
2006
@@ -259,7 +259,7 @@
         }
 
         return event.getJSONObject().toString();
-}
+    }
     
     public void updateEvent(String id, String title) throws Exception {
         log("DerbyCalendarApplet.updateEntry(" + id  + ", " + title + ")");

Modified: db/derby/code/trunk/java/demo/localcal/src/index.html
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/localcal/src/index.html?view=diff&rev=483157&r1=483156&r2=483157
==============================================================================
--- db/derby/code/trunk/java/demo/localcal/src/index.html (original)
+++ db/derby/code/trunk/java/demo/localcal/src/index.html Wed Dec  6 09:34:43 2006
@@ -57,16 +57,27 @@
   <script type="text/javascript" src="localcal.js"></script>
 
 </head>
-<body id="body">
+<body id="body" onload="derbycal.init()">
+  <h1>My Week of Events</h1>
+  <form name="dateForm">
+      <table>
+          <tr>
+               <td><strong>Start Date: </strong></td>
+               <td>&nbsp;&nbsp;&nbsp;</td>
+               <td><input name="startDate" type="text"
+                    onChange="derbycal.changeStartDate()" 
+                    style="{font-weight: bold ; font-size : 14;}"/></td>
+          </tr>
+      </table>
+  </form>
   <div id="login-div" class="login">
-  <h1 id="loginHeader">My Week of Events</h1>
-  <h3>Please login to Google Calendar</h3>
-  <form class="login-form" name="loginForm" >
+  <form class="login-form" name="loginForm" id="loginForm">
+      <h3>Please login to Google Calendar</h3>
       <table>
           <tr>
               <td><strong>Google Id: </strong></td>
               <td><input type="text" name="user" size="40"/></td>
-              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
+              <td><b>@gmail.com</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
               <td><strong>Password: </strong></td>
               <td><input type="password" name="password"/></td>
               <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
@@ -88,8 +99,6 @@
   </form>
   </div>
   <div id="main-div" class="main">
-      <h1>My Week of Events</h1>
-      <hr>
       <table>
           <tr>
               <form name="offlineForm">

Modified: db/derby/code/trunk/java/demo/localcal/src/localcal.js
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/localcal/src/localcal.js?view=diff&rev=483157&r1=483156&r2=483157
==============================================================================
--- db/derby/code/trunk/java/demo/localcal/src/localcal.js (original)
+++ db/derby/code/trunk/java/demo/localcal/src/localcal.js Wed Dec  6 09:34:43 2006
@@ -19,9 +19,7 @@
 
 var derbycal = {};
 
-// This is the Google Calendar id for the shared calendar for this
-// application
-derbycal.calid = "olj8s6vvk5pu2b7oib47t57pps@group.calendar.google.com";
+// INITIALIZATION VARIABLES.  Set these as you see fit
 
 // The offset from GMT for this calendar.  Change this if you want to change
 // time zones for the calendar.  Right now set to CST (Austin).
@@ -30,26 +28,92 @@
 derbycal.onlineColor = "#66FF66";
 derbycal.offlineColor = "#ccFFFF";
 
+// This needs to be in a valid date format for initialization a Javascript date
+// It should generally be on a Sunday, but it can be any day and we'll start
+// the calendar from the next Sunday after your given date.
+derbycal.startDate = "October 12, 2006";
+
+// === END INIT VARIABLES ==
+
 /** 
-** You need to change the dates if you want a different week showing
-** on the calendar.  Yes, I could calculate this, but I have bigger
-** fish to fry...
+* The array of days.  The days are hardcoded, the dates will be calculated
+* as part of the derbycal.init() function
 */
 derbycal.days = [ 
-    ["Sunday",      "2006-10-01"],
-    ["Monday",      "2006-10-02"],
-    ["Tuesday",     "2006-10-03"],
-    ["Wednesday",   "2006-10-04"],
-    ["Thursday",    "2006-10-05"],
-    ["Friday",      "2006-10-06"],
-    ["Saturday",    "2006-10-07"]
+    ["Sunday",      ""],
+    ["Monday",      ""],
+    ["Tuesday",     ""],
+    ["Wednesday",   ""],
+    ["Thursday",    ""],
+    ["Friday",      ""],
+    ["Saturday",    ""]
 ];
 
-derbycal.startDate = derbycal.days[0][1];
-derbycal.endDate   = derbycal.days[6][1];
+// Sorry, English-chauvinist code...
+derbycal.months = [ 
+    "January", "Febuary", "March", "April", "May", "June",
+    "July", "August", "September", "October", "November",
+    "December"
+];
 
 derbycal.offline   = false;
 
+
+/**
+* Do any initialization work.  This should be called when the
+* page is loaded
+*/
+derbycal.init = function() {
+  var today = new Date();
+  var dateForm = document.dateForm;
+  dateForm.startDate.value = derbycal.months[today.getMonth()] + " " +
+     today.getDate() + ", " + today.getFullYear();
+  derbycal.updateDays();
+}
+
+derbycal.updateDays = function() { 
+  derbycal.calcDays(document.dateForm.startDate.value);
+  derbycal.startDate = derbycal.days[0][1];
+  derbycal.endDate   = derbycal.days[6][1];  
+}
+
+derbycal.changeStartDate = function() {
+  derbycal.updateDays();
+  derbycal.refreshCalendar();
+}
+
+/**
+ * Given a starting day, set the dates for the derbycal.days
+ * array, starting with the next Sunday from the given start day.  
+ * This array is then used to set up the calendar.
+ */
+derbycal.calcDays = function(startDay) {
+    var date = new Date(startDay);
+
+    // adjust to the next Sunday, unless today is Sunday
+    var day = date.getDay();
+    var daysToSunday = 0;
+    if ( day != 0 ) {
+        daysToSunday = 7 - day;
+    }
+        
+    date.setDate(date.getDate() + daysToSunday);
+
+    // Update the date on the page to reflect Sunday's date
+    var dateForm = document.dateForm;
+    dateForm.startDate.value = derbycal.months[date.getMonth()] + 
+        " " + date.getDate() + ", " + date.getFullYear(); 
+
+    // Set the array of days to have the right dates based on
+    // the given start date
+    for ( day = 0 ; day < 7; day++ ) {
+        derbycal.days[day][1] = date.getFullYear() + "-" +
+                       (date.getMonth() + 1) + "-" +
+                       date.getDate();
+        date.setDate(date.getDate() + 1);
+    }
+} 
+
 /** 
  * Log in to Google Calendar
  */
@@ -58,17 +122,18 @@
     statusText.style.visibility = "visible";
 
     var loginForm = document.loginForm;
-    derbycal.user = loginForm.user.value;
+    derbycal.user = loginForm.user.value + "@gmail.com";
     derbycal.password = loginForm.password.value;
 
     try {
         // Get the events list from  Google Calendar
-        calapplet.login(derbycal.calid, derbycal.gmtOffset, 
+        calapplet.login(derbycal.user, derbycal.gmtOffset, 
             derbycal.user, derbycal.password,
             derbycal.startDate, derbycal.endDate, false);
 
 
     } catch ( e ) {
+        statusText.style.visibility = "hidden";
         alert("Error logging in to calendar : " + 
             derbycal.getExceptionMessage(e));
         return;
@@ -93,7 +158,6 @@
     derbycal.refreshCalendar();
 
     document.getElementById("workOfflineButton").style.visibility = "hidden";
-    document.getElementById("loginHeader").style.visibility = "hidden";
     document.getElementById("onlineButton").disabled = true;
 }
 
@@ -173,7 +237,7 @@
     var i = 0;
     while ( events != null  &&  i < events.length ) {
         var event = events[i++];
-        derbycal.addEventToPage(event.eventid, event.day, event.title);
+        derbycal.addEventToPage(event.eventid, event.day, event.date, event.title);
     }
 }
 derbycal.clearCalendarOnPage = function() {
@@ -210,7 +274,7 @@
         id = event.eventid;
 
         // Update the HTML
-        derbycal.addEventToPage(id, day, title);
+        derbycal.addEventToPage(id, day, date, title);
     } catch ( e ) {
         alert("Unable to add event: " + derbycal.getExceptionMessage(e));
     }
@@ -229,7 +293,12 @@
     throw "The day specified, " + day + " is not one I recognize";
 }
 
-derbycal.addEventToPage = function(id, day, title) {
+derbycal.addEventToPage = function(id, day, date, title) {
+    // Ignore the event if the date is out of range
+    if ( ! derbycal.dateInRange(date) ) {
+        return;
+    }
+    
     // Get the table for the specified day
     var table = document.getElementById(day);
 
@@ -253,6 +322,16 @@
         'value="' + title + '"></input></td>';
 
     table.appendChild(tr);
+}
+
+derbycal.dateInRange = function(date) {
+    for ( i = 0 ; i < 6 ; i++ ) {
+        if ( derbycal.days[i][1] == date ) {
+            return true;
+        }
+    }
+  
+    return false;
 }
 
 /**



Mime
View raw message