|
6 | 6 | import IntInput from '../IntInput.svelte'; |
7 | 7 | import BoolInput from '../BoolInput.svelte'; |
8 | 8 | import defaultSettings from '../../../app/defaultSettings.js'; |
| 9 | +import IconButton from '../IconButton.svelte'; |
9 | 10 |
|
10 | 11 | const tabs = ['General', 'Game Settings', 'Backups', 'Player Permissions', 'Advanced', 'Admins']; |
11 | 12 | let currentTab = 0; |
|
88 | 89 | .then(json => { |
89 | 90 | admins = json; |
90 | 91 | }); |
| 92 | +
|
| 93 | + let permissionLevel = 3; |
| 94 | + let isEditingAdmin = false; |
| 95 | + let editingAdmin = {}; |
| 96 | + function editAdmin(id){ |
| 97 | + isEditingAdmin = true; |
| 98 | + editingAdmin.id = id; |
| 99 | + editingAdmin.name = admins[id].name; |
| 100 | + editingAdmin.level = admins[id].level; |
| 101 | + } |
| 102 | + function sendEditAdmin(){ |
| 103 | + let body = { |
| 104 | + name: editingAdmin.name, |
| 105 | + level: editingAdmin.level |
| 106 | + }; |
| 107 | + if(editingAdmin.settingPassword && editingAdmin.password == editingAdmin.confirmPassword) { |
| 108 | + body.password = editingAdmin.password; |
| 109 | + } |
| 110 | + fetch(`/api/changeAdmin`, {cache: 'no-cache', method: 'post', headers: {'Content-Type': 'text/json'}, body: JSON.stringify(body)}) |
| 111 | + .then(response => { |
| 112 | + |
| 113 | + }); |
| 114 | + } |
91 | 115 | </script> |
92 | 116 |
|
93 | 117 | <div class="main" in:fly="{{ x: 200, duration: 600 }}" out:fly="{{ x: -200, duration: 600 }}"> |
|
164 | 188 | <BoolInput bind:value={settings.texturepackRequired} name="Texturepack Required"></BoolInput> |
165 | 189 | <BoolInput bind:value={settings.contentLogFileEnabled} name="Content Log File Enabled"></BoolInput> |
166 | 190 | {:else if currentTab == 5} |
167 | | - {#each admins as admin} |
168 | | - <div class='admin'> |
169 | | - <p class='admin-name'>{admin.name}</p> |
170 | | - <p class='admin-level'> |
171 | | - {#if admins.level == 1} |
172 | | - Player Manager |
173 | | - {:else if admins.level == 2} |
174 | | - Server Manager |
175 | | - {:else if admin.level == 3} |
176 | | - Owner |
177 | | - {/if} |
178 | | - </p> |
| 191 | + {#if isEditingAdmin} |
| 192 | + <div> |
| 193 | + <p class='admin-name'>{editingAdmin.name}</p> |
| 194 | + {#if permissionLevel == 3} |
| 195 | + <EnumInput bind:value={editingAdmin.level} name="Role" options={[1, 2, 3]} optionsDisplay={['Player Manager', 'Server Manager', 'Owner']}></EnumInput> |
| 196 | + {/if} |
| 197 | + {#if editingAdmin.settingPassword} |
| 198 | + <TextInput name="password" bind:value={editingAdmin.password} password>Set Password</TextInput> |
| 199 | + <TextInput name="confirm password" bind:value={editingAdmin.confirmPassword} password>Confirm Password</TextInput> |
| 200 | + {:else} |
| 201 | + <Button on:click={() => {editingAdmin.settingPassword = true}}>Set New Password</Button> |
| 202 | + {/if} |
| 203 | + <Button>Delete Admin</Button> |
| 204 | + <div> |
| 205 | + <button on:click={sendEditAdmin} style="float: left; width:50%;">Confirm</button> |
| 206 | + <button on:click={()=>{isEditingAdmin = false}} style="float: right; width:50%;">Cancel</button> |
| 207 | + </div> |
179 | 208 | </div> |
180 | | - {/each} |
| 209 | + {:else} |
| 210 | + {#each admins as admin, i} |
| 211 | + <div class='admin'> |
| 212 | + <div style="float: left; margin-right: 20px"> |
| 213 | + <p class='admin-name'>{admin.name}</p> |
| 214 | + <p class='admin-level'> |
| 215 | + {#if admin.level == 1} |
| 216 | + Player Manager |
| 217 | + {:else if admin.level == 2} |
| 218 | + Server Manager |
| 219 | + {:else if admin.level == 3} |
| 220 | + Owner |
| 221 | + {/if} |
| 222 | + </p> |
| 223 | + </div> |
| 224 | + {#if permissionLevel === 3} |
| 225 | + <IconButton style="float: right; margin-top: 10px;" src="/icons/edit.svg" on:click={() => {if(permissionLevel === 3) editAdmin(i)}}></IconButton> |
| 226 | + {/if} |
| 227 | + </div> |
| 228 | + {/each} |
| 229 | + {/if} |
181 | 230 | {/if} |
182 | 231 | {#if unsavedChanged} |
183 | 232 | <Button on:click={saveSettings}>Save Settings</Button> |
|
0 commit comments