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

RadFileExplorer: Enable/disable CreateNewFolder client-side

2 Answers 258 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Arnstein
Top achievements
Rank 2
Arnstein asked on 10 Nov 2011, 01:51 PM
Hi,
Using RadFileExplorer, I want the user to be able to create new subfolders. However, I want to limit this ability to certain existing folders.
Example: The user may create subfolders in folder "Pictures", but not in folder "Agreement".
I can use the server-side OnItemCommand event and cancel the operation if RadFileExplorerEventArgs.Command=="CreateDirectory" and RadFileExplorerEventArgs.Path is not a folder that allows subfolders, but at this point the user has already entered the name of the new folder and pressed OK.
The best solution,  I think, would be to disable the Create folder button (and context-menu choice) client-side, depending on which folder is the current folder. Something like this (for the toolbar button):

 

<telerik:RadFileExplorer OnClientFolderChange="OnClientFolderChange" EnableCreateNewFolder="True"....

Javascript:

function OnClientFolderChange(sender, args) {
    if(args.get_path() != 
"Pictures") {
        var tbitem = 
sender.get_toolbar().findItemByValue("NewFolder");
        
if(tbitem != 
null{
            tbitem.disable();
        }
    }
}

Unfortunately, this does not work. The toolbar button gets disabled, but then enabled again, immediately after.

In addition, this would be solved very easily if the EnableCreateNewFolder property of RadFileExplorer could be set client-side, using javascript. Is that possible, or do you guys have a different solution?

Thanks,

Arnstein

2 Answers, 1 is accepted

Sort by
0
Arnstein
Top achievements
Rank 2
answered on 14 Nov 2011, 03:12 PM
Here is an update to my original post.
It would have been much easier if the EnableCreateNewFolder property of RadFileExplorer had been accessible using javascript (maybe it is?), but I managed to solve the problem this way:
.ASPX:
<telerik:RadFileExplorer ID="rfe" EnableCreateNewFolder="True"
    OnClientFolderChange="OnClientFolderChange" 
...

.CS:
rfe.TreeView.OnClientContextMenuShown = "OnClientContextMenuShown";

JavaScript:
function OnClientFolderChange(sender, args) {
    
var p = 
args.get_path();
    
var show = (p.indexOf("/ROOT/Pictures") >= 
0);
    
var tb = sender.get_toolbar();
    
var tbitem = 
tb.findItemByValue("NewFolder");
    
if(tbitem != null
{
        tbitem.set_visible(show);
    }
}
function OnClientContextMenuShown(sender, args) {
    
var p = 
args.get_node().get_value();
    
var show = (p.indexOf("/ROOT/Pictures"
>= 0);
    
var cmitem = 
args.get_menu().findItemByValue("NewFolder");
    
if(cmitem != null
{
        cmitem.set_enabled(show);
    }
}

If anyone has a better solution, please let me know.

Regards,

Arnstein
0
Accepted
Dobromir
Telerik team
answered on 15 Nov 2011, 12:36 PM
Hi Arnstein,

The problem that you experience with the initial code comes from the fact that the state of the toolbar buttons is updated on every RadFileExplorer's inner AJAX request. After the ClientFolderChanged event is fired the explorer initiates new AJAX call to load the folder's content.

In order to achieve the required functionality, you can use the approach from your initial post but executed in the ClientFolderLoaded event.

Regarding the implementation of a client-side property controlling EnableCreateNewFolder, I have brought this to the attention of the developers and we will consider such implementation.

Best wishes,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
FileExplorer
Asked by
Arnstein
Top achievements
Rank 2
Answers by
Arnstein
Top achievements
Rank 2
Dobromir
Telerik team
Share this question
or