Help with edit button on context menu

5 posts, 0 answers
  1. Ignacio Ortuzar
    Ignacio Ortuzar avatar
    14 posts
    Member since:
    Aug 2009

    Posted 07 Sep 2009 Link to this post

    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.
  2. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 08 Sep 2009 Link to this post

    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.
  3. Ignacio Ortuzar
    Ignacio Ortuzar avatar
    14 posts
    Member since:
    Aug 2009

    Posted 08 Sep 2009 Link to this post

    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!!

  4. Ignacio Ortuzar
    Ignacio Ortuzar avatar
    14 posts
    Member since:
    Aug 2009

    Posted 08 Sep 2009 Link to this post

    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...
  5. Ignacio Ortuzar
    Ignacio Ortuzar avatar
    14 posts
    Member since:
    Aug 2009

    Posted 09 Sep 2009 Link to this post

    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.
Back to Top