/*
* $Id: files.js 609 2008-07-27 15:19:43Z lukejee $
*/
Ext.namespace('NGMP.files');

NGMP.files.FolderPropertiesDialog = function() {
	this.propertiesPanel = new Ext.Panel({
		title:LANG_properties,
		layout:'form',
		cls:'ngmp-form-panel',
		defaultType:'textfield',
		labelWidth:70,
		border:false,
		items:[{
			fieldLabel:LANG_name,
			name:'name',
			anchor:'100%'
		},
			new NGMP.form.PlainField({
				fieldLabel:LANG_path,
				id:'id'
			}),
			new NGMP.form.HtmlComponent({
				html:"<hr>"
			}),
			new NGMP.form.DateTimeField({
				fieldLabel:LANG_ctime,
				id:'ctime'
			}),
			new NGMP.form.DateTimeField({
				fieldLabel:LANG_mtime,
				id:'mtime'
			}),
			new NGMP.form.DateTimeField({
				fieldLabel:LANG_atime,
				id:'atime'
			}),
			new NGMP.form.HtmlComponent({
				html:'<hr>'
			}),
			new NGMP.form.PlainField({
				fieldLabel:LANG_type,
				id:'type'
			}),
			new NGMP.form.PlainField({
				fieldLabel:LANG_size,
				id:'size'
			}),
			new Ext.form.Checkbox({
				boxLabel:LANG_activate_sharing,
				name:'share',
				checked:false,
				hideLabel:true,
				height:20
			})
		]
	});

	this.readPermissionsTab = new NGMP.grid.PermissionsPanel({
		type:'READ'
	});	

	this.writePermissionsTab = new NGMP.grid.PermissionsPanel({
		type:'WRITE'
	});

	this.commentsPanel = new Ext.Panel({
		layout:'form',
		labelWidth:70,
		title:LANG_comments,
		border:false,
		items: new Ext.form.TextArea({
			name:'comments',
			fieldLabel:'',
			hideLabel:true,
			anchor:'100% 100%'
		})
	});
	this.tabPanel = new Ext.TabPanel({
		activeTab:0,
		deferredRender:false,
		border:false,
		anchor:'100% 100%',
		hideLabel:true,
		items:[this.propertiesPanel,this.commentsPanel,this.readPermissionsTab, this.writePermissionsTab]
	});
	this.formPanel = new Ext.form.FormPanel({
		border:false,
		defaultType:'textfield',
		items:this.tabPanel
	});
	NGMP.files.FolderPropertiesDialog.superclass.constructor.call(this,{
		title:LANG_properties,
		layout:'fit',
		width:400,
		height:400,
		closeAction:'hide',
		items:this.formPanel,
		buttons:[{
			text:LANG_ok,
			handler: function() {
				this.save(true);
			},
			scope:this
		},{
			text:LANG_apply,
			handler:function() {
				this.save(false);
			},
			scope:this
		},{
			text:LANG_close,
			handler:function() {
				this.hide();
			},
			scope:this
		}]
	});
	this.addEvents({
		rename:true
	});
};

Ext.extend(NGMP.files.FolderPropertiesDialog, Ext.Window, {
	show:function(A) {
		this.id = A;
		this.render(Ext.getBody());
		this.formPanel.load({
			url:'ngmp.php',
			params:{
				id:this.id,
				func:'filesFolderProperties'
			},
			waitMsg:LANG_loading,
			success:function(B,C) {
				this.formPanel.form.findField('share').setValue(C.result.data.acl>0);
				this.readPermissionsTab.setAcl(C.result.data.acl);
				this.writePermissionsTab.setAcl(C.result.data.acl);
				this.setWritePermission(C.result.data.write_permission);
				this.tabPanel.setActiveTab(0);
				NGMP.files.FolderPropertiesDialog.superclass.show.call(this);
			},
			failure:function(B,C) {
				Ext.Msg.alert(LANG_error,C.result.feedback);
			},
			scope:this
		});
	},
	setWritePermission:function(A) {
//		console.log('todo setWritePermission');
	},
	save:function(A) {
		this.formPanel.form.submit({
			url:'ngmp.php',
			params:{
				id:this.id,
				func:'filesFolderProperties'
			},
			waitMsg:LANG_saving,
			success:function(B,C) {
				this.readPermissionsTab.setAcl(C.result.data.acl);
				this.writePermissionsTab.setAcl(C.result.data.acl);
				if (C.result.id) {
					this.path = C.result.data.id;
					this.fireEvent('rename', this);
				}
				if (A) {
					this.hide();
				}
			},
			failure:function(B,C) {
			},
			scope:this
		});
	}
});

