IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4KB

  1. //
  2. // Copyright (C) Stanislaw Adaszewski, 2020
  3. // Contact: s.adaszewski@gmail.com
  4. // Website: https://adared.ch/wba
  5. // License: GNU Affero General Public License, Version 3
  6. //
  7. import { h, Component, createRef } from 'preact';
  8. import WBDialog from 'wb-dialog';
  9. import linkState from 'linkstate';
  10. import wbRenameObject from 'wb-rename-object';
  11. class WBRenameDialog extends Component {
  12. constructor(...args) {
  13. super(...args);
  14. this.dialogRef = createRef();
  15. this.state.inputId = uuid.v4();
  16. }
  17. show(item, callback) {
  18. const { inputId } = this.state;
  19. this.setState({
  20. 'item': item,
  21. 'newName': null,
  22. 'callback': callback || (() => {})
  23. });
  24. this.dialogRef.current.show();
  25. $('#' + inputId).focus();
  26. }
  27. hide() {
  28. this.dialogRef.current.hide();
  29. }
  30. render({ app }, { item, newName, callback, inputId }) {
  31. const { arvHost, arvToken } = app.state;
  32. return (
  33. <WBDialog title="Rename" ref={ this.dialogRef } accept={ () => {
  34. if (newName)
  35. wbRenameObject(arvHost, arvToken, item.uuid, newName).then(callback);
  36. } }>
  37. <div>
  38. <input type="text" class="form-control" id={ inputId }
  39. placeholder={ item ? item.name : 'Type new name here' }
  40. value={ newName } onChange={ linkState(this, 'newName') } />
  41. </div>
  42. </WBDialog>
  43. );
  44. }
  45. }
  46. export default WBRenameDialog;