forked from External/greenlight
		
	coffeescript classes instead of es6
This commit is contained in:
		
							
								
								
									
										62
									
								
								app/assets/javascripts/meeting.coffee
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								app/assets/javascripts/meeting.coffee
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
# Meeting class
 | 
			
		||||
 | 
			
		||||
_meetingInstance = null
 | 
			
		||||
 | 
			
		||||
class @Meeting
 | 
			
		||||
  constructor: (@id, @url, @name) ->
 | 
			
		||||
 | 
			
		||||
  # Gets the current instance or creates a new one
 | 
			
		||||
  @getInstance: ->
 | 
			
		||||
    if _meetingInstance
 | 
			
		||||
      return _meetingInstance
 | 
			
		||||
    id = $(".page-wrapper.rooms").data('room')
 | 
			
		||||
    url = @buildURL()
 | 
			
		||||
    name = $('.meeting-user-name').val()
 | 
			
		||||
    _meetingInstance = new Meeting(id, url, name)
 | 
			
		||||
    return _meetingInstance
 | 
			
		||||
 | 
			
		||||
  @buildURL: ->
 | 
			
		||||
    return location.protocol +
 | 
			
		||||
      '//' +
 | 
			
		||||
      location.hostname +
 | 
			
		||||
      '/rooms/' +
 | 
			
		||||
      $('.rooms').data('room')
 | 
			
		||||
 | 
			
		||||
  # Sends the end meeting request
 | 
			
		||||
  # Returns a response object
 | 
			
		||||
  endMeeting: ->
 | 
			
		||||
    return $.ajax({
 | 
			
		||||
      url: @url + "/end",
 | 
			
		||||
      type: 'DELETE'
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
  # Makes a call to get the join meeting url
 | 
			
		||||
  # Returns a response object
 | 
			
		||||
  #    The response object contains the URL to join the meeting
 | 
			
		||||
  getJoinMeetingResponse: ->
 | 
			
		||||
    return $.get @url + "/join?name=" + @name, ->
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  getId: ->
 | 
			
		||||
    return @id
 | 
			
		||||
 | 
			
		||||
  getURL: ->
 | 
			
		||||
    return @url
 | 
			
		||||
 | 
			
		||||
  getName: ->
 | 
			
		||||
    return @name
 | 
			
		||||
 | 
			
		||||
  setName: (name) ->
 | 
			
		||||
    @name = name
 | 
			
		||||
 | 
			
		||||
  getModJoined: ->
 | 
			
		||||
    return @modJoined
 | 
			
		||||
 | 
			
		||||
  setModJoined: (modJoined) ->
 | 
			
		||||
    @modJoined = modJoined
 | 
			
		||||
 | 
			
		||||
  getWaitingForMod: ->
 | 
			
		||||
    return @waitingForMod
 | 
			
		||||
 | 
			
		||||
  setWaitingForMod: (wMod) ->
 | 
			
		||||
    @waitingForMod = wMod
 | 
			
		||||
@@ -1,80 +0,0 @@
 | 
			
		||||
// Meeting class
 | 
			
		||||
 | 
			
		||||
var _meetingInstance = null;
 | 
			
		||||
 | 
			
		||||
class Meeting {
 | 
			
		||||
  constructor(id, url, name) {
 | 
			
		||||
    this.id = id;
 | 
			
		||||
    this.url = url;
 | 
			
		||||
    this.name = name;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Gets the current instance or creates a new one
 | 
			
		||||
  static getInstance() {
 | 
			
		||||
    if (_meetingInstance) {
 | 
			
		||||
      return _meetingInstance;
 | 
			
		||||
    }
 | 
			
		||||
    var id = $(".page-wrapper.rooms").data('room');
 | 
			
		||||
    var url = Meeting.buildURL();
 | 
			
		||||
    var name = $('.meeting-user-name').val();
 | 
			
		||||
    _meetingInstance = new Meeting(id, url, name);
 | 
			
		||||
    return _meetingInstance;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static buildURL() {
 | 
			
		||||
    return location.protocol +
 | 
			
		||||
      '//' +
 | 
			
		||||
      location.hostname +
 | 
			
		||||
      '/rooms/' +
 | 
			
		||||
      $('.rooms').data('room');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Sends the end meeting request
 | 
			
		||||
  // Returns a response object
 | 
			
		||||
  endMeeting() {
 | 
			
		||||
    return $.ajax({
 | 
			
		||||
      url: this.url + "/end",
 | 
			
		||||
      type: 'DELETE'
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Makes a call to get the join meeting url
 | 
			
		||||
  // Returns a response object
 | 
			
		||||
  //    The response object contains the URL to join the meeting
 | 
			
		||||
  getJoinMeetingResponse() {
 | 
			
		||||
    return $.get(this.url + "/join?name=" + this.name, function() {
 | 
			
		||||
    });
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  getId() {
 | 
			
		||||
    return this.id;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getURL() {
 | 
			
		||||
    return this.url;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getName() {
 | 
			
		||||
    return this.name;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setName(name) {
 | 
			
		||||
    this.name = name;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getModJoined() {
 | 
			
		||||
    return this.modJoined;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setModJoined(modJoined) {
 | 
			
		||||
    this.modJoined = modJoined;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getWaitingForMod() {
 | 
			
		||||
    return this.waitingForMod;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setWaitingForMod(wMod) {
 | 
			
		||||
    this.waitingForMod = wMod;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										137
									
								
								app/assets/javascripts/recordings.coffee
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								app/assets/javascripts/recordings.coffee
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,137 @@
 | 
			
		||||
# Recordings class
 | 
			
		||||
 | 
			
		||||
_recordingsInstance = null
 | 
			
		||||
 | 
			
		||||
class @Recordings
 | 
			
		||||
  constructor: ->
 | 
			
		||||
    # configure the datatable for recordings
 | 
			
		||||
    this.table = $('#recordings').dataTable({
 | 
			
		||||
      data: [],
 | 
			
		||||
      rowId: 'id',
 | 
			
		||||
      paging: false,
 | 
			
		||||
      searching: false,
 | 
			
		||||
      info: false,
 | 
			
		||||
      order: [[ 0, "desc" ]],
 | 
			
		||||
      language: {
 | 
			
		||||
        emptyTable: " "
 | 
			
		||||
      },
 | 
			
		||||
      columns: [
 | 
			
		||||
        { data: "start_time" },
 | 
			
		||||
        { data: "previews" },
 | 
			
		||||
        { data: "duration" },
 | 
			
		||||
        { data: "playbacks" },
 | 
			
		||||
        { data: "id" }
 | 
			
		||||
      ],
 | 
			
		||||
      columnDefs: [
 | 
			
		||||
        {
 | 
			
		||||
          targets: 0,
 | 
			
		||||
          render: (data, type, row) ->
 | 
			
		||||
            if type == 'display'
 | 
			
		||||
              return new Date(data)
 | 
			
		||||
                .toLocaleString($('html').attr('lang'),
 | 
			
		||||
                  {month: 'long', day: 'numeric', year: 'numeric',
 | 
			
		||||
                  hour12: 'true', hour: '2-digit', minute: '2-digit'})
 | 
			
		||||
            return data
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          targets: 1,
 | 
			
		||||
          render: (data, type, row) ->
 | 
			
		||||
            if type == 'display'
 | 
			
		||||
              str = ''
 | 
			
		||||
              for d in data
 | 
			
		||||
                str += '<img height="50" width="50" src="'+d.url+'" alt="'+d.alt+'"></img> '
 | 
			
		||||
              return str
 | 
			
		||||
            return data
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          targets: 3,
 | 
			
		||||
          render: (data, type, row) ->
 | 
			
		||||
            if type == 'display'
 | 
			
		||||
              str = ''
 | 
			
		||||
              if row.published
 | 
			
		||||
                for d in data
 | 
			
		||||
                  str += '<a href="'+d.url+'">'+d.type+'</a> '
 | 
			
		||||
              return str
 | 
			
		||||
            return data
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          targets: -1,
 | 
			
		||||
          render: (data, type, row) ->
 | 
			
		||||
            if type == 'display'
 | 
			
		||||
              roomName = Meeting.getInstance().getId()
 | 
			
		||||
              published = row.published
 | 
			
		||||
              eye = getPublishClass(published)
 | 
			
		||||
              return '<button type="button" class="btn btn-default recording-update" data-published="'+published+'">' +
 | 
			
		||||
                '<i class="fa '+eye+'" aria-hidden="true"></i></button> ' +
 | 
			
		||||
                '<a tabindex="0" role="button" class="btn btn-default has-popover"' +
 | 
			
		||||
                  'data-toggle="popover" data-placement="top">' +
 | 
			
		||||
                    '<i class="fa fa-trash-o" aria-hidden="true"></i>' +
 | 
			
		||||
                '</a>'
 | 
			
		||||
            return data
 | 
			
		||||
        }
 | 
			
		||||
      ]
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
  # Gets the current instance or creates a new one
 | 
			
		||||
  @getInstance: ->
 | 
			
		||||
    if _recordingsInstance && Recordings.initialized()
 | 
			
		||||
      return _recordingsInstance
 | 
			
		||||
    _recordingsInstance = new Recordings()
 | 
			
		||||
    return _recordingsInstance
 | 
			
		||||
 | 
			
		||||
  @initialize: ->
 | 
			
		||||
    Recordings.getInstance()
 | 
			
		||||
 | 
			
		||||
  @initialized: ->
 | 
			
		||||
    return $.fn.DataTable.isDataTable('#recordings') && _recordingsInstance
 | 
			
		||||
 | 
			
		||||
  # refresh the recordings from the server
 | 
			
		||||
  refresh: ->
 | 
			
		||||
    _this = this
 | 
			
		||||
    table_api = this.table.api()
 | 
			
		||||
    $.get "/rooms/"+Meeting.getInstance().getId()+"/recordings", (data) ->
 | 
			
		||||
      if !data.is_owner
 | 
			
		||||
        table_api.column(-1).visible(false)
 | 
			
		||||
      for recording in data.recordings
 | 
			
		||||
        totalMinutes = Math.round((new Date(recording.end_time) - new Date(recording.start_time)) / 1000 / 60)
 | 
			
		||||
        recording.duration = totalMinutes
 | 
			
		||||
      data.recordings.sort (a,b) ->
 | 
			
		||||
        return new Date(b.start_time) - new Date(a.start_time)
 | 
			
		||||
      table_api.clear()
 | 
			
		||||
      table_api.rows.add(data.recordings)
 | 
			
		||||
      table_api.columns.adjust().draw()
 | 
			
		||||
 | 
			
		||||
  # setup click handlers for the action buttons
 | 
			
		||||
  setupActionHandlers: ->
 | 
			
		||||
    table_api = this.table.api()
 | 
			
		||||
    this.table.on 'click', '.recording-update', (event) ->
 | 
			
		||||
      btn = $(this)
 | 
			
		||||
      row = table_api.row($(this).closest('tr')).data()
 | 
			
		||||
      url = $('.meeting-url').val()
 | 
			
		||||
      id = row.id
 | 
			
		||||
      published = btn.data('published')
 | 
			
		||||
      btn.prop('disabled', true)
 | 
			
		||||
      $.ajax({
 | 
			
		||||
        method: 'PATCH',
 | 
			
		||||
        url: url+'/recordings/'+id,
 | 
			
		||||
        data: {published: (!published).toString()}
 | 
			
		||||
      }).done((data) ->
 | 
			
		||||
 | 
			
		||||
      ).fail((data) ->
 | 
			
		||||
        btn.prop('disabled', false)
 | 
			
		||||
      )
 | 
			
		||||
 | 
			
		||||
    this.table.on 'click', '.recording-delete', (event) ->
 | 
			
		||||
      btn = $(this)
 | 
			
		||||
      row = table_api.row($(this).closest('tr')).data()
 | 
			
		||||
      url = $('.meeting-url').val()
 | 
			
		||||
      id = row.id
 | 
			
		||||
      btn.prop('disabled', true)
 | 
			
		||||
      $.ajax({
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
        url: url+'/recordings/'+id
 | 
			
		||||
      }).done((data) ->
 | 
			
		||||
 | 
			
		||||
      ).fail((data) ->
 | 
			
		||||
        btn.prop('disabled', false)
 | 
			
		||||
      )
 | 
			
		||||
@@ -1,163 +0,0 @@
 | 
			
		||||
// Recordings class
 | 
			
		||||
 | 
			
		||||
var _recordingsInstance = null;
 | 
			
		||||
 | 
			
		||||
class Recordings {
 | 
			
		||||
  constructor() {
 | 
			
		||||
    // configure the datatable for recordings
 | 
			
		||||
    this.table = $('#recordings').dataTable({
 | 
			
		||||
      data: [],
 | 
			
		||||
      rowId: 'id',
 | 
			
		||||
      paging: false,
 | 
			
		||||
      searching: false,
 | 
			
		||||
      info: false,
 | 
			
		||||
      order: [[ 0, "desc" ]],
 | 
			
		||||
      language: {
 | 
			
		||||
        emptyTable: " "
 | 
			
		||||
      },
 | 
			
		||||
      columns: [
 | 
			
		||||
        { data: "start_time" },
 | 
			
		||||
        { data: "previews" },
 | 
			
		||||
        { data: "duration" },
 | 
			
		||||
        { data: "playbacks" },
 | 
			
		||||
        { data: "id" }
 | 
			
		||||
      ],
 | 
			
		||||
      columnDefs: [
 | 
			
		||||
        {
 | 
			
		||||
          targets: 0,
 | 
			
		||||
          render: function(data, type, row) {
 | 
			
		||||
            if (type === 'display') {
 | 
			
		||||
              return new Date(data)
 | 
			
		||||
                .toLocaleString($('html').attr('lang'),
 | 
			
		||||
                  {month: 'long', day: 'numeric', year: 'numeric',
 | 
			
		||||
                  hour12: 'true', hour: '2-digit', minute: '2-digit'});
 | 
			
		||||
            }
 | 
			
		||||
            return data;
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          targets: 1,
 | 
			
		||||
          render: function(data, type, row) {
 | 
			
		||||
            if (type === 'display') {
 | 
			
		||||
              var str = '';
 | 
			
		||||
              for(let i in data) {
 | 
			
		||||
                str += '<img height="50" width="50" src="'+data[i].url+'" alt="'+data[i].alt+'"></img> ';
 | 
			
		||||
              }
 | 
			
		||||
              return str;
 | 
			
		||||
            }
 | 
			
		||||
            return data;
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          targets: 3,
 | 
			
		||||
          render: function(data, type, row) {
 | 
			
		||||
            if (type === 'display') {
 | 
			
		||||
              var str = '';
 | 
			
		||||
              if (row.published) {
 | 
			
		||||
                for(let i in data) {
 | 
			
		||||
                  str += '<a href="'+data[i].url+'">'+data[i].type+'</a> ';
 | 
			
		||||
                }
 | 
			
		||||
              }
 | 
			
		||||
              return str;
 | 
			
		||||
            }
 | 
			
		||||
            return data;
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          targets: -1,
 | 
			
		||||
          render: function(data, type, row) {
 | 
			
		||||
            if (type === 'display') {
 | 
			
		||||
              var roomName = Meeting.getInstance().getId();
 | 
			
		||||
              var published = row.published;
 | 
			
		||||
              var eye = getPublishClass(published);
 | 
			
		||||
              return '<button type="button" class="btn btn-default recording-update" data-published="'+published+'">' +
 | 
			
		||||
                '<i class="fa '+eye+'" aria-hidden="true"></i></button> ' +
 | 
			
		||||
                '<a tabindex="0" role="button" class="btn btn-default has-popover"' +
 | 
			
		||||
                  'data-toggle="popover" data-placement="top">' +
 | 
			
		||||
                    '<i class="fa fa-trash-o" aria-hidden="true"></i>' +
 | 
			
		||||
                '</a>';
 | 
			
		||||
            }
 | 
			
		||||
            return data;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      ]
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Gets the current instance or creates a new one
 | 
			
		||||
  static getInstance() {
 | 
			
		||||
    if (_recordingsInstance && Recordings.initialized()) {
 | 
			
		||||
      return _recordingsInstance;
 | 
			
		||||
    }
 | 
			
		||||
    _recordingsInstance = new Recordings();
 | 
			
		||||
    return _recordingsInstance;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static initialize() {
 | 
			
		||||
    Recordings.getInstance();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static initialized() {
 | 
			
		||||
    return $.fn.DataTable.isDataTable('#recordings') && _recordingsInstance;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // refresh the recordings from the server
 | 
			
		||||
  refresh() {
 | 
			
		||||
    var _this = this;
 | 
			
		||||
    var table_api = this.table.api();
 | 
			
		||||
    $.get("/rooms/"+Meeting.getInstance().getId()+"/recordings", function(data) {
 | 
			
		||||
      if (!data.is_owner) {
 | 
			
		||||
        table_api.column(-1).visible(false);
 | 
			
		||||
      }
 | 
			
		||||
      var i;
 | 
			
		||||
      for (i = 0; i < data.recordings.length; i++) {
 | 
			
		||||
        var totalMinutes = Math.round((new Date(data.recordings[i].end_time) - new Date(data.recordings[i].start_time)) / 1000 / 60);
 | 
			
		||||
        data.recordings[i].duration = totalMinutes;
 | 
			
		||||
      }
 | 
			
		||||
      data.recordings.sort(function(a,b) {
 | 
			
		||||
        return new Date(b.start_time) - new Date(a.start_time);
 | 
			
		||||
      });
 | 
			
		||||
      table_api.clear();
 | 
			
		||||
      table_api.rows.add(data.recordings);
 | 
			
		||||
      table_api.columns.adjust().draw();
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // setup click handlers for the action buttons
 | 
			
		||||
  setupActionHandlers() {
 | 
			
		||||
    var table_api = this.table.api();
 | 
			
		||||
    this.table.on('click', '.recording-update', function(event) {
 | 
			
		||||
      var btn = $(this);
 | 
			
		||||
      var row = table_api.row($(this).closest('tr')).data();
 | 
			
		||||
      var url = $('.meeting-url').val();
 | 
			
		||||
      var id = row.id;
 | 
			
		||||
      var published = btn.data('published');
 | 
			
		||||
      btn.prop('disabled', true);
 | 
			
		||||
      $.ajax({
 | 
			
		||||
        method: 'PATCH',
 | 
			
		||||
        url: url+'/recordings/'+id,
 | 
			
		||||
        data: {published: (!published).toString()}
 | 
			
		||||
      }).done(function(data) {
 | 
			
		||||
 | 
			
		||||
      }).fail(function(data) {
 | 
			
		||||
        btn.prop('disabled', false);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    this.table.on('click', '.recording-delete', function(event) {
 | 
			
		||||
      var btn = $(this);
 | 
			
		||||
      var row = table_api.row($(this).closest('tr')).data();
 | 
			
		||||
      var url = $('.meeting-url').val();
 | 
			
		||||
      var id = row.id;
 | 
			
		||||
      btn.prop('disabled', true);
 | 
			
		||||
      $.ajax({
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
        url: url+'/recordings/'+id
 | 
			
		||||
      }).done(function() {
 | 
			
		||||
 | 
			
		||||
      }).fail(function(data) {
 | 
			
		||||
        btn.prop('disabled', false);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user