remove unused code

This commit is contained in:
Unrud 2018-08-21 18:43:42 +02:00
parent c845c5a372
commit 464e4ca920

View File

@ -31,13 +31,6 @@ var SERVER = (location.protocol + '//' + location.hostname +
*/ */
var ROOT_PATH = location.pathname.replace(new RegExp("/+[^/]+/*(/index\\.html?)?$"), "") + '/'; var ROOT_PATH = location.pathname.replace(new RegExp("/+[^/]+/*(/index\\.html?)?$"), "") + '/';
/**
* time between updates of collections (milliseconds)
* @const
* @type {?int}
*/
var UPDATE_INTERVAL = null;
/** /**
* Regex to match and normalize color * Regex to match and normalize color
* @const * @const
@ -492,7 +485,6 @@ function LoginScene() {
var logout_view = document.getElementById("logoutview"); var logout_view = document.getElementById("logoutview");
var logout_user_form = logout_view.querySelector("[name=user]"); var logout_user_form = logout_view.querySelector("[name=user]");
var logout_btn = logout_view.querySelector("[name=link]"); var logout_btn = logout_view.querySelector("[name=link]");
var first_show = true;
/** @type {?number} */ var scene_index = null; /** @type {?number} */ var scene_index = null;
var user = ""; var user = "";
@ -569,15 +561,21 @@ function LoginScene() {
return false; return false;
} }
function remove_logout() {
logout_view.style.display = "none";
logout_btn.onclick = null;
logout_user_form.textContent = "";
}
this.show = function() { this.show = function() {
this.release(); remove_logout();
fill_form(); fill_form();
form.onsubmit = onlogin; form.onsubmit = onlogin;
scene_index = scene_stack.length - 1;
html_scene.style.display = "block"; html_scene.style.display = "block";
var direct_login = false; var direct_login = false;
if (typeof(sessionStorage) !== "undefined") { if (typeof(sessionStorage) !== "undefined") {
if (first_show && sessionStorage.getItem("radicale_user")) { // Try direct login when scene is shown for the first time and credentials are stored
if (scene_index === null && sessionStorage.getItem("radicale_user")) {
user_form.value = sessionStorage.getItem("radicale_user"); user_form.value = sessionStorage.getItem("radicale_user");
password_form.value = sessionStorage.getItem("radicale_password"); password_form.value = sessionStorage.getItem("radicale_password");
direct_login = true; direct_login = true;
@ -586,7 +584,7 @@ function LoginScene() {
sessionStorage.setItem("radicale_password", ""); sessionStorage.setItem("radicale_password", "");
} }
} }
first_show = false; scene_index = scene_stack.length - 1;
if (direct_login) { if (direct_login) {
onlogin(); onlogin();
} else { } else {
@ -605,10 +603,7 @@ function LoginScene() {
principal_req.abort(); principal_req.abort();
principal_req = null; principal_req = null;
} }
// remove logout remove_logout();
logout_view.style.display = "none";
logout_btn.onclick = null;
logout_user_form.textContent = "";
}; };
} }
@ -645,8 +640,6 @@ function CollectionsScene(user, password, collection, onerror) {
/** @type {?number} */ var scene_index = null; /** @type {?number} */ var scene_index = null;
var saved_template_display = null; var saved_template_display = null;
/** @type {?XMLHttpRequest} */ var collections_req = null; /** @type {?XMLHttpRequest} */ var collections_req = null;
var timer = null;
var from_update = false;
/** @type {?Array<Collection>} */ var collections = null; /** @type {?Array<Collection>} */ var collections = null;
/** @type {Array<Node>} */ var nodes = []; /** @type {Array<Node>} */ var nodes = [];
var filesInput = document.createElement("input"); var filesInput = document.createElement("input");
@ -705,10 +698,6 @@ function CollectionsScene(user, password, collection, onerror) {
} }
function show_collections(collections) { function show_collections(collections) {
nodes.forEach(function(node) {
template.parentNode.removeChild(node);
});
nodes = [];
collections.forEach(function (collection) { collections.forEach(function (collection) {
var node = template.cloneNode(true); var node = template.cloneNode(true);
var title_form = node.querySelector("[name=title]"); var title_form = node.querySelector("[name=title]");
@ -751,10 +740,8 @@ function CollectionsScene(user, password, collection, onerror) {
} }
function update() { function update() {
if (collections === null) { var loading_scene = new LoadingScene();
var 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) {
return; return;
@ -764,17 +751,8 @@ function CollectionsScene(user, password, collection, onerror) {
onerror(error); onerror(error);
pop_scene(scene_index - 1); pop_scene(scene_index - 1);
} else { } else {
var old_collections = collections;
collections = collections1; collections = collections1;
if (UPDATE_INTERVAL !== null) { pop_scene(scene_index);
timer = window.setTimeout(update, UPDATE_INTERVAL);
}
from_update = true;
if (old_collections === null) {
pop_scene(scene_index);
} else {
show_collections(collections);
}
} }
}); });
} }
@ -787,40 +765,26 @@ function CollectionsScene(user, password, collection, onerror) {
upload_btn.onclick = onupload; upload_btn.onclick = onupload;
filesInputForm.reset(); filesInputForm.reset();
filesInput.onchange = onfileschange; filesInput.onchange = onfileschange;
if (scene_index === null) { if (collections === null) {
scene_index = scene_stack.length - 1;
if (collections === null && collections_req !== null) {
pop_scene(scene_index - 1);
return;
}
update(); update();
} else if (collections === null) {
pop_scene(scene_index - 1);
} else { } else {
if (from_update) { // from update loading scene
show_collections(collections); show_collections(collections);
} else {
collections = null;
update();
}
} }
}; };
this.hide = function() { this.hide = function() {
html_scene.style.display = "none"; html_scene.style.display = "none";
template.style.display = saved_template_display; template.style.display = saved_template_display;
scene_index = scene_stack.length - 1;
new_btn.onclick = null; new_btn.onclick = null;
upload_btn.onclick = null; upload_btn.onclick = null;
filesInput.onchange = null; filesInput.onchange = null;
if (timer !== null) { collections = null;
window.clearTimeout(timer); // remove collection
timer = null; nodes.forEach(function(node) {
} template.parentNode.removeChild(node);
from_update = false; });
if (collections !== null && collections_req !== null) { nodes = [];
collections_req.abort();
collections_req = null;
}
show_collections([]);
}; };
this.release = function() { this.release = function() {
scene_index = null; scene_index = null;
@ -828,6 +792,7 @@ function CollectionsScene(user, password, collection, onerror) {
collections_req.abort(); collections_req.abort();
collections_req = null; collections_req = null;
} }
collections = null;
filesInputForm.reset(); filesInputForm.reset();
}; };
} }