FileManager - Detect move vs copy

7 posts, 0 answers
  1. Carlos
    Carlos avatar
    7 posts
    Member since:
    May 2020

    Posted 17 Jul 2020 Link to this post

    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,

  2. Carlos
    Carlos avatar
    7 posts
    Member since:
    May 2020

    Posted 17 Jul 2020 Link to this post

    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

                }
            });

  3. Neli
    Admin
    Neli avatar
    361 posts

    Posted 21 Jul 2020 Link to this post

    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

  4. Carlos
    Carlos avatar
    7 posts
    Member since:
    May 2020

    Posted 21 Jul 2020 in reply to Neli Link to this post

    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?

  5. Neli
    Admin
    Neli avatar
    361 posts

    Posted 23 Jul 2020 Link to this post

    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

  6. Carlos
    Carlos avatar
    7 posts
    Member since:
    May 2020

    Posted 23 Jul 2020 in reply to Neli Link to this post

    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.
  7. Martin
    Admin
    Martin avatar
    278 posts

    Posted 27 Jul 2020 Link to this post

    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

Back to Top