blob: 256c1fc329a71cef3d07241658934fc3ce659983 [file] [log] [blame]
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// logout: log out a user
function logout() {
GetAsync("/api/preferences.lua?logout=true", null, function() { location.href = document.location; })
}
// savePreferences: save account prefs to ES
function savePreferences() {
var prefarr = []
for (var i in pref_keys) {
var key = pref_keys[i]
var o = document.getElementById(key)
var val = o ? o.value : null
if (o && o.selectedIndex) {
val = o.options[o.selectedIndex].value
}
if (val) {
prefarr.push(key + "=" + val)
prefs[key] = val
}
}
GetAsync("/api/preferences.lua?save=true&" + prefarr.join("&"), null, hideComposer)
}
// showPreferences: show the account prefs in the splash window
function showPreferences() {
var obj = document.getElementById('splash')
obj.style.display = "block"
obj.innerHTML = "<p style='text-align: right;'><a href='javascript:void(0);' onclick='hideComposer(event)' style='color: #FFF;'>Hit escape to close this window or click here<big> &#x2612;</big></a></p><h3>User preferences:</h3>"
obj.innerHTML += "<p>You can change your preferences here. Some changes may not take place til you refresh your view.</p>"
// set up account section
var section = document.createElement('div')
section.setAttribute("class", "bs-callout bs-callout-success prefs")
section.innerHTML = "<h4>Account information:</h4>"
// full name
section.appendChild(generateFormDivs('fullname', 'Full name:', 'text', prefs.fullname ? prefs.fullname : login.credentials.fullname))
obj.appendChild(section)
// set up view section
var section = document.createElement('div')
section.setAttribute("class", "bs-callout bs-callout-primary prefs")
section.innerHTML = "<h4>Viewing preferences:</h4>"
// Display mode
section.appendChild(generateFormDivs('displayMode', 'Display mode, list view:', 'select', {
threaded: "Threaded view",
flat: "Flat view"
}, prefs.displayMode))
// groupBy mode
section.appendChild(generateFormDivs('groupBy', 'Display mode, email view:', 'select', {
thread: "Threaded view, nest by reference",
date: "Flat view, order by date"
}, prefs.groupBy))
// sortOrder mode
section.appendChild(generateFormDivs('sortOrder', 'Sort order in email view:', 'select', {
forward: "Sort emails by date, ascending",
backward: "Sort emails by date, descending"
}, prefs.sortOrder))
// compactQuotes mode
section.appendChild(generateFormDivs('compactQuotes', 'Compact quotes in emails:', 'select', {
yes: "Yes",
no: "No"
}, prefs.compactQuotes))
// social mode
section.appendChild(generateFormDivs('theme', 'Email view theme:', 'select', {
social: "Social theme",
default: "Default theme"
}, prefs.theme))
// hideStats mode
section.appendChild(generateFormDivs('hideStats', 'Hide statistics window:', 'select', {
yes: "Yes",
no: "No"
}, prefs.hideStats))
var btn = document.createElement('input')
btn.setAttribute("type", "button")
btn.setAttribute("class", "btn btn-warning")
btn.setAttribute("value", "Save preferences")
btn.setAttribute("onclick", "savePreferences()")
obj.appendChild(section)
// set up notifications section
var section = document.createElement('div')
section.setAttribute("class", "bs-callout bs-callout-success prefs")
section.innerHTML = "<h4>Notification preferences:</h4>"
// notifications mode
section.appendChild(generateFormDivs('notifications', 'Notify me on:', 'select', {
direct: "Only direct replies to my emails",
indirect: "Any reply that references my email",
none: "Don't notify me at all!"
}, prefs.notifications))
obj.appendChild(section)
// Save button
obj.appendChild(btn)
}
// setupUser: Set up the user dropdown (top right)
function setupUser() {
var uimg = document.getElementById('uimg')
if (!uimg) {
return
}
uimg.setAttribute("src", "/images/user.png")
uimg.setAttribute("title", "Logged in as " + login.credentials.fullname)
if (login.notifications && login.notifications > 0) {
uimg.setAttribute("src", "/images/user_notif.png")
uimg.setAttribute("title", "Logged in as " + login.credentials.fullname + " - You have " + login.notifications + " new notifications!")
}
var pd = document.getElementById('prefs_dropdown')
pd.innerHTML = ""
// thread item
var li = document.createElement("li")
var a = document.createElement("a")
var t = document.createTextNode("Start a new discussion")
a.setAttribute("href", "javascript:void(0);")
a.setAttribute("onclick", "compose(null, 'xlist')")
a.appendChild(t)
li.appendChild(a)
pd.appendChild(li)
// Prefs item
var li = document.createElement("li")
var a = document.createElement("a")
var t = document.createTextNode((prefs.fullname ? prefs.fullname : login.credentials.fullname) + "'s preferences")
a.setAttribute("href", "javascript:void(0);")
a.setAttribute("onclick", "showPreferences()")
a.appendChild(t)
li.appendChild(a)
pd.appendChild(li)
// Notifications item
var li = document.createElement("li")
var a = document.createElement("a")
var t = document.createTextNode("Notifications")
a.setAttribute("href", "notifications.html")
a.appendChild(t)
if (login.notifications && login.notifications > 0) {
a.setAttribute("style", "font-weight: bold;")
t.nodeValue = "Notifications (" + login.notifications + ")"
a.innerHTML += ' <span class="glyphicon glyphicon-star"> </span>'
}
li.appendChild(a)
pd.appendChild(li)
// Logout item
var li = document.createElement("li")
var a = document.createElement("a")
var t = document.createTextNode("Log out")
a.setAttribute("href", "javascript:void(0);")
a.setAttribute("onclick", "logout()")
a.appendChild(t)
li.appendChild(a)
pd.appendChild(li)
}
// set theme, both in prefs and localstorage (for non-logged-in-users)
function setTheme(theme) {
prefs.theme = theme
if (typeof(window.localStorage) !== "undefined") {
window.localStorage.setItem("pm_theme", theme)
}
if (document.getElementById('emails')) {
buildPage()
}
}