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

<delete>-keypress and folder edit mode

2 Answers 59 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Gard
Top achievements
Rank 1
Gard asked on 23 Jul 2010, 12:54 PM
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 Answers, 1 is accepted

Sort by
0
Gard
Top achievements
Rank 1
answered on 28 Jul 2010, 12:14 PM
Please, anyone?
0
Accepted
Petio Petkov
Telerik team
answered on 28 Jul 2010, 04:16 PM
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
Tags
FileExplorer
Asked by
Gard
Top achievements
Rank 1
Answers by
Gard
Top achievements
Rank 1
Petio Petkov
Telerik team
Share this question
or