NGMP.files.FilePropertiesDialog = function() {
	this.propertiesPanel = new Ext.Panel({
		layout:'form',
		title:LANG_properties,
		cls:'ngmp-form-panel',
		labelWidth:70,
		defaultType:'textfield',
		items:[{
			fieldLabel:LANG_name,
			id:'name',
			anchor:'100%'
		},
		new NGMP.form.PlainField({
			type:'plainfield',
			fieldLabel:LANG_path,
			id:'id'
		}),
		new NGMP.form.HtmlComponent({
			html:'<hr>'
		}),
		new NGMP.form.DateTimeField({
			fieldLabel:LANG_ctime,
			id:'ctime'
		}),
		new NGMP.form.DateTimeField({
			fieldLabel:LANG_mtime,
			id:'mtime'
		}),
		new NGMP.form.DateTimeField({
			fieldLabel:LANG_atime,
			id:'atime'
		}),
		new NGMP.form.HtmlComponent({
			html:'<hr>'
		}),
		new NGMP.form.PlainField({
			fieldLabel:LANG_type,
			id:'type'
		}),
		new NGMP.form.PlainField({
			fieldLabel:LANG_size,
			id:'size'
		})
		]
	});
	this.commentsPanel = new Ext.Panel({
		layout:'form',
		labelWidth:70,
		title:LANG_comments,
		border:false,
		items: new Ext.form.TextArea({
			name:'comments',
			fieldLabel:'',
			hideLabel:true,
			anchor:'100% 100%'
		})
	});
	this.tabPanel = new Ext.TabPanel({
		activeTab:0,
		deferredRender:false,
		border:false,
		anchor:'100% 100%',
		hideLabel:true,
		items:[this.propertiesPanel, this.commentsPanel]
	});
	this.formPanel = new Ext.form.FormPanel({
		border:false,
		defaultType:'textfield',
		items:this.tabPanel
	});
	NGMP.files.FilePropertiesDialog.superclass.constructor.call(this, {
		title:LANG_properties,
		layout:'fit',
		width:400,
		height:400,
		closeAction:'hide',
		items:this.formPanel,
		buttons:[{
			text:LANG_ok,
			handler:function() {
				this.save(true);
			},
			scope:this
		},{
			text:LANG_apply,
			handler:function() {
				this.save(false);
			},
			scope:this
		},{
			text:LANG_close,
			handler:function() {
				this.hide();
			},
			scope:this
		}]
	});
	this.addEvents({
		rename:true
	});
};

Ext.extend(NGMP.files.FilePropertiesDialog, Ext.Window, {
	show:function(A) {
		this.id = A;
		this.render(Ext.getBody());
		this.formPanel.form.load({
			url:'ngmp.php',
			params:{
				id:this.id,
				func:'filesFileProperties'
			},
			waitMsg:LANG_loading,
			success:function(B,C) {
				this.readonly = !C.result.data.write_permission;
				this.setWritePermission();
				this.tabPanel.setActiveTab(0);
				NGMP.files.FilePropertiesDialog.superclass.show.call(this);
			},
			failure:function(D,E) {
				Ext.Msg.alert(LANG_error, C.result.feedback);
			},
			scope:this
		});
	},
	setWritePermission:function() {
		var B = this.formPanel.form;
		B.findField('name').setDisabled(this.readonly);
		B.findField('comments').setDisabled(this.readonly);
	},
	save:function(A) {
		if (this.readonly) {
			if (A)
				this.hide();
		} else {
			this.formPanel.form.submit({
				url:'ngmp.php',
				params:{
					id:this.id,
					func:'filesFileProperties'
				},
				waitMsg:LANG_saving,
				success:function(B,C) {
					if(C.result.path) {
						this.path = C.result.path;
						this.fireEvent('rename',this);
					}
					if (A) {
						this.hide();
					}
				},
				failure:function(C,D) {
					var B = '';
					if (D.failureType == 'client') {
						B = LANG_error_in_form;
					} else {
						B = D.result.feedback;
					}
					Ext.Msg.alert(LANG_error, B);
				},
				scope:this
			});
		}
	}
});


