{"size": 1344, "ext": "js", "max_stars_repo_path": "src/Feature/Preference/website/content/Feature/preferencesList.js", "max_stars_repo_name": "mtelligent/UserSettings", "max_stars_repo_stars_event_min_datetime": "2020-01-14T18:28:02.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-16T20:00:20.000Z", "max_issues_repo_path": "src/Feature/Preference/website/content/Feature/preferencesList.js", "max_issues_repo_name": "mtelligent/UserSettings", "max_issues_repo_issues_event_min_datetime": "2020-01-06T22:32:25.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-06T22:32:26.000Z", "max_forks_repo_path": "src/Feature/Preference/website/content/Feature/preferencesList.js", "max_forks_repo_name": "mtelligent/UserSettings", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 28.5957446809, "max_line_length": 69, "alphanum_fraction": 0.4977678571}
﻿XA.component.preferencesList = (function ($, document) {

    function init() {

        $('.preferences-list-item').click(function (event) {

            event.preventDefault();

            var valueToSet = $(this).attr("data-value");
            var targetUrl = $(this).attr("data-targetUrl");
            var container = $(this).parent();
            var area = container.attr("data-area");
            var key = container.attr("data-key");

            setPreference(area, key, valueToSet, targetUrl);
        });

        function setPreference(area, key, valueToSet, targetUrl) {
            var data = "=" + valueToSet;
            var url = "/api/sf/1.0/userSettings/" + area + "/" + key;
            $.post(url, data).done(function () {
                if (targetUrl && targetUrl.length > 0) {
                    window.location.href = targetUrl;
                }
                else {
                    $(".preferences-list-container").hide();
                    $(".preferences-list-thank-you-message").show();
                }
            }).fail(function(){
                console.log("error saving preference");
            });
        }

    }


    var pub = {};

    pub.init = function () {
        init();
    };

    return pub;

}(jQuery, document));

XA.register("preferencesList", XA.component.preferencesList);