Commit 874e42ad by Dányi Bence

cloud.js reindent

parent 13a3166b
var toggleDetails; var toggleDetails;
$(function(){ $(function() {
function getCookie(name) { function getCookie(name) {
var cookieValue = null; var cookieValue = null;
if (document.cookie && document.cookie != '') { if(document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';'); var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) { for(var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]); var cookie = jQuery.trim(cookies[i]);
if (cookie.substring(0, name.length + 1) == (name + '=')) { if(cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break; break;
} }
...@@ -15,165 +15,204 @@ $(function(){ ...@@ -15,165 +15,204 @@ $(function(){
return cookieValue; return cookieValue;
} }
var csrftoken = getCookie('csrftoken'); var csrftoken = getCookie('csrftoken');
function csrfSafeMethod(method) { function csrfSafeMethod(method) {
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); return(/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
} }
$.ajaxSetup({ $.ajaxSetup({
crossDomain: false, crossDomain: false,
beforeSend: function(xhr, settings) { beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type)) { if(!csrfSafeMethod(settings.type)) {
xhr.setRequestHeader("X-CSRFToken", csrftoken); xhr.setRequestHeader("X-CSRFToken", csrftoken);
} }
} }
}); });
toggleDetails=function(){ toggleDetails = function() {
if($(this).next('.details').is(':hidden')){ if($(this).next('.details').is(':hidden')) {
$(this).next('.details').slideDown(700); $(this).next('.details').slideDown(700);
$(this).parent('.wm').addClass('opened'); $(this).parent('.wm').addClass('opened');
} else { } else {
var that=this; var that = this;
$(this).next('.details').slideUp(700,function(){ $(this).next('.details').slideUp(700, function() {
$(that).parent('.wm').removeClass('opened'); $(that).parent('.wm').removeClass('opened');
}); });
} }
} }
$('.wm .summary').unbind('click').click(toggleDetails); $('.wm .summary').unbind('click').click(toggleDetails);
$('#load-more-files').click(function(){ $('#load-more-files').click(function() {
$('.actions', this).show(); $('.actions', this).show();
var that=this; var that = this;
setTimeout(function(){ setTimeout(function() {
$(that).prev('li').slideDown(500,function(){ $(that).prev('li').slideDown(500, function() {
$('.actions', that).hide(); $('.actions', that).hide();
}); });
},2000); }, 2000);
}) })
$('#new-wm-button').click(function(){ $('#new-wm-button').click(function() {
$('#modal').show(); $('#modal').show();
$('#modal-container').html($('#new-wm').html()); $('#modal-container').html($('#new-wm').html());
$('#modal-container .wm .summary').each(function(){ $('#modal-container .wm .summary').each(function() {
this.originalHeight=parseInt($(this).next('.details').css('height')); this.originalHeight = parseInt($(this).next('.details').css('height'));
}) })
$('#modal-container .wm .summary').click(toggleDetails); $('#modal-container .wm .summary').click(toggleDetails);
}); });
$('#new-template-button').click(function(){ $('#new-template-button').click(function() {
$('#modal').show(); $('#modal').show();
$('#modal-container').html($('#new-template').html()); $('#modal-container').html($('#new-template').html());
}); });
$('#shadow').click(function(){ $('#shadow').click(function() {
$('#modal').hide(); $('#modal').hide();
}) })
$('#new-template-button').click(function(){ $('#new-template-button').click(function() {
$.get('/ajax/templateWizard', function(data){ $.get('/ajax/templateWizard', function(data) {
$('#modal-container').html(data); $('#modal-container').html(data);
}) })
$('#modal').show(); $('#modal').show();
}); });
var Model=function(){
var self=this; function Model() {
self.files=ko.observableArray(); var self = this;
self.allFiles=[]; self.files = ko.observableArray();
self.notInRoot=ko.observable(false); self.allFiles = [];
self.fileLimit=5; self.notInRoot = ko.observable(false);
self.jumpUp=function(){ self.fileLimit = 5;
var s=self.currentPath(); var disabled = false;
self.currentPath(s.substr(0,s.substr(0,s.length-1).lastIndexOf('/')+1));
loadFolder(self.currentPath()); function throttle(f) {
return function() {
if(disabled) {
console.log('disabled');
return
};
disabled = true;
setTimeout(function() {
disabled = false;
}, 700);
f.apply(null, arguments);
}
} }
var loadFolder=function(path){ self.jumpUp = function() {
self.fileLimit=5; var s = self.currentPath();
loadFolder(s.substr(0, s.substr(0, s.length - 1).lastIndexOf('/') + 1));
}
var loadFolder = throttle(function(path) {
self.currentPath(path);
self.fileLimit = 5;
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
data: 'path='+path, data: 'path=' + path,
url: '/ajax/store/list', url: '/ajax/store/list',
dataType: 'json', dataType: 'json',
success: function(data){ success: function(data) {
$('.file-list .real').css({left:0,position:'relative'}).animate({left:'-100%'},500).promise().done(function(){ $('.file-list .real').css({
left: 0,
position: 'relative'
}).animate({
left: '-100%'
}, 500).promise().done(function() {
loadFolderDone(data); loadFolderDone(data);
$('.file-list .real').css({left:'-300%',position:'relative'}).animate({left:0},500); $('.file-list .real').css({
left: '-300%',
position: 'relative'
}).animate({
left: 0
}, 500);
}); });
}, },
}) })
} })
var loadFolderDone=function(data){
function loadFolderDone(data) {
var viewData = [];
var added = 0;
self.notInRoot(self.currentPath().lastIndexOf('/') !== 0); self.notInRoot(self.currentPath().lastIndexOf('/') !== 0);
self.files([]); self.files([]);
self.allFiles=data; self.allFiles = data;
var viewData=[]; for(var i in data) {
var added=0;
for(var i in data){
added++; added++;
if(added<6) if(added < 6) addFile(data[i]);
addFile(data[i]);
} }
} }
var addFile=function(d){ function addFile(d) {
var viewData; var viewData;
if(d.TYPE === 'D'){ if(d.TYPE === 'D') {
viewData={ viewData = {
originalName: d.NAME, originalName: d.NAME,
name: d.NAME.length>30?(d.NAME.substr(0,27)+'...'):d.NAME, name: d.NAME.length > 30 ? (d.NAME.substr(0, 27) + '...') : d.NAME,
size: 'katalógus', size: 'katalógus',
type: 'katalógus', type: 'katalógus',
mTime: d.MTIME, mTime: d.MTIME,
getTypeClass: 'name filetype-folder', getTypeClass: 'name filetype-folder',
clickHandler: function(item){ clickHandler: function(item) {
self.currentPath(self.currentPath()+item.originalName+'/'); loadFolder(self.currentPath() + item.originalName + '/');
loadFolder(self.currentPath());
} }
}; };
} else { } else {
viewData={ viewData = {
originalName: d.NAME, originalName: d.NAME,
name: d.NAME.length>30?(d.NAME.substr(0,27)+'...'):d.NAME, name: d.NAME.length > 30 ? (d.NAME.substr(0, 27) + '...') : d.NAME,
size: d.SIZE+'K', size: d.SIZE + 'K',
type: 'fájl', type: 'fájl',
mTime: d.MTIME, mTime: d.MTIME,
getTypeClass: 'name filetype-text', getTypeClass: 'name filetype-text',
clickHandler: function(item, event){ clickHandler: function(item, event) {}
}
}; };
} }
self.files.push(viewData); self.files.push(viewData);
} }
self.fadeIn=function(e){ self.fadeIn = function(e) {
console.log(e,arguments);
$(e).hide().slideDown(500); $(e).hide().slideDown(500);
} }
self.currentPath=ko.observable('/'); self.currentPath = ko.observable('/');
self.showMore=function(){ self.showMore = function() {
for(var i=self.fileLimit;i<self.fileLimit+5;i++){ for(var i = self.fileLimit; i < self.fileLimit + 5; i++) {
if(self.allFiles[i] === undefined) break; if(self.allFiles[i] === undefined) break;
addFile(self.allFiles[i]); addFile(self.allFiles[i]);
} }
self.fileLimit+=5; self.fileLimit += 5;
} }
self.download=function(item){ self.download = function(item) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
data: 'dl='+self.currentPath()+item.originalName, data: 'dl=' + self.currentPath() + item.originalName,
url: '/ajax/store/download', url: '/ajax/store/download',
dataType: 'json', dataType: 'json',
success: function(data){ success: function(data) {
window.location.href=data.url; window.location.href = data.url;
} }
}) })
} }
self.delete=function(item){ self.delete = function(item) {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
data: 'rm='+self.currentPath()+item.originalName, data: 'rm=' + self.currentPath() + item.originalName,
url: '/ajax/store/delete', url: '/ajax/store/delete',
dataType: 'json', dataType: 'json',
success: function(data){ success: function(data) {
loadFolder(self.currentPath()); loadFolder(self.currentPath());
} }
}) })
} }
loadFolder(self.currentPath()); loadFolder(self.currentPath());
} }
var model=new Model(); var model = new Model();
ko.applyBindings(model); ko.applyBindings(model);
document.addEventListener('dragenter', function(e){console.log(e);e.stopPropagation();e.preventDefault();return false;}); document.addEventListener('dragenter', function(e) {
document.addEventListener('dragover', function(e){console.log(e);e.stopPropagation();e.preventDefault();return false;}); console.log(e);
document.addEventListener('drop', function(e){console.log(e);e.stopPropagation();e.preventDefault();return false;}); e.stopPropagation();
e.preventDefault();
return false;
});
document.addEventListener('dragover', function(e) {
console.log(e);
e.stopPropagation();
e.preventDefault();
return false;
});
document.addEventListener('drop', function(e) {
console.log(e);
e.stopPropagation();
e.preventDefault();
return false;
});
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment