Project

General

Profile

Download (4.43 KB) Statistics
| Branch: | Tag: | Revision:

haketilo / html / settings.js @ 4c6a2323

1
/**
2
 * This file is part of Haketilo.
3
 *
4
 * Function: Driving Haketilo's settings page.
5
 *
6
 * Copyright (C) 2022 Wojtek Kosior
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * As additional permission under GNU GPL version 3 section 7, you
19
 * may distribute forms of that code without the copy of the GNU
20
 * GPL normally required by section 4, provided you include this
21
 * license notice and, in case of non-source distribution, a URL
22
 * through which recipients can access the Corresponding Source.
23
 * If you modify file(s) with this exception, you may extend this
24
 * exception to your version of the file(s), but you are not
25
 * obligated to do so. If you do not wish to do so, delete this
26
 * exception statement from your version.
27
 *
28
 * As a special exception to the GPL, any HTML file which merely
29
 * makes function calls to this code, and for that purpose
30
 * includes it by reference shall be deemed a separate work for
31
 * copyright law purposes. If you modify this code, you may extend
32
 * this exception to your version of the code, but you are not
33
 * obligated to do so. If you do not wish to do so, delete this
34
 * exception statement from your version.
35
 *
36
 * You should have received a copy of the GNU General Public License
37
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
38
 *
39
 * I, Wojtek Kosior, thereby promise not to sue for violation of this file's
40
 * license. Although I request that you do not make use of this code in a
41
 * proprietary program, I am not going to enforce this in court.
42
 */
43

    
44
#IMPORT html/dialog.js
45

    
46
#FROM html/DOM_helpers.js     IMPORT by_id
47
#FROM html/text_entry_list.js IMPORT blocking_allowing_lists, repo_list
48
#FROM html/item_list.js       IMPORT mapping_list, resource_list
49
#FROM html/payload_create.js  IMPORT payload_create_form
50

    
51
let tab_names = ["blocking", "mappings", "resources", "new_payload", "repos"];
52
let current_tab_name = "new_payload";
53

    
54
const [tabs, heads] = [{}, {}];
55

    
56
for (const tab_name of tab_names) {
57
    tabs[tab_name] = by_id(`${tab_name}_tab`);
58
    heads[tab_name] = by_id(`${tab_name}_head`);
59
}
60

    
61
function switch_to_tab(target_tab_name) {
62
    if (current_tab_name == target_tab_name)
63
	return;
64

    
65
    tabs[current_tab_name].classList.remove("active_tab");
66
    heads[current_tab_name].classList.remove("active_head");
67

    
68
    current_tab_name = target_tab_name;
69
    tabs[current_tab_name].classList.add("active_tab");
70
    heads[current_tab_name].classList.add("active_head");
71
}
72

    
73
for (const [tab_name, head] of Object.entries(heads))
74
    head.addEventListener("click", () => switch_to_tab(tab_name));
75

    
76
async function set_up_blocking_tab() {
77
    const containers = ["editable", "dialog"]
78
	  .map(n => by_id(`blocking_${n}_container`));
79

    
80
    function show_container(idx) {
81
	containers[idx].classList.remove("hide");
82
	containers[1 - idx].classList.add("hide");
83
    }
84

    
85
    const dialog_ctx = dialog.make(...[1, 0].map(n => () => show_container(n)));
86
    containers[1].append(dialog_ctx.main_div);
87

    
88
    const [blocking_list, allowing_list] =
89
	  await blocking_allowing_lists(dialog_ctx);
90

    
91
    by_id("blocking_list_container").append(blocking_list.main_div);
92
    by_id("allowing_list_container").append(allowing_list.main_div);
93
}
94

    
95
async function set_up_mappings_tab() {
96
    tabs["mappings"].append((await mapping_list()).main_div);
97
}
98

    
99
async function set_up_resources_tab() {
100
    tabs["resources"].append((await resource_list()).main_div);
101
}
102

    
103
function set_up_new_payload_tab() {
104
    tabs["new_payload"].append(payload_create_form().main_div);
105
}
106

    
107
async function set_up_repos_tab() {
108
    const containers = ["list", "dialog"]
109
	  .map(n => by_id(`repos_${n}_container`));
110

    
111
    function show_container(idx) {
112
	containers[idx].classList.remove("hide");
113
	containers[1 - idx].classList.add("hide");
114
    }
115

    
116
    const dialog_ctx = dialog.make(...[1, 0].map(n => () => show_container(n)));
117
    containers[1].append(dialog_ctx.main_div);
118
    containers[0].append((await repo_list(dialog_ctx)).main_div);
119
}
120

    
121
set_up_blocking_tab();
122
set_up_mappings_tab();
123
set_up_resources_tab();
124
set_up_new_payload_tab();
125
set_up_repos_tab();
(22-22/24)