Skip to content

Commit 1abab9d

Browse files
committed
Move DN export to its own modal, leveraging page-modal
1 parent 410daf6 commit 1abab9d

File tree

4 files changed

+80
-60
lines changed

4 files changed

+80
-60
lines changed

resources/views/frames/dn.blade.php

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ul class="nav">
1212
@if(isset($page_actions) && $page_actions->contains('export'))
1313
<li>
14-
<span data-bs-toggle="modal" data-bs-target="#entry_export-modal">
14+
<span id="entry-export" data-bs-toggle="modal" data-bs-target="#page-modal">
1515
<button class="btn btn-outline-dark p-1 m-1" data-bs-toggle="tooltip" data-bs-placement="bottom" title="@lang('Export')"><i class="fas fa-fw fa-download fs-5"></i></button>
1616
</span>
1717
</li>
@@ -114,27 +114,6 @@
114114
</div>
115115
</div>
116116

117-
<!-- EXPORT -->
118-
<div class="modal fade" id="entry_export-modal" tabindex="-1" aria-labelledby="entry_export-label" aria-hidden="true">
119-
<div class="modal-dialog modal-lg modal-fullscreen-lg-down">
120-
<div class="modal-content">
121-
<div class="modal-header">
122-
<h1 class="modal-title fs-5" id="entry_export-label">LDIF for {{ $dn }}</h1>
123-
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
124-
</div>
125-
126-
<div class="modal-body">
127-
<div id="entry_export"><div class="fa-3x"><i class="fas fa-spinner fa-pulse fa-sm"></i></div></div>
128-
</div>
129-
130-
<div class="modal-footer">
131-
<button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button>
132-
<button type="button" class="btn btn-sm btn-primary" id="entry_export-download">Download</button>
133-
</div>
134-
</div>
135-
</div>
136-
</div>
137-
138117
@if($up=$o->getObject('userpassword'))
139118
<!-- CHECK USERPASSWORD -->
140119
<div class="modal fade" id="userpassword_check-modal" tabindex="-1" aria-labelledby="userpassword_check-label" aria-hidden="true">
@@ -177,18 +156,6 @@
177156
var dn = '{{ $o->getDNSecure() }}';
178157
var oc = {!! $o->getObject('objectclass')->values !!};
179158
180-
function download(filename,text) {
181-
var element = document.createElement('a');
182-
183-
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
184-
element.setAttribute('download', filename);
185-
element.style.display = 'none';
186-
document.body.appendChild(element);
187-
188-
element.click();
189-
document.body.removeChild(element);
190-
}
191-
192159
function editmode() {
193160
$('#dn-edit input[name="dn"]').val(dn);
194161
@@ -231,7 +198,7 @@ function editmode() {
231198
$('#newattrs').append(data);
232199
},
233200
error: function(e) {
234-
if (e.status != 412)
201+
if (e.status !== 412)
235202
alert('That didnt work? Please try again....');
236203
},
237204
url: '{{ url('entry/attr/add') }}/'+item.target.value,
@@ -249,13 +216,6 @@ function editmode() {
249216
$('#newattr-select').remove();
250217
});
251218
252-
$('#entry_export-download').on('click',function(item) {
253-
item.preventDefault();
254-
255-
let ldif = $('#entry_export').find('pre:first'); // update this selector in your local version
256-
download('ldap-export.ldif',ldif.html());
257-
});
258-
259219
$('#page-modal').on('shown.bs.modal',function(item) {
260220
var that = $(this).find('.modal-content');
261221
@@ -273,7 +233,44 @@ function editmode() {
273233
that.empty().html(data);
274234
},
275235
error: function(e) {
276-
if (e.status != 412)
236+
if (e.status !== 412)
237+
alert('That didnt work? Please try again....');
238+
},
239+
})
240+
break;
241+
242+
case 'entry-export':
243+
$.ajax({
244+
method: 'GET',
245+
url: '{{ url('modal/export') }}/'+dn,
246+
dataType: 'html',
247+
cache: false,
248+
beforeSend: function() {
249+
that.empty().append('<span class="p-3"><i class="fas fa-3x fa-spinner fa-pulse"></i></span>');
250+
},
251+
success: function(data) {
252+
that.empty().html(data);
253+
254+
that = $('#entry_export');
255+
256+
$.ajax({
257+
type: 'GET',
258+
url: '{{ url('entry/export') }}/'+dn,
259+
cache: false,
260+
beforeSend: function() {
261+
that.empty().append('<span class="p-3"><i class="fas fa-3x fa-spinner fa-pulse"></i></span>');
262+
},
263+
success: function(data) {
264+
that.empty().append(data);
265+
},
266+
error: function(e) {
267+
if (e.status !== 412)
268+
alert('That didnt work? Please try again....');
269+
},
270+
})
271+
},
272+
error: function(e) {
273+
if (e.status !== 412)
277274
alert('That didnt work? Please try again....');
278275
},
279276
})
@@ -284,21 +281,6 @@ function editmode() {
284281
}
285282
});
286283
287-
$('#entry_export-modal').on('shown.bs.modal',function() {
288-
$.ajax({
289-
type: 'GET',
290-
success: function(data) {
291-
$('#entry_export').empty().append(data);
292-
},
293-
error: function(e) {
294-
if (e.status != 412)
295-
alert('That didnt work? Please try again....');
296-
},
297-
url: '{{ url('entry/export') }}/'+dn,
298-
cache: false
299-
})
300-
})
301-
302284
@if($up)
303285
$('button[id=userpassword_check-submit]').on('click',function(item) {
304286
var that = $(this);
@@ -342,7 +324,7 @@ function editmode() {
342324
})
343325
},
344326
error: function(e) {
345-
if (e.status != 412)
327+
if (e.status !== 412)
346328
alert('That didnt work? Please try again....');
347329
},
348330
url: '{{ url('entry/password/check') }}',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="modal-header bg-danger text-white">
2-
<h1 class="modal-title fs-5" id="entry_export-label">
2+
<h1 class="modal-title fs-5">
33
<i class="fas fa-fw fa-exclamation-triangle"></i> <strong>@lang('WARNING')</strong>: @lang('Delete') <strong>{{ Crypt::decryptString($dn) }}</strong>
44
</h1>
55
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div class="modal-header bg-dark text-white">
2+
<h1 class="modal-title fs-5">
3+
LDIF for {{ Crypt::decryptString($dn) }}
4+
</h1>
5+
</div>
6+
7+
<div class="modal-body">
8+
<div id="entry_export"></div>
9+
</div>
10+
11+
<div class="modal-footer">
12+
<x-modal.close/>
13+
<button id="entry_export-download" type="button" class="btn btn-sm btn-primary">Download</button>
14+
</div>
15+
16+
<script>
17+
function download(filename,text) {
18+
var element = document.createElement('a');
19+
20+
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
21+
element.setAttribute('download', filename);
22+
element.style.display = 'none';
23+
document.body.appendChild(element);
24+
25+
element.click();
26+
document.body.removeChild(element);
27+
}
28+
29+
$(document).ready(function() {
30+
$('button[id=entry_export-download]').on('click',function(item) {
31+
item.preventDefault();
32+
33+
let ldif = $('#entry_export').find('pre:first');
34+
download('ldap-export.ldif',ldif.html());
35+
});
36+
});
37+
</script>

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@
5454
Route::post('import/process/{type}','import');
5555

5656
Route::view('modal/delete/{dn}','modals.entry-delete');
57+
Route::view('modal/export/{dn}','modals.entry-export');
5758
});
5859
});

0 commit comments

Comments
 (0)