Open rename folder editor right after folder creation

Hey guys,

I’m trying to trigger event which opens “rename folder/file” editor. But cannot see the editor.

I have filemanager instance:

this.ui = window.webix.ui({
  view: ‘filemanager’,
  id: ‘files’,
  on: {
    onSuccessResponse: this.onSuccessResponseHandler
  },
  …

On onSuccessResponse event handler I’m trying to trigger onItemRename but nothing happens even callEvent returns true:

onSuccessResponseHandler = ({ action, id, source }) => {
  if (action === ‘create’ && source === ‘newFolder’ && id){
  // a is true
  const a = this.ui.callEvent(‘onItemRename’, [id]);
}

Am I using wrong event? Which event emitter and event should I use for it?

Thanks

try to call editFile
https://docs.webix.com/api__ui.filemanager_editfile.html

editFile doesn’t help. I’m not sure but it’s done for editing files. The thing I need is rename file/folder editor (which appears when clicking on Rename context menu item).

editFile is for editing both files and folders.
in your case I suppose that editing should be delayed in onSuccessResponse event. as item is not yet added to list.
try this

onSuccessResponseHandler = ({ action, id, source }) => {
    if (action === 'create' && source === 'newFolder' && id){
        webix.delay(this.ui.editFile, this.ui, [id]);
    }
}

@integral looks like it just breaks the webix.js script without any ‘rename folder editor’ opened:

Uncaught TypeError: Cannot read property ‘value’ of undefined
  at u.Va (webix.js:45)
  at u.edit (webix.js:45)
  at u.editFile (filemanager.js:426)
  at webix.js:9

https://snippet.webix.com/hakagdeq
in this snippet you can see that after onSuccessResponseHandler event item’s id is changed or item is changed with another. and you cannot begin edit in this event.
but you can use onAfterAdd event to start rename. with some checking to detect if it is a folder.
not sure, why folder’s id not provided in onAfterCreateFolder event. this event would be more suitable I think.

@intregal thanks for the proposed solution. It works for me from time to time, when I added setTimeout it started to work better. But it still works strange on the root directory and raises an error in nested folders.

  1. On root it opens prompt in the left sidebar tree for the first time. After that it opens editor on the top of elements in filemanager.

  2. When I try to create a folder in nested folders I get the following error:

Uncaught TypeError: Cannot read property ‘offsetLeft’ of undefined
  at u.qt (webix.js:45)
  at u.Pa (webix.js:45)
  at u.Va (webix.js:45)
  at u.edit (webix.js:45)
  at u.editFile (filemanager.js:426)
  at eval (webix-file-manager.js?3b2d:198)

Do you have any thoughts about 1st and 2nd cases?

Thanks.

btw you can get this error if you create newFolder in the snipper https://snippet.webix.com/hakagdeq, get inside it and try create a new folder one more time…

@Dennis
we forgot about second argument in onSuccessResponseHandler, where new id is returned
check this snippet
https://snippet.webix.com/b6hbc912
but not sure how to solve if folder is added to empty or not expanded folder.

found some undocumented methods
https://snippet.webix.com/qfxj6b48

thanks for the help @intregal!
your solution works perfectly

First snippet (longer) doesn’t work properly all time. Just click on the right, blank area and create a folder and nothing happens (condition is passing, the problem is later). And I am not sure, but generally file edit is opening on left files tree, sometimes on the right (for me better option), it’s annoying.

Anyway… Delay? It’s ugly hack! Webix team, come on!