@@ -136,13 +136,18 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Domain Information</
136
136
< label for ="webshot "
137
137
class ="relative cursor-pointer rounded-md bg-white font-semibold text-red-600 focus-within:outline-none focus-within:ring-2 focus-within:ring-red-600 focus-within:ring-offset-2 hover:text-red-500 ">
138
138
< span class ="text-red-600 "> Upload a webshot</ span >
139
- < input id ="webshot " name ="webshot " type ="file " class ="sr-only " />
139
+ < input id ="webshot "
140
+ name ="webshot "
141
+ type ="file "
142
+ class ="sr-only "
143
+ onchange ="displayWebshotPreview() " />
140
144
</ label >
141
145
< p class ="pl-1 "> or drag and drop</ p >
142
146
</ div >
143
147
< p class ="text-xs leading-5 text-gray-600 "> PNG, JPG, GIF up to 10MB</ p >
144
148
</ div >
145
149
</ div >
150
+ < div id ="webshotPreview " class ="mt-4 "> </ div >
146
151
</ div >
147
152
</ div >
148
153
</ div >
@@ -152,13 +157,13 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Domain Managers</h2>
152
157
Add Emails which will be allowed to start hunts and manage reported bugs.
153
158
Email should be domain mail and should be registerd user on BLT.
154
159
</ p >
155
- < button onclick ="add_email_container () "
160
+ < button onclick ="add_user_selection () "
156
161
type ="button "
157
162
class ="w-[120px] h-[40px] bg-red-500 text-white font-bold rounded-md mt-2 hover:bg-red-600 transition-all ">
158
- Add Email
163
+ Add User
159
164
</ button >
160
- < div class ="sm:col-span-4 mt-5 " id ="email -container ">
161
- < label for ="email " class ="block text-sm font-medium leading-6 text-gray-900 "> Email address </ label >
165
+ < div class ="sm:col-span-4 mt-5 " id ="user-selection -container ">
166
+ < label for ="user " class ="block text-sm font-medium leading-6 text-gray-900 "> Select Domain Manager </ label >
162
167
</ div >
163
168
</ div >
164
169
< div class ="border-b border-gray-900/10 pb-12 mt-5 ">
@@ -199,9 +204,6 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Notifications</h2>
199
204
</ div >
200
205
</ div >
201
206
< div class ="mt-6 flex items-center justify-end gap-x-6 ">
202
- < button type ="button "
203
- onclick ="cancelForm() "
204
- class ="text-md font-semibold leading-6 text-gray-900 "> Cancel</ button >
205
207
< button type ="submit "
206
208
class ="rounded-md bg-red-600 px-11 py-3 text-md font-semibold text-white shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600 ">
207
209
Save
@@ -212,38 +214,53 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Notifications</h2>
212
214
{% endblock body %}
213
215
{% block js %}
214
216
< script >
215
- function remove_email_container ( ) {
216
- let email_container = document . getElementById ( "email-container" ) ;
217
- let lst_child = email_container . lastElementChild ;
218
- email_container . removeChild ( lst_child ) ;
217
+ function remove_user_selection ( event ) {
218
+ let user_container = document . getElementById ( "user-selection-container" ) ;
219
+ let parentDiv = event . target . closest ( '.user-selection' ) ;
220
+ user_container . removeChild ( parentDiv ) ;
221
+ updateUserSelections ( ) ;
219
222
}
220
223
221
- function add_email_container ( ) {
222
- const email_container_child_html = document . createElement ( 'div' ) ;
223
- email_container_child_html . innerHTML = `
224
- <div class="mt-2 flex flex-row items-center w-[50%]">
225
- <input name="email" type="email" autocomplete="email" required class="w-[90%] block rounded-md border-0 py-1.5 pl-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-red-600 sm:text-sm sm:leading-6" />
226
- <button type="button" onclick="remove_email_container()">
227
- <i class="fa-sharp fa-solid fa-trash fa-lg text-[#596780] ml-4 hover:text-black"></i>
228
- </button>
229
- </div>
224
+ function add_user_selection ( ) {
225
+ const user_selection_child_html = document . createElement ( 'div' ) ;
226
+ user_selection_child_html . classList . add ( 'mt-2' , 'flex' , 'flex-row' , 'items-center' , 'w-[50%]' , 'user-selection' ) ;
227
+ user_selection_child_html . innerHTML = `
228
+ <select name="user" class="w-[90%] block rounded-md border-0 py-1.5 pl-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-red-600 sm:text-sm sm:leading-6" onchange="updateUserSelections()">
229
+ ${ getUserOptions ( [ ] ) }
230
+ </select>
231
+ <button type="button" onclick="remove_user_selection(event)">
232
+ <i class="fa-sharp fa-solid fa-trash fa-lg text-[#596780] ml-4 hover:text-black"></i>
233
+ </button>
230
234
` ;
231
235
232
- let email_container = document . getElementById ( "email-container" ) ;
233
- email_container . appendChild ( email_container_child_html )
236
+ let user_container = document . getElementById ( "user-selection-container" ) ;
237
+ user_container . appendChild ( user_selection_child_html ) ;
238
+ updateUserSelections ( ) ;
234
239
}
235
240
236
- </ script >
237
- < script >
238
- function cancelForm ( ) {
239
- let deleteForm = document . getElementById ( "deleteForm" ) ;
240
- let confirmDelete = confirm ( "Are you sure you want to cancel, your progress would be lost." ) ;
241
- if ( confirmDelete === true ) {
242
- deleteForm . submit ( ) ;
243
- }
241
+ function getUserOptions ( excludeList ) {
242
+ let optionsHtml = '<option value="" disabled selected>Select a user</option>' ;
243
+ { % for user in users % }
244
+ if ( ! excludeList . includes ( '{{ user.email }}' ) ) {
245
+ optionsHtml += `<option value="{{ user.email }}">{{ user.username }} ({{ user.email }})</option>` ;
246
+ }
247
+ { % endfor % }
248
+ return optionsHtml ;
249
+ }
250
+
251
+ function updateUserSelections ( ) {
252
+ const selects = document . querySelectorAll ( '#user-selection-container select' ) ;
253
+ const selectedUsers = Array . from ( selects ) . map ( select => select . value ) ;
254
+
255
+ selects . forEach ( select => {
256
+ const currentValue = select . value ;
257
+ select . innerHTML = getUserOptions ( selectedUsers . filter ( user => user !== currentValue ) ) ;
258
+ select . value = currentValue ; // Preserve the current value after options are updated
259
+ } ) ;
244
260
}
245
261
246
262
263
+
247
264
function displayLogoPreview ( ) {
248
265
var fileInput = document . getElementById ( "logo" ) ;
249
266
var previewDiv = document . getElementById ( "previewLogoDiv" ) ;
@@ -265,5 +282,41 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Notifications</h2>
265
282
}
266
283
}
267
284
285
+ function displayWebshotPreview ( ) {
286
+ var fileInput = document . getElementById ( "webshot" ) ;
287
+ var previewDiv = document . getElementById ( "webshotPreview" ) ;
288
+
289
+ if ( fileInput . files . length > 0 ) {
290
+ var file = fileInput . files [ 0 ] ;
291
+ var reader = new FileReader ( ) ;
292
+
293
+ reader . onload = function ( event ) {
294
+ var img = new Image ( ) ;
295
+ img . src = event . target . result ;
296
+
297
+ img . onload = function ( ) {
298
+ var canvas = document . createElement ( "canvas" ) ;
299
+ var ctx = canvas . getContext ( "2d" ) ;
300
+
301
+ var maxDim = 300 ;
302
+ var scale = Math . min ( maxDim / img . width , maxDim / img . height ) ;
303
+
304
+ canvas . width = img . width * scale ;
305
+ canvas . height = img . height * scale ;
306
+
307
+ ctx . drawImage ( img , 0 , 0 , canvas . width , canvas . height ) ;
308
+
309
+ previewDiv . innerHTML = "" ;
310
+ previewDiv . style . display = "flex" ;
311
+ previewDiv . style . justifyContent = "center" ;
312
+ previewDiv . appendChild ( canvas ) ;
313
+ } ;
314
+ } ;
315
+
316
+ reader . readAsDataURL ( file ) ;
317
+ } else {
318
+ previewDiv . innerHTML = "" ;
319
+ }
320
+ }
268
321
</ script >
269
322
{% endblock js %}
0 commit comments