<commit_before>
var AIRTIME = (function (AIRTIME) {
    var mod;

    if (AIRTIME.publish === undefined) {
        AIRTIME.publish = {};
    }

    mod = AIRTIME.publish;

    var endpoint = 'rest/media/';
    var dialogUrl = 'library/publish-dialog';
    var PUBLISH_APP_NAME = 'publish';


    //AngularJS app
    var publishApp = angular.module(PUBLISH_APP_NAME, [])
        .controller('Publish', function ($scope, $http, mediaId, tab) {
            $scope.publishData = {};
            var sourceInterval;

            tab.contents.on("click", "input[type='checkbox']", function () {
                var noSourcesChecked = true;
                $.each(tab.contents.find("input[type='checkbox']"), function () {
                    if ($(this).is(":checked")) {
                        noSourcesChecked = false;
                    }
                });
                tab.contents.find(".publish-btn").prop("disabled", noSourcesChecked);
            });

            function fetchSourceData() {
                var csrfToken = jQuery("#csrf").val();
                $http.get(endpoint + mediaId, {csrf_token: csrfToken})
                    .success(function (json) {
                        $scope.media = json;
                        tab.setName($scope.media.track_title);
                    });

                // Get an object containing all sources, their translated labels,
                // and their publication state for the file with the given ID
                $http.get(endpoint + mediaId + '/publish-sources', {csrf_token: csrfToken})
                    .success(function (json) {
                        $scope.sources = { toPublish: [], published: []};
                        $.each(json, function () {
                            if (Math.abs(this.status) == 1) {
                                $scope.sources.published.push(this);
                            } else {
                                $scope.sources.toPublish.push(this);
                            }
                        });
                    });
            }

            function init() {
                fetchSourceData();
                sourceInterval = setInterval(function() {
                    fetchSourceData();
                }, 5000);

                tab.assignOnCloseHandler(function () {
                    clearInterval(sourceInterval);
                    $scope.$destroy();
                });
            }


            $scope.openEditDialog = function() {
                var uid = AIRTIME.library.MediaTypeStringEnum.FILE + "_" + mediaId;
                $.get(baseUrl + "library/edit-file-md/id/" + mediaId, {format: "json"}, function (json) {
                    AIRTIME.playlist.fileMdEdit(json, uid);
                });
            };

            $scope.publish = function () {
                var data = {};
                jQuery.each($scope.publishData, function (k, v) {
                    if (v) {
                        if (k == "soundcloud") {
                            alert($.i18n._("Your track is being uploaded and will "
                                + "appear on SoundCloud in a couple of minutes"));
                        }
                        data[k] = 'publish';  // FIXME: should be more robust
                    }
                });

                if (data && Object.keys(data).length > 0) {
                    $http.put(endpoint + mediaId + '/publish', {csrf_token: jQuery("#csrf").val(), sources: data})
                        .success(function () {
                            fetchSourceData();<commit_msg>Disable publish button when finished publishing to selected source(s)<commit_after>
var AIRTIME = (function (AIRTIME) {
    var mod;

    if (AIRTIME.publish === undefined) {
        AIRTIME.publish = {};
    }

    mod = AIRTIME.publish;

    var endpoint = 'rest/media/';
    var dialogUrl = 'library/publish-dialog';
    var PUBLISH_APP_NAME = 'publish';


    //AngularJS app
    var publishApp = angular.module(PUBLISH_APP_NAME, [])
        .controller('Publish', function ($scope, $http, mediaId, tab) {
            $scope.publishData = {};
            var sourceInterval;

            tab.contents.on("click", "input[type='checkbox']", function () {
                var noSourcesChecked = true;
                $.each(tab.contents.find("input[type='checkbox']"), function () {
                    if ($(this).is(":checked")) {
                        noSourcesChecked = false;
                    }
                });
                tab.contents.find(".publish-btn").prop("disabled", noSourcesChecked);
            });

            function fetchSourceData() {
                var csrfToken = jQuery("#csrf").val();
                $http.get(endpoint + mediaId, {csrf_token: csrfToken})
                    .success(function (json) {
                        $scope.media = json;
                        tab.setName($scope.media.track_title);
                    });

                // Get an object containing all sources, their translated labels,
                // and their publication state for the file with the given ID
                $http.get(endpoint + mediaId + '/publish-sources', {csrf_token: csrfToken})
                    .success(function (json) {
                        $scope.sources = { toPublish: [], published: []};
                        $.each(json, function () {
                            if (Math.abs(this.status) == 1) {
                                $scope.sources.published.push(this);
                            } else {
                                $scope.sources.toPublish.push(this);
                            }
                        });
                    });
            }

            function init() {
                fetchSourceData();
                sourceInterval = setInterval(function() {
                    fetchSourceData();
                }, 5000);

                tab.assignOnCloseHandler(function () {
                    clearInterval(sourceInterval);
                    $scope.$destroy();
                });
            }


            $scope.openEditDialog = function() {
                var uid = AIRTIME.library.MediaTypeStringEnum.FILE + "_" + mediaId;
                $.get(baseUrl + "library/edit-file-md/id/" + mediaId, {format: "json"}, function (json) {
                    AIRTIME.playlist.fileMdEdit(json, uid);
                });
            };

            $scope.publish = function () {
                var data = {};
                jQuery.each($scope.publishData, function (k, v) {
                    if (v) {
                        if (k == "soundcloud") {
                            alert($.i18n._("Your track is being uploaded and will "
                                + "appear on SoundCloud in a couple of minutes"));
                        }
                        data[k] = 'publish';  // FIXME: should be more robust
                    }
                });

                if (data && Object.keys(data).length > 0) {
                    $http.put(endpoint + mediaId + '/publish', {csrf_token: jQuery("#csrf").val(), sources: data})
                        .success(function () {
                            tab.contents.find(".publish-btn").prop("disabled", true);
                            fetchSourceData();
{'fraction_non_alphanumeric': 0.1235632183908046, 'fraction_numerical': 0.0021893814997263274, 'mean_word_length': 1.2351681957186544, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5443733', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1709, 'n_words': 359}