<commit_before>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

"use strict";

let {setResetHandler, setSubmitHandler} = require("./events");
let state = require("./state");
let {$, getActivePanel, setActivePanel} = require("./utils");

let currentRequest = null;

setSubmitHandler("site-selection", () => done($("site-selection-site").value.trim()));
setResetHandler("site-selection", () => done(null));

function done(value)
{
  if (!currentRequest)
    return;

  setActivePanel(currentRequest.originalSelection, true);
  if (value)
    currentRequest.resolve(value);
  else
    currentRequest.reject();
  currentRequest = null;
}

function show(message)
{
  $("site-selection-label").textContent = message;
  $("site-selection-site").value = state.site;

  let originalSelection = getActivePanel();
  setActivePanel("site-selection");

  return new Promise((resolve, reject) =>
  {
    currentRequest = {
      resolve, reject, originalSelection
    };
  });
}
exports.show = show;<commit_msg>Issue #52 - Made sure current website name is pre-filled properly when selecting website<commit_after>/*
 * This Source Code is subject to the terms of the Mozilla Public License
 * version 2.0 (the "License"). You can obtain a copy of the License at
 * http://mozilla.org/MPL/2.0/.
 */

"use strict";

let {setResetHandler, setSubmitHandler} = require("./events");
let state = require("./state");
let {$, getActivePanel, setActivePanel} = require("./utils");

let currentRequest = null;

setSubmitHandler("site-selection", () => done($("site-selection-site").value.trim()));
setResetHandler("site-selection", () => done(null));

function done(value)
{
  if (!currentRequest)
    return;

  setActivePanel(currentRequest.originalSelection, true);
  if (value)
    currentRequest.resolve(value);
  else
    currentRequest.reject();
  currentRequest = null;
}

function show(message)
{
  $("site-selection-label").textContent = message;

  let originalSelection = getActivePanel();
  setActivePanel("site-selection");

  $("site-selection-site").value = state.site;
  $("site-selection-site").select();

  return new Promise((resolve, reject) =>
  {
    currentRequest = {
      resolve, reject, originalSelection
    };
  });
}
exports.show = show;
{'fraction_non_alphanumeric': 0.15539689206215876, 'fraction_numerical': 0.004199916001679967, 'mean_word_length': 4.425968109339408, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1752445', 'n_tokens_mistral': 706, 'n_tokens_neox': 687, 'n_words': 176}