Passed
Push — master ( 998e10...1efe83 )
by Marcel
06:10
created

js/settings/settings.js (51 issues)

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
Use the function form of "use strict".
Loading history...
15
16
$(document).ready(function () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
document does not seem to be defined.
Loading history...
17
18
    var settings_link;
19
    if (OC.config.versionstring.split('.')[0] <= 10) //ownCloud
0 ignored issues
show
OC does not seem to be defined.
Loading history...
There were too many errors found in this file; checking aborted after 10%.

If JSHint finds too many errors in a file, it aborts checking altogether because it suspects a configuration issue.

Further Reading:

Loading history...
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 () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
27
        document.location = settings_link;
0 ignored issues
show
document does not seem to be defined.
Loading history...
28
    });
29
30
    $('#audioplayerSettings').on('click', function () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
31
        document.location = settings_link;
0 ignored issues
show
document does not seem to be defined.
Loading history...
32
    });
33
34
    $(document).on('click', '#scanAudios, #scanAudiosFirst', function () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
document does not seem to be defined.
Loading history...
35
        OCA.Audioplayer.audiosInstance.openScannerDialog();
36
    }.bind(OCA.Audioplayer.audiosInstance));
37
38
    $(document).on('click', '#resetAudios', function () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
document does not seem to be defined.
Loading history...
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')) {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
60
        this.AudioPlayer.actions.play(0);
61
        this.AudioPlayer.actions.stop();
62
    }
63
64
    this.showInitScreen();
65
66
    $('#category_selector').val('');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
67
    this.setUserValue('category', this.CategorySelectors[0] + '-');
68
    $('#myCategory').html('');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
69
    $('#alben').addClass('active');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
70
    $('#individual-playlist').remove();
0 ignored issues
show
$ does not seem to be defined.
Loading history...
71
    $('#individual-playlist-info').hide();
0 ignored issues
show
$ does not seem to be defined.
Loading history...
72
    $('#individual-playlist-header').hide();
0 ignored issues
show
$ does not seem to be defined.
Loading history...
73
    $('.coverrow').remove();
0 ignored issues
show
$ does not seem to be defined.
Loading history...
74
    $('.songcontainer').remove();
0 ignored issues
show
$ does not seem to be defined.
Loading history...
75
    $('#activePlaylist').html('');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
76
    $('.sm2-playlist-target').html('');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
77
    $('.sm2-playlist-cover').css('background-color', '#ffffff').html('');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
78
79
    $.ajax({
0 ignored issues
show
$ does not seem to be defined.
Loading history...
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>');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
92
    $('#audios_import').load(OC.generateUrl('apps/audioplayer/getimporttpl'), function () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
93
        this.scanInit();
94
    }.bind(this));
95
};
96
97
Audios.prototype.scanInit = function () {
98
99
    $('#audios_import_dialog').ocdialog({
0 ignored issues
show
$ does not seem to be defined.
Loading history...
100
        width: 500,
101
        modal: true,
102
        resizable: false,
103
        close: function () {
104
            this.scanStop();
105
            $('#audios_import_dialog').ocdialog('destroy');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
106
            $('#audios_import').remove();
0 ignored issues
show
$ does not seem to be defined.
Loading history...
107
        }.bind(this)
108
    });
109
110
    $('#audios_import_done_close').click(function () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
111
        this.percentage = 0;
112
        $('#audios_import_dialog').ocdialog('close');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
113
    }.bind(this));
114
115
    $('#audios_import_progress_cancel').click(function () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
116
        this.scanStop();
117
    }.bind(this));
118
119
    $('#audios_import_submit').click(function () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
120
        this.processScan();
121
    }.bind(this));
122
123
    $('#audios_import_progressbar').progressbar({value: 0});
0 ignored issues
show
$ does not seem to be defined.
Loading history...
124
};
125
126
Audios.prototype.processScan = function () {
127
    $('#audios_import_form').css('display', 'none');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
128
    $('#audios_import_process').css('display', 'block');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
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'),
0 ignored issues
show
$ does not seem to be defined.
Loading history...
138
        {}, function (data) {
139
            if (data.status === 'success') {
140
                $('#audios_import_process').css('display', 'none');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
141
                $('#audios_import_done').css('display', 'block');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
142
                $('#audios_import_done_message').html(data.message);
0 ignored issues
show
$ does not seem to be defined.
Loading history...
143
                this.init();
144
            } else {
145
                $('#audios_import_progressbar').progressbar('option', 'value', 100);
0 ignored issues
show
$ does not seem to be defined.
Loading history...
146
                $('#audios_import_done_message').html(data.message);
0 ignored issues
show
$ does not seem to be defined.
Loading history...
147
            }
148
        }.bind(this));
149
};
150
151
Audios.prototype.scanStop = function () {
152
    this.percentage = 0;
153
    $.ajax({
0 ignored issues
show
$ does not seem to be defined.
Loading history...
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'),
0 ignored issues
show
$ does not seem to be defined.
Loading history...
167
        {}, function (data) {
168
            if (data.status === 'success') {
169
                this.percentage = parseInt(data.percent);
170
                $('#audios_import_progressbar').progressbar('option', 'value', parseInt(data.percent));
0 ignored issues
show
$ does not seem to be defined.
Loading history...
171
                $('#audios_import_process_progress').text(data.prog);
0 ignored issues
show
$ does not seem to be defined.
Loading history...
172
                $('#audios_import_process_message').text(data.msg);
0 ignored issues
show
$ does not seem to be defined.
Loading history...
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');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
179
                    $('#audios_import_done').css('display', 'block');
0 ignored issues
show
$ does not seem to be defined.
Loading history...
180
                }
181
            } else {
182
                //alert("getprogress error");
183
            }
184
        }.bind(this));
185
    return 0;
186
};
187