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