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.

46 lines
1.2KB

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