NGMP.files.FilesModule = function(A) {
	if (!A) {
		A = {};
	}
	if (!A.root) {
		A.root = 'root';
	}

    this.layout = 'border';

	this.guid = new NGMP.utils.GUID();

	this.locationTextField = new Ext.form.TextField({
		id:'files-location',
		fieldLabel:LANG_location,
		name:'files-location',
		anchor:'100%',
		readOnly:true
	});

	this.locationPanel = new Ext.Panel({
		region:'north',
		layout:'form',
		border:false,
		autoHeight:true,
		labelWidth:75,
		plain:true,
		cls:'ngmp-files-location-panel',
		items:this.locationTextField
	});
	this.treePanel = new Ext.tree.TreePanel({
		region:'center',
		title: LANG_locations,
		layout:'fit',
		hideMode:'visibility',
		split:true,
		autoScroll:true,
		width: 200,
		animate:true,
		loader: new Ext.tree.TreeLoader({
			dataUrl:'ngmp.php',
			baseParams:{
				func:'filesTree'
			},
			preloadChildren:true
		}),
		collapsed: A.treeCollapsed,
		collapsible: false,
		containerScroll:true,
		rootVisible: A.treeRootVisible,
		bodyStyle:'background-color: white',
		pathSeparator:'|',
		ddAppendOnly: true,
		ddGroup:'FilesDD',
		enableDD:true
	});
	this.rootNode = new Ext.tree.AsyncTreeNode({
		text: LANG_folders,
		draggable:false,
		id:A.root,
		iconCls:'folder-default'
	});
	this.treePanel.setRootNode(this.rootNode);

	if (!A.treeRootVisible) {
		this.rootNode.on('load', function(B) {
			if (B.childNodes[0]) {
				var C = B.childNodes[0];
				this.setPath(C.id);
			}
		},this, {
			single:true
		});
	}

	this.treePanel.on('click', function(B) {
		this.setPath(B.id, true);
	},this);

	this.treePanel.on('contextmenu', function(B,D) {
		D.stopEvent();
		this.contextTreePath = B.id;
		var C = D.getXY();
		this.filesContextMenu.showAt([C[0], C[1]], 'folder', 'tree');
	},this);

	this.treePanel.on('beforenodedrop', function(D) {
		var C;
		if (D.data.selections) {
			C=D.data.selections;
		} else {
			var B = {};
			B.data = {};
			B.data.extension='folder';
			B.data.path = D.data.node.id;
			C= [B];
		}
		this.paste('cut', D.target.id, C);
	},this);

	this.quotaPanel = new Ext.Panel({
		region:'south',
		height:185,
		minHeight:120,
		maxHeight:120,
		collapsible:true,
		bodyStyle:'background-color:transparent;',
		split:false,
		title:LANG_files_quota,
		border:true,
		frame:true,
		titleCollapse: true,
		autoLoad:{
			url:'ngmp.php?func=filesQuota',
			scripts:false,
			scope:this,
			nocache:true
		}
	});
	this.filesTreePanel = new Ext.Panel({
		title:LANG_files,
		width:210,
		region:'west',
		iconCls:'icon-files',
		layout:'border',
		collapsible:true,
		hideBorders:true,
		titleCollapse:true,
		bodyStyle:'background-color:transparent',
		items:[this.treePanel, this.quotaPanel]
	});

	this.gridStore = new NGMP.data.JsonStore({
		url:'ngmp.php',
		baseParams: {
			func:'filesGrid'
		},
		root:'results',
		totalProperty:'total',
		id:'id',
		fields: ['id', 'text', 'type','grid_display','extension','size',{name:'mtime', type:'date', dateFormat:'timestamp'},'extension'],
		remoteSort:true
	});

	this.gridStore.on('load', function(C) {
//		console.log('path='+this.path);
		var B = this.path.lastIndexOf("/");
		this.parentPath = this.path.substr(0,B);
	//	console.log('parentPath='+this.parentPath);
		if (this.parentPath == 'personal:/')
			this.parentPath = 'personal://';
		if (this.parentPath == 'shared:/')
			this.parentPath = 'shared://';	

		if (this.path == 'personal://' || this.path == this.rootNode.id || this.path == 'shared://') {
			this.upButton.setDisabled(true);
		} else {
			this.upButton.setDisabled(false);
		}
	},this);
	this.gridPanel = new NGMP.grid.GridPanel({
		region:'center',
		layout:'fit',
		split:true,
		store:this.gridStore,
		deleteConfig:{
			scope:this,
			success:function() {
				var B = this.treePanel.getNodeById(this.path);
				if (B) {
					B.reload();
				}
			}
		},
		columns:[
			{header: LANG_name, dataIndex:'grid_display', sortable:true},
			{header: LANG_type, dataIndex:'type', sortable: true},
			{header: LANG_size, dataIndex:'size', sortable: true},
			{
				header: LANG_date_modified, 
				dataIndex:'mtime', 
				sortable: true,
				renderer: function(value) {
					return value.dateFormat("Y/m/d H:i");
				}
			}
		],
		view: new Ext.grid.GridView({
			autoFill:true,
			forceFit:true
		}),
		sm: new Ext.grid.RowSelectionModel(),
		loadMask:true,
		enableDragDrop:true,
		ddGroup:'FilesDD'
	});
	this.gridPanel.on('rowdblclick', this.onGridDoubleClick,this);
	this.filesContextMenu = new NGMP.files.FilesContextMenu();
	this.filesContextMenu.on('properties', function(C,B) {
		if (B == 'tree') {
			this.showFolderPropertiesDialog(this.path);
		} else {
			this.showGridPropertiesDialog();
		}
	},this);
	this.filesContextMenu.on('cut', function(C,B) {
		this.onCutCopy('cut',B);
	},this);
	this.filesContextMenu.on('copy', function(C,B) {
		this.onCutCopy('copy',B);
	},this);
	this.filesContextMenu.on('delete', function(C,B) {
		this.onDelete(B);
	},this);

	this.filesContextMenu.on('compress', function(C,B) {
		this.onCompress(B);
	},this);

	this.filesContextMenu.on('decompress', function(C,B) {
		this.onDecompress(B);
	},this);
	this.gridPanel.on('rowcontextmenu', this.onGridRowContextMenu,this);
	this.uploadButton = new Ext.Button({
		iconCls:"icon-upload",
		text:LANG_upload,
		cls:"x-btn-text-icon",
		handler:function() {
			var C = new NGMP.dialog.UploadDialog.Dialog({
				url:'ngmp.php',
				iconCls:'icon-uplaod',
				base_params:{
					func:'filesUpload',
					uid:this.guid.id,
					root:this.path
				},
				reset_on_hide:false,
				allow_close_on_upload:false,
				modal:true
			});
			C.on('uploadsuccess', function(H,G,F) {
		//		console.log('uploadsuccess');
				this.refreshQuota();
			},this);
			C.show(this.getEl());
		},
		scope:this
	});
	this.upButton = new Ext.Button({
		iconCls:'icon-up',
		text:LANG_up,
		cls:'x-btn-text-icon',
		handler: function() {
			this.setPath(this.parentPath,true);
		},
		scope:this,
		disabled: true
	});

	this.deleteButton = new Ext.Button({
		iconCls:'icon-delete',
		text:LANG_delete,
		cls:'x-btn-text-icon',
		handler:function() {
			this.onDelete('grid');
		},
		scope:this
	});
	
	this.cutButton = new Ext.Button({
		iconCls:'icon-cut',
		text:LANG_cut,
		cls:'x-btn-text-icon',
		handler:function() {
			this.onCutCopy('cut','grid');
		},
		scope:this
	});

	this.copyButton = new Ext.Button({
		iconCls:'icon-copy',
		text:LANG_file_copy,
		cls:'x-btn-text-icon',
		handler: function() {
			this.onCutCopy('copy','grid');
		},
		scope:this
	});

	this.pasteButton = new Ext.Button({
		iconCls:'icon-paste',
		text:LANG_paste,
		cls:'x-btn-text-icon',
		handler:this.onPaste,
		scope:this,
		disabled:true
	});

	this.tbar = new Ext.Toolbar({
		items:[{
			cls:'x-btn-text-icon',
			iconCls:'icon-add',
			text:LANG_add
		}, this.uploadButton, '-', this.upButton,'-', this.copyButton,'-',this.cutButton, this.pasteButton,'-',this.deleteButton]
	});
	this.items = [this.locationPanel,this.filesTreePanel, this.gridPanel];
		
	NGMP.files.FilesModule.superclass.constructor.call(this,A);
};
Ext.extend(NGMP.files.FilesModule,Ext.Panel, {
	fileClickHandler: false,
	scope:this,
	pasteSelections:Array(),
	pasteMode:'cut',
	afterRender: function (){
		NGMP.files.FilesModule.superclass.afterRender.call(this);
		if (this.isVisible()) {
			this.onShow();
		}			
	},
	onShow: function() {
		NGMP.files.FilesModule.superclass.onShow.call(this);
		if (!this.loaded) {
			this.buildNewMenu();
			this.setRootNode(this.root);
			this.loaded = true;
		} else {
			this.rootNode.reload();
		}
	},
	setRootPath : function(A) {
		this.root = A;
		tihs.loaded = false;
 	},
	setRootNode: function(A) {
		this.rootNode.id = A;
		this.rootNode.attributes.id = A;
		delete this.rootNode.children;
		this.rootNode.expanded = false;
		this.rootNode.childrenRendered = false;
		if (A){
			this.rootNode.on('load', function(B) {
				if (B.childNodes[0]) {
					var C=B.childNodes[0];
					this.setPath(C.id);
				}
			},this, {
				single:true
			});
		} else {
			this.setPath(A);
		}
		this.rootNode.reload();
	},
	buildNewMenu: function() {
//		console.log('build new menu');
	},
	setPath:function(B,A) {
		this.path = B;
		this.gridStore.baseParams.path = B;
		this.gridStore.load();
		this.locationTextField.setValue(B);
		if (A) {
			var C = this.treePanel.getNodeById(B);
			if (C) {
				C.select();
				C.expand();
			}
		}
		this.refreshQuota();
	},
	reload:function() {
		this.gridStore.load();
		var A = this.treePanel.getNodeById(this.path);
		if (A) {
			A.reload();
		}
	},
	refreshQuota: function() {
		this.quotaPanel.getUpdater().refresh();
	},
	onGridRowContextMenu: function(B,G,E) {
		E.stopEvent();
		var A = B.getSelectionModel();
		if (A.isSelected(G) !== true) {
			A.clearSelections();
			A.selectRow(G);
		}
		var F = "";
		var C = A.getSelections();
		if (C.length == '1') {
			F=C[0].data.extension;
		}
		var D = E.getXY();
		this.filesContextMenu.showAt([D[0],D[1]],F,'grid');
	},
	onCompress: function(A,B) {
//		console.log('todo on compress');
	},
	onDecompress: function(A) {
//		console.log('todo on decompress');
	},
	onCutCopy:function(D,A) {
		if (A == 'tree') {
			var B = {};
			B.data = {};
			B.data.extension = "folder";
			B.data.path = this.contextTreePath;
			this.pasteSelections[B];
		} else {
			var C = this.gridPanel.getSelectionModel();
			this.pasteSelections = C.getSelections();
		}
		this.pasteMode = D;
		if (this.pasteSelections.length) {
			this.pasteButton.setDisabled(false);
		}
	},
	onPaste:function() {
		for (var A = 0; A<this.pasteSelections.length;A++) {
		//	console.log('id='+this.pasteSelections[A].data.id);
		}
		this.paste(this.pasteMode, this.path, this.pasteSelections);
	},
	onDelete: function(A) {
		if (A == 'tree') {
			alert('todo');
		} else {
			this.gridPanel.deleteSelected();
		}
	},
	paste: function(E,A,B) {
		var G = Array();
		for (var D = 0;D<B.length;D++) {
			G.push(B[D].data.id);
		}
		var F = {
			func:'paste',
			paste_sources:Ext.encode(G),
			paste_destination:A,
			paste_mode:E,
			path:this.path
		};
		this.sendOverwrite(F);
 	},
	sendOverwrite:function(A) {
		if (!A.command) {
			A.command = 'ask';
		}
		A.func = 'filesCopyCutPaste';
		this.overwriteParams = A;
		Ext.Ajax.request({
			url:'ngmp',
			params: this.overwriteParams,
			callback: function(C,E,B) {
				if (!E) {
					Ext.Msg.alert(LANG_error, LANG_request_error);
				} else {
					var D = Ext.decode(B.responseText);
					if (!D.success && D.file_exists) {
						Ext.Msg.alert(LANG_error, D.feedback);
					} else {
						if (D.file_exists) {
							if (!this.overwriteDialog) {
								this.overwriteDialog = new Ext.Window({
									width:500,
									autoHeight:true,
									closeable:false,
									closeAction:'hide',
									plain:true,
									border:true,
									title:LANG_fileexists,
									modal:true,
									buttons:[{
										text:LANG_yes,
										handler:function() {
											this.overwriteParams.command = 'yes';
											this.sendOverwrite(this.overwriteParams);
										},
										scope:this
									},{
										text:LANG_yes_to_all,
										handler:function() {
											this.overwriteParams.command = 'yestoall';
											this.sendOverwrite(this.overwriteParams);
										},
										scope:this
									},{
										text:LANG_no_to_all,
										handler:function() {
											this.overwriteParams.command = 'notoall';
											this.sendOverwrite(this.overwriteParams);
										},
										scope:this
									},{
										text:LANG_cancel,
										handler:function(){
											this.gridStore.reload();
											this.overwriteDialog.hide();
										},
										scope:this
									}]
								});
								this.overwriteDialog.render(Ext.getBody());
							}
							this.overwriteDialog.body.update(LANG_do_you_wish_to_overwrite_the_file + D.file_exists+ "'?");
							this.overwriteDialog.show();
						} else {
							delete A.paste_sources;
							delete A.paste_destination;
							this.path = C;
							this.reload();
							if (this.overwriteDialog) {
								this.overwriteDialog.hide();
							}
						}
					}
				}
			},
			scope:this
		});
	},
	showFolderPropertiesDialog:function(A) {
		if (!this.folderPropertiesDialog) {
			this.folderPropertiesDialog = new NGMP.files.FolderPropertiesDialog();
			this.folderPropertiesDialog.on('rename', function() {
				this.reload();
			},this);
		}
		this.folderPropertiesDialog.show(A);
   	},
	showFilePropertiesDialog:function(A) {
		this.filePropertiesDialog = new NGMP.files.FilePropertiesDialog();
		this.filePropertiesDialog.on('rename', function() {
			this.gridStore.load();
		},this);
		this.filePropertiesDialog.show(A);
	},
	showGridPropertiesDialog:function() {
		var A = this.gridPanel.getSelectionModel();
		var B = A.getSelections();
		if (B.length === 0) {
			Ext.Msg.alert(LANG_error, LANG_no_item_selected);
		} else {
			if (B.length > 1) {
				Ext.Msg.alert(LANG_error, LANG_please_select_only_one_item);
			} else {
				if (B[0].data.extension == 'folder') {
					this.showFolderPropertiesDialog(B[0].data.id);
				} else {
					this.showFilePropertiesDialog(B[0].data.id);
				}
			}
		}
	},
	onGridDoubleClick: function(C,D,E) {
		var A = C.getSelectionModel();
		var B = A.getSelected();
		if (B.data.extension == 'folder') {
			this.setPath(B.data.id, true);
		} else {
			if (this.fileClickHandler) {
				this.fileClickHandler.call(this.scope);
			} else {
				this.openFile(B.data.id);
			}
		}
	},
	openFile: function(A) {
		window.location.href='ngmp.php?func=filesDownload&file='+A;
	}
});

