<commit_before>var cls = window.cls || (window.cls = {});

cls.StorageViewActions = function(id)
{
  const
  MODE_DEFAULT = "default",
  MODE_EDIT = "edit";

  this.id = id;
  this.inherited_shortcuts = "storage";
  ActionHandlerInterface.apply(this);
  this._handlers = {};

  this._update = function(storage_id, success)
  {
    window.storages[storage_id].update();
  }.bind(this, id);

  this._handlers["edit"] = function(event, target)
  {
    this.mode = MODE_EDIT; // todo: why doesn't this work?
    ActionBroker.get_instance()._action_context.mode = MODE_EDIT;

    var container = target;
    while(container && !container.getAttribute("data-storage-id"))
    {
      container = container.parentNode;
    }
    if (container)
    {
      var table_elem = container.querySelector(".sortable-table");
      var table = ObjectRegistry.get_instance().get_object(table_elem.getAttribute("data-table-object-id"));
      table.restore_columns(table_elem);
      // can't directly work with target because restore_columns has renewed it.
      var ref = target.getAttribute("data-object-id");
      var tr = container.querySelector("tr[data-object-id='"+ref+"']")
      tr.addClass("edit_mode");
      this._handlers["select-row"](event, tr);
      var textarea = tr.querySelector("textarea");
      if(textarea)
      {
        this._handlers["textarea-autosize"](null, textarea);
      }
    }
  }.bind(this);

  this._handlers["submit"] = function(event, target)
  {
    this.mode = MODE_DEFAULT;
    var container = target;
    while(container && !container.getAttribute("data-storage-id"))
    {
      container = container.parentNode;
    }

    if(container)
    {
      var storage_id = container.getAttribute("data-storage-id");
      var edit_trs = container.querySelectorAll("tr.edit_mode");
      for (var i=0, edit_tr; edit_tr = edit_trs[i]; i++)
      {
        var rt_id        = +edit_tr.querySelector("[name=rt_id]").value;
        var original_key = edit_tr.querySelector("[name=original_key]").value;
        var key          = edit_tr.querySelector("[name=key]").value;
        var value        = edit_tr.querySelector("[name=value]").value;
        window.storages[storage_id].remove_item(rt_id, original_key, this._update);
        window.storages[storage_id].set_item(rt_id, key, value, this._update);
      }
      return false;
    }
  }.bind(this);

  this._handlers["remove-item"] = function(event, target, object_ids)
  {
    var container = target;
    while(container && !container.getAttribute("data-storage-id"))
    {
      container = container.parentNode;
    }
    if (container)
    {
      var storage_id = container.getAttribute("data-storage-id");<commit_msg>Fixed adding items; Changing key works now<commit_after>var cls = window.cls || (window.cls = {});

cls.StorageViewActions = function(id)
{
  const
  MODE_DEFAULT = "default",
  MODE_EDIT = "edit";

  this.id = id;
  this.inherited_shortcuts = "storage";
  ActionHandlerInterface.apply(this);
  this._handlers = {};

  this._update = function(storage_id, success)
  {
    window.storages[storage_id].update();
  }.bind(this, id);

  this._handlers["edit"] = function(event, target)
  {
    this.mode = MODE_EDIT; // todo: why doesn't this work?
    ActionBroker.get_instance()._action_context.mode = MODE_EDIT;

    var container = target;
    while(container && !container.getAttribute("data-storage-id"))
    {
      container = container.parentNode;
    }
    if (container)
    {
      var table_elem = container.querySelector(".sortable-table");
      var table = ObjectRegistry.get_instance().get_object(table_elem.getAttribute("data-table-object-id"));
      table.restore_columns(table_elem);
      // can't directly work with target because restore_columns has renewed it.
      var ref = target.getAttribute("data-object-id");
      var tr = container.querySelector("tr[data-object-id='"+ref+"']")
      tr.addClass("edit_mode");
      this._handlers["select-row"](event, tr);
      var textarea = tr.querySelector("textarea");
      if(textarea)
      {
        this._handlers["textarea-autosize"](null, textarea);
      }
    }
  }.bind(this);

  this._handlers["submit"] = function(event, target)
  {
    this.mode = MODE_DEFAULT;
    var container = target;
    while(container && !container.getAttribute("data-storage-id"))
    {
      container = container.parentNode;
    }

    if(container)
    {
      var storage_id = container.getAttribute("data-storage-id");
      var edit_trs = container.querySelectorAll("tr.edit_mode");
      for (var i=0, edit_tr; edit_tr = edit_trs[i]; i++)
      {
        var rt_id        = +edit_tr.querySelector("[name=rt_id]").value;
        var original_key = edit_tr.querySelector("[name=original_key]") && edit_tr.querySelector("[name=original_key]").value;
        var key          = edit_tr.querySelector("[name=key]").value;
        var value        = edit_tr.querySelector("[name=value]").value;

        var add_function = function(cb)
        {
          window.storages[storage_id].set_item(rt_id, key, value, cb);
        };
        var remove_old_function = function(cb)
        {
          window.storages[storage_id].remove_item(rt_id, original_key, cb);
        };
        
        if (key && original_key)
        {
          remove_old_function(add_function.bind(this, this._update));
        }
        else
        if (key)
        {
          add_function(this._update);
        }
        else
        {
          this._update();
        }
      }
      return false;
    }
  }.bind(this);

  this._handlers["remove-item"] = function(event, target, object_ids)
  {
    var container = target;
    while(container && !container.getAttribute("data-storage-id"))
    {
      container = container.parentNode;
    }
    if (container)
    {
      var storage_id = container.getAttribute("data-storage-id");
{'fraction_non_alphanumeric': 0.1421518556350017, 'fraction_numerical': 0.00034048348655090226, 'mean_word_length': 2.9535666218034993, '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': '3374792', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1827, 'n_words': 305}