client/entity-editor/alias-editor/actions.js

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.UPDATE_ALIAS_SORT_NAME = exports.UPDATE_ALIAS_PRIMARY = exports.UPDATE_ALIAS_NAME = exports.UPDATE_ALIAS_LANGUAGE = exports.REMOVE_EMPTY_ALIASES = exports.REMOVE_ALIAS_ROW = exports.HIDE_ALIAS_EDITOR = exports.ADD_ALIAS_ROW = void 0;
exports.addAliasRow = addAliasRow;
exports.debouncedUpdateAliasName = debouncedUpdateAliasName;
exports.debouncedUpdateAliasSortName = debouncedUpdateAliasSortName;
exports.hideAliasEditor = hideAliasEditor;
exports.removeAliasRow = removeAliasRow;
exports.removeEmptyAliases = removeEmptyAliases;
exports.updateAliasLanguage = updateAliasLanguage;
exports.updateAliasPrimary = updateAliasPrimary;
/*
 * Copyright (C) 2016  Ben Ockmore
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

var UPDATE_ALIAS_NAME = 'UPDATE_ALIAS_NAME';
exports.UPDATE_ALIAS_NAME = UPDATE_ALIAS_NAME;
var UPDATE_ALIAS_SORT_NAME = 'UPDATE_ALIAS_SORT_NAME';
exports.UPDATE_ALIAS_SORT_NAME = UPDATE_ALIAS_SORT_NAME;
var ADD_ALIAS_ROW = 'ADD_ALIAS_ROW';
exports.ADD_ALIAS_ROW = ADD_ALIAS_ROW;
var UPDATE_ALIAS_LANGUAGE = 'UPDATE_ALIAS_LANGUAGE';
exports.UPDATE_ALIAS_LANGUAGE = UPDATE_ALIAS_LANGUAGE;
var UPDATE_ALIAS_PRIMARY = 'UPDATE_ALIAS_PRIMARY';
exports.UPDATE_ALIAS_PRIMARY = UPDATE_ALIAS_PRIMARY;
var REMOVE_ALIAS_ROW = 'REMOVE_ALIAS_ROW';
exports.REMOVE_ALIAS_ROW = REMOVE_ALIAS_ROW;
var HIDE_ALIAS_EDITOR = 'HIDE_ALIAS_EDITOR';
exports.HIDE_ALIAS_EDITOR = HIDE_ALIAS_EDITOR;
var REMOVE_EMPTY_ALIASES = 'REMOVE_EMPTY_ALIASES';
exports.REMOVE_EMPTY_ALIASES = REMOVE_EMPTY_ALIASES;
/**
 * Produces an action indicating that the name for a particular alias within
 * the editor should be updated with the provided value. The action is
 * marked to be debounced by the keystroke debouncer defined for
 * redux-debounce.
 *
 * @param {number} rowId - The ID of the row in the alias editor to update.
 * @param {string} value - The new value to be used for the alias name.
 * @returns {Action} The resulting UPDATE_ALIAS_NAME action.
 */
function debouncedUpdateAliasName(rowId, value) {
  return {
    meta: {
      debounce: 'keystroke'
    },
    payload: {
      rowId: rowId,
      value: value
    },
    type: UPDATE_ALIAS_NAME
  };
}

/**
 * Produces an action indicating that the sort name for a particular alias
 * within the editor should be updated with the provided value. The action is
 * marked to be debounced by the keystroke debouncer defined for
 * redux-debounce.
 *
 * @param {number} rowId - The ID of the row in the alias editor to update.
 * @param {string} value - The new value to be used for the alias sort name.
 * @returns {Action} The resulting UPDATE_ALIAS_SORT_NAME action.
 */
function debouncedUpdateAliasSortName(rowId, value) {
  return {
    meta: {
      debounce: 'keystroke'
    },
    payload: {
      rowId: rowId,
      value: value
    },
    type: UPDATE_ALIAS_SORT_NAME
  };
}

/**
 * Produces an action indicating that the language for a particular alias
 * within the editor should be updated with the provided value.
 *
 * @param {number} rowId - The ID of the row in the alias editor to update.
 * @param {number} value - The new value to be used for the alias language ID.
 * @returns {Action} The resulting UPDATE_ALIAS_LANGUAGE action.
 */
function updateAliasLanguage(rowId, value) {
  return {
    payload: {
      rowId: rowId,
      value: value
    },
    type: UPDATE_ALIAS_LANGUAGE
  };
}

/**
 * Produces an action indicating that the primary flag for a particular alias
 * within the editor should be updated with the provided value.
 *
 * @param {number} rowId - The ID of the row in the alias editor to update.
 * @param {boolean} value - The new value to be used for the alias primary flag.
 * @returns {Action} The resulting UPDATE_ALIAS_PRIMARY action.
 */
function updateAliasPrimary(rowId, value) {
  return {
    payload: {
      rowId: rowId,
      value: value
    },
    type: UPDATE_ALIAS_PRIMARY
  };
}
var nextAliasRowId = 0;

/**
 * Produces an action indicating that a row for a new alias should be added
 * to the alias editor. The row is assigned an ID based on an incrementing
 * variable existing on the client.
 *
 * @returns {Action} The resulting ADD_ALIAS_ROW action.
 */
function addAliasRow() {
  /*
   * Prepend 'n' here to indicate new alias, and avoid conflicts with IDs of
   * existing aliases.
   */
  return {
    payload: "n".concat(nextAliasRowId++),
    type: ADD_ALIAS_ROW
  };
}

/**
 * Produces an action indicating that the row with the provided ID should be
 * removed from the alias editor.
 *
 * @param {number} rowId - The ID for the row to be deleted.
 * @returns {Action} The resulting REMOVE_ALIAS_ROW action.
 */
function removeAliasRow(rowId) {
  return {
    payload: rowId,
    type: REMOVE_ALIAS_ROW
  };
}

/**
 * Produces an action indicating that the alias editor should be hidden from
 * view.
 *
 * @see showAliasEditor
 *
 * @returns {Action} The resulting HIDE_ALIAS_EDITOR action.
 */
function hideAliasEditor() {
  return {
    type: HIDE_ALIAS_EDITOR
  };
}

/**
 * Produces an action indicating that the empty rows should be deleted.
 *
 * @returns {Action} The resulting REMOVE_EMPTY_ALIASES action.
 */
function removeEmptyAliases() {
  return {
    type: REMOVE_EMPTY_ALIASES
  };
}
//# sourceMappingURL=actions.js.map