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

Help with edit button on context menu

4 Answers 91 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Ignacio Ortuzar
Top achievements
Rank 1
Ignacio Ortuzar asked on 07 Sep 2009, 09:34 PM
Hi

I'm trying to make an edit button on the context menu, so when the user click it, the page will be redirected to another page to edit the selected file.

All is OK, but I want to disable the button when the selected item is a directory an enable when the item is a file.

I have the following code to change de CSS class, this is executed when a item is selected.

function OnFileSelected(sender, args) { 
            var textbox = document.getElementById("ctl00_ContentPlaceHolder1_TextBox1"); 
            var item = args.get_item(); 
            textbox.value = item.get_path(); 
 
            var menuEdit = document.getElementById("menuEdit"); 
            if (item.isDirectory()) { 
                menuEdit.setAttribute("class""rmLink rmDisabled"); 
            } 
            else { 
                menuEdit.setAttribute("class""rmLink"); 
            } 
        } 


The problem is when I click with the right mouse button, the CSS class are reseted, so the Edit button always is enable. I suppose that another javascript method executed when I press right button, but I don't know how to solve it.

Please help me.

Regards.

4 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 08 Sep 2009, 12:03 PM
Hello Ignacio,

This can be achieved by using the client-side API. For convenience I attached a small sample that shows a possible approach.


Kind regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ignacio Ortuzar
Top achievements
Rank 1
answered on 08 Sep 2009, 04:14 PM
Thanks Georgi for your reply!!

The code works good, but now I've another problem.

To add some functionality to my custom command I write the following line in the page load method:

this.rfe_fileManager.GridContextMenu.OnClientItemClicked = "OnClientItemClicked"
 
So when I click on any command the js method OnClientItemClicked run, but I can't identify what item was clicked.

This is my js code:
<script type="text/javascript"
        var foldercheck = null
        var selectedFile = ""
 
        function OnClientLoad(sender, args) { 
            sender.get_gridContextMenu().add_showing(CheckForFolder); 
        } 
 
        function OnClientItemSelected(sender, args) { 
            foldercheck = !args.get_item().isDirectory(); 
             
            selectedFile = args.get_item().get_path(); 
        } 
 
        function CheckForFolder(sender, args) { 
            sender.findItemByText("Edit").set_enabled(foldercheck); 
        } 
 
        function OnClientItemClicked(sender, args) { 
            var url = "/test.aspx?file=" + selectedFile;  
            window.location = url; 
        }  
    </script>  

but it has a problem, because if I click rename (for example) the method redirect to the test page, I need to ask if the clicked item is the Edit command, but I don't know how. I think I need a sender.get_gridContextMenu() variable, but how can get some information about the clicked command??

Thank you very much!!

0
Ignacio Ortuzar
Top achievements
Rank 1
answered on 08 Sep 2009, 09:36 PM
I was making some changes based on this thread and the code looks like this:

<script type="text/javascript"
        var foldercheck = null
        var selectedFile = ""
 
        function OnClientLoad(sender, args) { 
            sender.get_gridContextMenu().add_showing(CheckForFolder); 
            sender.get_gridContextMenu().add_itemClicked(OnClientItemClicked);  
        } 
 
        function OnClientItemSelected(sender, args) { 
            foldercheck = !args.get_item().isDirectory(); 
             
            selectedFile = args.get_item().get_path(); 
        } 
 
        function CheckForFolder(sender, args) { 
            sender.findItemByText("Edit").set_enabled(foldercheck); 
        } 
 
        function OnClientItemClicked(sender, args) { 
 
            var buttonValue = args.get_menuItem().get_value(); 
            if (buttonValue == "menuEdit"
                alert("custom context menu item clicked"); 
        }  
    </script>  

but, the method args.get_menuItem() doesn't return a value or object (I think it doesn't exist), the method get_item() doesn't work neither.

thanks in advance...
0
Ignacio Ortuzar
Top achievements
Rank 1
answered on 09 Sep 2009, 02:59 PM
Finally I solved the problem...it was that the method get_menuItem() don't exist, but if you use the method get_item() it returns the clicked menu item, so if you use the line var buttonValue = args.get_item().get_value(); it returns the menu item value.

Thanks.
Tags
FileExplorer
Asked by
Ignacio Ortuzar
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Ignacio Ortuzar
Top achievements
Rank 1
Share this question
or