Skip to content

Commit 1abc2cc

Browse files
committed
Move userpassword check to its own modal, leveraging page-modal
1 parent 1abab9d commit 1abc2cc

File tree

5 files changed

+110
-97
lines changed

5 files changed

+110
-97
lines changed

resources/views/components/attribute/password.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<div class="row">
2424
<div class="offset-1 col-4 p-2">
2525
<span class="p-0 m-0">
26-
<button type="button" class="btn btn-sm btn-outline-dark mt-3" data-bs-toggle="modal" data-bs-target="#userpassword_check-modal"><i class="fas fa-user-check"></i> @lang('Check Password')</button>
26+
<button id="entry-userpassword-check" type="button" class="btn btn-sm btn-outline-dark mt-3" data-bs-toggle="modal" data-bs-target="#page-modal"><i class="fas fa-user-check"></i> @lang('Check Password')</button>
2727
</span>
2828
</div>
2929
</div>

resources/views/frames/dn.blade.php

Lines changed: 20 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -113,42 +113,6 @@
113113
<div class="modal-content"></div>
114114
</div>
115115
</div>
116-
117-
@if($up=$o->getObject('userpassword'))
118-
<!-- CHECK USERPASSWORD -->
119-
<div class="modal fade" id="userpassword_check-modal" tabindex="-1" aria-labelledby="userpassword_check-label" aria-hidden="true">
120-
<div class="modal-dialog modal-lg modal-fullscreen-lg-down">
121-
<div class="modal-content">
122-
<div class="modal-header">
123-
<h1 class="modal-title fs-5" id="userpassword_check-label">Check Passwords for {{ $dn }}</h1>
124-
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
125-
</div>
126-
127-
<div class="modal-body">
128-
<table class="table table-bordered p-1">
129-
@foreach($up->values as $key => $value)
130-
<tr>
131-
<th>Check</th>
132-
<td>{{ $up->render_item_old($key) }}</td>
133-
<td>
134-
<input type="password" style="width: 90%" name="password[{{$key}}]"> <i class="fas fa-fw fa-lock"></i>
135-
<div class="invalid-feedback pb-2">
136-
Invalid Password
137-
</div>
138-
</td>
139-
</tr>
140-
@endforeach
141-
</table>
142-
</div>
143-
144-
<div class="modal-footer">
145-
<button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button>
146-
<button type="button" class="btn btn-sm btn-primary" id="userpassword_check-submit"><i class="fas fa-fw fa-spinner fa-spin d-none"></i> Check</button>
147-
</div>
148-
</div>
149-
</div>
150-
</div>
151-
@endif
152116
@endsection
153117

154118
@section('page-scripts')
@@ -254,7 +218,7 @@ function editmode() {
254218
that = $('#entry_export');
255219
256220
$.ajax({
257-
type: 'GET',
221+
method: 'GET',
258222
url: '{{ url('entry/export') }}/'+dn,
259223
cache: false,
260224
beforeSend: function() {
@@ -276,68 +240,30 @@ function editmode() {
276240
})
277241
break;
278242
243+
case 'entry-userpassword-check':
244+
$.ajax({
245+
method: 'GET',
246+
url: '{{ url('modal/userpassword-check') }}/'+dn,
247+
dataType: 'html',
248+
cache: false,
249+
beforeSend: function() {
250+
that.empty().append('<span class="p-3"><i class="fas fa-3x fa-spinner fa-pulse"></i></span>');
251+
},
252+
success: function(data) {
253+
that.empty().html(data);
254+
},
255+
error: function(e) {
256+
if (e.status !== 412)
257+
alert('That didnt work? Please try again....');
258+
},
259+
})
260+
break;
261+
279262
default:
280263
console.log('No action for button:'+$(item.relatedTarget).attr('id'));
281264
}
282265
});
283266
284-
@if($up)
285-
$('button[id=userpassword_check-submit]').on('click',function(item) {
286-
var that = $(this);
287-
288-
var passwords = $('#userpassword_check-modal')
289-
.find('input[name^="password["')
290-
.map((key,item)=>item.value);
291-
292-
if (passwords.length === 0) return false;
293-
294-
$.ajax({
295-
type: 'POST',
296-
beforeSend: function() {
297-
// Disable submit, add spinning icon
298-
that.prop('disabled',true);
299-
that.find('i').removeClass('d-none');
300-
},
301-
complete: function() {
302-
that.prop('disabled',false);
303-
that.find('i').addClass('d-none');
304-
},
305-
success: function(data) {
306-
data.forEach(function(item,key) {
307-
var i = $('#userpassword_check-modal')
308-
.find('input[name="password['+key+']')
309-
.siblings('i');
310-
311-
var feedback = $('#userpassword_check-modal')
312-
.find('input[name="password['+key+']')
313-
.siblings('div.invalid-feedback');
314-
315-
if (item === 'OK') {
316-
i.removeClass('text-danger').addClass('text-success').removeClass('fa-lock').addClass('fa-lock-open');
317-
if (feedback.is(':visible'))
318-
feedback.hide();
319-
} else {
320-
i.removeClass('text-success').addClass('text-danger').removeClass('fa-lock-open').addClass('fa-lock');
321-
if (! feedback.is(':visible'))
322-
feedback.show();
323-
}
324-
})
325-
},
326-
error: function(e) {
327-
if (e.status !== 412)
328-
alert('That didnt work? Please try again....');
329-
},
330-
url: '{{ url('entry/password/check') }}',
331-
data: {
332-
dn: dn,
333-
password: Array.from(passwords),
334-
},
335-
dataType: 'json',
336-
cache: false
337-
})
338-
});
339-
@endif
340-
341267
@if(old())
342268
editmode();
343269
@endif

