<commit_before>"use strict";
/**
 * Functions to interface with the DOM
 */
/**
 * This global, "static" object contains all functions for interacting with
 * the DOM. Additionally, all globals for DOM functions
 * are encapsulated here.
 */
var ViewActions = function () {

  var topQuestionsContainer, recentQuestionsContainer, MAX_TOP_QUESTIONS,
      BASE_SCORE, roomData, graph, owner, regexJoinRoom, activePoll, timer,
      questionTemplate, roomID, topQuestionsText, recentQuestionsText,
      deleteRoomMsg;

  /**
   * Sets up the initial state of the page. When this function returns, the page
   * should be ready for the user
   */
  var setupUIImpl = function () {

    regexJoinRoom            = /^([A-Za-z]+-[A-Za-z]+-\d+)$/;
    topQuestionsContainer    = $('#top-questions-container');
    recentQuestionsContainer = $('#recent-questions-container');
    questionTemplate         = Handlebars.compile($('#question-template').html());
    recentQuestionsText      = $('#recent-question-init-text').html();
    topQuestionsText         = $('#top-question-init-text').html();
    deleteRoomMsg            = $('#delete-room-msg').html();
    roomData                 = $('.room-name');
    timer                    = new Timer($('.start-poll-text'));
    activePoll               = false;
    MAX_TOP_QUESTIONS        = 5;
    BASE_SCORE               = 0;
    roomID                   = '';

    /**
     * Set up sorted container for top questions.
     * @see https://mixitup.kunkalabs.com/docs/#method-instantiate
     */
    topQuestionsContainer.mixItUp({
      layout: {
        display: 'block'
      },
      callbacks: {
        onMixEnd: checkMaxQuestions
      }
    });

    var options = {
      trigger: 'manual'
    };

    $('.add-question-text').tooltip(options);
  };



    //TODO remove this once we know we don't need it
    var resizeQuestionContainers = function() {
        /**
         *    css doesn't really let you set the max-height to the parent container,
         *    then begin scrolling thereafter. As a result, we have to set the height
         *    manually on window resize
         */
        var topQ = $('#top-questions-container');
        var recQ = $('.scroll-wrapper');
        var doc = $(document).height();
        var topQOffset = topQ.offset().top;
        var recQOffset = recQ.offset().top + $('.askquestion').outerHeight();
        topQ.css('height', doc - topQOffset +'px' );
        recQ.css('height', doc - recQOffset +'px' );
        console.log("resize called :(");
    };

//============================================================================//
//---------------------------- Join/Make Room --------------------------------//
//============================================================================//
  /**
   * Enter the room as an owner
   * @param roomInfo = {room_id : string, room_name : string,
   * owner_id : string}
   */
  var enterRoomOwnerImpl = function (roomInfo) {
    if (!roomInfo) {
      $('#login-info .room-name-field').addClass('has-error');
    }
    else {
      roomData.data('owner', true);
      $('body').find('.owner-view').each(function () {
        $(this).removeClass('hidden').addClass('show');
      });
      $('.student-view').addClass('hidden');
      $('span.leave-room-text').text('Delete Room');
      owner = true;
      graph = new Graph();
      roomInit(roomInfo);
    }
  }

  /**
   * Enter the room as an audience member
   * @param roomInfo = {room_name : string, room_id : string,
   * questions : array, top_questions : array}
   */
  var enterRoomImpl = function (roomInfo) {
    owner = false;
    if (!roomInfo) {
      $('#room-name-field').addClass('has-error');
    }
    else {
      if (roomID === '' || roomID !== roomInfo.room_id) {
        console.log('Room Id: ' + roomInfo.room_id);
        roomInit(roomInfo);
        addAllQuestions(roomInfo);
      } else {
        $('.login-overlay').addClass('animated slideOutUp');
      }

      if (roomInfo.active_poll) {
        activePoll = roomInfo.active_poll;
        $('.test-in-progress-btn').addClass('active');
      }
    }
  }

  var roomInit = function (roomInfo) {
    roomID = roomInfo.room_id;
    //topQuestionsContainer.html(topQuestionsText);
    //recentQuestionsContainer.html(recentQuestionsText);
    $('#room-name-field').removeClass('has-error');
    roomData.html(roomInfo.room_name);
    roomData.attr('data-room-id', roomID);
    $('.room-name').data('room-id', roomID);
    $('.login-overlay').addClass('animated slideOutUp');
    $('.drop-down-room-id').text(roomID);

  }

  /**
   * Callback for leave room action.
   */
  var leaveRoomImpl = function () {
    var room_id = roomID;

    if (owner) {
      bootbox.dialog({
        message: deleteRoomMsg,
        title: "<strong>Are you sure?</strong>",
        buttons: {
          main:    {
            label:     "Stay",
            className: "btn-success"
          },
          danger:  {
            label:     "Delete",
            className: "btn-danger",
            callback:  function () {
              owner = false;
              socket.emit('leave room', room_id);
            }
          }
        }
      });
    } else {
      socket.emit('leave room', room_id);
    }
  }

<commit_msg>Fixed logout/login poll error for owner<commit_after>"use strict";
/**
 * Functions to interface with the DOM
 */
/**
 * This global, "static" object contains all functions for interacting with
 * the DOM. Additionally, all globals for DOM functions
 * are encapsulated here.
 */
var ViewActions = function () {

  var topQuestionsContainer, recentQuestionsContainer, MAX_TOP_QUESTIONS,
      BASE_SCORE, roomData, graph, owner, regexJoinRoom, activePoll, timer,
      questionTemplate, roomID, topQuestionsText, recentQuestionsText,
      deleteRoomMsg;

  /**
   * Sets up the initial state of the page. When this function returns, the page
   * should be ready for the user
   */
  var setupUIImpl = function () {

    regexJoinRoom            = /^([A-Za-z]+-[A-Za-z]+-\d+)$/;
    topQuestionsContainer    = $('#top-questions-container');
    recentQuestionsContainer = $('#recent-questions-container');
    questionTemplate         = Handlebars.compile($('#question-template').html());
    recentQuestionsText      = $('#recent-question-init-text').html();
    topQuestionsText         = $('#top-question-init-text').html();
    deleteRoomMsg            = $('#delete-room-msg').html();
    roomData                 = $('.room-name');
    timer                    = new Timer($('.start-poll-text'));
    activePoll               = false;
    MAX_TOP_QUESTIONS        = 5;
    BASE_SCORE               = 0;
    roomID                   = '';

    /**
     * Set up sorted container for top questions.
     * @see https://mixitup.kunkalabs.com/docs/#method-instantiate
     */
    topQuestionsContainer.mixItUp({
      layout: {
        display: 'block'
      },
      callbacks: {
        onMixEnd: checkMaxQuestions
      }
    });

    var options = {
      trigger: 'manual'
    };

    $('.add-question-text').tooltip(options);
  };



    //TODO remove this once we know we don't need it
    var resizeQuestionContainers = function() {
        /**
         *    css doesn't really let you set the max-height to the parent container,
         *    then begin scrolling thereafter. As a result, we have to set the height
         *    manually on window resize
         */
        var topQ = $('#top-questions-container');
        var recQ = $('.scroll-wrapper');
        var doc = $(document).height();
        var topQOffset = topQ.offset().top;
        var recQOffset = recQ.offset().top + $('.askquestion').outerHeight();
        topQ.css('height', doc - topQOffset +'px' );
        recQ.css('height', doc - recQOffset +'px' );
        console.log("resize called :(");
    };

//============================================================================//
//---------------------------- Join/Make Room --------------------------------//
//============================================================================//
  /**
   * Enter the room as an owner
   * @param roomInfo = {room_id : string, room_name : string,
   * owner_id : string}
   */
  var enterRoomOwnerImpl = function (roomInfo) {
    if (!roomInfo) {
      $('#login-info .room-name-field').addClass('has-error');
    }
    else {
      roomData.data('owner', true);
      $('body').find('.owner-view').each(function () {
        $(this).removeClass('hidden').addClass('show');
      });
      $('.student-view').addClass('hidden');
      $('span.leave-room-text').text('Delete Room');
      owner = true;
      graph = new Graph();
      roomInit(roomInfo);
    }
  }

  /**
   * Enter the room as an audience member
   * @param roomInfo = {room_name : string, room_id : string,
   * questions : array, top_questions : array}
   */
  var enterRoomImpl = function (roomInfo) {
    owner = false;
    if (!roomInfo) {
      $('#room-name-field').addClass('has-error');
    }
    else {
      if (roomID === '' || roomID !== roomInfo.room_id) {
        console.log('Room Id: ' + roomInfo.room_id);
        roomInit(roomInfo);
        addAllQuestions(roomInfo);
      } else {
        $('.login-overlay').addClass('animated slideOutUp');
      }

      if (roomInfo.active_poll) {
        activePoll = roomInfo.active_poll;
        $('.test-in-progress-btn').addClass('active');
      }
    }
  }

  var roomInit = function (roomInfo) {
    roomID = roomInfo.room_id;
    //topQuestionsContainer.html(topQuestionsText);
    //recentQuestionsContainer.html(recentQuestionsText);
    $('#room-name-field').removeClass('has-error');
    roomData.html(roomInfo.room_name);
    roomData.attr('data-room-id', roomID);
    $('.room-name').data('room-id', roomID);
    $('.login-overlay').addClass('animated slideOutUp');
    $('.drop-down-room-id').text(roomID);

  }

  /**
   * Callback for leave room action.
   */
  var leaveRoomImpl = function () {
    var room_id = roomID;

    if (owner) {
      bootbox.dialog({
        message: deleteRoomMsg,
        title: "<strong>Are you sure?</strong>",
        buttons: {
          main:    {
            label:     "Stay",
            className: "btn-success"
          },
          danger:  {
            label:     "Delete",
            className: "btn-danger",
            callback:  function () {
              owner = false;
              activePoll = false;
              timer.stop();
              graph.clearData();
              $('.start-poll-btn').removeClass('poll-on');
              socket.emit('leave room', room_id);
            }
          }
        }
      });
    } else {
      socket.emit('leave room', room_id);
    }
  }


{'fraction_non_alphanumeric': 0.18552288797915892, 'fraction_numerical': 0.0003721622627465575, 'mean_word_length': 2.1839454976303316, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2212688', 'n_tokens_mistral': 3130, 'n_tokens_neox': 2993, 'n_words': 664}