This is a migrated thread and some comments may be shown as answers.

FileManager - Detect move vs copy

6 Answers 302 Views
FileManager
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Veteran
Carlos asked on 17 Jul 2020, 12:13 PM

I see that when doing a copy a Create call is executed and when doing a move it executes Create and Destroy. Is there a way to detect when a copy was done vs a move?  When doing a move, I actually need to do a move in the back end so a Create and Destroy does not work for me.

 

Thanks,

6 Answers, 1 is accepted

Sort by
0
Carlos
Top achievements
Rank 1
Veteran
answered on 17 Jul 2020, 09:20 PM

I found that I can override the MoveCommand as below and it works for my scenario.

 

filemanagerNS.commands.MoveCommand = filemanagerNS.FileManagerCommand.extend({
            exec: function () {
                var that = this,
                    filemanager = that.filemanager, // get the kendo.ui.FileManager instance
                    options = that.options, // get the options passed through the tool
                    target = options.target // options.target is available only when command is executed from the context menu
                selectedFiles = filemanager.getSelected(); // get the selected files

                //My move logic here

            }
        });

0
Neli
Telerik team
answered on 21 Jul 2020, 07:11 AM

Hello Carlos,

Thank you for sharing your solution. It could be helpful for someone else in the community in the future.

If it is suitable for your scenario, you could subscribe to the execute event of the FileManager. In the event handler, you could check if the 'Move' or 'Copy' action is selected by checking the "e.command" as in the example below:

 function onExecute(e) {          
            kendoConsole.log("event: Execute  --> " + e.command);
        }   

Here is a small Dojo example where the type of the selected command is logged in a Kendo Console. 

Regards,
Neli
Progress Telerik

0
Carlos
Top achievements
Rank 1
Veteran
answered on 21 Jul 2020, 01:41 PM

Hi Neli,

Thanks for the follow up.  I did try that, but I didn't find a way to cancel the command so it was executing the default Move/Copy calls after executing my custom call.  Is there a way cancel command from the Execute event?

0
Neli
Telerik team
answered on 23 Jul 2020, 08:55 AM

Hi Carlos,

If you need to cancel a command in the execute event handler of the FileManager widget you could use the preventDefault() method and prevent the default behavior.

In the example below the "Move" of the items will be canceled in case the name of the item contains the string "demos":

  function onExecute(e) { 
          var items = e.options.items;         
          var hasDemos = items.some(function(v) { 
            return v.includes("demos"); 
          })

          kendoConsole.log("event: Execute  --> " + e.command);
          if(e.command == "MoveCommand" && hasDemos == true){
             e.preventDefault()
             alert("Canceled!!!")
          }
  }     

Here is a Dojo example where the implementation provided above is used. 

I hope the provided information will be helpful.

Regards,
Neli
Progress Telerik

0
Carlos
Top achievements
Rank 1
Veteran
answered on 23 Jul 2020, 12:53 PM
Thanks again Neli.  One last thing, is there a place in the documentation with a list of the default commands and a list of all the default toolbar commands available?  All I've found is this(https://docs.telerik.com/kendo-ui/controls/data-management/filemanager/toolbar), but was looking more for a list of what the command names are for when you are using the Execute event or anything along those lines.
0
Martin
Telerik team
answered on 27 Jul 2020, 08:34 AM

Hello Carlos,

Currently we do not have a list of the command names. You can either check the source code or console log the e.command in the execute event to see the name of the command.

Regards,
Martin
Progress Telerik

Tags
FileManager
Asked by
Carlos
Top achievements
Rank 1
Veteran
Answers by
Carlos
Top achievements
Rank 1
Veteran
Neli
Telerik team
Martin
Telerik team
Share this question
or