Web: Use let and const instead of var
This commit is contained in:
parent
8b7a680a1e
commit
60de01870e
@ -21,21 +21,21 @@
|
|||||||
* @const
|
* @const
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
var SERVER = (location.protocol + '//' + location.hostname +
|
const SERVER = (location.protocol + '//' + location.hostname +
|
||||||
(location.port ? ':' + location.port : ''));
|
(location.port ? ':' + location.port : ''));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path of the root collection on the server (must end with /)
|
* Path of the root collection on the server (must end with /)
|
||||||
* @const
|
* @const
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
var ROOT_PATH = location.pathname.replace(new RegExp("/+[^/]+/*(/index\\.html?)?$"), "") + '/';
|
const ROOT_PATH = location.pathname.replace(new RegExp("/+[^/]+/*(/index\\.html?)?$"), "") + '/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regex to match and normalize color
|
* Regex to match and normalize color
|
||||||
* @const
|
* @const
|
||||||
*/
|
*/
|
||||||
var COLOR_RE = new RegExp("^(#[0-9A-Fa-f]{6})(?:[0-9A-Fa-f]{2})?$");
|
const COLOR_RE = new RegExp("^(#[0-9A-Fa-f]{6})(?:[0-9A-Fa-f]{2})?$");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escape string for usage in XML
|
* Escape string for usage in XML
|
||||||
@ -54,7 +54,7 @@ function escape_xml(s) {
|
|||||||
/**
|
/**
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
var CollectionType = {
|
const CollectionType = {
|
||||||
PRINCIPAL: "PRINCIPAL",
|
PRINCIPAL: "PRINCIPAL",
|
||||||
ADDRESSBOOK: "ADDRESSBOOK",
|
ADDRESSBOOK: "ADDRESSBOOK",
|
||||||
CALENDAR_JOURNAL_TASKS: "CALENDAR_JOURNAL_TASKS",
|
CALENDAR_JOURNAL_TASKS: "CALENDAR_JOURNAL_TASKS",
|
||||||
@ -65,9 +65,8 @@ var CollectionType = {
|
|||||||
JOURNAL: "JOURNAL",
|
JOURNAL: "JOURNAL",
|
||||||
TASKS: "TASKS",
|
TASKS: "TASKS",
|
||||||
is_subset: function(a, b) {
|
is_subset: function(a, b) {
|
||||||
var components = a.split("_");
|
let components = a.split("_");
|
||||||
var i;
|
for (let i = 0; i < components.length; i++) {
|
||||||
for (i = 0; i < components.length; i++) {
|
|
||||||
if (b.search(components[i]) === -1) {
|
if (b.search(components[i]) === -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -81,7 +80,7 @@ var CollectionType = {
|
|||||||
}
|
}
|
||||||
return this.ADDRESSBOOK;
|
return this.ADDRESSBOOK;
|
||||||
}
|
}
|
||||||
var union = "";
|
let union = "";
|
||||||
if (a.search(this.CALENDAR) !== -1 || b.search(this.CALENDAR) !== -1) {
|
if (a.search(this.CALENDAR) !== -1 || b.search(this.CALENDAR) !== -1) {
|
||||||
union += (union ? "_" : "") + this.CALENDAR;
|
union += (union ? "_" : "") + this.CALENDAR;
|
||||||
}
|
}
|
||||||
@ -120,16 +119,16 @@ function Collection(href, type, displayname, description, color) {
|
|||||||
* @return {XMLHttpRequest}
|
* @return {XMLHttpRequest}
|
||||||
*/
|
*/
|
||||||
function get_principal(user, password, callback) {
|
function get_principal(user, password, callback) {
|
||||||
var request = new XMLHttpRequest();
|
let request = new XMLHttpRequest();
|
||||||
request.open("PROPFIND", SERVER + ROOT_PATH, true, user, password);
|
request.open("PROPFIND", SERVER + ROOT_PATH, true, user, password);
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
if (request.readyState !== 4) {
|
if (request.readyState !== 4) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (request.status === 207) {
|
if (request.status === 207) {
|
||||||
var xml = request.responseXML;
|
let xml = request.responseXML;
|
||||||
var principal_element = xml.querySelector("*|multistatus:root > *|response:first-of-type > *|propstat > *|prop > *|current-user-principal > *|href");
|
let principal_element = xml.querySelector("*|multistatus:root > *|response:first-of-type > *|propstat > *|prop > *|current-user-principal > *|href");
|
||||||
var displayname_element = xml.querySelector("*|multistatus:root > *|response:first-of-type > *|propstat > *|prop > *|displayname");
|
let displayname_element = xml.querySelector("*|multistatus:root > *|response:first-of-type > *|propstat > *|prop > *|displayname");
|
||||||
if (principal_element) {
|
if (principal_element) {
|
||||||
callback(new Collection(
|
callback(new Collection(
|
||||||
principal_element.textContent,
|
principal_element.textContent,
|
||||||
@ -163,7 +162,7 @@ function get_principal(user, password, callback) {
|
|||||||
* @return {XMLHttpRequest}
|
* @return {XMLHttpRequest}
|
||||||
*/
|
*/
|
||||||
function get_collections(user, password, collection, callback) {
|
function get_collections(user, password, collection, callback) {
|
||||||
var request = new XMLHttpRequest();
|
let request = new XMLHttpRequest();
|
||||||
request.open("PROPFIND", SERVER + collection.href, true, user, password);
|
request.open("PROPFIND", SERVER + collection.href, true, user, password);
|
||||||
request.setRequestHeader("depth", "1");
|
request.setRequestHeader("depth", "1");
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
@ -171,28 +170,27 @@ function get_collections(user, password, collection, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (request.status === 207) {
|
if (request.status === 207) {
|
||||||
var xml = request.responseXML;
|
let xml = request.responseXML;
|
||||||
var collections = [];
|
let collections = [];
|
||||||
var response_query = "*|multistatus:root > *|response";
|
let response_query = "*|multistatus:root > *|response";
|
||||||
var responses = xml.querySelectorAll(response_query);
|
let responses = xml.querySelectorAll(response_query);
|
||||||
var i;
|
for (let i = 0; i < responses.length; i++) {
|
||||||
for (i = 0; i < responses.length; i++) {
|
let response = responses[i];
|
||||||
var response = responses[i];
|
let href_element = response.querySelector(response_query + " > *|href");
|
||||||
var href_element = response.querySelector(response_query + " > *|href");
|
let resourcetype_query = response_query + " > *|propstat > *|prop > *|resourcetype";
|
||||||
var resourcetype_query = response_query + " > *|propstat > *|prop > *|resourcetype";
|
let resourcetype_element = response.querySelector(resourcetype_query);
|
||||||
var resourcetype_element = response.querySelector(resourcetype_query);
|
let displayname_element = response.querySelector(response_query + " > *|propstat > *|prop > *|displayname");
|
||||||
var displayname_element = response.querySelector(response_query + " > *|propstat > *|prop > *|displayname");
|
let calendarcolor_element = response.querySelector(response_query + " > *|propstat > *|prop > *|calendar-color");
|
||||||
var calendarcolor_element = response.querySelector(response_query + " > *|propstat > *|prop > *|calendar-color");
|
let addressbookcolor_element = response.querySelector(response_query + " > *|propstat > *|prop > *|addressbook-color");
|
||||||
var addressbookcolor_element = response.querySelector(response_query + " > *|propstat > *|prop > *|addressbook-color");
|
let calendardesc_element = response.querySelector(response_query + " > *|propstat > *|prop > *|calendar-description");
|
||||||
var calendardesc_element = response.querySelector(response_query + " > *|propstat > *|prop > *|calendar-description");
|
let addressbookdesc_element = response.querySelector(response_query + " > *|propstat > *|prop > *|addressbook-description");
|
||||||
var addressbookdesc_element = response.querySelector(response_query + " > *|propstat > *|prop > *|addressbook-description");
|
let components_query = response_query + " > *|propstat > *|prop > *|supported-calendar-component-set";
|
||||||
var components_query = response_query + " > *|propstat > *|prop > *|supported-calendar-component-set";
|
let components_element = response.querySelector(components_query);
|
||||||
var components_element = response.querySelector(components_query);
|
let href = href_element ? href_element.textContent : "";
|
||||||
var href = href_element ? href_element.textContent : "";
|
let displayname = displayname_element ? displayname_element.textContent : "";
|
||||||
var displayname = displayname_element ? displayname_element.textContent : "";
|
let type = "";
|
||||||
var type = "";
|
let color = "";
|
||||||
var color = "";
|
let description = "";
|
||||||
var description = "";
|
|
||||||
if (resourcetype_element) {
|
if (resourcetype_element) {
|
||||||
if (resourcetype_element.querySelector(resourcetype_query + " > *|addressbook")) {
|
if (resourcetype_element.querySelector(resourcetype_query + " > *|addressbook")) {
|
||||||
type = CollectionType.ADDRESSBOOK;
|
type = CollectionType.ADDRESSBOOK;
|
||||||
@ -214,9 +212,9 @@ function get_collections(user, password, collection, callback) {
|
|||||||
description = calendardesc_element ? calendardesc_element.textContent : "";
|
description = calendardesc_element ? calendardesc_element.textContent : "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var sane_color = color.trim();
|
let sane_color = color.trim();
|
||||||
if (sane_color) {
|
if (sane_color) {
|
||||||
var color_match = COLOR_RE.exec(sane_color);
|
let color_match = COLOR_RE.exec(sane_color);
|
||||||
if (color_match) {
|
if (color_match) {
|
||||||
sane_color = color_match[1];
|
sane_color = color_match[1];
|
||||||
} else {
|
} else {
|
||||||
@ -228,8 +226,8 @@ function get_collections(user, password, collection, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
collections.sort(function(a, b) {
|
collections.sort(function(a, b) {
|
||||||
/** @type {string} */ var ca = a.displayname || a.href;
|
/** @type {string} */ let ca = a.displayname || a.href;
|
||||||
/** @type {string} */ var cb = b.displayname || b.href;
|
/** @type {string} */ let cb = b.displayname || b.href;
|
||||||
return ca.localeCompare(cb);
|
return ca.localeCompare(cb);
|
||||||
});
|
});
|
||||||
callback(collections, null);
|
callback(collections, null);
|
||||||
@ -265,7 +263,7 @@ function get_collections(user, password, collection, callback) {
|
|||||||
* @return {XMLHttpRequest}
|
* @return {XMLHttpRequest}
|
||||||
*/
|
*/
|
||||||
function upload_collection(user, password, collection_href, file, callback) {
|
function upload_collection(user, password, collection_href, file, callback) {
|
||||||
var request = new XMLHttpRequest();
|
let request = new XMLHttpRequest();
|
||||||
request.open("PUT", SERVER + collection_href, true, user, password);
|
request.open("PUT", SERVER + collection_href, true, user, password);
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
if (request.readyState !== 4) {
|
if (request.readyState !== 4) {
|
||||||
@ -290,7 +288,7 @@ function upload_collection(user, password, collection_href, file, callback) {
|
|||||||
* @return {XMLHttpRequest}
|
* @return {XMLHttpRequest}
|
||||||
*/
|
*/
|
||||||
function delete_collection(user, password, collection, callback) {
|
function delete_collection(user, password, collection, callback) {
|
||||||
var request = new XMLHttpRequest();
|
let request = new XMLHttpRequest();
|
||||||
request.open("DELETE", SERVER + collection.href, true, user, password);
|
request.open("DELETE", SERVER + collection.href, true, user, password);
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
if (request.readyState !== 4) {
|
if (request.readyState !== 4) {
|
||||||
@ -315,7 +313,7 @@ function delete_collection(user, password, collection, callback) {
|
|||||||
* @return {XMLHttpRequest}
|
* @return {XMLHttpRequest}
|
||||||
*/
|
*/
|
||||||
function create_edit_collection(user, password, collection, create, callback) {
|
function create_edit_collection(user, password, collection, create, callback) {
|
||||||
var request = new XMLHttpRequest();
|
let request = new XMLHttpRequest();
|
||||||
request.open(create ? "MKCOL" : "PROPPATCH", SERVER + collection.href, true, user, password);
|
request.open(create ? "MKCOL" : "PROPPATCH", SERVER + collection.href, true, user, password);
|
||||||
request.onreadystatechange = function() {
|
request.onreadystatechange = function() {
|
||||||
if (request.readyState !== 4) {
|
if (request.readyState !== 4) {
|
||||||
@ -327,13 +325,13 @@ function create_edit_collection(user, password, collection, create, callback) {
|
|||||||
callback(request.status + " " + request.statusText);
|
callback(request.status + " " + request.statusText);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var displayname = escape_xml(collection.displayname);
|
let displayname = escape_xml(collection.displayname);
|
||||||
var calendar_color = "";
|
let calendar_color = "";
|
||||||
var addressbook_color = "";
|
let addressbook_color = "";
|
||||||
var calendar_description = "";
|
let calendar_description = "";
|
||||||
var addressbook_description = "";
|
let addressbook_description = "";
|
||||||
var resourcetype;
|
let resourcetype;
|
||||||
var components = "";
|
let components = "";
|
||||||
if (collection.type === CollectionType.ADDRESSBOOK) {
|
if (collection.type === CollectionType.ADDRESSBOOK) {
|
||||||
addressbook_color = escape_xml(collection.color + (collection.color ? "ff" : ""));
|
addressbook_color = escape_xml(collection.color + (collection.color ? "ff" : ""));
|
||||||
addressbook_description = escape_xml(collection.description);
|
addressbook_description = escape_xml(collection.description);
|
||||||
@ -352,7 +350,7 @@ function create_edit_collection(user, password, collection, create, callback) {
|
|||||||
components += '<C:comp name="VTODO" />';
|
components += '<C:comp name="VTODO" />';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var xml_request = create ? "mkcol" : "propertyupdate";
|
let xml_request = create ? "mkcol" : "propertyupdate";
|
||||||
request.send('<?xml version="1.0" encoding="UTF-8" ?>' +
|
request.send('<?xml version="1.0" encoding="UTF-8" ?>' +
|
||||||
'<' + xml_request + ' xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav" xmlns:CR="urn:ietf:params:xml:ns:carddav" xmlns:I="http://apple.com/ns/ical/" xmlns:INF="http://inf-it.com/ns/ab/">' +
|
'<' + xml_request + ' xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav" xmlns:CR="urn:ietf:params:xml:ns:carddav" xmlns:I="http://apple.com/ns/ical/" xmlns:INF="http://inf-it.com/ns/ab/">' +
|
||||||
'<set>' +
|
'<set>' +
|
||||||
@ -430,7 +428,7 @@ Scene.prototype.release = function() {};
|
|||||||
/**
|
/**
|
||||||
* @type {Array<Scene>}
|
* @type {Array<Scene>}
|
||||||
*/
|
*/
|
||||||
var scene_stack = [];
|
let scene_stack = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push scene onto stack.
|
* Push scene onto stack.
|
||||||
@ -458,14 +456,14 @@ function pop_scene(index) {
|
|||||||
}
|
}
|
||||||
scene_stack[scene_stack.length - 1].hide();
|
scene_stack[scene_stack.length - 1].hide();
|
||||||
while (scene_stack.length - 1 > index) {
|
while (scene_stack.length - 1 > index) {
|
||||||
var old_length = scene_stack.length;
|
let old_length = scene_stack.length;
|
||||||
scene_stack.pop().release();
|
scene_stack.pop().release();
|
||||||
if (old_length - 1 === index + 1) {
|
if (old_length - 1 === index + 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scene_stack.length >= 1) {
|
if (scene_stack.length >= 1) {
|
||||||
var scene = scene_stack[scene_stack.length - 1];
|
let scene = scene_stack[scene_stack.length - 1];
|
||||||
scene.show();
|
scene.show();
|
||||||
} else {
|
} else {
|
||||||
throw "Scene stack is empty";
|
throw "Scene stack is empty";
|
||||||
@ -477,19 +475,19 @@ function pop_scene(index) {
|
|||||||
* @implements {Scene}
|
* @implements {Scene}
|
||||||
*/
|
*/
|
||||||
function LoginScene() {
|
function LoginScene() {
|
||||||
var html_scene = document.getElementById("loginscene");
|
let html_scene = document.getElementById("loginscene");
|
||||||
var form = html_scene.querySelector("[name=form]");
|
let form = html_scene.querySelector("[name=form]");
|
||||||
var user_form = html_scene.querySelector("[name=user]");
|
let user_form = html_scene.querySelector("[name=user]");
|
||||||
var password_form = html_scene.querySelector("[name=password]");
|
let password_form = html_scene.querySelector("[name=password]");
|
||||||
var error_form = html_scene.querySelector("[name=error]");
|
let error_form = html_scene.querySelector("[name=error]");
|
||||||
var logout_view = document.getElementById("logoutview");
|
let logout_view = document.getElementById("logoutview");
|
||||||
var logout_user_form = logout_view.querySelector("[name=user]");
|
let logout_user_form = logout_view.querySelector("[name=user]");
|
||||||
var logout_btn = logout_view.querySelector("[name=link]");
|
let logout_btn = logout_view.querySelector("[name=link]");
|
||||||
|
|
||||||
/** @type {?number} */ var scene_index = null;
|
/** @type {?number} */ let scene_index = null;
|
||||||
var user = "";
|
let user = "";
|
||||||
var error = "";
|
let error = "";
|
||||||
/** @type {?XMLHttpRequest} */ var principal_req = null;
|
/** @type {?XMLHttpRequest} */ let principal_req = null;
|
||||||
|
|
||||||
function read_form() {
|
function read_form() {
|
||||||
user = user_form.value;
|
user = user_form.value;
|
||||||
@ -504,7 +502,7 @@ function LoginScene() {
|
|||||||
function onlogin() {
|
function onlogin() {
|
||||||
try {
|
try {
|
||||||
read_form();
|
read_form();
|
||||||
var password = password_form.value;
|
let password = password_form.value;
|
||||||
if (user) {
|
if (user) {
|
||||||
error = "";
|
error = "";
|
||||||
// setup logout
|
// setup logout
|
||||||
@ -512,7 +510,7 @@ function LoginScene() {
|
|||||||
logout_btn.onclick = onlogout;
|
logout_btn.onclick = onlogout;
|
||||||
logout_user_form.textContent = user;
|
logout_user_form.textContent = user;
|
||||||
// Fetch principal
|
// Fetch principal
|
||||||
var loading_scene = new LoadingScene();
|
let loading_scene = new LoadingScene();
|
||||||
push_scene(loading_scene, false);
|
push_scene(loading_scene, false);
|
||||||
principal_req = get_principal(user, password, function(collection, error1) {
|
principal_req = get_principal(user, password, function(collection, error1) {
|
||||||
if (scene_index === null) {
|
if (scene_index === null) {
|
||||||
@ -524,13 +522,13 @@ function LoginScene() {
|
|||||||
pop_scene(scene_index);
|
pop_scene(scene_index);
|
||||||
} else {
|
} else {
|
||||||
// show collections
|
// show collections
|
||||||
var saved_user = user;
|
let saved_user = user;
|
||||||
user = "";
|
user = "";
|
||||||
if (typeof(sessionStorage) !== "undefined") {
|
if (typeof(sessionStorage) !== "undefined") {
|
||||||
sessionStorage.setItem("radicale_user", saved_user);
|
sessionStorage.setItem("radicale_user", saved_user);
|
||||||
sessionStorage.setItem("radicale_password", password);
|
sessionStorage.setItem("radicale_password", password);
|
||||||
}
|
}
|
||||||
var collections_scene = new CollectionsScene(
|
let collections_scene = new CollectionsScene(
|
||||||
saved_user, password, collection, function(error1) {
|
saved_user, password, collection, function(error1) {
|
||||||
error = error1;
|
error = error1;
|
||||||
user = saved_user;
|
user = saved_user;
|
||||||
@ -572,7 +570,7 @@ function LoginScene() {
|
|||||||
fill_form();
|
fill_form();
|
||||||
form.onsubmit = onlogin;
|
form.onsubmit = onlogin;
|
||||||
html_scene.style.display = "block";
|
html_scene.style.display = "block";
|
||||||
var direct_login = false;
|
let direct_login = false;
|
||||||
if (typeof(sessionStorage) !== "undefined") {
|
if (typeof(sessionStorage) !== "undefined") {
|
||||||
// Try direct login when scene is shown for the first time and credentials are stored
|
// Try direct login when scene is shown for the first time and credentials are stored
|
||||||
if (scene_index === null && sessionStorage.getItem("radicale_user")) {
|
if (scene_index === null && sessionStorage.getItem("radicale_user")) {
|
||||||
@ -612,7 +610,7 @@ function LoginScene() {
|
|||||||
* @implements {Scene}
|
* @implements {Scene}
|
||||||
*/
|
*/
|
||||||
function LoadingScene() {
|
function LoadingScene() {
|
||||||
var html_scene = document.getElementById("loadingscene");
|
let html_scene = document.getElementById("loadingscene");
|
||||||
this.show = function() {
|
this.show = function() {
|
||||||
html_scene.style.display = "block";
|
html_scene.style.display = "block";
|
||||||
};
|
};
|
||||||
@ -632,26 +630,26 @@ function LoadingScene() {
|
|||||||
* scene is popped.
|
* scene is popped.
|
||||||
*/
|
*/
|
||||||
function CollectionsScene(user, password, collection, onerror) {
|
function CollectionsScene(user, password, collection, onerror) {
|
||||||
var html_scene = document.getElementById("collectionsscene");
|
let html_scene = document.getElementById("collectionsscene");
|
||||||
var template = html_scene.querySelector("[name=collectiontemplate]");
|
let template = html_scene.querySelector("[name=collectiontemplate]");
|
||||||
var new_btn = html_scene.querySelector("[name=new]");
|
let new_btn = html_scene.querySelector("[name=new]");
|
||||||
var upload_btn = html_scene.querySelector("[name=upload]");
|
let upload_btn = html_scene.querySelector("[name=upload]");
|
||||||
|
|
||||||
/** @type {?number} */ var scene_index = null;
|
/** @type {?number} */ let scene_index = null;
|
||||||
var saved_template_display = null;
|
let saved_template_display = null;
|
||||||
/** @type {?XMLHttpRequest} */ var collections_req = null;
|
/** @type {?XMLHttpRequest} */ let collections_req = null;
|
||||||
/** @type {?Array<Collection>} */ var collections = null;
|
/** @type {?Array<Collection>} */ let collections = null;
|
||||||
/** @type {Array<Node>} */ var nodes = [];
|
/** @type {Array<Node>} */ let nodes = [];
|
||||||
var filesInput = document.createElement("input");
|
let filesInput = document.createElement("input");
|
||||||
filesInput.setAttribute("type", "file");
|
filesInput.setAttribute("type", "file");
|
||||||
filesInput.setAttribute("accept", ".ics, .vcf");
|
filesInput.setAttribute("accept", ".ics, .vcf");
|
||||||
filesInput.setAttribute("multiple", "");
|
filesInput.setAttribute("multiple", "");
|
||||||
var filesInputForm = document.createElement("form");
|
let filesInputForm = document.createElement("form");
|
||||||
filesInputForm.appendChild(filesInput);
|
filesInputForm.appendChild(filesInput);
|
||||||
|
|
||||||
function onnew() {
|
function onnew() {
|
||||||
try {
|
try {
|
||||||
var create_collection_scene = new CreateEditCollectionScene(user, password, collection);
|
let create_collection_scene = new CreateEditCollectionScene(user, password, collection);
|
||||||
push_scene(create_collection_scene, false);
|
push_scene(create_collection_scene, false);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -666,9 +664,9 @@ function CollectionsScene(user, password, collection, onerror) {
|
|||||||
|
|
||||||
function onfileschange(e) {
|
function onfileschange(e) {
|
||||||
try {
|
try {
|
||||||
var files = filesInput.files;
|
let files = filesInput.files;
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
var upload_scene = new UploadCollectionScene(user, password, collection, files);
|
let upload_scene = new UploadCollectionScene(user, password, collection, files);
|
||||||
push_scene(upload_scene);
|
push_scene(upload_scene);
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
@ -679,7 +677,7 @@ function CollectionsScene(user, password, collection, onerror) {
|
|||||||
|
|
||||||
function onedit(collection) {
|
function onedit(collection) {
|
||||||
try {
|
try {
|
||||||
var edit_collection_scene = new CreateEditCollectionScene(user, password, collection);
|
let edit_collection_scene = new CreateEditCollectionScene(user, password, collection);
|
||||||
push_scene(edit_collection_scene, false);
|
push_scene(edit_collection_scene, false);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -689,7 +687,7 @@ function CollectionsScene(user, password, collection, onerror) {
|
|||||||
|
|
||||||
function ondelete(collection) {
|
function ondelete(collection) {
|
||||||
try {
|
try {
|
||||||
var delete_collection_scene = new DeleteCollectionScene(user, password, collection);
|
let delete_collection_scene = new DeleteCollectionScene(user, password, collection);
|
||||||
push_scene(delete_collection_scene, false);
|
push_scene(delete_collection_scene, false);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -699,19 +697,19 @@ function CollectionsScene(user, password, collection, onerror) {
|
|||||||
|
|
||||||
function show_collections(collections) {
|
function show_collections(collections) {
|
||||||
collections.forEach(function (collection) {
|
collections.forEach(function (collection) {
|
||||||
var node = template.cloneNode(true);
|
let node = template.cloneNode(true);
|
||||||
var title_form = node.querySelector("[name=title]");
|
let title_form = node.querySelector("[name=title]");
|
||||||
var description_form = node.querySelector("[name=description]");
|
let description_form = node.querySelector("[name=description]");
|
||||||
var url_form = node.querySelector("[name=url]");
|
let url_form = node.querySelector("[name=url]");
|
||||||
var color_form = node.querySelector("[name=color]");
|
let color_form = node.querySelector("[name=color]");
|
||||||
var delete_btn = node.querySelector("[name=delete]");
|
let delete_btn = node.querySelector("[name=delete]");
|
||||||
var edit_btn = node.querySelector("[name=edit]");
|
let edit_btn = node.querySelector("[name=edit]");
|
||||||
if (collection.color) {
|
if (collection.color) {
|
||||||
color_form.style.color = collection.color;
|
color_form.style.color = collection.color;
|
||||||
} else {
|
} else {
|
||||||
color_form.style.display = "none";
|
color_form.style.display = "none";
|
||||||
}
|
}
|
||||||
var possible_types = [CollectionType.ADDRESSBOOK];
|
let possible_types = [CollectionType.ADDRESSBOOK];
|
||||||
[CollectionType.CALENDAR, ""].forEach(function(e) {
|
[CollectionType.CALENDAR, ""].forEach(function(e) {
|
||||||
[CollectionType.union(e, CollectionType.JOURNAL), e].forEach(function(e) {
|
[CollectionType.union(e, CollectionType.JOURNAL), e].forEach(function(e) {
|
||||||
[CollectionType.union(e, CollectionType.TASKS), e].forEach(function(e) {
|
[CollectionType.union(e, CollectionType.TASKS), e].forEach(function(e) {
|
||||||
@ -728,7 +726,7 @@ function CollectionsScene(user, password, collection, onerror) {
|
|||||||
});
|
});
|
||||||
title_form.textContent = collection.displayname || collection.href;
|
title_form.textContent = collection.displayname || collection.href;
|
||||||
description_form.textContent = collection.description;
|
description_form.textContent = collection.description;
|
||||||
var href = SERVER + collection.href;
|
let href = SERVER + collection.href;
|
||||||
url_form.href = href;
|
url_form.href = href;
|
||||||
url_form.textContent = href;
|
url_form.textContent = href;
|
||||||
delete_btn.onclick = function(ev) {return ondelete(collection);};
|
delete_btn.onclick = function(ev) {return ondelete(collection);};
|
||||||
@ -740,7 +738,7 @@ function CollectionsScene(user, password, collection, onerror) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
var loading_scene = new LoadingScene();
|
let loading_scene = new LoadingScene();
|
||||||
push_scene(loading_scene, false);
|
push_scene(loading_scene, false);
|
||||||
collections_req = get_collections(user, password, collection, function(collections1, error) {
|
collections_req = get_collections(user, password, collection, function(collections1, error) {
|
||||||
if (scene_index === null) {
|
if (scene_index === null) {
|
||||||
@ -806,19 +804,19 @@ function CollectionsScene(user, password, collection, onerror) {
|
|||||||
* @param {Array<File>} files
|
* @param {Array<File>} files
|
||||||
*/
|
*/
|
||||||
function UploadCollectionScene(user, password, collection, files) {
|
function UploadCollectionScene(user, password, collection, files) {
|
||||||
var html_scene = document.getElementById("uploadcollectionscene");
|
let html_scene = document.getElementById("uploadcollectionscene");
|
||||||
var template = html_scene.querySelector("[name=filetemplate]");
|
let template = html_scene.querySelector("[name=filetemplate]");
|
||||||
var template_pending_form = template.querySelector("[name=pending]");
|
let template_pending_form = template.querySelector("[name=pending]");
|
||||||
var template_success_form = template.querySelector("[name=success]");
|
let template_success_form = template.querySelector("[name=success]");
|
||||||
var template_error_form = template.querySelector("[name=error]");
|
let template_error_form = template.querySelector("[name=error]");
|
||||||
var saved_template_display = null;
|
let saved_template_display = null;
|
||||||
var close_btn = html_scene.querySelector("[name=close]");
|
let close_btn = html_scene.querySelector("[name=close]");
|
||||||
var saved_close_btn_display = null;
|
let saved_close_btn_display = null;
|
||||||
|
|
||||||
/** @type {?number} */ var scene_index = null;
|
/** @type {?number} */ let scene_index = null;
|
||||||
/** @type {?XMLHttpRequest} */ var upload_req = null;
|
/** @type {?XMLHttpRequest} */ let upload_req = null;
|
||||||
/** @type {Array<string>} */ var errors = [];
|
/** @type {Array<string>} */ let errors = [];
|
||||||
/** @type {?Array<Node>} */ var nodes = null;
|
/** @type {?Array<Node>} */ let nodes = null;
|
||||||
|
|
||||||
function upload_next() {
|
function upload_next() {
|
||||||
try {
|
try {
|
||||||
@ -829,8 +827,8 @@ function UploadCollectionScene(user, password, collection, files) {
|
|||||||
close_btn.style.display = saved_close_btn_display;
|
close_btn.style.display = saved_close_btn_display;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var file = files[errors.length];
|
let file = files[errors.length];
|
||||||
var upload_href = collection.href + random_uuid() + "/";
|
let upload_href = collection.href + random_uuid() + "/";
|
||||||
upload_req = upload_collection(user, password, upload_href, file, function(error) {
|
upload_req = upload_collection(user, password, upload_href, file, function(error) {
|
||||||
if (scene_index === null) {
|
if (scene_index === null) {
|
||||||
return;
|
return;
|
||||||
@ -860,9 +858,9 @@ function UploadCollectionScene(user, password, collection, files) {
|
|||||||
if (nodes === null) {
|
if (nodes === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var pending_form = nodes[i].querySelector("[name=pending]");
|
let pending_form = nodes[i].querySelector("[name=pending]");
|
||||||
var success_form = nodes[i].querySelector("[name=success]");
|
let success_form = nodes[i].querySelector("[name=success]");
|
||||||
var error_form = nodes[i].querySelector("[name=error]");
|
let error_form = nodes[i].querySelector("[name=error]");
|
||||||
if (errors.length > i) {
|
if (errors.length > i) {
|
||||||
pending_form.style.display = "none";
|
pending_form.style.display = "none";
|
||||||
if (errors[i]) {
|
if (errors[i]) {
|
||||||
@ -890,10 +888,10 @@ function UploadCollectionScene(user, password, collection, files) {
|
|||||||
}
|
}
|
||||||
close_btn.onclick = onclose;
|
close_btn.onclick = onclose;
|
||||||
nodes = [];
|
nodes = [];
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
var file = files[i];
|
let file = files[i];
|
||||||
var node = template.cloneNode(true);
|
let node = template.cloneNode(true);
|
||||||
var name_form = node.querySelector("[name=name]");
|
let name_form = node.querySelector("[name=name]");
|
||||||
name_form.textContent = file.name;
|
name_form.textContent = file.name;
|
||||||
node.style.display = saved_template_display;
|
node.style.display = saved_template_display;
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
@ -933,20 +931,20 @@ function UploadCollectionScene(user, password, collection, files) {
|
|||||||
* @param {Collection} collection
|
* @param {Collection} collection
|
||||||
*/
|
*/
|
||||||
function DeleteCollectionScene(user, password, collection) {
|
function DeleteCollectionScene(user, password, collection) {
|
||||||
var html_scene = document.getElementById("deletecollectionscene");
|
let html_scene = document.getElementById("deletecollectionscene");
|
||||||
var title_form = html_scene.querySelector("[name=title]");
|
let title_form = html_scene.querySelector("[name=title]");
|
||||||
var error_form = html_scene.querySelector("[name=error]");
|
let error_form = html_scene.querySelector("[name=error]");
|
||||||
var delete_btn = html_scene.querySelector("[name=delete]");
|
let delete_btn = html_scene.querySelector("[name=delete]");
|
||||||
var cancel_btn = html_scene.querySelector("[name=cancel]");
|
let cancel_btn = html_scene.querySelector("[name=cancel]");
|
||||||
var no_btn = html_scene.querySelector("[name=no]");
|
let no_btn = html_scene.querySelector("[name=no]");
|
||||||
|
|
||||||
/** @type {?number} */ var scene_index = null;
|
/** @type {?number} */ let scene_index = null;
|
||||||
/** @type {?XMLHttpRequest} */ var delete_req = null;
|
/** @type {?XMLHttpRequest} */ let delete_req = null;
|
||||||
var error = "";
|
let error = "";
|
||||||
|
|
||||||
function ondelete() {
|
function ondelete() {
|
||||||
try {
|
try {
|
||||||
var loading_scene = new LoadingScene();
|
let loading_scene = new LoadingScene();
|
||||||
push_scene(loading_scene);
|
push_scene(loading_scene);
|
||||||
delete_req = delete_collection(user, password, collection, function(error1) {
|
delete_req = delete_collection(user, password, collection, function(error1) {
|
||||||
if (scene_index === null) {
|
if (scene_index === null) {
|
||||||
@ -1004,7 +1002,7 @@ function DeleteCollectionScene(user, password, collection) {
|
|||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
function randHex(length) {
|
function randHex(length) {
|
||||||
var s = Math.floor(Math.random() * Math.pow(16, length)).toString(16);
|
let s = Math.floor(Math.random() * Math.pow(16, length)).toString(16);
|
||||||
while (s.length < length) {
|
while (s.length < length) {
|
||||||
s = "0" + s;
|
s = "0" + s;
|
||||||
}
|
}
|
||||||
@ -1021,36 +1019,35 @@ function randHex(length) {
|
|||||||
* Otherwise the collection will be edited.
|
* Otherwise the collection will be edited.
|
||||||
*/
|
*/
|
||||||
function CreateEditCollectionScene(user, password, collection) {
|
function CreateEditCollectionScene(user, password, collection) {
|
||||||
var edit = collection.type !== CollectionType.PRINCIPAL;
|
let edit = collection.type !== CollectionType.PRINCIPAL;
|
||||||
var html_scene = document.getElementById(edit ? "editcollectionscene" : "createcollectionscene");
|
let html_scene = document.getElementById(edit ? "editcollectionscene" : "createcollectionscene");
|
||||||
var title_form = edit ? html_scene.querySelector("[name=title]") : null;
|
let title_form = edit ? html_scene.querySelector("[name=title]") : null;
|
||||||
var error_form = html_scene.querySelector("[name=error]");
|
let error_form = html_scene.querySelector("[name=error]");
|
||||||
var displayname_form = html_scene.querySelector("[name=displayname]");
|
let displayname_form = html_scene.querySelector("[name=displayname]");
|
||||||
var description_form = html_scene.querySelector("[name=description]");
|
let description_form = html_scene.querySelector("[name=description]");
|
||||||
var type_form = html_scene.querySelector("[name=type]");
|
let type_form = html_scene.querySelector("[name=type]");
|
||||||
var color_form = html_scene.querySelector("[name=color]");
|
let color_form = html_scene.querySelector("[name=color]");
|
||||||
var submit_btn = html_scene.querySelector("[name=submit]");
|
let submit_btn = html_scene.querySelector("[name=submit]");
|
||||||
var cancel_btn = html_scene.querySelector("[name=cancel]");
|
let cancel_btn = html_scene.querySelector("[name=cancel]");
|
||||||
|
|
||||||
/** @type {?number} */ var scene_index = null;
|
/** @type {?number} */ let scene_index = null;
|
||||||
/** @type {?XMLHttpRequest} */ var create_edit_req = null;
|
/** @type {?XMLHttpRequest} */ let create_edit_req = null;
|
||||||
var error = "";
|
let error = "";
|
||||||
/** @type {?Element} */ var saved_type_form = null;
|
/** @type {?Element} */ let saved_type_form = null;
|
||||||
|
|
||||||
var href = edit ? collection.href : collection.href + random_uuid() + "/";
|
let href = edit ? collection.href : collection.href + random_uuid() + "/";
|
||||||
var displayname = edit ? collection.displayname : "";
|
let displayname = edit ? collection.displayname : "";
|
||||||
var description = edit ? collection.description : "";
|
let description = edit ? collection.description : "";
|
||||||
var type = edit ? collection.type : CollectionType.CALENDAR_JOURNAL_TASKS;
|
let type = edit ? collection.type : CollectionType.CALENDAR_JOURNAL_TASKS;
|
||||||
var color = edit && collection.color ? collection.color : "#" + randHex(6);
|
let color = edit && collection.color ? collection.color : "#" + randHex(6);
|
||||||
|
|
||||||
function remove_invalid_types() {
|
function remove_invalid_types() {
|
||||||
if (!edit) {
|
if (!edit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/** @type {HTMLOptionsCollection} */ var options = type_form.options;
|
/** @type {HTMLOptionsCollection} */ let options = type_form.options;
|
||||||
// remove all options that are not supersets
|
// remove all options that are not supersets
|
||||||
var i;
|
for (let i = options.length - 1; i >= 0; i--) {
|
||||||
for (i = options.length - 1; i >= 0; i--) {
|
|
||||||
if (!CollectionType.is_subset(type, options[i].value)) {
|
if (!CollectionType.is_subset(type, options[i].value)) {
|
||||||
options.remove(i);
|
options.remove(i);
|
||||||
}
|
}
|
||||||
@ -1075,9 +1072,9 @@ function CreateEditCollectionScene(user, password, collection) {
|
|||||||
function onsubmit() {
|
function onsubmit() {
|
||||||
try {
|
try {
|
||||||
read_form();
|
read_form();
|
||||||
var sane_color = color.trim();
|
let sane_color = color.trim();
|
||||||
if (sane_color) {
|
if (sane_color) {
|
||||||
var color_match = COLOR_RE.exec(sane_color);
|
let color_match = COLOR_RE.exec(sane_color);
|
||||||
if (!color_match) {
|
if (!color_match) {
|
||||||
error = "Invalid color";
|
error = "Invalid color";
|
||||||
fill_form();
|
fill_form();
|
||||||
@ -1085,10 +1082,10 @@ function CreateEditCollectionScene(user, password, collection) {
|
|||||||
}
|
}
|
||||||
sane_color = color_match[1];
|
sane_color = color_match[1];
|
||||||
}
|
}
|
||||||
var loading_scene = new LoadingScene();
|
let loading_scene = new LoadingScene();
|
||||||
push_scene(loading_scene);
|
push_scene(loading_scene);
|
||||||
var collection = new Collection(href, type, displayname, description, sane_color);
|
let collection = new Collection(href, type, displayname, description, sane_color);
|
||||||
var callback = function(error1) {
|
let callback = function(error1) {
|
||||||
if (scene_index === null) {
|
if (scene_index === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user