diff --git a/src/www/js/AddressBook.js b/src/www/js/AddressBook.js index 3665703..42203cd 100644 --- a/src/www/js/AddressBook.js +++ b/src/www/js/AddressBook.js @@ -280,83 +280,6 @@ Dragonfly.AddressBook.ContactPicker.prototype.newContactHandler = function (evt) this.popup.edit (evt, contact, this.newContactId); }; -// The FakeFriendPopup manages the interaction for unknown contacts. -Dragonfly.AddressBook.FakeFriendPopup = function (elem) -{ - Dragonfly.PopupBuble.apply (this, arguments); -}; - -Dragonfly.AddressBook.FakeFriendPopup.prototype = clone (Dragonfly.PopupBuble.prototype) -Dragonfly.AddressBook.FakeFriendPopup.prototype.dispose = -Dragonfly.AddressBook.FakeFriendPopup.prototype.disposeZone = function () -{ - this.hide(); - delete this.contact; - delete this.formNames; -}; - -Dragonfly.AddressBook.FakeFriendPopup.prototype.summarize = function (contact, elem) -{ - var d = Dragonfly; - - this.hide (); - this.setClosable (true); - this.contact = contact = (contact) ? contact : this.contact; - - var editId = d.nextId ('person-add'); - - var html = new d.HtmlBuilder(); - html.push ('

' + contact.fn + ''); - html.push (''); - html.push ('
'); - - var loc = new d.Location ({ tab: 'mail', set:'all', handler:'contacts', - contact: contact.bongoId }); - html.push ('

', - '', _('Show Conversations'), '', - '', _('Add'), '
'); - html.set (this.contentId); - - Event.observe (editId, 'click', this.add.bindAsEventListener (this)); - this.showVertical (elem); -} - -Dragonfly.AddressBook.FakeFriendPopup.prototype.add = function () -{ - var AB = Dragonfly.AddressBook; - this.serializeContact(); - this.elem.innerHTML = this.contact.fn; - - Dragonfly.notify (_('Saving changes...'), true); - AB.saveContact (this.contact).addCallbacks (bind ( - function (result) { - // update preferences with contact ID - if (this.setMyContact) { - var id = (this.myId == '') ? result.bongoId : this.myId; - AB.Preferences.setMyContactId (id); - } - - // Create sidebox element if this is a new contact - if (result.bongoId) { - this.contact.bongoId = result.bongoId; - this.setElem (AB.sideboxPicker.addItem (this.contact.fn, result.bongoId)); - $(this.elem).scrollIntoView(); - } - - Dragonfly.notify (_('Changes saved.')); - this.summarize (); - this.shouldAutohide = true; - callLater (2, bind ('autohide', this)); - return result; - }, this), bind ('showError', this)); -}; - // The ContactPopup manages the interaction for creating and editing contacts Dragonfly.AddressBook.ContactPopup = function (elem) { @@ -482,14 +405,14 @@ Dragonfly.AddressBook.ContactPopup.prototype.loadContact = function () var form = $(this.formId); form.fn.value = this.contact.fn; - var myId = AB.Preferences.getMyContactId(); + //var myId = AB.Preferences.getMyContactId(); - logDebug('myID: ' + myId); + //logDebug('myID: ' + myId); logDebug('form id: ' + form); logDebug('this.contact: ' + this.contact); logDebug('this.contact.fn: ' + this.contact.fn); - form.isMyContact.checked = myId && (myId == this.contact.bongoId); + //form.isMyContact.checked = myId && (myId == this.contact.bongoId); for (var i = 0; i < Fields.props.length; i++) { var prop = Fields.props[i]; @@ -515,13 +438,13 @@ Dragonfly.AddressBook.ContactPopup.prototype.serializeContact = function () var form = $(this.formId); contact.fn = form.fn.value; - if (form.isMyContact.checked) { + /*if (form.isMyContact.checked) { this.setMyContact = true; this.myId = this.contact.bongoId || ''; } else if (this.contact.bongoId == AB.Preferences.getMyContactId()) { this.setMyContact = true; this.myId = null; - } + }*/ // clear out existing properties forEach (props, function (prop) { delete contact[prop]; }); @@ -602,8 +525,7 @@ Dragonfly.AddressBook.ContactPopup.prototype.edit = function (evt, contact, elem var form = [ '

