Skip to content

Instantly share code, notes, and snippets.

@ekinertac
Created April 30, 2012 15:29
Show Gist options
  • Save ekinertac/2559296 to your computer and use it in GitHub Desktop.
Save ekinertac/2559296 to your computer and use it in GitHub Desktop.
Tacirnet Filemanager Javascript Codes
var protocol = window.location.protocol,
domain = window.location.hostname,
filePath = protocol + '//' + domain + '/admin/tacir-filemanager-git/',
deletePath = protocol + '//' + domain + '/admin/tacir-filemanager-sil/',
createFolderPath = protocol + '//' + domain + '/admin/tacir-filemanager/tacir-filemanager-yeniklasor/',
renamePath = protocol + '//' + domain + '/admin/tacir-filemanager-isimdegistir/';
function getFolder(folderPath){
if(!folderPath){
folderPath = $('#path').attr('data-value');
}
$.getJSON( filePath + folderPath + '/1/', function (res) {
$('#path').attr('data-value',folderPath + '/');
$('table tbody').empty();
if(res.dizinler != 'hata'){
for (var i=0;i < res.dizinler.length;i++) {
$('tbody').append('<tr>');
if(res.dizinler[i][2] === 0){
var name = res.dizinler[i][1];
$('tbody tr:last').append('\
<td class="fileName"><a class="folder" href="'+ name +'"><i class="folder"></i>' + name + '</a></td>\
<td class="type">Klasör</td>\
<td class="size">-</td>\
<td class="date">-</td>');
}else{
if(res.dizinler[i].length > 3){
var type = res.dizinler[i][0],
name = res.dizinler[i][1],
size = res.dizinler[i][3],
date = res.dizinler[i][4];
$('tbody tr:last').append('\
<td class="fileName"><a class="file" href="'+ name +'"><i class="'+res.dizinler[i][5].replace('.','')+'"></i>' + name + '</a></td>\
<td class="type">'+type+'</td>\
<td class="size">'+size+'</td>\
<td class="date">'+date+'</td>');
}
}
}
}
});
}
getFolder();
// click ve double click eventleri
$('table#fileManager tbody tr').live('click',function (e) {
if ($(this).hasClass('active')) {
if (!e.ctrlKey) {
$('table#fileManager tbody tr').removeClass('active');
} else {
$(this).removeClass('active');
}// else if
$('#fileOptions').hide();
} else {
if (!e.ctrlKey) {
$('table#fileManager tbody tr').removeClass('active');
}
$(this).addClass('active');
$('#fileOptions').show();
$('.btn-inverse span').remove();
$('.btn-inverse').append('<span> ' + $(this).find('td:first a').html() + '</span>');
}// else if
});// tr active selection
$('table#fileManager tbody a.file').live('click',function(){
return false;
});// a.file click
$('table#fileManager tbody a.folder').live('click',function(){
var name = $(this).attr('href');
var a = $('#path').attr('data-value');
$('#prevPath').attr('data-value',a);
a = a + name;
$('.breadcrumb').append('<li><a href="'+ $('#path').attr('data-value') + name + '/">' + name + '</a><span class="divider">/</span></li>');
getFolder(a);
return false;
});// a.folder click
$('.breadcrumb li a').live('click',function(){
var path = $(this).attr('href'),
li = $(this).parent(),
liSize = $('.breadcrumb li').size(),
thisIndex = li.index();
for(var i=1;i < liSize - thisIndex;i++){
$('.breadcrumb li:last').remove();
}
getFolder(path);
return false;
});
$('table#fileManager tbody tr').live('dblclick',function(e) {
var name = $(this).find('a').attr('href'),
a = $('#path').attr('data-value');
$('#prevPath').attr('data-value',a);
a = a + name;
getFolder(a);
return false;
});// tr dblclick
// copyUrl
// download
// rename
// move
// delete
$('#copyUrl').click(function(e) {// dosyanın tam url'i alınacak
var fileName = $('#fileManager tr.active').find('a').attr('href');
var msg = prompt('Dosyanın tam server yolu',fileName);
});
$('#delete').click(function () {
var fileName = $('#fileManager tr.active').find('a').attr('href');
type = $('#fileManager tr.active').find('.type').html();
if(type == 'Klasör'){
var box = confirm('"' + fileName + '" klasörü ve içindeki tüm veriler silinecek. Onaylıyor musunuz ?');
}else{
var box = confirm('"' + fileName + '" dosyası silinecek. Onaylıyor musunuz ?');
}
if(box){
$.getJSON(deletePath + $('#path').attr('data-value') + '/' + fileName,function(){
getFolder();
});
}
});
$('#rename').click(function () {
var fileName = $('#fileManager tr.active').find('a').attr('href');
var msg = prompt('Dosya adını değiştirin',fileName);
if(msg){
$.getJSON(renamePath + $('#path').attr('data-value') + fileName + '/' + msg,function(){
getFolder();
});
}
});
$('#download').click(function(){
window.open('http://google.com');
});
$('#createFolder').click(function () {
var msg = prompt('Yeni Klasör Adı');
if(msg){
$.getJSON(createFolderPath + $('#path').attr('data-value') + '/' + msg,function(){
getFolder();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment