<commit_before>'use strict';

var Backbone = require('backbone');
var Dispatcher = require('../dispatcher');
var Socket = require('../ros-events');

/**
 * View template.
 */

var agentTemplate = require('../templates/agent.hbs');

var targetTemplate = require('../templates/target.panel.hbs');
var stateTemplate = require('../templates/state.panel.hbs');
var missionTemplate = require('../templates/mission.panel.hbs');
var validationTempalte = require('../templates/validation-panel.hbs');

var victimNotification = require('../templates/victim.alert.hbs');
var victimDialog = require('../templates/victim.dialog.hbs');


var AgentView = Backbone.View.extend({

  template: agentTemplate,
  targetPanelTemplate: targetTemplate,
  statePanelTemplate: stateTemplate,
  missionPanelTemplate: missionTemplate,
  validationPanelTemplate: validationTempalte,

  victimNotificationTemplate: victimNotification,
  victimDialogTemplate: victimDialog,

  waitingForValidation: false,

  initialize: function() {
    console.log('View Agent initialized');

    this.model.subscribe();
    Dispatcher.on('agent:change:state', this.udpateState, this);
    Dispatcher.on('agent:change:target', this.updateTarget, this);
    Dispatcher.on('agent:change:mission', this.updateMission, this);
    Dispatcher.on('agent:victim:alert', this.showVictimAlert, this);
  },

  events: {
    'click #reject-victim': 'rejectVictim',
    'click #accept-victim': 'acceptVictim'
  },

  rejectVictim: function() {
    console.log('Victim rejected');
    this.waitingForValidaiton = false;
    Socket.emit('web/victim/response', false);
    this.$('#validation-panel').addClass('.hide').fadeOut(1000);
  },

  acceptVictim: function() {
    console.log('Victim accepted');
    this.waitingForValidaiton = false;
    Socket.emit('web/victim/response', true);
    this.$('#validation-panel').addClass('.hide').fadeOut(1000);
  },

  updateMission: function() {
      this.renderPartial(
        this.missionPanelTemplate, '#mission-panel', 'mission panel');
  },

  updateState: function() {
      this.renderPartial(
        this.statePanelTemplate, '#robot-state-panel', 'state panel');
  },

  updateTarget: function() {
      this.renderPartial(
        this.targetPanelTemplate, '#target-panel', 'target panel');
  },

  renderPartial: function(template, selector, debugMsg) {
    if (debugMsg !== undefined) console.log('Rendering ' + debugMsg);

    var context = template(this.model.toJSON());
    this.$(selector).html(context);
  },

  render: function() {

    this.$el.html(this.template(this.model.toJSON()));

    this.renderPartial(this.statePanelTemplate, '#robot-state-panel', 'state panel');
    this.renderPartial(this.targetPanelTemplate, '#target-panel', 'target panel');
    this.renderPartial(this.missionPanelTemplate, '#mission-panel', 'mission panel');

    if (this.waitingForValidation) {
      this.renderPartial(
        this.validationPanelTemplate, '#validation-panel', 'validation panel');
    }

    return this;
  },

  showVictimAlert: function() {
    console.log('Show victim alert');<commit_msg>Fix typo<commit_after>'use strict';

var Backbone = require('backbone');
var Dispatcher = require('../dispatcher');
var Socket = require('../ros-events');

/**
 * View template.
 */

var agentTemplate = require('../templates/agent.hbs');

var targetTemplate = require('../templates/target.panel.hbs');
var stateTemplate = require('../templates/state.panel.hbs');
var missionTemplate = require('../templates/mission.panel.hbs');
var validationTempalte = require('../templates/validation-panel.hbs');

var victimNotification = require('../templates/victim.alert.hbs');
var victimDialog = require('../templates/victim.dialog.hbs');


var AgentView = Backbone.View.extend({

  template: agentTemplate,
  targetPanelTemplate: targetTemplate,
  statePanelTemplate: stateTemplate,
  missionPanelTemplate: missionTemplate,
  validationPanelTemplate: validationTempalte,

  victimNotificationTemplate: victimNotification,
  victimDialogTemplate: victimDialog,

  waitingForValidation: false,

  initialize: function() {
    console.log('View Agent initialized');

    this.model.subscribe();
    Dispatcher.on('agent:change:state', this.udpateState, this);
    Dispatcher.on('agent:change:target', this.updateTarget, this);
    Dispatcher.on('agent:change:mission', this.updateMission, this);
    Dispatcher.on('agent:victim:alert', this.showVictimAlert, this);
  },

  events: {
    'click #reject-victim': 'rejectVictim',
    'click #accept-victim': 'acceptVictim'
  },

  rejectVictim: function() {
    console.log('Victim rejected');
    this.waitingForValidation = false;
    Socket.emit('web/victim/response', false);
    this.$('#validation-panel').addClass('.hide').fadeOut(1000);
  },

  acceptVictim: function() {
    console.log('Victim accepted');
    this.waitingForValidation = false;
    Socket.emit('web/victim/response', true);
    this.$('#validation-panel').addClass('.hide').fadeOut(1000);
  },

  updateMission: function() {
      this.renderPartial(
        this.missionPanelTemplate, '#mission-panel', 'mission panel');
  },

  updateState: function() {
      this.renderPartial(
        this.statePanelTemplate, '#robot-state-panel', 'state panel');
  },

  updateTarget: function() {
      this.renderPartial(
        this.targetPanelTemplate, '#target-panel', 'target panel');
  },

  renderPartial: function(template, selector, debugMsg) {
    if (debugMsg !== undefined) console.log('Rendering ' + debugMsg);

    var context = template(this.model.toJSON());
    this.$(selector).html(context);
  },

  render: function() {

    this.$el.html(this.template(this.model.toJSON()));

    this.renderPartial(this.statePanelTemplate, '#robot-state-panel', 'state panel');
    this.renderPartial(this.targetPanelTemplate, '#target-panel', 'target panel');
    this.renderPartial(this.missionPanelTemplate, '#mission-panel', 'mission panel');

    if (this.waitingForValidation === true) {
      this.renderPartial(
        this.validationPanelTemplate, '#validation-panel', 'validation panel');
    }

    return this;
  },

  showVictimAlert: function() {
    console.log('Show victim alert');
{'fraction_non_alphanumeric': 0.15764895330112721, 'fraction_numerical': 0.0025764895330112722, 'mean_word_length': 4.467429577464789, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3925213', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1784, 'n_words': 319}