diff --git a/src/www/js/Dragonfly.js b/src/www/js/Dragonfly.js
index bf48afd..ab9cd98 100644
--- a/src/www/js/Dragonfly.js
+++ b/src/www/js/Dragonfly.js
@@ -929,8 +929,8 @@ Dragonfly.start = function ()
// set current timezone to default and build timezone selector
d.curTzid = c.Preferences.getDefaultTimezone();
- d.tzselector = new d.TzSelector (d.curTzid, 'tzselect', true);
- d.tzselector.setChangeListener (function () { d.setCurrentTzid (d.tzselector.getTzid()); });
+ //d.tzselector = new d.TzSelector (d.curTzid, 'tzselect', true);
+ //d.tzselector.setChangeListener (function () { d.setCurrentTzid (d.tzselector.getTzid()); });
var def = new d.MultiDeferred ([ c.loadCalendars(),
d.AddressBook.sideboxPicker.load() ]);
diff --git a/src/www/js/Preferences.js b/src/www/js/Preferences.js
index f6d36ff..1d62751 100644
--- a/src/www/js/Preferences.js
+++ b/src/www/js/Preferences.js
@@ -1,3 +1,6 @@
+/*
+ Setup the Preferences handler
+*/
Dragonfly.Preferences = {
defaultSet: 'all',
defaultHandler: 'dragonfly'
@@ -9,8 +12,22 @@ Dragonfly.Preferences.handlers = { };
Dragonfly.Preferences.sets = [ 'all' ];
Dragonfly.Preferences.setLabels = { all: 'All' };
+/*
+ Dragonfly.Preferences.prefs
+ namespace
+
+ Summary: The core preferences code.
+*/
+
Dragonfly.Preferences.prefs = { };
+/*
+ Dragonfly.Preferences.defaultPrefs
+ array
+
+ Summary: Stores the default preferences
+ that a user should have.
+*/
Dragonfly.Preferences.defaultPrefs = {
addressbook: {
me: null
@@ -30,6 +47,14 @@ Dragonfly.Preferences.defaultPrefs = {
}
};
+/*
+ Dragonfly.Preferences.load ()
+ function
+
+ Summary: Loads the preferences from the server
+ into the preferences handler for each
+ service (ie. mail, calendar etc)
+*/
Dragonfly.Preferences.load = function ()
{
var d = Dragonfly;
@@ -73,6 +98,17 @@ Dragonfly.Preferences.load = function ()
});
};
+/*
+ Dragonfly.Preferences.save ()
+ function
+
+ Summary: Saves the preferences from all
+ the preference handlers back onto
+ the server, via JSON.
+
+ Throws: an error if the preferences object is null
+ or undefined.
+*/
Dragonfly.Preferences.save = function ()
{
var d = Dragonfly;
@@ -88,6 +124,13 @@ Dragonfly.Preferences.save = function ()
}
};
+/*
+ Dragonfly.Preferences.reset ()
+ function
+
+ Summary: Resets the current preferences to their defaults
+ and saves the default vales back onto the server.
+*/
Dragonfly.Preferences.reset = function()
{
var p = Dragonfly.Preferences;
@@ -95,6 +138,16 @@ Dragonfly.Preferences.reset = function()
p.save();
}
+/*
+ Dragonfly.Preferences._lookup (obj, path)
+ function
+
+ Summary: Looks up an preference value from within the
+ path.
+
+ Argument: obj The object to lookup
+ path Path to lookup from
+*/
Dragonfly.Preferences._lookup = function (obj, path)
{
try {
@@ -108,6 +161,22 @@ Dragonfly.Preferences._lookup = function (obj, path)
}
}
+/*
+ Dragonfly.Preferences.get (key)
+ function
+
+ Summary: Gets the preference value for the specified
+ key.
+
+ Argument: key The key that is associated with
+ preference value you want to find.
+
+ Throws: an error if the key cannot be found in both
+ the user's current preferences and the defaults.
+
+ a warning if the key cannot be found in the
+ user's current preferences.
+*/
Dragonfly.Preferences.get = function (key)
{
var p = Dragonfly.Preferences;
@@ -140,6 +209,11 @@ Dragonfly.Preferences.set = function (key, value)
throw new Error ('Invalid Preference Key ' + key);
}
+/*
+ The Preferences editor (the UI component)
+*/
+
+// Setup the editor handler.
Dragonfly.Preferences.Editor = { };
Dragonfly.Preferences.handlers['dragonfly'] = Dragonfly.Preferences.Editor;
@@ -149,18 +223,140 @@ Dragonfly.Preferences.Editor.parsePath = function (loc, path)
return loc;
};
+/*
+ Dragonfly.Preferences.Editor.build (loc)
+ function
+
+ Summary: Builds the HTML elements for the preferences
+ editor.
+
+ Notes: This function is called automatically by the
+ location hash handler.
+
+ Argument: loc The current Dragonfly location.
+*/
Dragonfly.Preferences.Editor.build = function (loc)
{
var d = Dragonfly;
+ var showmethemoney = true;
Element.setHTML ('toolbar', '');
Element.hide ('toolbar');
- var html = new d.HtmlBuilder ('
');
-
- html.push ('
',
- '
',
- '
The Preferences editor goes here! :)
',
- '
');
-
- html.set ('content-iframe');
+
+ var html = new d.HtmlBuilder ();
+
+ if (!showmethemoney)
+ {
+ // Push the following HTML if we haven't completed our handler!
+ html.push ('
');
+ html.set ('content-iframe');
+
+ // Come up with some magic tabs!
+ var notebook = new d.Notebook();
+ var userpage = notebook.appendPage('About Me');
+ var composerpage = notebook.appendPage('Composer');
+ var calendarpage = notebook.appendPage('Calendar');
+
+ var userhtml = new d.HtmlBuilder ();
+ userhtml.push ('
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
');
+ userhtml.set (userpage);
+
+ var composerhtml = new d.HtmlBuilder ();
+ composerhtml.push ('
',
+ '
',
+ '
',
+ '
Please don\'t abuse the above feature for now.
',
+ '
');
+ composerhtml.set (composerpage);
+
+ var calendarhtml = new d.HtmlBuilder ();
+ calendarhtml.push ('
Nothing to see here, move along.
');
+ calendarhtml.set (calendarpage);
+
+ var form = [
+ ''];
+
+ var actions = [{ value: _('genericCancel'), onclick: 'dispose'}, { value: _('genericSave'), onclick: 'save'}];
+
+ // Now, fill in the content with tabs & buttons.
+ this.contentId = 'preferences-container';
+ this.buildInterface (form, actions);
+ logDebug('Created UI OK - setting up TzSelector widget...');
+
+ // Setup timezone widget
+ d.tzselector = new d.TzSelector (d.curTzid, 'tzpicker', true);
+ }
+
+ logDebug('We just got built.');
+}
+
+
+Dragonfly.Preferences.Editor.save = function ()
+{
+ var d = Dragonfly;
+
+ // TODO: Set values from form.
+ d.setCurrentTzid (d.tzselector.getTzid());
+ d.Preferences.prefs.mail.from = $('from').value;
+ d.Preferences.save();
+}
+
+Dragonfly.Preferences.Editor.dispose = function ()
+{
+ var d = Dragonfly;
+
+ // Send user back to summary.
+ var loc = new d.Location({tab: 'summary'});
+ d.go('#' + loc);
+}
+
+Dragonfly.Preferences.Editor.load = function (loc, jsob)
+{
+ var d = Dragonfly;
+
+ document.title = 'Preferences: ' + Dragonfly.title;
+
+ // Fill form with values.
+ $('from').value = jsob.mail.from;
+
+ logDebug('We just loaded.');
+}
+
+Dragonfly.Preferences.Editor.buildInterface = function (children, actions, observer)
+{
+ var d = Dragonfly;
+
+ var html = new d.HtmlBuilder ();
+ d.HtmlBuilder.buildChild (html, children);
+ html.push ('
');
+ for (var i = 0, ids = [ ]; i < actions.length; i++){
+ var action = actions[i];
+ ids.push (d.nextId ('button'));
+ html.push (' ' : '>');
+ }
+ html.push ('
');
+
+ html.set (this.contentId);
+ for (var i = 0; i < actions.length; i++){
+ logDebug('Setting up actions for ' + actions[i].value);
+ var clickHandler = actions[i].onclick;
+ Event.observe (ids[i], 'click', bind (clickHandler, observer || this));
+ logDebug('Done!');
+ }
}