aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.WebDashboard/Html/scripts/AdvancedMetadataConfigurationPage.js
blob: 8b89add10a34e704c0dcea1781f6b19e00d0f7fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var AdvancedMetadataConfigurationPage = {

    onPageShow: function () {

        Dashboard.showLoadingMsg();

        var page = this;

        var promise1 = ApiClient.getServerConfiguration();
        var promise2 = ApiClient.getItemTypes({ HasInternetProvider: true });

        $.when(promise1, promise2).done(function (response1, response2) {

            AdvancedMetadataConfigurationPage.load(page, response1[0], response2[0]);

        });
    },

    load: function (page, config, itemTypes) {

        AdvancedMetadataConfigurationPage.loadItemTypes(page, config, itemTypes);
        Dashboard.hideLoadingMsg();
    },

    loadItemTypes: function (page, configuration, types) {

        var html = '<div data-role="controlgroup">';

        for (var i = 0, length = types.length; i < length; i++) {

            var type = types[i];
            var id = "checkbox-" + i + "a";

            var checkedAttribute = configuration.InternetProviderExcludeTypes.indexOf(type) != -1 ? ' checked="checked"' : '';

            html += '<input' + checkedAttribute + ' class="chkItemType" data-itemtype="' + type + '" type="checkbox" name="' + id + '" id="' + id + '" onchange="AdvancedMetadataConfigurationPage.submit();" />';
            html += '<label for="' + id + '">' + type + '</label>';
        }

        html += "</div>";

        $('#divItemTypes', page).html(html).trigger("create");
    },

    submit: function () {

        $('.btnSubmit', $.mobile.activePage)[0].click();

    },

    onSubmit: function () {
        Dashboard.showLoadingMsg();

        var form = this;

        ApiClient.getServerConfiguration().done(function (config) {

            config.InternetProviderExcludeTypes = $.map($('.chkItemType:checked', form), function (currentCheckbox) {

                return currentCheckbox.getAttribute('data-itemtype');
            });

            ApiClient.updateServerConfiguration(config);
        });

        // Disable default form submission
        return false;
    }
};

$(document).on('pageshow', "#advancedMetadataConfigurationPage", AdvancedMetadataConfigurationPage.onPageShow);