Commit bc3656cb by Dányi Bence

store: limit number of shown files

parent 16c72327
...@@ -71,14 +71,16 @@ $(function(){ ...@@ -71,14 +71,16 @@ $(function(){
var Model=function(){ var Model=function(){
var self=this; var self=this;
self.files=ko.observableArray(); self.files=ko.observableArray();
self.allFiles=[];
self.notInRoot=ko.observable(false); self.notInRoot=ko.observable(false);
self.fileLimit=5;
self.jumpUp=function(){ self.jumpUp=function(){
var s=self.currentPath(); var s=self.currentPath();
self.currentPath(s.substr(0,s.substr(0,s.length-1).lastIndexOf('/')+1)); self.currentPath(s.substr(0,s.substr(0,s.length-1).lastIndexOf('/')+1));
loadFolder(self.currentPath()); loadFolder(self.currentPath());
} }
var loadFolder=function(path){ var loadFolder=function(path){
console.log('loadFolder'); self.fileLimit=5;
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
data: 'path='+path, data: 'path='+path,
...@@ -94,39 +96,57 @@ $(function(){ ...@@ -94,39 +96,57 @@ $(function(){
} }
var loadFolderDone=function(data){ var loadFolderDone=function(data){
self.notInRoot(self.currentPath().lastIndexOf('/') !== 0); self.notInRoot(self.currentPath().lastIndexOf('/') !== 0);
self.files([]);
self.allFiles=data;
var viewData=[]; var viewData=[];
var added=0;
for(var i in data){ for(var i in data){
var d=data[i]; added++;
if(data[i].TYPE === 'D'){ if(added<6)
viewData[i]={ addFile(data[i]);
originalName: d.NAME, }
name: d.NAME.length>30?(d.NAME.substr(0,27)+'...'):d.NAME, }
size: 'katalógus', var addFile=function(d){
type: 'katalógus', var viewData;
mTime: d.MTIME, if(d.TYPE === 'D'){
getTypeClass: 'name filetype-folder', viewData={
clickHandler: function(item){ originalName: d.NAME,
self.currentPath(self.currentPath()+item.originalName+'/'); name: d.NAME.length>30?(d.NAME.substr(0,27)+'...'):d.NAME,
loadFolder(self.currentPath()); size: 'katalógus',
} type: 'katalógus',
}; mTime: d.MTIME,
} else { getTypeClass: 'name filetype-folder',
viewData[i]={ clickHandler: function(item){
originalName: d.NAME, self.currentPath(self.currentPath()+item.originalName+'/');
name: d.NAME.length>30?(d.NAME.substr(0,27)+'...'):d.NAME, loadFolder(self.currentPath());
size: data[i].SIZE+'K', }
type: 'fájl', };
mTime: d.MTIME, } else {
getTypeClass: 'name filetype-text', viewData={
clickHandler: function(item, event){ originalName: d.NAME,
} name: d.NAME.length>30?(d.NAME.substr(0,27)+'...'):d.NAME,
}; size: d.SIZE+'K',
} type: 'fájl',
mTime: d.MTIME,
getTypeClass: 'name filetype-text',
clickHandler: function(item, event){
}
};
} }
self.files(viewData); self.files.push(viewData);
}
self.fadeIn=function(e){
console.log(e,arguments);
$(e).hide().slideDown(500);
} }
self.currentPath=ko.observable('/'); self.currentPath=ko.observable('/');
self.showMore=function(){
for(var i=self.fileLimit;i<self.fileLimit+5;i++){
if(self.allFiles[i] === undefined) break;
addFile(self.allFiles[i]);
}
self.fileLimit+=5;
}
self.download=function(item){ self.download=function(item){
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
......
...@@ -203,7 +203,13 @@ ...@@ -203,7 +203,13 @@
<div class="clear"></div> <div class="clear"></div>
</div> </div>
</li> </li>
<!-- ko foreach: files --> <li class="wm small real" data-bind="visible: files().length == 0">
<div class="summary">
<div class="name">Nincs megjeleníthető fájl.</div>
<div class="clear"></div>
</div>
</li>
<!-- ko foreach: {data:files,afterAdd:fadeIn} -->
<li class="wm real"> <li class="wm real">
<div class="summary" data-bind="click: clickHandler"> <div class="summary" data-bind="click: clickHandler">
<div class="name" data-bind="text: name, attr: {class: getTypeClass}"></div> <div class="name" data-bind="text: name, attr: {class: getTypeClass}"></div>
...@@ -231,13 +237,10 @@ ...@@ -231,13 +237,10 @@
</div> </div>
</li> </li>
<!-- /ko --> <!-- /ko -->
<li class="file-details wm" id="load-more-files"> <li class="file-details wm" id="load-more-files" data-bind="visible: (files().length>0 && files().length != allFiles.length)">
<div class="summary"> <div class="summary" data-bind="click: showMore">
<div class="name filetype-more"> <div class="name filetype-more">
Mutasd a régebbi fájlokat! Mutass több fájlt!
</div>
<div class="actions" style="text-align: right; display: none">
<img src="/static/load-4.gif" alt="loading" />
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
......
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