1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 function StartCodeTime ( ) {
41 CodeTimeInitial
= new Date();
44 function EndCodeTime ( str
) {
45 var CodeTimeFinal
= new Date();
46 var diff
= CodeTimeFinal
.getTime() - CodeTimeInitial
.getTime();
47 dump("Timing " + str
+ " took " + diff
+ " milliseconds.\n");
50 // ************************************************************
52 // ************************************************************
55 currentTime
= new Date(); // a new Date object with the current time
56 monthShowing
= new Date();
57 nowShowing
= new Date();
59 month_names_internal
= new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
62 // the namespace of the RDF literals
63 rdf_ns
="http://when.com/1999/07/03-appts-rdf#";
65 // find the location of the appointments data - relative URLs don't work (now, anyway)
67 // the filename within the directory of the XUL document
68 var RDFRelFileName
= 'bug12012.rdf';
70 dump("Getting window.location.href...\n");
71 // to get the directory, start with the filename of the XUL document
72 var baseURL
= window
.location
.href
;
75 // XXX Needs three slashes because of file:// URL parsing bug (see Bug 9236)
76 //if ((baseURL.indexOf("file:/") != -1) && (baseURL.indexOf("file:///") == -1)) {
77 //baseURL = "file:///" + baseURL.substring(6);
79 if (baseURL
.indexOf("file:") == 0) {
80 baseURL
= baseURL
.substring(5);
81 while (baseURL
.charAt(0) == '/') {
82 baseURL
= baseURL
.substring(1);
84 baseURL
= "file:///" + baseURL
;
87 // and take off whatever is after the last "/"
88 baseURL
= baseURL
.substring(0, baseURL
.lastIndexOf("/") + 1);
90 // combine these to get the filename for the RDF
91 RDFFileName
= baseURL
+ RDFRelFileName
;
92 appts_resourcename
= RDFFileName
+ "#WhenComAppointmentsRoot";
95 RDFService
= Components
.classes
['@mozilla.org/rdf/rdf-service;1'].getService();
96 RDFService
= RDFService
.QueryInterface(Components
.interfaces
.nsIRDFService
);
98 // ************************************************************
99 // Event handler for Edit code
100 // ************************************************************
102 function ascendToTR (node
) {
104 while ( rv
.nodeName
.toLowerCase() != "tr" ) {
110 function handleRClick ( event
) {
111 // XXX event.type and event.currentNode and event.button are broken
112 var currentNode
= ascendToTR(event
.target
);
113 EditApptById(currentNode
.getAttribute("id"));
116 // ************************************************************
117 // Functions for event handlers (e.g., onclick)
118 // ************************************************************
120 function gotoURL( url
) {
121 window
.content
.location
= url
;
124 function getAddDiv() {
125 return document
.documentElement
.firstChild
.nextSibling
.nextSibling
.firstChild
.firstChild
;
128 function getScheduleDiv() {
129 return document
.documentElement
.firstChild
.nextSibling
.nextSibling
.firstChild
.firstChild
.nextSibling
;
132 function getPickDiv() {
133 return document
.documentElement
.firstChild
.nextSibling
.nextSibling
.firstChild
.firstChild
.nextSibling
.nextSibling
;
136 function buttonDisabled ( number
) {
141 var tabTR
= document
.getElementById("tabsTR");
142 tabTR
.childNodes
.item(0).className
= "tab";
143 tabTR
.childNodes
.item(1).className
= "tab";
144 tabTR
.childNodes
.item(2).className
= "tab";
145 tabTR
.childNodes
.item(number
).className
= "tab disable";
147 // XXX BUG These two lines cause failure to display
148 // setting is on an XULElement
149 //tabTR.parentNode.parentNode.style.border="medium solid black";
150 //tabTR.parentNode.parentNode.style.border="none";
152 // XXX BUG These two lines cover up most of a shifting bug...
153 // Setting is on a table
154 tabTR
.parentNode
.style
.border
="medium solid black";
155 tabTR
.parentNode
.style
.border
="none";
159 function divActive( number
) {
164 buttonDisabled(number
)
167 var AddDiv
= getAddDiv();
168 var ScheduleDiv
= getScheduleDiv();
169 var PickDiv
= getPickDiv()
172 ScheduleDiv
.style
.display
= "none";
173 PickDiv
.style
.display
= "none";
174 AddDiv
.style
.display
= "block";
175 } else if ( number
== 1 ) {
176 AddDiv
.style
.display
= "none";
177 PickDiv
.style
.display
= "none";
178 ScheduleDiv
.style
.display
= "block";
180 } else if ( number
== 2 ) {
181 AddDiv
.style
.display
= "none";
182 ScheduleDiv
.style
.display
= "none";
183 PickDiv
.style
.display
= "block";
188 function editButtonsActive( number
) {
192 var adddiv
= getAddDiv();
193 var addbdiv
= GetElementWithIdIn("addbuttons", adddiv
);
194 var edbdiv
= GetElementWithIdIn("editbuttons", adddiv
);
197 edbdiv
.style
.display
= "none";
198 addbdiv
.style
.display
= "block";
199 } else if (number
== 1) {
200 addbdiv
.style
.display
= "none";
201 edbdiv
.style
.display
= "block";
207 nowShowing
.setDate(nowShowing
.getDate() + 1);
211 function nextWeek() {
212 nowShowing
.setDate(nowShowing
.getDate() + 7);
217 nowShowing
.setDate(nowShowing
.getDate() - 1);
221 function prevWeek() {
222 nowShowing
.setDate(nowShowing
.getDate() - 7);
227 nowShowing
= new Date();
233 function nextMonth() {
234 monthShowing
.setMonth(monthShowing
.getMonth() + 1);
238 function prevMonth() {
239 monthShowing
.setMonth(monthShowing
.getMonth() - 1);
243 function nextYear() {
244 monthShowing
.setFullYear(monthShowing
.getFullYear() + 1);
248 function prevYear() {
249 monthShowing
.setFullYear(monthShowing
.getFullYear() - 1);
253 function thisMonth() {
254 monthShowing
= new Date();
258 function pickDate( year
, month
, date
) {
259 // the month is 1..12
260 nowShowing
= new Date(year
, month
- 1, date
);
261 divActive(1); // calls ShowSchedule
265 // ************************************************************
267 // ************************************************************
269 // XXX Should this be needed?
271 function GetElementWithIdIn ( id
, ancestor
) {
272 // recursive search for an element with a given id
273 if ( ancestor
.getAttribute("id") == id
) {
275 } else { // else shows logic, not really needed because of return
276 for (var i
= 0; i
< ancestor
.childNodes
.length
; i
++ ) {
277 // This isn't an official way to use named constants, but
278 // Mozilla supports it
279 if ( ancestor
.childNodes
.item(i
).nodeType
== Node
.ELEMENT_NODE
) {
280 var rv
= GetElementWithIdIn(id
, ancestor
.childNodes
.item(i
));
282 return rv
; // exits the function here, since we found the target
290 // ************************************************************
291 // The Appointment type
292 // ************************************************************
294 function ApptToString () {
295 return "[" + String(this.date
) + "," + this.title
+ "]";
298 Appointment
.prototype.toString
= ApptToString
;
300 function Appointment ( date
, title
, desc
, dur
, id
) { // used as a constructor
301 this.date
= date
; // date
302 this.title
= title
; // title
303 this.desc
= desc
; // description
304 this.dur
= dur
; // duration (minutes)
305 this.id
= id
; // id (in the RDF and in the table row)
307 // A useful debugging function:
308 // XXX If error in string, get silent error:
309 //this.toString = new Function('return "[" + String(this.date) + "," + this.title + "]"');
312 function compareAppt ( x
, y
) { // for passing to Array::sort
313 // should return negative if x<y, 0 if x=y, and positive if x>y
314 // Date::getTime returns milliseconds since Jan 1, 1970, so
315 return x
.date
.getTime() - y
.date
.getTime();
318 // ************************************************************
319 // Code used for showing the schedule
320 // ************************************************************
322 function getOutputTBody() {
323 // get the TBody element for output
324 // XXX a hack, since getElementById doesn't work with mixed XUL/HTML, it
327 //return document.documentElement.childNodes.item(2).childNodes.item(1);
329 // hack within a hack, to get around bug 8044
331 return getScheduleDiv().firstChild
.nextSibling
.firstChild
.nextSibling
;
333 // return getScheduleDiv().firstChild.nextSibling.firstChild;
336 function getOutputForDate() {
338 return getScheduleDiv().firstChild
.firstChild
.firstChild
.nextSibling
.nextSibling
;
341 function timeString( date
) {
342 var minutes
= date
.getMinutes();
344 minutes
= "0" + minutes
;
346 var hours
= date
.getHours();
354 } else if (hours
> 12) {
357 return hours
+ ":" + minutes
+ suffix
;
360 function dateString( date
) {
363 // return date.getFullYear() + "-" + ( date.getMonth() + 1) + "-" + date.getDate();
365 return month_names_internal
[date
.getMonth()] + // both 0-based
366 " " + date
.getDate() + ", " + date
.getFullYear();
369 function getAttr(rdf_datasource
,service
,attr_name
) {
370 var attr
= rdf_datasource
.GetTarget(service
,
371 RDFService
.GetResource(rdf_ns
+ attr_name
),
374 attr
= attr
.QueryInterface(
375 Components
.interfaces
.nsIRDFLiteral
);
381 function ReadAndSort () {
383 // enumerate all of the flash datasources.
384 var enumerator
= appts_container
.GetElements();
386 // put all the appointments into an array
387 allAppts
= new Array();
390 while (enumerator
.hasMoreElements()) {
391 var service
= enumerator
.getNext().QueryInterface(
392 Components
.interfaces
.nsIRDFResource
);
394 // get the title text
395 var title
= getAttr(rdf_datasource
, service
, 'title');
397 // get the description text
398 var descrip
= getAttr(rdf_datasource
, service
, 'notes');
400 // get the date, and see if it's for us
401 var year
= getAttr(rdf_datasource
, service
, 'year');
402 var month
= getAttr(rdf_datasource
, service
, 'month');
403 var date
= getAttr(rdf_datasource
, service
, 'date');
404 var hour
= getAttr(rdf_datasource
, service
, 'hour');
405 var minute
= getAttr(rdf_datasource
, service
, 'minute');
407 // get the full resource URL:
408 var theid
= service
.Value
;
409 // and use only the fragment identifier:
410 theid
= theid
.substring(theid
.lastIndexOf("#") + 1);
412 var duration
= getAttr(rdf_datasource
, service
, 'duration');
414 var apptDate
= new Date(year
, month
- 1, date
, hour
, minute
);
416 allAppts
[allAppts
.length
] = new Appointment( apptDate
, title
, descrip
, duration
, theid
);
419 window
.alert("Caught exception [[" + ex
+ "]]\n");
424 var todaysAppts
= new Array();
426 for ( var i
= 0 ; i
< allAppts
.length
; i
++ ) {
427 var appt
= allAppts
[i
];
428 if ( (appt
.date
.getFullYear() == nowShowing
.getFullYear())
429 && (appt
.date
.getMonth() == nowShowing
.getMonth())
430 && (appt
.date
.getDate() == nowShowing
.getDate()) ) {
432 todaysAppts
[todaysAppts
.length
] = appt
;
436 // sort todaysAppts using the JavaScript builtin Array::sort(), by
437 // providing a sort function
438 todaysAppts
.sort( compareAppt
);
443 function ShowSchedule() {
444 // Get the nodes where we will output
445 var outTB
= getOutputTBody();
446 var outDate
= getOutputForDate();
448 // Remove all its existing children, since we'll rewrite them
449 while (outTB
.hasChildNodes() ) {
450 outTB
.removeChild(outTB
.firstChild
);
452 while (outDate
.hasChildNodes() ) {
453 outDate
.removeChild(outDate
.firstChild
);
456 // Write the date at the top
457 outDate
.appendChild(document
.createTextNode(dateString(nowShowing
)));
459 // and write the appointments to the table...
461 // XXX Hack: get around insertRow() bug.
462 var newrow
= outTB
.insertRow(outTB
.rows
.length
);
464 // Get the appointments for today, already sorted, from some kind of input
465 // this is an Array of Appointment
467 var todaysAppts
= ReadAndSort();
469 for ( var i
= 0 ; i
< todaysAppts
.length
; i
++ ) {
470 var appt
= todaysAppts
[i
];
472 // add the appointment to the list:
474 var newrow
= outTB
.insertRow(outTB
.rows
.length
);
476 // set up event handling
477 newrow
.setAttribute("id", appt
.id
);
478 // XXX extra param shouldn't be needed
479 newrow
.addEventListener("click", handleRClick
, false, false);
481 // XXX Hack: get around insertCell() bug by switching order.
482 var titlecell
= newrow
.insertCell(1);
483 var timecell
= newrow
.insertCell(0);
484 timecell
.appendChild(document
.createTextNode(timeString(appt
.date
)));
485 titlecell
.appendChild(document
.createTextNode(appt
.title
));
489 // ************************************************************
490 // Code used for the Goto date function
491 // ************************************************************
493 // monthShowing holds Year and Month for current Calendar
495 function monthString( date
) {
497 // return date.getFullYear() + "-" + ( date.getMonth() + 1);
498 return month_names_internal
[date
.getMonth()] + // both 0-based
499 " " + date
.getFullYear();
502 function ShowPick() {
503 var pickDiv
= getPickDiv(); // for speed
505 var outCal
= GetElementWithIdIn("calendar", pickDiv
);
506 var outDate
= GetElementWithIdIn("MonthOutput", pickDiv
);
507 // EndCodeTime("two runs of GetElementWithIdIn");
510 // Remove all existing children, since we'll rewrite them
511 while (outCal
.hasChildNodes() ) {
512 outCal
.removeChild(outCal
.firstChild
);
514 while (outDate
.hasChildNodes() ) {
515 outDate
.removeChild(outDate
.firstChild
);
517 // EndCodeTime("removing existing children");
520 // Write the month at the top
521 outDate
.appendChild(document
.createTextNode(monthString(monthShowing
)));
522 // EndCodeTime("initial stuff");
524 // and write the calendar to the table...
527 // XXX Hack: get around insertRow() bug.
528 var myrow
= outCal
.insertRow(0);
529 // EndCodeTime("initial stuff");
531 // make room before the first day, which starts on a strange day of the week
532 // note that getDay(), 0=Sunday and 6=Saturday
535 var curDay
= new Date(monthShowing
); // get the month we want to show
536 curDay
.setDate(1); // start with the first day of the month
537 // EndCodeTime("setting curDay");
540 myrow
= outCal
.insertRow(outCal
.rows
.length
);
541 var junkcell
= myrow
.insertCell(0); // XXX Bug in insertCell
542 for (var i
= 0 ; i
< curDay
.getDay() ; i
++ ) {
543 myrow
.insertCell(myrow
.cells
.length
);
545 // EndCodeTime("writing extra cells");
549 var targMonth
= monthShowing
.getMonth(); // for speed - saves 30ms
551 var testNowShowing
= (
552 ( monthShowing
.getFullYear() == nowShowing
.getFullYear()) &&
553 ( monthShowing
.getMonth() == nowShowing
.getMonth()) );
554 var testCurrentTime
= (
555 ( monthShowing
.getFullYear() == currentTime
.getFullYear()) &&
556 ( monthShowing
.getMonth() == currentTime
.getMonth()) );
558 while ( curDay
.getMonth() == targMonth
) {
559 if ( ( curDay
.getDay() == 0) && (curDay
.getDate() != 1) ) {
560 // if it's Sunday, and not the 1st of the month
561 // then add a new row
562 myrow
= outCal
.insertRow(outCal
.rows
.length
);
563 junkcell
= myrow
.insertCell(0); // XXX Bug in insertCell
565 mycell
= myrow
.insertCell( myrow
.cells
.length
);
566 // put the number of the current date in the cell
567 mycell
.appendChild( document
.createTextNode( curDay
.getDate() ) );
568 // and set the onClick handler
569 mycell
.setAttribute("onclick", "pickDate(" + curDay
.getFullYear()
570 + "," + (curDay
.getMonth() + 1)
571 + "," + curDay
.getDate()
574 var classNm
= "caldate";
575 if ( testNowShowing
&& ( curDay
.getDate() == nowShowing
.getDate())) {
576 classNm
+= " nowshowing";
578 if ( testCurrentTime
&& ( curDay
.getDate() == currentTime
.getDate())) {
581 mycell
.setAttribute("class", classNm
);
583 curDay
.setDate(curDay
.getDate() + 1);
585 // EndCodeTime("writing the days");
589 // ************************************************************
590 // Code used for Adding to the data
591 // ************************************************************
593 function makeAssert ( source
, data
, name
) {
594 var target
= RDFService
.GetLiteral(data
);
595 var arc
= RDFService
.GetResource(rdf_ns
+ name
);
596 rdf_datasource
.Assert(source
, arc
, target
, true);
599 function SendBackToSource( appt
) {
601 // make a resource for the new appointment
603 // These four all write, but only first appt works
604 // var sourceNode = RDFService.GetResource("http://www.w3.org/1999/02/22-rdf-syntax-ns#Description");
605 // var sourceNode = RDFService.GetResource("");
606 // var sourceNode = RDFService.GetResource("aoeuidhtns");
607 // var sourceNode = RDFService.GetResource("http://when.com/aoeuidhtns#");
609 // milliseconds since 1970-01-01 00:00 should be a good enough
610 // unique identifier (creation time of appt)
612 = RDFService
.GetResource(RDFFileName
+"#" + appt
.id
);
614 // create literals and assert a relationship to the new appointment
615 // for each piece of data
617 makeAssert( sourceNode
, appt
.date
.getFullYear(), 'year');
618 makeAssert( sourceNode
, appt
.date
.getMonth() + 1, 'month'); // month is 0..1 in the date structure
619 makeAssert( sourceNode
, appt
.date
.getDate(), 'date');
620 makeAssert( sourceNode
, appt
.date
.getHours(), 'hour');
621 makeAssert( sourceNode
, appt
.date
.getMinutes(), 'minute');
622 makeAssert( sourceNode
, appt
.title
, 'title');
623 makeAssert( sourceNode
, appt
.desc
, 'notes');
624 makeAssert( sourceNode
, appt
.dur
, 'duration');
626 // connect the new appointment to the datasource
628 appts_container
.AppendElement( sourceNode
);
630 // write the datasource back to disk
633 rdf_remote_datasource
.Flush(); // must be a RemoteDataSource, after 1999-06-23
635 window
.alert("Caught exception [[" + ex
+ "]] in Flush().\n");
640 function Add( appt
) {
642 // Add it to our internal data -- note that we don't show it!
643 allAppts
[allAppts
.length
] = appt
;
645 // and add it to the external data
646 SendBackToSource( appt
);
650 function ResetAddFormTo( year
, month
, date
, hrs
, min
, durhrs
, durmin
, title
, notes
) {
651 var addDiv
= getAddDiv(); // for speed
653 var yearselect
= GetElementWithIdIn("addyear", addDiv
);
654 var monthselect
= GetElementWithIdIn("addmonth", addDiv
);
655 var dayselect
= GetElementWithIdIn("addday", addDiv
);
656 var hourselect
= GetElementWithIdIn("addtimehrs", addDiv
);
657 var minselect
= GetElementWithIdIn("addtimemin", addDiv
);
658 var durhourselect
= GetElementWithIdIn("adddurhrs", addDiv
);
659 var durminselect
= GetElementWithIdIn("adddurmin", addDiv
);
661 var titleInput
= GetElementWithIdIn("addtitle", addDiv
);
662 var notesInput
= GetElementWithIdIn("addnotes", addDiv
);
664 if (yearselect
!= null) { // "if (yearselect)" works too
665 // Subtract the value of the first year in the list to set
666 // selectedIndex. JavaScript converts the string value to a number.
667 yearselect
.selectedIndex
=
668 year
- yearselect
.options
.item(0).value
;
670 window
.alert("Hit a null.");
673 if (monthselect
!= null) {
674 // selectedIndex 0 based, so subtract one
675 monthselect
.selectedIndex
= month
- 1;
677 window
.alert("Hit a null.");
680 if (dayselect
!= null) {
681 // selectedIndex 0 based, so subtract one
682 dayselect
.selectedIndex
= date
- 1;
684 window
.alert("Hit a null.");
687 if (hourselect
!= null) {
689 hourselect
.selectedIndex
= hrs
;
691 window
.alert("Hit a null.");
694 if (minselect
!= null) {
695 minselect
.selectedIndex
= Math
.round(min
/ 5);
697 window
.alert("Hit a null.");
700 if (durhourselect
!= null) {
701 durhourselect
.selectedIndex
= durhrs
;
703 window
.alert("Hit a null.");
706 if (durminselect
!= null) {
707 durminselect
.selectedIndex
= Math
.round(durmin
/ 5);
709 window
.alert("Hit a null.");
712 if (titleInput
!= null) {
713 if ( title
== null) {
716 titleInput
.value
= title
;
718 window
.alert("Hit a null.");
721 if (notesInput
!= null) {
722 if ( notes
== null) {
725 notesInput
.value
= notes
;
727 window
.alert("Hit a null.");
732 function ResetAddForm() {
733 editButtonsActive(0);
734 ResetAddFormTo( nowShowing
.getFullYear(),
735 nowShowing
.getMonth() + 1,
736 nowShowing
.getDate(),
737 nowShowing
.getHours() + 1, // upcoming hour
740 0, // duration minutes
745 function SubmitAddForm() {
746 var addDiv
= getAddDiv(); // for speed
748 var title
= GetElementWithIdIn("addtitle", addDiv
);
749 var years
= GetElementWithIdIn("addyear", addDiv
);
750 var months
= GetElementWithIdIn("addmonth", addDiv
);
751 var days
= GetElementWithIdIn("addday", addDiv
);
752 var timehrs
= GetElementWithIdIn("addtimehrs", addDiv
);
753 var timemin
= GetElementWithIdIn("addtimemin", addDiv
);
754 var durhrs
= GetElementWithIdIn("adddurhrs", addDiv
);
755 var durmin
= GetElementWithIdIn("adddurmin", addDiv
);
756 var notes
= GetElementWithIdIn("addnotes", addDiv
);
758 if ( ( title
== null ) ||
760 ( months
== null ) ||
762 ( timehrs
== null ) ||
763 ( timemin
== null ) ||
764 ( durhrs
== null ) ||
765 ( durmin
== null ) ||
766 ( notes
== null ) ) {
767 window
.alert("Something is null. Addition failed.\n");
770 var apptid
= "appt" + (new Date().getTime());
771 Add( new Appointment( new Date ( years
.value
, months
.value
- 1,
772 days
.value
, timehrs
.value
,
776 (durhrs
.value
* 60) + (durmin
.value
* 1),
783 // ************************************************************
784 // Edit code, which uses add form
785 // ************************************************************
787 function getApptById( id
) {
788 for (var i
= 0 ; i
< allAppts
.length
; i
++ ) {
789 if ( allAppts
[i
].id
== id
) {
796 function removeApptById ( id
) {
797 for (var i
= 0 ; i
< allAppts
.length
; i
++ ) {
798 if ( allAppts
[i
].id
== id
) {
800 allAppts
[i
] = allAppts
[allAppts
.length
- 1];
801 allAppts
[allAppts
.length
- 1] = null;
802 allAppts
.length
-= 1;
808 function EditApptById( theid
) {
809 idEditing
= theid
; // global variable
811 var apptEditing
= getApptById( idEditing
);
812 if ( apptEditing
== null) {
813 window
.alert("Null appointment. Something's wrong.\n");
816 divActive(0); // XXX This should come later, but...
817 editButtonsActive(1);
818 ResetAddFormTo( apptEditing
.date
.getFullYear(),
819 apptEditing
.date
.getMonth() + 1,
820 apptEditing
.date
.getDate(),
821 apptEditing
.date
.getHours(),
822 apptEditing
.date
.getMinutes(),
823 Math
.floor(apptEditing
.dur
/ 60),
824 apptEditing
.dur
% 60,
829 function getAttrLiteral(rdf_datasource
,service
,attr_name
) {
830 var attr
= rdf_datasource
.GetTarget(service
,
831 RDFService
.GetResource(rdf_ns
+ attr_name
),
834 attr
= attr
.QueryInterface(
835 Components
.interfaces
.nsIRDFLiteral
);
839 function makeUnAssert ( rdf_datasource
, resource
, name
) {
840 var target
= getAttrLiteral(rdf_datasource
, resource
, name
);
841 var data
= getAttr(rdf_datasource
, resource
, name
); // function above
842 var arc
= RDFService
.GetResource(rdf_ns
+ name
);
843 rdf_datasource
.Unassert(resource
, arc
, target
);
846 function DeleteEditing() {
847 // delete from our list:
848 removeApptById(idEditing
);
850 // delete from the data source
851 var sourceNode
= RDFService
.GetResource(RDFFileName
+"#" + idEditing
);
852 appts_container
.RemoveElement( sourceNode
, true );
854 // Need to unassert all of sourceNode's relationships
855 makeUnAssert(rdf_datasource
, sourceNode
, 'year');
856 makeUnAssert(rdf_datasource
, sourceNode
, 'month');
857 makeUnAssert(rdf_datasource
, sourceNode
, 'date');
858 makeUnAssert(rdf_datasource
, sourceNode
, 'hour');
859 makeUnAssert(rdf_datasource
, sourceNode
, 'minute');
860 makeUnAssert(rdf_datasource
, sourceNode
, 'title');
861 makeUnAssert(rdf_datasource
, sourceNode
, 'notes');
862 makeUnAssert(rdf_datasource
, sourceNode
, 'duration');
865 rdf_remote_datasource
.Flush(); // must be a RemoteDataSource, after 1999-06-23
867 window
.alert("Caught exception [[" + ex
+ "]] in Flush().\n");
872 function EditFormSubmit() {
878 function EditFormDelete() {
883 function EditFormCancel() {
887 // ************************************************************
889 // ************************************************************
893 // Initialize the Sidebar
895 // Install all the datasources named in the Flash Registry into
896 // the tree control. Datasources are listed as members of the
897 // NC:FlashDataSources sequence, and are loaded in the order that
898 // they appear in that sequence.
900 // First try to construct a new one and load it
901 // synchronously. nsIRDFService::GetDataSource() loads RDF/XML
902 // asynchronously by default.
903 rdf_datasource
= Components
.classes
['@mozilla.org/rdf/datasource;1?name=xml-datasource'].createInstance();
904 rdf_datasource
= rdf_datasource
.QueryInterface(Components
.interfaces
.nsIRDFDataSource
);
906 rdf_remote_datasource
= rdf_datasource
.QueryInterface(Components
.interfaces
.nsIRDFRemoteDataSource
);
907 rdf_remote_datasource
.Init(RDFFileName
); // this will throw if it's already been opened and registered.
909 dump("Reading datasource synchronously.\n");
910 // read it in synchronously.
911 rdf_remote_datasource
.Refresh(true);
914 // if we get here, then the RDF/XML has been opened and read
915 // once. We just need to grab the datasource.
916 dump("Datasource already read. Grabbing.\n");
917 rdf_datasource
= RDFService
.GetDataSource(RDFFileName
);
920 // Create a 'container' wrapper around the appts_resourcename
921 // resource so we can use some utility routines that make access a
923 // NOT var, so it's global
924 appts_container
= Components
.classes
['@mozilla.org/rdf/container;1'].createInstance();
925 appts_container
= appts_container
.QueryInterface(Components
.interfaces
.nsIRDFContainer
);
927 appts_resource
= RDFService
.GetResource(appts_resourcename
);
928 appts_container
.Init(rdf_datasource
, appts_resource
);
933 if (document
.getElementById("ApptsWindow")) {
934 dump("Calling init:\n");
937 // XXX Bug 9136 - this doesn't work when form is hidden.
941 dump("Calling divActive(1):\n");
943 dump("Done initializing.\n");
944 // and let events take things from there...
946 setTimeout("Boot()", 0);