<delete>-keypress and folder edit mode

3 posts, 1 answers
  1. Gard
    Gard avatar
    2 posts
    Member since:
    Jul 2010

    Posted 23 Jul 2010 Link to this post

    Hi guys!
    [client side] I've added a keypress-hook to the <delete> button and added a call to the "FileExplorer.deleteSelectedItems".
    Problem is; when editing(renaming) folder in treeview and pressing <delete>-button this is interpreted as "deleteSelectedItems".
    I've tried to use the item.get_isUpdating() method, but this always returns "false". How do I figure out if an element is
    in "edit-mode"? Do you have any other solution(s) to how this may be solved?

    $(function() {
        hookDeleteEvent();
    });
    var keyCodeForDeleteButton = 46;
    function hookDeleteEvent() {
        $(document).keyup(function(e) {
            if (e.keyCode == keyCodeForDeleteButton) {
                runDeleteOnSelectedElement();
            }
        });
    }
     
    function runDeleteOnSelectedElement() {
        var explorer = $find("<%=DocumentBrowser.ClientID %>");
        if (userMayDeleteSelectedFiles(explorer)) explorer.deleteSelectedItems();
    }
     
    function userMayDeleteSelectedFiles(explorer) {
        if (isInEditMode(explorer)) return false;
        return true;
    }
     
    function isInEditMode(explorer) {
        var item = explorer.get_selectedItem();
        return item.get_isUpdating();
    }

    BR
    -Gard
  2. Gard
    Gard avatar
    2 posts
    Member since:
    Jul 2010

    Posted 28 Jul 2010 Link to this post

    Please, anyone?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Petio Petkov
    Admin
    Petio Petkov avatar
    825 posts

    Posted 28 Jul 2010 Link to this post

    Hi Gard,

    I created for you a simple example, which illustrates how to achieve your goal. Here it is the code:
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </asp:ScriptManager>
        <script type="text/javascript">
            $(function ()
            {
                hookDeleteEvent();
            });
      
            var keyCodeForDeleteButton = 46;
            function hookDeleteEvent()
            {
                $(document).keyup(function (e)
                {
                    if (e.keyCode == keyCodeForDeleteButton)
                    {
                        runDeleteOnSelectedElement();
                    }
                });
            }
            function runDeleteOnSelectedElement()
            {
                var explorer = $find("<%=DocumentBrowser.ClientID %>");
      
                //Get a reference to the RadFileExplorer's treeview
                var treeView = explorer.get_tree();
                //Check currently selected node wheter or not is in edit mode
                var currentlySelectedNode = treeView.get_selectedNode();
                if (currentlySelectedNode)
                {
                    if (currentlySelectedNode._editing == true)
                    {
                        return;
                    }
                }
                //Get a reference to the RadFileExplorer's toolbar
                var toolbar = explorer.get_toolbar();
                //Get  Delete command client-side object
                var delCommand = toolbar.findItemByValue("Delete");
                delCommand.click();
            }
        </script>
        <div>
            <telerik:RadFileExplorer ID="DocumentBrowser" runat="server">
                <Configuration ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" MaxUploadFileSize="104857600" />
            </telerik:RadFileExplorer>
        </div>
        </form>
    </body>
    </html>
    Hope this helps.

    Sincerely yours,
    Petio Petkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top