{"size": 2362, "ext": "js", "max_stars_repo_path": "web/js/recordingsController.js", "max_stars_repo_name": "isaacandy/Boardroom-v3", "max_stars_repo_stars_event_min_datetime": "2018-11-03T18:35:41.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-27T01:59:42.000Z", "max_issues_repo_path": "web/js/recordingsController.js", "max_issues_repo_name": "isaacandy/Boardroom-v3", "max_issues_repo_issues_event_min_datetime": "2021-03-08T22:56:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T04:05:23.000Z", "max_forks_repo_path": "web/js/recordingsController.js", "max_forks_repo_name": "isaacandy/Boardroom-v3", "max_forks_repo_forks_event_min_datetime": "2018-11-03T18:33:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-03T18:33:57.000Z"}
{"max_stars_count": 7, "max_issues_count": 3, "max_forks_count": 1, "avg_line_length": 28.4578313253, "max_line_length": 105, "alphanum_fraction": 0.6024555461}
/* global Modal, FirebaseModel, RecordingsView */

!(function (exports) {
  'use strict';

  var model = null;

  function init(enableArchiveManager, firebaseUrl, firebaseToken) {
    var dependenciesLoaded;
    if (enableArchiveManager) {
      dependenciesLoaded = LazyLoader.dependencyLoad([
        '/js/models/firebase.js',
        '/js/recordingsView.js'
      ]).then(function () {
        return FirebaseModel
                  .init(firebaseUrl, firebaseToken);
      });
    } else {
      dependenciesLoaded = Promise.resolve();
    }

    return dependenciesLoaded.then(function (aModel) {
      model = aModel;
      Utils.sendEvent('recordings-model-ready', null, exports);
      addListeners();
      aModel && RecordingsView.init(model);
    });
  }

  function onDeleteArchive(data) {
    var previousStatus = data.status;
    data.status = 'deleting';
    Request.deleteArchive(data.id)
      .then(function () {
        Utils.sendEvent('RecordingsController:deleteArchive', { id: data.id });
      })
      .catch(function () {
        // Archived couldn't be deleted from server...
        data.status = previousStatus;
      });
  }

  var handlers = {
    delete: function (data) {
      var selector = '.archive-delete-modal';
      function loadModalText() {
        document.querySelector(selector + ' .username').textContent = data.username;
      }
      return Modal.show(selector, loadModalText).then(function () {
        return new Promise(function () {
          var ui = document.querySelector(selector);
          ui.addEventListener('click', function onClicked(evt) { // eslint-disable-line consistent-return
            var classList = evt.target.classList;
            evt.stopImmediatePropagation();
            evt.preventDefault();

            (classList.contains('delete-archive')) && onDeleteArchive(data);

            if (classList.contains('btn')) {
              ui.removeEventListener('click', onClicked);
              return Modal.hide(selector);
            }
          });
        });
      });
    }
  };

  var addListeners = function () {
    exports.addEventListener('archive', function (evt) {
      var handler = handlers[evt.detail.action];
      handler && handler(evt.detail);
    });
  };

  exports.RecordingsController = {
    init: init,
    get model() {
      return model;
    }
  };
}(this));
