· 6 years ago · Dec 04, 2019, 02:02 PM
1<script>
2 $(function () {
3 // Replace vinyl.png with real cover
4 $('#cover').attr('src', $('#cover').data('src'));
5 // Get tracks from MusicBrainz API
6 $.getJSON('{{ $record->recordUrl }}')
7 .done(function (data) {
8 console.log(data);
9 // loop over each track
10 $.each(data.media[0].tracks, function (key, value) {
11 // Construct a table row
12
13 let row = `<tr>
14 <td>${value.position}</td>
15 <td>${value.title}</td>
16 <td>${vinylShop.to_mm_ss(value.recording.length)}</td>
17 </tr>`;
18 // Append the row to the tbody tag
19 $('tbody').append(row);
20
21 });
22 })
23 .fail(function (error) {
24 console.log("error", error);
25 });
26
27 // Delete this record
28 @auth()
29 @if(auth()->user()->admin)
30 $('#deleteRecord').click(function () {
31 let id = '{{ $record->id }}';
32 console.log(`delete record ${id}`);
33 // Show Noty
34 let modal = new Noty({
35 timeout: false,
36 layout: 'center',
37 modal: true,
38 type: 'warning',
39 text: '<p>Delete the record <b>{{ $record->title }}</b>?</p>',
40 buttons: [
41 Noty.button('Delete record', 'btn btn-danger', function () {
42 // Delete record and close modal
43 let pars = {
44 '_token': '{{ csrf_token() }}',
45 '_method': 'delete'
46 };
47 $.post(`/admin/records/${id}`, pars, 'json')
48 .done(function (data) {
49 console.log('data', data);
50 // Show toast
51 new Noty({
52 type: data.type,
53 text: data.text
54 }).show();
55 // After 2 seconds, redirect to the public master page
56 setTimeout(function () {
57 $(location).attr('href', '/shop'); // jQuery
58 // window.location = '/shop'; // JavaScript
59 }, 2000);
60 })
61 .fail(function (e) {
62 console.log('error', e);
63 });
64 modal.close();
65 }),
66 Noty.button('Cancel', 'btn btn-secondary ml-2', function () {
67 modal.close();
68 })
69 ]
70 }).show();
71 });
72 @endif
73 @endauth
74 })
75
76 </script>