1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
<script>
import { onMount } from "svelte";
import dialogPolyfill from 'dialog-polyfill'
import Button from "../../ComponentLib/Button/Button.svelte";
import PrettyVar from "../../ComponentLib/PrettyVar.svelte";
import { openSocket, authorizedSocket } from "../../stores/socketStore.js";
import { notif } from "../../stores/notifs";
let modal;
let activeTab = 0;
let name;
let sourceMode;
function open() {
modal.showModal()
}
function register(node) {
dialogPolyfill.registerDialog(node);
}
function createMode() {
let template = "template/base";
if (activeTab == 1) {
template = sourceMode;
}
authorizedSocket.emit("mode:create", name, template, (res) => {
if (!res.success) {
notif({title: "Error", text: "Could not create mode...", type: "danger"})
};
modal.close();
});
}
let builtinModes = [];
let userModes = [];
// let remoteModes = [];
openSocket.on("modelist", (modes) => {
builtinModes = [];
for (let i = 0; i < modes.length; i++) {
if (modes[i].substr(0, 8) === "builtin/") {
builtinModes.push([modes[i], modes[i].replace("builtin/", "")]);
}
if (modes[i].substr(0, 5) === "user/") {
userModes.push([modes[i], modes[i].replace("user/", "")]);
}
// if (modes[i].substr(0, 6) === "remote") {
// remotes.push(modes[i].replace("", ""));
// }
}
});
onMount(async() => {
openSocket.emit("modelist:get");
})
</script>
<style>
dialog {
padding: 0;
border: none;
border-radius: 15px;
}
.tabs {
display: flex;
width: 100%;
}
.tabs i {
position: relative;
flex-grow: 1;
text-align: center;
font-size: 20px;
padding: 15px;
}
.tabs i:hover {
color: var(--theme-primary);
}
.tabs i.active {
color: var(--theme-primary);
}
.tabs > *:not(:last-child):after {
content: "";
position: absolute;
width: 1px;
height: 43%;
border-left: 0.1px solid var(--grey-400);
left: 100%;
}
.divider-h {
margin-left: 15px;
margin-right: 15px;
border-top: 0.01px solid var(--grey-400);
}
.content {
padding: 15px;
box-sizing: border-box;
}
input, select {
display: block;
width: 100%;
box-sizing: border-box;
}
.buttons {
padding: 0 15px 15px 15px;
display: flex;
}
.buttons > * {
flex-grow: 1;
}
.buttons > *:not(:last-child) {
margin-right: 5px;
}
.buttons > *:not(:first-child) {
margin-left: 5px;
}
</style>
<slot name="trigger" {open}></slot>
<dialog bind:this={modal} use:register>
<div class="tabs">
<i class:active={activeTab == 0} on:click={() => { activeTab = 0; }} class="far fa-file"></i>
<i class:active={activeTab == 1} on:click={() => { activeTab = 1; }} class="far fa-clone"></i>
</div>
<div class="divider-h"></div>
<div class="content">
{#if [0, 1].includes(activeTab)}
<div>
<label for="fname">Mode name</label>
<input type="text" id="fname" placeholder="My_Awesome_New_Mode" bind:value={name} />
{#if activeTab == 1}
<label for="sourcemode">Source</label>
<select bind:value={sourceMode}>
<optgroup label="builtin">
{#each builtinModes as mode}
<option value={mode[0]}><PrettyVar varText={mode[1]} /></option>
{/each}
</optgroup>
<optgroup label="user">
{#each userModes as mode}
<option value={mode[0]}><PrettyVar varText={mode[1]} /></option>
{/each}
</optgroup>
</select>
{/if}
</div>
{/if}
</div>
<div class="buttons">
<div><Button fullWidth=true on:click={() => modal.close() } color={"var(--theme-primary)"} backgroundColor={"white"}>Cancel</Button></div>
<div><Button fullWidth=true on:click={createMode}>Create</Button></div>
</div>
</dialog>
|