<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI.Widgets" TagPrefix="widgets" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI.Dialogs" TagPrefix="dialogs" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<script type="text/javascript">
	Type.registerNamespace("Telerik.Web.UI.Editor.DialogControls");

	Telerik.Web.UI.Editor.DialogControls.FileBrowser = function(element)
	{
		Telerik.Web.UI.Editor.DialogControls.FileBrowser.initializeBase(this, [element]);
	}

	Telerik.Web.UI.Editor.DialogControls.FileBrowser.prototype = {
		initialize: function()
		{
			this.set_insertButton($get("InsertButton"));
			this.set_cancelButton($get("CancelButton"));

			var previewer = this.get_previewerType();
			var previewerType = eval("Telerik.Web.UI.Widgets." + previewer);
			$create(previewerType, { "browser": this }, null, null, $get(previewer));
			this.set_filePreviewer($find(previewer));
			this.set_fileBrowser($find("RadFileExplorer1"));

			Telerik.Web.UI.Editor.DialogControls.FileBrowser.callBaseMethod(this, 'initialize');
		},

		dispose: function()
		{
			Telerik.Web.UI.Editor.DialogControls.FileBrowser.callBaseMethod(this, 'dispose');
			this._insertButton = null;
			this._cancelButton = null;
		}
	}

Telerik.Web.UI.Editor.DialogControls.FileBrowser.registerClass('Telerik.Web.UI.Editor.DialogControls.FileBrowser', Telerik.Web.UI.Widgets.FileManager);


function OnClientDelete(oExplorer, args)
{
    var isRoot = isRootDir(oExplorer.get_tree(), args.get_path());
    // Check whether the moved item is a directorty and whether it is the root directory; 
    if (args.get_item().isDirectory() && isRoot)
    {
        alert("You cannot delete the root directory");
        args.set_cancel(true);
    }
}

function OnClientMove(oExplorer, args)
{
    var isRoot = isRootDir(oExplorer.get_tree(), args.get_path());
    // Check whether the moved item is a directorty and whether it is the root directory; 
    if (args.get_item().isDirectory() && isRoot)
    {
        // Check whether this is a renaming ; 
        if (isRenaming(args.get_newPath()))
        {// The renaming operation ; 
            alert("You cannot rename the root directory");
            args.set_cancel(true);
        }
    }
}

function isRootDir(oTree, path)
{
    var dirForDelete = oTree.findNodeByValue(path);

    if (dirForDelete != null)
    {
        return dirForDelete.get_level() == 0;
    }

    // Will occurs only when the "path" parameter is not a valid folder path.
    else return false
}

function isRenaming(destPath)
{
    if (destPath.search("/\//") == -1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

</script>
<style type="text/css">
.RadFileExplorer .RadGrid .rgPager .rgWrap {float:none;}
.RadFileExplorer .RadGrid .rgPager .RadSlider {float:none;}
.RadFileExplorer .RadGrid .rgPager .rgSliderLabel {float:left;}
.RadFileExplorer .RadGrid .rgPager .rgInfoPart {text-align:right;}
</style>
<table class="reDialog ManagerDialog NoMarginDialog" border="0" cellpadding="0"
	cellspacing="0" style="width: 100%;">
	<tr id="listRow">
		<td rowspan="2" class="FileExplorerPlaceholder">
			<telerik:RadFileExplorer ID="RadFileExplorer1" Height="450px" Width="400px" TreePaneWidth="150px"
				runat="Server" EnableOpenFile="false" AllowPaging="true" PageSize="100" OnClientDelete="OnClientDelete" OnClientMove="OnClientMove" />
		</td>
		<td rowspan="2" class="DialogSeparator">
			&nbsp;
		</td>
		<td style="width: 100%; vertical-align: top; padding: 0; height: 412px;">
			<asp:PlaceHolder ID="PreviewerPlaceHolder" runat="server" />
		</td>
	</tr>
	<tr>
		<td class="reBottomcell">
			<table border="0" cellpadding="0" cellspacing="0" class="reConfirmCancelButtonsTbl">
				<tr>
					<td>
						<button type="button" id="InsertButton">
							<script type="text/javascript">setInnerHtml("InsertButton", localization["Insert"]);</script>
						</button>
					</td>
					<td class="reRightMostCell">
						<button type="button" id="CancelButton">
							<script type="text/javascript">setInnerHtml("CancelButton", localization["Cancel"]);</script>
						</button>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