resources/views/modals/entry-export.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
<div class="modal-footer">
1212
<x-modal.close/>
13-
<button id="entry_export-download" type="button" class="btn btn-sm btn-primary">Download</button>
13+
<button id="entry_export-download" type="button" class="btn btn-sm btn-primary">@lang('Download')</button>
1414
</div>
1515

16-
<script>
16+
<script type="text/javascript">
1717
function download(filename,text) {
1818
var element = document.createElement('a');
1919
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
@php
2+
$o = $server->fetch(Crypt::decryptString($dn))
3+
@endphp
4+
<div class="modal-header bg-dark text-white">
5+
<h1 class="modal-title fs-5">Check Passwords for {{ $o->getDN() }}</h1>
6+
</div>
7+
8+
<div class="modal-body">
9+
<table class="table table-bordered p-1">
10+
@foreach(($up=$o->getObject('userpassword'))->values as $key => $value)
11+
<tr>
12+
<th>Check</th>
13+
<td>{{ $up->render_item_old($key) }}</td>
14+
<td>
15+
<input type="password" style="width: 90%" name="password[{{$key}}]"> <i class="fas fa-fw fa-lock"></i>
16+
<div class="invalid-feedback pb-2">
17+
@lang('Invalid Password')
18+
</div>
19+
</td>
20+
</tr>
21+
@endforeach
22+
</table>
23+
</div>
24+
25+
<div class="modal-footer">
26+
<x-modal.close/>
27+
<button id="userpassword_check-submit" type="button" class="btn btn-sm btn-primary"><i class="fas fa-fw fa-spinner fa-spin d-none"></i> @lang('Check')</button>
28+
</div>
29+
30+
<script type="text/javascript">
31+
$('button[id=userpassword_check-submit]').on('click',function(item) {
32+
var that = $(this);
33+
34+
var passwords = $('#page-modal')
35+
.find('input[name^="password["')
36+
.map((key,item)=>item.value);
37+
38+
if (passwords.length === 0) return false;
39+
40+
$.ajax({
41+
method: 'POST',
42+
url: '{{ url('entry/password/check') }}',
43+
data: {
44+
dn: dn,
45+
password: Array.from(passwords),
46+
},
47+
dataType: 'json',
48+
cache: false,
49+
beforeSend: function() {
50+
// Disable submit, add spinning icon
51+
that.prop('disabled',true);
52+
that.find('i').removeClass('d-none');
53+
},
54+
complete: function() {
55+
that.prop('disabled',false);
56+
that.find('i').addClass('d-none');
57+
},
58+
success: function(data) {
59+
data.forEach(function(item,key) {
60+
var i = $('#page-modal')
61+
.find('input[name="password['+key+']')
62+
.siblings('i');
63+
64+
var feedback = $('#page-modal')
65+
.find('input[name="password['+key+']')
66+
.siblings('div.invalid-feedback');
67+
68+
if (item === 'OK') {
69+
i.removeClass('text-danger').addClass('text-success').removeClass('fa-lock').addClass('fa-lock-open');
70+
if (feedback.is(':visible'))
71+
feedback.hide();
72+
73+
} else {
74+
i.removeClass('text-success').addClass('text-danger').removeClass('fa-lock-open').addClass('fa-lock');
75+
if (! feedback.is(':visible'))
76+
feedback.show();
77+
}
78+
})
79+
},
80+
error: function(e) {
81+
if (e.status !== 412)
82+
alert('That didnt work? Please try again....');
83+
},
84+
})
85+
});
86+
</script>

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@
5555

5656
Route::view('modal/delete/{dn}','modals.entry-delete');
5757
Route::view('modal/export/{dn}','modals.entry-export');
58+
Route::view('modal/userpassword-check/{dn}','modals.entry-userpassword-check');
5859
});
5960
});

0 commit comments

Comments
 (0)