NGMP.files.FilesContextMenu = function(A) {
	if (!A) {
		A = {};
	}
	A.shadow = 'frame';
	A.minWidth = 180;
	
	this.downloadButton = new Ext.menu.Item({
		iconCls:'icon-download',
		text:LANG_download,
		cls:'x-btn-text-icon',
		handler:function() {
			this.fireEvent('download', this, this.clickedAt);
		},
		scope:this
	});

	this.deleteButton = new Ext.menu.Item({
		iconCls:'icon-delete',
		text:LANG_delete,
		cls:'x-btn-text-icon',
		handler:function() {
			this.fireEvent('delete',this,this.clickedAt);
		},
		scope:this
	});

	this.cutButton = new Ext.menu.Item({
		iconCls:'icon-cut',
		text:LANG_cut,
		cls:'x-btn-text-icon',
		handler: function() {
			this.fireEvent('cut',this,this.clickedAt);
		},
		scope:this
	});

	this.copyButton = new Ext.menu.Item({
		iconCls:'icon-copy',
		text:LANG_file_copy,
		cls:'x-btn-text-icon',
		handler: function() {
			this.fireEvent('copy',this,this.clickedAt);
		},
		scope:this
	});

	this.compressButton=new Ext.menu.Item({
		iconCls:"icon-compress",
		text:LANG_compress,
		cls:"x-btn-text-icon",
		handler:function() {
			this.fireEvent("compress",this,this.clickedAt);
		},
		scope:this
	});
	this.decompressButton=new Ext.menu.Item({
		iconCls:"icon-decompress",
		text:LANG_decompress,
		cls:"x-btn-text-icon",
		handler:function() {
			this.fireEvent("decompress",this,this.clickedAt);
		},
		scope:this
	});
	A.items=[
		this.downloadButton,
		{
			iconCls:"icon-properties",
			text:LANG_properties,
			handler:function() {
				this.fireEvent('properties', this, this.clickedAt);
			},
			scope:this
  		},
		new Ext.menu.Separator(),
		this.cutButton,
		this.copyButton,
		new Ext.menu.Separator(),
		this.deleteButton,
		this.compressSeparator=new Ext.menu.Separator(),
		this.compressButton,
		this.decompressButton
	];
	NGMP.files.FilesContextMenu.superclass.constructor.call(this,A);
		this.addEvents({
			properties:true,
			paste:true,
			cut:true,
			copy:true,
			"delete":true,
			compress:true,
			decompress:true
	});
};
Ext.extend(NGMP.files.FilesContextMenu, Ext.menu.Menu, {
	clickedAt:'grid',
	showAt:function(B,C,A) {
		this.clickedAt =A;
		switch(C) {
			case 'zip':
			case 'tar':
			case 'tgz':
			case 'gz':
				this.downloadButton.show();
				this.decompressButton.show();
				this.compressButton.hide();
				break;
			case '':
			case 'folder':
				this.downloadButton.hide();
				this.decompressButton.hide();
				this.compressButton.show();
				break;
			default:
				this.downloadButton.show();
				this.compressButton.show();
				this.decompressButton.hide();
				break;
		}
		NGMP.files.FilesContextMenu.superclass.showAt.call(this,B);
	}
});

NGMP.moduleManager.addModule('files', NGMP.files.FilesModule, {
	title:LANG_files,
	iconCls:'icon-files',
	frame:false
});