', notebook, '
']; + 'src="img/contact-unknown.png">

', notebook, '']; var actions = [{ value: _('Cancel'), onclick: 'dispose'}, { value: _('Save'), onclick: 'save'}]; if (this.contact.bongoId) { // only add delete for pre-existing contacts @@ -642,10 +564,10 @@ Dragonfly.AddressBook.ContactPopup.prototype.save = function () AB.saveContact (this.contact).addCallbacks (bind ( function (result) { // update preferences with contact ID - if (this.setMyContact) { + /*if (this.setMyContact) { var id = (this.myId == '') ? result.bongoId : this.myId; AB.Preferences.setMyContactId (id); - } + }*/ // Create sidebox element if this is a new contact if (result.bongoId) { @@ -678,3 +600,153 @@ Dragonfly.AddressBook.ContactPopup.prototype.delConfirm = function () this.show(); }; +Dragonfly.AddressBook.UserProfile = function (elem) +{ + this.formId = elem; + this.bongoId = null; +}; + +Dragonfly.AddressBook.UserProfile.prototype = {}; + +Dragonfly.AddressBook.UserProfile.prototype.build = function (contact) +{ + var d = Dragonfly; + + this.contact = contact; + + this.formNames = { }; + + var notebook = new d.Notebook(); + for (var i = 0; i < Dragonfly.AddressBook.ContactPopup.prototype.Form.length; i++) { + var tab = d.AddressBook.ContactPopup.prototype.Form[i]; + var page = notebook.appendPage (tab.category); + this.buildTab (new d.HtmlBuilder(), tab).set(page); + } + + var html = new d.HtmlBuilder (); + html.push ('

