forked from External/greenlight
		
	clean active_meetings.js and landing.js
This commit is contained in:
		@@ -21,15 +21,17 @@ var MEETINGS = {}
 | 
			
		||||
var WAITING = {}
 | 
			
		||||
var LOADING_DELAY = 1750 // milliseconds.
 | 
			
		||||
 | 
			
		||||
// Updates the previous meetings section.
 | 
			
		||||
var updatePreviousMeetings = function(){
 | 
			
		||||
  $("ul.previously-joined li").each(function(idx, li) {
 | 
			
		||||
    previous_meeting = $(li);
 | 
			
		||||
    var previous_meeting = $(li);
 | 
			
		||||
    if(Object.keys(MEETINGS).indexOf(previous_meeting.text()) > -1){
 | 
			
		||||
      previous_meeting.remove()
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Adds a user to a meeting.
 | 
			
		||||
var addUser = function(data){
 | 
			
		||||
  if(data['role'] == 'MODERATOR'){
 | 
			
		||||
    MEETINGS[data['meeting']]['moderators'].push(data['user'])
 | 
			
		||||
@@ -39,6 +41,7 @@ var addUser = function(data){
 | 
			
		||||
  updateMeetingText(MEETINGS[data['meeting']])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Removes a user from a meeting.
 | 
			
		||||
var removeUser = function(data){
 | 
			
		||||
  if(data['role'] == 'MODERATOR'){
 | 
			
		||||
    MEETINGS[data['meeting']]['moderators'].splice(MEETINGS[data['meeting']]['moderators'].indexOf(data['user']), 1);
 | 
			
		||||
@@ -48,21 +51,26 @@ var removeUser = function(data){
 | 
			
		||||
  updateMeetingText(MEETINGS[data['meeting']])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Updates the display text for an active meeting.
 | 
			
		||||
var updateMeetingText = function(m){
 | 
			
		||||
  // If a meeting has a moderators property, it is running.
 | 
			
		||||
  var body;
 | 
			
		||||
  if(m.hasOwnProperty('moderators')){
 | 
			
		||||
    var list;
 | 
			
		||||
    if(m['moderators'].length + m['participants'].length == 0){
 | 
			
		||||
      list = '(empty)'
 | 
			
		||||
    } else {
 | 
			
		||||
      list = m['moderators'].join('(mod), ') + (m['moderators'].length > 0 ? '(mod)' : '') +
 | 
			
		||||
      (m['participants'].length > 0 && m['moderators'].length != 0 ? ', ' : '') + m['participants'].join(', ')
 | 
			
		||||
        (m['participants'].length > 0 && m['moderators'].length != 0 ? ', ' : '') + m['participants'].join(', ')
 | 
			
		||||
    }
 | 
			
		||||
    var body = '<a>' + m['name'] + '</a><i>: ' + list + '</i>'
 | 
			
		||||
    body = '<a>' + m['name'] + '</a><i>: ' + list + '</i>'
 | 
			
		||||
  // Otherwise it hasn't started (users waiting the join).
 | 
			
		||||
  } else {
 | 
			
		||||
    var body = '<a>' + m['name'] + '</a><i> (not yet started): ' + 
 | 
			
		||||
                m['users'].join(', ') + '</i>'
 | 
			
		||||
    body = '<a>' + m['name'] + '</a><i> (not yet started): ' + 
 | 
			
		||||
                  m['users'].join(', ') + '</i>'
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // If the item doesn't exist, add it and set up join meeting event.
 | 
			
		||||
  if($('#' + m['name'].replace(' ', '_')).length == 0){
 | 
			
		||||
    var meeting_item = $('<li id = ' + m['name'].replace(' ', '_') + '>' + body + '</li>')
 | 
			
		||||
    $('.actives').append(meeting_item);
 | 
			
		||||
@@ -71,11 +79,13 @@ var updateMeetingText = function(m){
 | 
			
		||||
    meeting_item.click(function(){
 | 
			
		||||
      joinMeeting(m['name']);
 | 
			
		||||
    });
 | 
			
		||||
  // Otherwise, just change the body.
 | 
			
		||||
  } else {
 | 
			
		||||
    $('#' + m['name'].replace(' ', '_')).html(body)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Initially populates the active meetings when the page loads using the API.
 | 
			
		||||
var initialPopulate = function(){
 | 
			
		||||
  // Only populate on room resources.
 | 
			
		||||
  var chopped = window.location.href.split('/')
 | 
			
		||||
@@ -95,9 +105,6 @@ var initialPopulate = function(){
 | 
			
		||||
      if(meetings[i]['metadata']['room-id'] != $('body').data('current-user')) { continue; }
 | 
			
		||||
      var name = meetings[i]['meetingName']
 | 
			
		||||
      
 | 
			
		||||
      var participants = []
 | 
			
		||||
      var moderators = []
 | 
			
		||||
      
 | 
			
		||||
      var attendees;
 | 
			
		||||
      if(meetings[i]['attendees']['attendee'] instanceof Array){
 | 
			
		||||
        attendees = meetings[i]['attendees']['attendee']
 | 
			
		||||
@@ -105,6 +112,9 @@ var initialPopulate = function(){
 | 
			
		||||
        attendees = [meetings[i]['attendees']['attendee']]
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      var participants = []
 | 
			
		||||
      var moderators = []
 | 
			
		||||
      
 | 
			
		||||
      jQuery.each(attendees, function(i, attendee){
 | 
			
		||||
        // The API doesn't return a empty array when empty, just undefined.
 | 
			
		||||
        if(attendee != undefined){
 | 
			
		||||
@@ -131,22 +141,19 @@ var initialPopulate = function(){
 | 
			
		||||
    updatePreviousMeetings();
 | 
			
		||||
    $('.hidden-list').show();
 | 
			
		||||
    $('.active-spinner').hide();
 | 
			
		||||
  }).error(function(){
 | 
			
		||||
    console.log('Not on a page to load meetings.')
 | 
			
		||||
    return true;
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Checks if a meeting has been prveiously joined by the user.
 | 
			
		||||
var isPreviouslyJoined = function(meeting){
 | 
			
		||||
  joinedMeetings = localStorage.getItem('joinedRooms-' + $('body').data('current-user'));
 | 
			
		||||
  var joinedMeetings = localStorage.getItem('joinedRooms-' + $('body').data('current-user'));
 | 
			
		||||
  if (joinedMeetings == '' || joinedMeetings == null){ return false; }
 | 
			
		||||
  return joinedMeetings.split(',').indexOf(meeting) >= 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Removes an active meeting.
 | 
			
		||||
var removeActiveMeeting = function(meeting){
 | 
			
		||||
  if(meeting){
 | 
			
		||||
    $('#' + meeting['name'].replace(' ', '_')).remove()
 | 
			
		||||
  }
 | 
			
		||||
  if(meeting){ $('#' + meeting['name'].replace(' ', '_')).remove() }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Directly join a meeting from active meetings.
 | 
			
		||||
@@ -177,13 +184,16 @@ $(document).on('turbolinks:load', function(){
 | 
			
		||||
  if($('body').data('current-user')){
 | 
			
		||||
 | 
			
		||||
    MEETINGS = {}
 | 
			
		||||
    // Ensure actives is empty.
 | 
			
		||||
    $('.actives').empty();
 | 
			
		||||
 | 
			
		||||
    if(!App.messages){
 | 
			
		||||
      // Setup actioncable.
 | 
			
		||||
      App.messages = App.cable.subscriptions.create('RefreshMeetingsChannel', {
 | 
			
		||||
        received: function(data) {
 | 
			
		||||
          console.log('Recieved ' + data['method'] + ' action for ' + data['meeting'] + ' with room id ' + data['room'] + '.')
 | 
			
		||||
          if(isPreviouslyJoined(data['meeting']) && data['room'] == $('body').data('current-user')){
 | 
			
		||||
            // Handle webhook event.
 | 
			
		||||
            if(data['method'] == 'create'){
 | 
			
		||||
              // Create an empty meeting.
 | 
			
		||||
              MEETINGS[data['meeting']] = {'name': data['meeting'],
 | 
			
		||||
@@ -224,6 +234,7 @@ $(document).on('turbolinks:load', function(){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    console.log('Populating active meetings.');
 | 
			
		||||
    // Short delay to hide the previous meetings population.
 | 
			
		||||
    setTimeout(initialPopulate, LOADING_DELAY);
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,7 @@
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // setup event handlers
 | 
			
		||||
    $('.center-panel-wrapper').on ('click', '.meeting-join', function (event) {
 | 
			
		||||
    $('.center-panel-wrapper').on ('click', '.meeting-join', function () {
 | 
			
		||||
      var name = $('.meeting-user-name').val();
 | 
			
		||||
      Meeting.getInstance().setUserName(name);
 | 
			
		||||
      Meeting.getInstance().setMeetingId($(".page-wrapper").data('id'));
 | 
			
		||||
@@ -56,7 +56,7 @@
 | 
			
		||||
              $(location).attr("href", data.response.join_url);
 | 
			
		||||
            }
 | 
			
		||||
          });
 | 
			
		||||
          jqxhr.fail(function(xhr, status, error) {
 | 
			
		||||
          jqxhr.fail(function() {
 | 
			
		||||
            console.info("meeting join failed");
 | 
			
		||||
          });
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -69,11 +69,11 @@
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $('.center-panel-wrapper').on ('click', '.meeting-start', function (event) {
 | 
			
		||||
    $('.center-panel-wrapper').on ('click', '.meeting-start', function () {
 | 
			
		||||
      Turbolinks.visit($('.meeting-url').val());
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $('.center-panel-wrapper').on ('input', '.meeting-user-name', function (event) {
 | 
			
		||||
    $('.center-panel-wrapper').on ('input', '.meeting-user-name', function () {
 | 
			
		||||
      if ($(this).val() === '') {
 | 
			
		||||
        $(this).parent().addClass('has-error')
 | 
			
		||||
      } else {
 | 
			
		||||
@@ -95,20 +95,17 @@
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $('.center-panel-wrapper').on ('click', '.meeting-end', function (event) {
 | 
			
		||||
    $('.center-panel-wrapper').on ('click', '.meeting-end', function () {
 | 
			
		||||
      var jqxhr = Meeting.getInstance().endMeeting();
 | 
			
		||||
      var btn = $(this);
 | 
			
		||||
      btn.prop("disabled", true);
 | 
			
		||||
      jqxhr.done(function(data) {
 | 
			
		||||
 | 
			
		||||
      });
 | 
			
		||||
      jqxhr.fail(function(xhr, status, error) {
 | 
			
		||||
      jqxhr.fail(function() {
 | 
			
		||||
        console.info("meeting end failed");
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $('.center-panel-wrapper').on ('click', '.meeting-url-copy', function (event) {
 | 
			
		||||
      meetingURLInput = $('.meeting-url');
 | 
			
		||||
    $('.center-panel-wrapper').on ('click', '.meeting-url-copy', function () {
 | 
			
		||||
      var meetingURLInput = $('.meeting-url');
 | 
			
		||||
 | 
			
		||||
      // copy URL
 | 
			
		||||
      meetingURLInput.select();
 | 
			
		||||
@@ -135,7 +132,7 @@
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // button used to send invitations to the meeting (i.e. "mailto:" link)
 | 
			
		||||
    $('.center-panel-wrapper').on('click', '.meeting-invite', function (event) {
 | 
			
		||||
    $('.center-panel-wrapper').on('click', '.meeting-invite', function () {
 | 
			
		||||
      var meetingURL = Meeting.getInstance().getURL();
 | 
			
		||||
      var subject = $(this).data("invite-subject");
 | 
			
		||||
      var body = $(this).data("invite-body").replace("&&URL&&", meetingURL);
 | 
			
		||||
@@ -143,16 +140,16 @@
 | 
			
		||||
      window.open(mailto);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $('.center-panel-wrapper').on('mouseleave', '.meeting-url-copy', function (event, msg) {
 | 
			
		||||
    $('.center-panel-wrapper').on('mouseleave', '.meeting-url-copy', function () {
 | 
			
		||||
      $(this).blur();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    $('.center-panel-wrapper').on('focus', '.meeting-url', function (event, msg) {
 | 
			
		||||
    $('.center-panel-wrapper').on('focus', '.meeting-url', function () {
 | 
			
		||||
      $(this).select();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // only allow ctrl commands
 | 
			
		||||
    $('.center-panel-wrapper').on('keydown', '.meeting-url', function (event, msg) {
 | 
			
		||||
    $('.center-panel-wrapper').on('keydown', '.meeting-url', function (event) {
 | 
			
		||||
      if(!event.ctrlKey) {
 | 
			
		||||
        event.preventDefault();
 | 
			
		||||
      }
 | 
			
		||||
@@ -164,7 +161,7 @@
 | 
			
		||||
      container: 'body'
 | 
			
		||||
    };
 | 
			
		||||
    $(document).tooltip(options);
 | 
			
		||||
    var options = {
 | 
			
		||||
    options = {
 | 
			
		||||
      selector: '.bottom-tooltip',
 | 
			
		||||
      container: 'body',
 | 
			
		||||
      placement: 'bottom'
 | 
			
		||||
@@ -183,7 +180,7 @@
 | 
			
		||||
 | 
			
		||||
  var initIndex = function() {
 | 
			
		||||
 | 
			
		||||
    $('.center-panel-wrapper').on('input', '.meeting-name', function (event, msg) {
 | 
			
		||||
    $('.center-panel-wrapper').on('input', '.meeting-name', function () {
 | 
			
		||||
      var newId = $(this).val();
 | 
			
		||||
      Meeting.getInstance().setMeetingId(newId);
 | 
			
		||||
      $(".page-wrapper.meetings").data('id', newId);
 | 
			
		||||
@@ -207,7 +204,7 @@
 | 
			
		||||
    displayRoomURL();
 | 
			
		||||
    var roomAdmin = $('.page-wrapper.rooms').data('admin-id');
 | 
			
		||||
 | 
			
		||||
    $('.center-panel-wrapper').on('input', '.meeting-name', function (event, msg) {
 | 
			
		||||
    $('.center-panel-wrapper').on('input', '.meeting-name', function () {
 | 
			
		||||
      var newId = $(this).val();
 | 
			
		||||
      Meeting.getInstance().setMeetingId(newId);
 | 
			
		||||
      $('.meeting-url').val(Meeting.getInstance().getURL());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user