// This file is part of Indico.
// Copyright (C) 2002 - 2020 CERN
//
// Indico is free software; you can redistribute it and/or
// modify it under the terms of the MIT License; see the
// LICENSE file for more details.

/* global choiceConfirmPrompt:false */

import {$T} from 'indico/utils/i18n';

(function(global) {
  // TODO: Add plugin i18n
  var $t = $T;

  global.eventManageVCRooms = function() {
    $('.js-vcroom-remove').on('click', function(e) {
      e.preventDefault();
      var $this = $(this);
      var title, msg;

      function execute(url) {
        var csrf = $('<input>', {
          type: 'hidden',
          name: 'csrf_token',
          value: $('#csrf-token').attr('content'),
        });
        $('<form>', {
          action: url,
          method: 'post',
        })
          .append(csrf)
          .appendTo('body')
          .submit();
      }

      if ($this.data('numEvents') === 1) {
        title = $t('Delete videoconference room');
        msg =
          $t('Do you really want to remove this videoconference room from the event?') +
          ' ' +
          $t('Since it is only used in this event, it will be deleted from the server, too!');
        confirmPrompt(msg, title).then(function() {
          execute($this.data('href'));
        });
      } else {
        title = $t('Detach videoconference room');
        msg = $t
          .ngettext(
            '*',
            'This videoconference room is used in other Indico events.<br>Do you want to \
                     <strong>delete</strong> it from all {0} events or just <strong>detach</strong> \
                     it from this event?',
            $this.data('numEvents')
          )
          .format($this.data('numEvents'));
        choiceConfirmPrompt(msg, title, $t('Detach'), $t('Delete')).then(function(choice) {
          var url = build_url($this.data('href'), {delete_all: choice === 2 ? '1' : ''});
          execute(url);
        });
      }
    });

    $('.js-vcroom-refresh').on('click', function(e) {
      e.preventDefault();
      var $this = $(this);
      var csrf = $('<input>', {
        type: 'hidden',
        name: 'csrf_token',
        value: $('#csrf-token').attr('content'),
      });
      $('<form>', {
        action: $this.data('href'),
        method: 'post',
      })
        .append(csrf)
        .appendTo('body')
        .submit();
    });

    $('.vc-room-entry.deleted').qtip({
      content: $T(
        'This room has been deleted and cannot be used. \
                         You can detach it from the event, however.'
      ),
      position: {
        my: 'top center',
        at: 'bottom center',
      },
    });

    $('.toggle-details')
      .on('click', function(e) {
        e.preventDefault();
        var $this = $(this);

        if ($this.closest('.vc-room-entry.deleted').length) {
          return;
        }

        $this
          .closest('tr')
          .next('tr')
          .find('.details-container')
          .slideToggle({
            start: function() {
              $this.toggleClass('icon-next icon-expand');
            },
          });
      })
      .filter('.vc-room-entry:not(.deleted) .toggle-details')
      .qtip({content: $T('Click to toggle collapse status')});

    $('.toggle .i-button').on('click', function() {
      var toggle = $(this);
      toggle.toggleClass('icon-eye icon-eye-blocked');
      var $input = toggle.siblings('input');
      $input.prop('type', $input.prop('type') === 'text' ? 'password' : 'text');
    });
  };
})(window);

@@ -248,16 +248,54 @@
 pt:false
+, confirmPrompt:false, build_url:false
  */%0A%0Aimp
@@ -379,19 +379,21 @@
  i18n%0A  
-var
+const
  $t = $T
@@ -515,35 +515,37 @@
 efault();%0A      
-var
+const
  $this = $(this)
@@ -552,19 +552,19 @@
 ;%0A      
-var
+let
  title, 
@@ -603,27 +603,29 @@
 ) %7B%0A        
-var
+const
  csrf = $('%3C
@@ -1025,27 +1025,20 @@
    msg =
-%0A          
+ %60$%7B
 $t('Do y
@@ -1109,26 +1109,15 @@
 t?')
- +%0A          ' ' +
+%7D $%7B$t(
 %0A   
@@ -1123,19 +1123,16 @@
         
-$t(
 'Since i
@@ -1202,17 +1202,28 @@
 r, too!'
-)
+%0A        )%7D%60
 ;%0A      
@@ -1543,25 +1543,16 @@
         
-         
 %3Cstrong%3E
@@ -1624,25 +1624,16 @@
 rong%3E %5C%0A
-         
         
@@ -1852,19 +1852,21 @@
         
-var
+const
  url = b
@@ -2069,27 +2069,29 @@
 lt();%0A      
-var
+const
  $this = $(t
@@ -2102,19 +2102,21 @@
 ;%0A      
-var
+const
  csrf = 
@@ -2523,35 +2523,8 @@
 sed.
- %5C%0A                        
  You
@@ -2758,19 +2758,21 @@
         
-var
+const
  $this =
@@ -3018,18 +3018,8 @@
 tart
-: function
 () %7B
@@ -3299,19 +3299,21 @@
 %7B%0A      
-var
+const
  toggle 
@@ -3388,11 +3388,13 @@
     
-var
+const
  $in

Format VC JS with eslint