'); + d.HtmlBuilder.buildChild(html, notebook); + + html.set(this.formId); + + //var actions = [{ value: _('Save'), onclick: 'save'}]; + //Dragonfly.Preferences.Editor.buildInterface (form, actions, this.belement); + + if (this.contact != null) + { + this.loadContact(); + } +}; + +Dragonfly.AddressBook.UserProfile.prototype.loadContact = function () +{ + var AB = Dragonfly.AddressBook; + var Fields = AB.ContactPopup.prototype.FieldTypes; + + var form = $(this.formId); + form.fn.value = this.contact.fn; + + //logDebug('myID: ' + myId); + + //form.isMyContact.checked = myId && (myId == this.contact.bongoId); + + for (var i = 0; i < Fields.props.length; i++) { + var prop = Fields.props[i]; + var values = this.contact[prop]; + if (!values) { + continue; + } + for (var j = 0; j < values.length; j++) { + var value = values[j]; + var input = this.getFreeField (AB.ContactPopup.prototype.getName (prop, value.type), false); + if (input) { + input.value = $V(value); + } + } + } +}; + +Dragonfly.AddressBook.UserProfile.prototype.getFreeField = function (name, asString) +{ + if (asString) { + var n = this.formNames[name]; + n = (n == undefined) ? 0 : n + 1; + this.formNames[name] = n; + return name + String (n); + } + return $(this.formId)[name+'0']; +}; + +Dragonfly.AddressBook.UserProfile.prototype.buildTab = function (html, tab) +{ + var fields = tab.fields; + var formFields = this.formFields; + + html.push (''); + return html; +}; + +Dragonfly.AddressBook.UserProfile.prototype.save = function () +{ + var AB = Dragonfly.AddressBook; + this.serializeContact(); + //this.elem.innerHTML = this.contact.fn; + + AB.saveContact (this.contact).addCallbacks (bind ( + function (result) { + // update preferences with contact ID + if (result.bongoId) + { + this.bongoId = result.bongoId; + } + else + { + this.bongoId = AB.Preferences.getMyContactId(); + } + + return result; + }, this)); +}; + +Dragonfly.AddressBook.UserProfile.prototype.serializeContact = function () +{ + var AB = Dragonfly.AddressBook; + var props = AB.ContactPopup.prototype.FieldTypes.props; + var contact = this.contact; + var form = $(this.formId); + contact.fn = form.fn.value; + + // clear out existing properties + forEach (props, function (prop) { delete contact[prop]; }); + + for (var name in this.formNames) { // for each type of field + var count = this.formNames[name]; + var components = name.split ('-'); + var prop = components[0]; + var types = components.slice(1); + + for (var i = 0; i <= count; i++) { // for each field + var value = form[name+String(i)].value; + if (value && value != '') { + var proparray = contact[prop] || [ ]; + proparray.push ({value:value, type:types}); + contact[prop] = proparray; + } + } + } +}; diff --git a/src/www/js/BongoCalendar.js b/src/www/js/BongoCalendar.js index cdb5901..166795b 100644 --- a/src/www/js/BongoCalendar.js +++ b/src/www/js/BongoCalendar.js @@ -65,17 +65,11 @@ Dragonfly.Calendar.BongoCalendar.prototype.parseJSON = function (jsob) { var d = Dragonfly; - // TODO: This is really nasty. function calColor (calname) { return { 'Personal': 'blue', - 'Red Sox': 'red', - 'US Holidays': 'orange', 'Holidays': 'orange', - 'The Moon': 'gray', - 'Novell': 'red', - 'openSUSE': 'green', 'Meetings': 'brown' }[calname] || d.getRandomColor(); } @@ -95,7 +89,6 @@ Dragonfly.Calendar.BongoCalendar.prototype.parseJSON = function (jsob) this.subscriptionUrl = "/user/" + d.userName + "/calendar/" + d.escapeHTML(this.cal.name) + "/events"; - /* // this should probably trust the server... switch (this.type) { case 'personal': @@ -112,7 +105,6 @@ Dragonfly.Calendar.BongoCalendar.prototype.parseJSON = function (jsob) this.cal.username = jsob.username; break; } - */ }; Dragonfly.Calendar.BongoCalendar.prototype.refresh = function () diff --git a/src/www/js/Dragonfly.js b/src/www/js/Dragonfly.js index 02f53b3..774162f 100644 --- a/src/www/js/Dragonfly.js +++ b/src/www/js/Dragonfly.js @@ -1,6 +1,6 @@ Dragonfly = { title: 'Bongo', - version: 'SVN r2483+', + version: 'M3', userName: '', tabs: { }, NAME: 'Dragonfly' @@ -937,16 +937,13 @@ Dragonfly.start = function () d.translateElements(); d.setLoginMessage (_('Logged in: loading contacts and calendars...')); - - // setup the preferences dialog tabs - //d.setupPrefs(); - + // 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()); }); - var def = new d.MultiDeferred ([ c.loadCalendars(), + /*var def = new d.MultiDeferred ([ c.loadCalendars(), + d.AddressBook.sideboxPicker.load() ]);*/ + var def = new DeferredList ([ c.loadCalendars(), d.AddressBook.sideboxPicker.load() ]); return def.addCallbacks ( function (res) { @@ -965,8 +962,12 @@ Dragonfly.start = function () $('login-password').value = ''; Element.setText ('user-name', d.userName); Element.setHTML ('logout-text', d.format(_('Log out {0}...'), d.userName)); + Dragonfly.logoutMessage = _('You have logged out successfully.'); showElement ('content'); + // Listen for clicks to main content thing, so we can hide popups. + Event.observe ('content', 'click', Dragonfly.hidePopups.bindAsEventListener(this)); + // Add administration link if we're admin if (d.userName == 'admin') { @@ -1030,6 +1031,20 @@ Dragonfly.initHtmlZones = function () Event.observe (window, 'unload', bind ('disposeZone', d.contentZone)); }; +Dragonfly.hidePopups = function () +{ + if (Dragonfly.lastPopup) + { + Dragonfly.lastPopup.dispose(); + logDebug('Attempted popup dispose complete.'); + Dragonfly.lastPopup = null; + } + else + { + logDebug('Nothing to dispose'); + } +} + Dragonfly.main = function () { Dragonfly.browserDetect(); diff --git a/src/www/js/Login.js b/src/www/js/Login.js index 464403f..b1e1088 100644 --- a/src/www/js/Login.js +++ b/src/www/js/Login.js @@ -110,7 +110,6 @@ Dragonfly.translateLogin = function () Element.setHTML ('login-language-label', _('Language')); Element.setHTML ('login-default-label', _('Remember me')); $('login-button').value = _('Login'); - Dragonfly.logoutMessage = _('You have logged out successfully.'); }; Dragonfly.languageSuccess = function () @@ -193,7 +192,7 @@ Dragonfly.showLoginPane = function () if (location.hash == '#LoggedOut') { Dragonfly.setLoginMessage (Dragonfly.logoutMessage); - d.langFaliure = true; // Stops us from removing the 'You have logged out' message when we load the lang. + Dragonfly.langFaliure = true; // Stops us from removing the 'You have logged out' message when we load the lang. location.hash = (Dragonfly.isWebkit) ? '' : '#'; $('login-user').focus(); } else { diff --git a/src/www/js/Preferences.js b/src/www/js/Preferences.js index 5407773..5146ec3 100644 --- a/src/www/js/Preferences.js +++ b/src/www/js/Preferences.js @@ -241,90 +241,90 @@ Dragonfly.Preferences.Editor.parsePath = function (loc, path) Dragonfly.Preferences.Editor.build = function (loc) { var d = Dragonfly; - var showmethemoney = true; Element.setHTML ('toolbar', ''); Element.hide ('toolbar'); var html = new d.HtmlBuilder (); + // First, build the container. + html.push ('
', '
'); + html.set ('content-iframe'); - if (!showmethemoney) - { - // Push the following HTML if we haven't completed our handler! - html.push ('
', '', - '', - '', - '

The Preferences editor goes here! :)

'); - - html.set ('content-iframe'); - } - else - { - // First, build the container. - 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('Mail'); - 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.

', - '', - '
', _('items'), '
'); - composerhtml.set (composerpage); - - var calendarhtml = new d.HtmlBuilder (); - calendarhtml.push ('', - '', - '', + // Come up with some magic tabs! + var notebook = new d.Notebook(); + var userpage = notebook.appendPage('General'); + var mailpage = notebook.appendPage('Mail'); + var calendarpage = notebook.appendPage('Calendar'); + var composerpage = notebook.appendPage('Composer'); + + var userhtml = new d.HtmlBuilder (); + userhtml.push ('
', + '', + '', + '', + '
', '
'); + userhtml.set (userpage); + + var mailhtml = new d.HtmlBuilder (); + mailhtml.push ('', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '
Please don\'t abuse the above feature for now.

', + '', + '
', _('items'), '
'); + mailhtml.set (mailpage); + + var calendarhtml = new d.HtmlBuilder (); + calendarhtml.push ('', + '', + '', + '', + ' ', + '', + '', // '', // '', - '
'); - calendarhtml.set (calendarpage); - - var form = [ - '
', notebook, '
']; - - var actions = [{ value: _('Cancel'), onclick: 'dispose'}, { value: _('Save'), 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); - } + ''); + calendarhtml.set (calendarpage); + + var composerhtml = new d.HtmlBuilder(); + composerhtml.push('', + '', + '', + '', + '', + '
'); + composerhtml.set(composerpage); + + var form = [ + '
', notebook, '
']; + + var actions = [{ value: _('Cancel'), onclick: 'dispose'}, { value: _('Save'), onclick: 'save'}]; + + // Now, fill in the content with tabs & buttons. + this.buildInterface (form, actions, 'preferences-container'); + 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.'); }; @@ -335,6 +335,11 @@ Dragonfly.Preferences.Editor.save = function () var d = Dragonfly; var p = d.Preferences; + // User profile + Dragonfly.notify (_('Saving changes...'), true); + var result = this.profileEditor.save(); + p.prefs.addressbook.me = this.profileEditor.bongoId; + // Timezone d.setCurrentTzid (d.tzselector.getTzid()); @@ -349,9 +354,16 @@ Dragonfly.Preferences.Editor.save = function () // Calendar prefs p.prefs.calendar.defaultView = $('defaultcalview').value; p.prefs.calendar.dayStart = 7; // Yes, hardwire this one (for now)! + p.prefs.calendar.sharePublicDefault = $('calshareyes').checked; + + // Composer prefs + p.prefs.composer = {}; + p.prefs.composer.messageType = $('defaultcompose'); + p.prefs.composer.lineWidth = $('linewidth'); // Finish up p.save(); + Dragonfly.notify (_('Changes saved.')); this.dispose(); }; @@ -379,20 +391,40 @@ Dragonfly.Preferences.Editor.load = function (loc, jsob) logWarning('You have no prefs. I should probably warn you, or.. something.'); } - if (jsob.mail.autoBcc) { $('autobcc').value = jsob.mail.autoBcc; } - if (jsob.mail.pageSize) { $('mailpagesize').value = jsob.mail.pageSize; } - if (jsob.mail.signature) { $('signature').value = jsob.mail.signature; } - if (jsob.mail.usesig) { $('usesig').checked = jsob.mail.usesig; } - if (jsob.mail.colorQuotes) { $('colorquotes').checked = jsob.mail.colorQuotes; } + if (jsob.mail && jsob.mail.autoBcc) { $('autobcc').value = jsob.mail.autoBcc; } + if (jsob.mail && jsob.mail.pageSize) { $('mailpagesize').value = jsob.mail.pageSize; } + if (jsob.mail && jsob.mail.signature) { $('signature').value = jsob.mail.signature; } + if (jsob.mail && jsob.mail.usesig) { $('usesig').checked = jsob.mail.usesig; } + if (jsob.mail && jsob.mail.colorQuotes) { $('colorquotes').checked = jsob.mail.colorQuotes; } // Calendar prefs - if (jsob.calendar.defaultView) { $('defaultcalview').value = jsob.calendar.defaultView; } + if (jsob.calendar && jsob.calendar.defaultView) { $('defaultcalview').value = jsob.calendar.defaultView; } + if (jsob.calendar && jsob.calendar.sharePublicDefault) { $('calshareyes').checked = jsob.calendar.sharePublicDefault; $('calshareno').checked = !jsob.calendar.sharePublicDefault } else { $('calshareno').checked = true; } //if (jsob.calendar.dayStart) { $('daystart').value = jsob.calendar.dayStart; } + + // Composer prefs + if (jsob.composer && jsob.composer.messageType) { $('defaultcompose').value = jsob.composer.messageType; } + if (jsob.composer && jsob.composer.lineWidth) { $('linewidth').value = jsob.composer.lineWidth ; } else { $('linewidth').value = '80'; } + // Now, load up the profile editor! + var pe = new d.AddressBook.UserProfile('userprofile'); + if (jsob.addressbook.me && jsob.addressbook.me != null) + { + // We've already setup our profile - load it! + d.AddressBook.loadContact(jsob.addressbook.me).addCallback(bind ('build', pe)); + } + else + { + // Build empty profile editor UI. + pe.build(Dragonfly.AddressBook.buildNewContact()); + } + + this.profileEditor = pe; + logDebug('We just loaded.'); }; -Dragonfly.Preferences.Editor.buildInterface = function (children, actions, observer) +Dragonfly.Preferences.Editor.buildInterface = function (children, actions, element) { var d = Dragonfly; @@ -407,11 +439,11 @@ Dragonfly.Preferences.Editor.buildInterface = function (children, actions, obser } html.push (''); - html.set (this.contentId); + html.set (element); 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)); + Event.observe (ids[i], 'click', bind (clickHandler, this)); logDebug('Done!'); } }; diff --git a/src/www/js/Widgets.js b/src/www/js/Widgets.js index 3f9cbc0..474f5a7 100644 --- a/src/www/js/Widgets.js +++ b/src/www/js/Widgets.js @@ -361,6 +361,7 @@ Dragonfly.PopupBuble.prototype.connectHtml = function (elem) this.dispose(); } }.bindAsEventListener(this)); + return elem; }; @@ -378,6 +379,7 @@ Dragonfly.PopupBuble.prototype.addPoppedOut = function () { if (this.elem) { addElementClass (this.elem, 'popped-out'); + //Dragonfly.lastPopup = this; } }; @@ -560,7 +562,7 @@ Dragonfly.PopupBuble.prototype.show = function (elem, position) } if (!this.elem) { return; - } + } this.addPoppedOut (); @@ -621,7 +623,7 @@ Dragonfly.PopupBuble.prototype.show = function (elem, position) } $(this.id).style.visibility = 'visible'; - + return; logDebug ('positioning summary:'); logDebug (' elemMetrics:', repr (elemMetrics));