adding support for creating and deleting calendars

This commit is contained in:
pavlov%pavlov.net 2005-02-01 00:56:51 +00:00
Родитель 6cf3e9a4ec
Коммит db4de01899
7 изменённых файлов: 169 добавлений и 33 удалений

Просмотреть файл

@ -73,21 +73,11 @@ calCalendarManager.prototype = {
return this;
},
findDB: function() {
var pathString = "c:\\builds\\mozilla\\objdir-sunbird\\dist\\bin\\calendar.db";
var dbFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
dbFile.initWithPath(pathString);
var ioservice = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
uri = ioservice.newFileURI(dbFile);
return uri.QueryInterface(Components.interfaces.nsIFileURL);
},
initDB: function() {
var calendarTable = "id INTEGER PRIMARY KEY, name STRING, type STRING, uri STRING";
var dbService = Components.classes[kStorageServiceContractID].getService(kStorageServiceIID);
this.mDB = dbService.getProfileStorage("profile");
// this.mDB = dbService.openDatabase(this.findDB().file);
try {
this.mDB.createTable("cal_calendars", calendarTable);
} catch (e) {
@ -138,6 +128,7 @@ calCalendarManager.prototype = {
*/
createCalendar: function(name, type, uri) {
var calendar = Components.classes["@mozilla.org/calendar/calendar;1?type=" + type].createInstance(Components.interfaces.calICalendar);
calendar.name = name;
calendar.uri = uri;
return calendar;
},

Просмотреть файл

@ -196,8 +196,8 @@ function calendarInit()
update_date();
checkForMailNews();
//updateColors();
//updateColors();
}
function updateColors()
@ -333,6 +333,11 @@ function calendarFinish()
gICalLib.removeObserver( gEventSource.alarmObserver );
}
function newCalendarDialog()
{
openDialog("chrome://calendar/content/calendarCreation.xul", "caEditServer", "chrome,titlebar,modal" );
}
function launchPreferences()
{
if (applicationName == "Mozilla" || applicationName == "Firebird")
@ -723,6 +728,11 @@ function createAttachment()
return Components.classes["@mozilla.org/calendar/attachment;1"].createInstance(Components.interfaces.calIAttachment);
}
function getCalendarManager()
{
return Components.classes["@mozilla.org/calendar/manager;1"].getService(Components.interfaces.calICalendarManager);
}
function makeURL(uriString)
{
var ioservice = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
@ -1671,3 +1681,27 @@ function calendarDefaultTimezone() {
return gDefaultTimezone;
}
function doCreateWizardFinish()
{
var name = document.getElementById("calendar-name").value;
var uri = document.getElementById("calendar-uri").value;
var type = document.getElementById("initial-radiogroup").value;
dump(name + "\n");
dump(uri + "\n");
dump(type + "\n");
var calManager = getCalendarManager();
try {
var newCalendar = calManager.createCalendar(name, type, makeURL(uri));
} catch (ex) {
dump(ex);
return false;
}
calManager.registerCalendar(newCalendar);
addCalendarToUI(newCalendar);
return true;
}

Просмотреть файл

@ -99,7 +99,7 @@
<command id="modify_todo_command" oncommand="modifyToDoCommand( event )"/>
<command id="delete_todo_command" oncommand="deleteToDoCommand()" disabled="true"/>
<command id="new_local_calendar_command" oncommand="gCalendarWindow.calendarManager.launchNewCalendarFileDialog()"/>
<command id="new_local_calendar_command" oncommand="newCalendarDialog()"/>
<command id="open_local_calendar_command" oncommand="gCalendarWindow.calendarManager.launchOpenCalendarFileDialog()"/>
<command id="edit_local_calendar_command" oncommand="gCalendarWindow.calendarManager.launchEditCalendarDialog()"/>
<command id="new_server_command" oncommand="gCalendarWindow.calendarManager.launchAddRemoteCalendarDialog()"/>
@ -518,7 +518,7 @@
<tabpanel>
<!--<vbox id="left-hand-above-splitter" flex="1">-->
<listbox id="list-calendars-listbox" class="unifinder-tree-class" flex="1"
contextmenu="calendarlist-context-menu" datasources="rdf:null" ref="urn:calendarcontainer">
contextmenu="calendarlist-context-menu">
<listhead>
<listheader flex="1" crop="end" label="&calendar.calendarlistbox.label;"/>
<listheader/>
@ -527,24 +527,6 @@
<listcol flex="1"/>
<listcol/>
</listcols>
<template>
<rule>
<listitem uri="rdf:*"
calendarPath="rdf:http://home.netscape.com/NC-rdf#path"
onclick="switchCalendar( event );">
<listcell class="calendar-list-item-class"
label="rdf:http://home.netscape.com/NC-rdf#name"
flex="1"
type="checkbox"
checked="rdf:http://home.netscape.com/NC-rdf#active"/>
<!-- If you add something between the above listcell and this listcell,
or between the next listcell and the image tag, you have to modify calendarManager.js -->
<listcell>
<image class="calendar-list-item-class"/>
</listcell>
</listitem>
</rule>
</template>
</listbox>
<!--</vbox>-->
</tabpanel>

Просмотреть файл

@ -0,0 +1,61 @@
<?xml version="1.0"?>
<!-- Style sheets -->
<?xml-stylesheet href="chrome://calendar/skin/calendar.css" type="text/css"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!-- The Window -->
<wizard
id="calendar-wizard"
title="Mozilla Calendar Wizard"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onwizardfinish="return doCreateWizardFinish();"
persist="screenX screenY"
>
<script type="application/x-javascript" src="chrome://calendar/content/calendar.js"/>
<wizardpage pageid="initialPage" description="Create new calendar" next="finish" onpageshow="">
<hbox><label value="name:"/><textbox id="calendar-name"/></hbox>
<hbox><label value="uri:"/><textbox id="calendar-uri"/></hbox>
<radiogroup id="initial-radiogroup">
<radio value="local"
label="Local Calendar"
selected="true"/>
<radio value="ics"
label="WebCal Calendar"/>
<radio value="caldav"
label="CalDAV Calendar"/>
</radiogroup>
</wizardpage>
<!--
<wizardpage pageid="remote"
label="Select your remote control"
description="Pick your type"
onpagehide=""
onpageshow="onPageShow( 'import' );">
<radiogroup id="remote-type">
<radio value="caldav"
label="CalDAV"
selected="true"/>
<radio value="webcal"
label="WebCal"/>
</radiogroup>
<textbox id="url"/>
</wizardpage>
-->
<wizardpage pageid="finish"
label="Done"
description="Hi mom"
onpagehide=""
onpageshow="">
label="Find a File"/>
<description>
Calendar created! Way to go!
</description>
</wizardpage>
</wizard>

Просмотреть файл

@ -154,6 +154,19 @@ function CalendarWindow( )
calendar.addObserver(calendarObserver, calendar.ITEM_FILTER_TYPE_ALL);
// fill in the calendars list
dump("\n\n\nlooking for calendars!!\n\n\n");
var calendars = getCalendarManager().getCalendars({});
for (var i = 0; i < calendars.length; i++) {
dump(calendars[i]);
addCalendarToUI(calendars[i]);
}
/*
this.calendarEventDataSourceObserver =
{
@ -234,6 +247,19 @@ function CalendarWindow( )
}
function addCalendarToUI(calendar)
{
var listItem = document.createElement("listitem");
var listCell = document.createElement("listcell");
listCell.setAttribute("label", calendar.name);
listItem.appendChild(listCell);
listItem.calendar = calendar;
var calendarList = document.getElementById("list-calendars-listbox");
calendarList.appendChild(listItem);
}
/** PUBLIC
*
* You must call this when you have finished with the CalendarWindow.
@ -1045,3 +1071,44 @@ CalendarView.prototype.preferredDaysOff = function() {
}
return isDayOff;
}
function deleteCalendar( )
{
// Show a dialog with option to import events with or without dialogs
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService();
promptService = promptService.QueryInterface(Components.interfaces.nsIPromptService);
var result = {value:0};
var buttonPressed =
promptService.confirmEx(window,
gCalendarBundle.getString( "deleteCalendarTitle" ), gCalendarBundle.getString( "deleteCalendarMessage" ),
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0) +
(promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1) +
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2),
gCalendarBundle.getString( "deleteCalendarOnly" ),null,gCalendarBundle.getString( "deleteCalendarAndFile" ),null, result);
var calendarList = document.getElementById("list-calendars-listbox");
var selectedCalendar = calendarList.currentItem.calendar;
if (buttonPressed == 0) {
// Delete calendar
getCalendarManager().unregisterCalendar(selectedCalendar);
}
else if(buttonPressed == 2) //delete calendar and file
{
getCalendarManager().unregisterCalendar(selectedCalendar);
getCalendarManager().deleteCalendar(selectedCalendar);
}
else if(buttonPressed == 1) // CANCEL
{
return false;
}
calendarList.removeChild(calendarList.currentItem);
refreshView();
return true;
}

Просмотреть файл

@ -20,6 +20,7 @@ calendar.jar:
content/calendar/calPrintEngine.js (content/calPrintEngine.js)
content/calendar/calPrintEngine.xul (content/calPrintEngine.xul)
content/calendar/calPrintEngine.css (content/calPrintEngine.css)
content/calendar/calendarCreation.xul (content/calendarCreation.xul)
content/calendar/clipboard.js (content/clipboard.js)
* content/calendar/contents.rdf (content/contents.rdf)
content/calendar/dateUtils.js (content/dateUtils.js)

Просмотреть файл

@ -70,7 +70,7 @@
<command id="modify_todo_command" oncommand="modifyToDoCommand( event )"/>
<command id="delete_todo_command" oncommand="deleteToDoCommand()" disabled="true"/>
<command id="new_local_calendar_command" oncommand="gCalendarWindow.calendarManager.launchNewCalendarFileDialog()"/>
<command id="new_local_calendar_command" oncommand="newCalendarDialog()"/>
<command id="open_local_calendar_command" oncommand="gCalendarWindow.calendarManager.launchOpenCalendarFileDialog()"/>
<command id="edit_local_calendar_command" oncommand="gCalendarWindow.calendarManager.launchEditCalendarDialog()"/>
<command id="new_server_command" oncommand="gCalendarWindow.calendarManager.launchAddRemoteCalendarDialog()"/>