Source: modal/commands/OpenSimpleInputModal.es.js

  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. import {render} from '@liferay/frontend-js-react-web';
  15. import React from 'react';
  16. import {unmountComponentAtNode} from 'react-dom';
  17. import SimpleInputModal from '../components/SimpleInputModal.es';
  18. const DEFAULT_MODAL_CONTAINER_ID = 'modalContainer';
  19. const DEFAULT_RENDER_DATA = {
  20. portletId: 'UNKNOWN_PORTLET_ID',
  21. };
  22. function getDefaultModalContainer() {
  23. let container = document.getElementById(DEFAULT_MODAL_CONTAINER_ID);
  24. if (!container) {
  25. container = document.createElement('div');
  26. container.id = DEFAULT_MODAL_CONTAINER_ID;
  27. document.body.appendChild(container);
  28. }
  29. return container;
  30. }
  31. function dispose() {
  32. unmountComponentAtNode(getDefaultModalContainer());
  33. }
  34. function openSimpleInputModalImplementation({
  35. alert,
  36. checkboxFieldLabel,
  37. checkboxFieldName,
  38. checkboxFieldValue,
  39. dialogTitle,
  40. formSubmitURL,
  41. idFieldName,
  42. idFieldValue,
  43. mainFieldLabel,
  44. mainFieldName,
  45. namespace,
  46. onFormSuccess,
  47. placeholder,
  48. }) {
  49. dispose();
  50. render(
  51. <SimpleInputModal
  52. alert={alert}
  53. checkboxFieldLabel={checkboxFieldLabel}
  54. checkboxFieldName={checkboxFieldName}
  55. checkboxFieldValue={checkboxFieldValue}
  56. closeModal={dispose}
  57. dialogTitle={dialogTitle}
  58. formSubmitURL={formSubmitURL}
  59. idFieldName={idFieldName}
  60. idFieldValue={idFieldValue}
  61. initialVisible="true"
  62. mainFieldLabel={mainFieldLabel}
  63. mainFieldName={mainFieldName}
  64. namespace={namespace}
  65. onFormSuccess={onFormSuccess}
  66. placeholder={placeholder}
  67. />,
  68. DEFAULT_RENDER_DATA,
  69. getDefaultModalContainer()
  70. );
  71. }
  72. let didEmitDeprecationWarning = false;
  73. /**
  74. * Function that implements the SimpleInputModal pattern, which allows
  75. * manipulating small amounts of data with a form shown inside a modal.
  76. *
  77. * @deprecated As of Athanasius (7.3.x), replaced by the default export
  78. */
  79. export function openSimpleInputModal(data) {
  80. if (process.env.NODE_ENV === 'development' && !didEmitDeprecationWarning) {
  81. console.warn(
  82. 'The named "openSimpleInputModal" export is deprecated: use the default export instead'
  83. );
  84. didEmitDeprecationWarning = true;
  85. }
  86. return openSimpleInputModalImplementation.call(null, data);
  87. }
  88. export default openSimpleInputModalImplementation;