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('RestController', function ($scope, $http, mediaId, tab) { $scope.publishSources = {}; function init () { $http.get(endpoint + mediaId, { csrf_token: jQuery("#csrf").val() }) .success(function (json) { console.log(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: jQuery("#csrf").val() }) .success(function (json) { $scope.sources = json; // Store the data (whether each source should be published to when publish is clicked) // in a separate array so we don't overwrite the labels $scope.publishData = {}; jQuery.each($scope.sources.toPublish, function (k, v) { $scope.publishData[k] = false; }); }); } $scope.publish = function () { $http.put(endpoint + mediaId + '/publish', { csrf_token: jQuery("#csrf").val(), sources: $scope.publishData }).success(function () { init(); }); }; $scope.remove = function (source) { // TODO }; $scope.discard = function () { tab.close(); $scope.media = {}; }; init(); }); /* var selected = $("#podcast_table").find(".selected"), ids = []; var selectedData = AIRTIME.library.podcastTableWidget.getSelectedRows(); selectedData.forEach(function(el) { ids.push(el.id); });*/ function _bootstrapAngularApp(mediaId, tab) { publishApp.value('mediaId', mediaId); publishApp.value('tab', tab); var wrapper = AIRTIME.tabs.getActiveTab().contents.find(".editor_pane_wrapper"); wrapper.attr("ng-controller", "RestController"); angular.bootstrap(wrapper.get(0), [PUBLISH_APP_NAME]); } mod.publishSelectedTracks = function() { /* _bulkAction("GET", function(json) { json.forEach(function(el) { var uid = AIRTIME.library.MediaTypeStringEnum.FILE+"_"+el.id; var mediaId = el.id; $http.get(dialogUrl, { csrf_token: jQuery("#csrf").val() }) .success(function(json) { AIRTIME.tabs.openTab(json, uid, null); _bootstrapAngularApp(mediaId); }); }); });*/ }; mod.publishTrack = function(mediaId) { jQuery.get(dialogUrl, { csrf_token: jQuery("#csrf").val() }) .success(function(html) { var tab = AIRTIME.tabs.openTab(html, mediaId, null); _bootstrapAngularApp(mediaId, tab); }); /* _bulkAction("GET", function(json) { json.forEach(function(el) { var uid = AIRTIME.library.MediaTypeStringEnum.FILE+"_"+el.id; $http.get(dialogUrl, { csrf_token: jQuery("#csrf").val() }) .success(function(json) { AIRTIME.tabs.openTab(json, uid, null); _bootstrapAngularApp(el.media); }); }); });*/ }; return AIRTIME; }(AIRTIME || {}));