1 | /** |
||
2 | * Audio Player |
||
3 | * |
||
4 | * This file is licensed under the Affero General Public License version 3 or |
||
5 | * later. See the LICENSE.md file. |
||
6 | * |
||
7 | * @author Marcel Scherello <[email protected]> |
||
8 | * @copyright 2016-2019 Marcel Scherello |
||
9 | */ |
||
10 | |||
11 | /* global Audios */ |
||
12 | // OK because ./js/app.js is sourced before in html |
||
13 | |||
14 | 'use strict'; |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
15 | |||
16 | $(document).ready(function () { |
||
17 | |||
18 | var settings_link; |
||
19 | if (OC.config.versionstring.split('.')[0] <= 10) //ownCloud |
||
20 | { |
||
21 | settings_link = OC.generateUrl('settings/personal?sectionid=audioplayer'); |
||
22 | } else { //Nextcloud |
||
23 | settings_link = OC.generateUrl('settings/user/audioplayer'); |
||
24 | } |
||
25 | |||
26 | $('#sonos').on('click', function () { |
||
27 | document.location = settings_link; |
||
28 | }); |
||
29 | |||
30 | $('#audioplayerSettings').on('click', function () { |
||
31 | document.location = settings_link; |
||
32 | }); |
||
33 | |||
34 | $(document).on('click', '#scanAudios, #scanAudiosFirst', function () { |
||
35 | OCA.Audioplayer.audiosInstance.openScannerDialog(); |
||
36 | }.bind(OCA.Audioplayer.audiosInstance)); |
||
37 | |||
38 | $(document).on('click', '#resetAudios', function () { |
||
39 | OCA.Audioplayer.audiosInstance.openResetDialog(); |
||
40 | }.bind(OCA.Audioplayer.audiosInstance)); |
||
41 | }); |
||
42 | |||
43 | Audios.prototype.openResetDialog = function () { |
||
44 | OC.dialogs.message( |
||
45 | t('audioplayer', 'Are you sure?') + ' ' + t('audioplayer', 'All library entries will be deleted!'), |
||
46 | t('audioplayer', 'Reset library'), |
||
47 | 'notice', |
||
48 | OCdialogs.YES_NO_BUTTONS, |
||
49 | function (e) { |
||
50 | if (e === true) { |
||
51 | this.resetLibrary(); |
||
52 | } |
||
53 | }.bind(this), |
||
54 | true |
||
55 | ); |
||
56 | }; |
||
57 | |||
58 | Audios.prototype.resetLibrary = function () { |
||
59 | if ($('.sm2-bar-ui').hasClass('playing')) { |
||
60 | this.AudioPlayer.actions.play(0); |
||
61 | this.AudioPlayer.actions.stop(); |
||
62 | } |
||
63 | |||
64 | this.showInitScreen(); |
||
65 | |||
66 | $('#category_selector').val(''); |
||
67 | this.setUserValue('category', this.CategorySelectors[0] + '-'); |
||
68 | $('#myCategory').html(''); |
||
69 | $('#alben').addClass('active'); |
||
70 | $('#individual-playlist').remove(); |
||
71 | $('#individual-playlist-info').hide(); |
||
72 | $('#individual-playlist-header').hide(); |
||
73 | $('.coverrow').remove(); |
||
74 | $('.songcontainer').remove(); |
||
75 | $('#activePlaylist').html(''); |
||
76 | $('.sm2-playlist-target').html(''); |
||
77 | $('.sm2-playlist-cover').css('background-color', '#ffffff').html(''); |
||
78 | |||
79 | $.ajax({ |
||
80 | type: 'GET', |
||
81 | url: OC.generateUrl('apps/audioplayer/resetmedialibrary'), |
||
82 | success: function (jsondata) { |
||
83 | if (jsondata.status === 'success') { |
||
84 | OC.Notification.showTemporary(t('audioplayer', 'Resetting finished!')); |
||
85 | } |
||
86 | } |
||
87 | }); |
||
88 | }; |
||
89 | |||
90 | Audios.prototype.openScannerDialog = function () { |
||
91 | $('body').append('<div id="audios_import"></div>'); |
||
92 | $('#audios_import').load(OC.generateUrl('apps/audioplayer/getimporttpl'), function () { |
||
93 | this.scanInit(); |
||
94 | }.bind(this)); |
||
95 | }; |
||
96 | |||
97 | Audios.prototype.scanInit = function () { |
||
98 | |||
99 | $('#audios_import_dialog').ocdialog({ |
||
100 | width: 500, |
||
101 | modal: true, |
||
102 | resizable: false, |
||
103 | close: function () { |
||
104 | this.scanStop(); |
||
105 | $('#audios_import_dialog').ocdialog('destroy'); |
||
106 | $('#audios_import').remove(); |
||
107 | }.bind(this) |
||
108 | }); |
||
109 | |||
110 | $('#audios_import_done_close').click(function () { |
||
111 | this.percentage = 0; |
||
112 | $('#audios_import_dialog').ocdialog('close'); |
||
113 | }.bind(this)); |
||
114 | |||
115 | $('#audios_import_progress_cancel').click(function () { |
||
116 | this.scanStop(); |
||
117 | }.bind(this)); |
||
118 | |||
119 | $('#audios_import_submit').click(function () { |
||
120 | this.processScan(); |
||
121 | }.bind(this)); |
||
122 | |||
123 | $('#audios_import_progressbar').progressbar({value: 0}); |
||
124 | }; |
||
125 | |||
126 | Audios.prototype.processScan = function () { |
||
127 | $('#audios_import_form').css('display', 'none'); |
||
128 | $('#audios_import_process').css('display', 'block'); |
||
129 | |||
130 | this.scanSend(); |
||
131 | window.setTimeout(function () { |
||
132 | this.scanUpdate(); |
||
133 | }.bind(this), 1500); |
||
134 | }; |
||
135 | |||
136 | Audios.prototype.scanSend = function () { |
||
137 | $.post(OC.generateUrl('apps/audioplayer/scanforaudiofiles'), |
||
138 | {}, function (data) { |
||
139 | if (data.status === 'success') { |
||
140 | $('#audios_import_process').css('display', 'none'); |
||
141 | $('#audios_import_done').css('display', 'block'); |
||
142 | $('#audios_import_done_message').html(data.message); |
||
143 | this.init(); |
||
144 | } else { |
||
145 | $('#audios_import_progressbar').progressbar('option', 'value', 100); |
||
146 | $('#audios_import_done_message').html(data.message); |
||
147 | } |
||
148 | }.bind(this)); |
||
149 | }; |
||
150 | |||
151 | Audios.prototype.scanStop = function () { |
||
152 | this.percentage = 0; |
||
153 | $.ajax({ |
||
154 | type: 'POST', |
||
155 | url: OC.generateUrl('apps/audioplayer/scanforaudiofiles'), |
||
156 | data: { |
||
157 | 'scanstop': true |
||
158 | }, |
||
159 | success: function () { |
||
160 | } |
||
161 | }); |
||
162 | }; |
||
163 | |||
164 | Audios.prototype.scanUpdate = function () { |
||
165 | |||
166 | $.post(OC.generateUrl('apps/audioplayer/getprogress'), |
||
167 | {}, function (data) { |
||
168 | if (data.status === 'success') { |
||
169 | this.percentage = parseInt(data.percent); |
||
170 | $('#audios_import_progressbar').progressbar('option', 'value', parseInt(data.percent)); |
||
171 | $('#audios_import_process_progress').text(data.prog); |
||
172 | $('#audios_import_process_message').text(data.msg); |
||
173 | if (data.percent < 100) { |
||
174 | window.setTimeout(function () { |
||
175 | this.scanUpdate(); |
||
176 | }.bind(this), 1500); |
||
177 | } else { |
||
178 | $('#audios_import_process').css('display', 'none'); |
||
179 | $('#audios_import_done').css('display', 'block'); |
||
180 | } |
||
181 | } else { |
||
182 | //alert("getprogress error"); |
||
183 | } |
||
184 | }.bind(this)); |
||
185 | return 0; |
||
186 | }; |
||
187 |