采用dataset,datafile两个表处理文件列表
This commit is contained in:
parent
e92ad55483
commit
7b6833fbfd
|
@ -4,30 +4,37 @@ class FilelistController extends Zend_Controller_Action {
|
|||
$uuid=$this->_request->getParam('uuid');
|
||||
$filelist=new FilelistTable();
|
||||
$adapter=$filelist->getAdapter();
|
||||
$db=$adapter->query("select file_name,file_path,id,meta_uuid from westdc_fileinfo where meta_uuid='$uuid' order by id");
|
||||
$db=$adapter->query("select f.filename,f.id,s.uuid,f.depth from datafile f,dataset s where s.id=f.dsid and s.uuid='$uuid' and f.depth=1 and f.filename<>'/uuid.txt' order by f.isdir desc,f.filename");
|
||||
$files=$db->fetchAll();
|
||||
$documents=array();
|
||||
/* $documents=array();
|
||||
$i=0;
|
||||
foreach($files as $file) {
|
||||
$fileName=$file['file_name'];
|
||||
$pathArray=explode("/",$fileName);
|
||||
if(empty($pathArray[2])) {
|
||||
$documents[$i] = $file;
|
||||
$i++;
|
||||
if($fileName!=='/uuid.txt') {
|
||||
$pathArray=explode("/",$fileName);
|
||||
if(empty($pathArray[2])) {
|
||||
$documents[$i] = $file;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
echo Zend_Json::encode($documents);
|
||||
echo Zend_Json::encode($files);
|
||||
}
|
||||
function subAction() {
|
||||
$uuid=$this->_request->getParam('uuid');
|
||||
$id=$this->_request->getParam('id');
|
||||
$subpath=$this->_request->getParam('subpath');
|
||||
//$subPath=urldecode($getUrl);
|
||||
//$depth=substr_count($subPath,'/');
|
||||
$depth=$this->_request->getParam('depth');
|
||||
$depth++;
|
||||
$filelist=new FilelistTable();
|
||||
$adapter=$filelist->getAdapter();
|
||||
$subPath=$adapter->fetchOne("select file_name from westdc_fileinfo where id='$id'");
|
||||
$db=$adapter->query("select file_name,file_path,id,meta_uuid from westdc_fileinfo where meta_uuid='$uuid' order by id");
|
||||
$db=$adapter->query("select f.filename,f.id,s.uuid,f.depth from datafile f,dataset s where s.id=f.dsid and s.uuid='".$uuid."' and f.depth=".$depth." and f.filename<>'/uuid.txt' and f.filename ilike (select filename from datafile where id=".$subpath.")||'%' order by f.isdir desc,f.filename");
|
||||
$files=$db->fetchAll();
|
||||
/*
|
||||
$documents=array();
|
||||
$i=0;
|
||||
foreach($files as $subFile) {
|
||||
|
@ -49,10 +56,10 @@ class FilelistController extends Zend_Controller_Action {
|
|||
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
echo Zend_Json::encode($documents);
|
||||
echo Zend_Json::encode($files);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,99 +1,61 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
var Window = Class.create();
|
||||
var w;
|
||||
Window.prototype = {
|
||||
initialize:function(){
|
||||
$('show-list').observe('click',this.onClick.bindAsEventListener(this));
|
||||
$('window-closer').observe('click',function(e){
|
||||
$('window-outter').hide();
|
||||
$('file-list').update('');
|
||||
});
|
||||
this.subTemplate = new Template("<li><span id='span_#{id}'>+</span> <a href='#' onclick=\"w.onSubClick('#{id}','#{meta_uuid}','#{file_name}');return false;\">#{file_name}</a><div id='uuid_#{id}' style='display:none;'><ol id='uuid_ol_#{id}'></ol></div></li>");
|
||||
this.emptySubTemplate = new Template("<li>#{file_name}</li>");
|
||||
},
|
||||
onClick:function(event){
|
||||
var screenSizes = this.getPageSize();
|
||||
var width = (screenSizes[0]-960)/2;
|
||||
$('window-outter').setStyle({
|
||||
right: width + 'px'
|
||||
$('show-list').observe('click', (function(event) {
|
||||
$('file-list').update('<li>loading</li>');
|
||||
var screenSizes = this.getPageSize();
|
||||
var width = (screenSizes[0]-960)/2;
|
||||
$('window-outter').setStyle({
|
||||
right: width + 'px'
|
||||
}).show();
|
||||
var target = event.element();
|
||||
if(target){
|
||||
var options = {
|
||||
method: 'get',
|
||||
onSuccess: this.onSuccess.bind(this),
|
||||
onCreate:function(){
|
||||
$('window-loading').show();
|
||||
},
|
||||
onComplete:function(){
|
||||
$('window-loading').hide();
|
||||
},
|
||||
onException:function(){
|
||||
alert('Something went wrong...');
|
||||
},
|
||||
onFailure: function(){
|
||||
alert('Something went wrong...');
|
||||
}
|
||||
};
|
||||
new Ajax.Request('/filelist/uuid/'+target.rel, options);
|
||||
}
|
||||
},
|
||||
onSubClick:function(id,uuid,fileName){
|
||||
if($('uuid_'+id).getStyle('display')!='none'){
|
||||
$('uuid_'+id).hide();
|
||||
$('span_'+id).update('+');
|
||||
}else {
|
||||
var options = {
|
||||
method: 'get',
|
||||
parameters: {
|
||||
'uuid':uuid,
|
||||
'id': id
|
||||
},
|
||||
onSuccess: (function(transport){
|
||||
this.onSubSuccess(transport,id)
|
||||
}).bind(this),
|
||||
onCreate:function(){
|
||||
$('window-loading').show();
|
||||
},
|
||||
onComplete:function(){
|
||||
$('window-loading').hide();
|
||||
},
|
||||
onException:function(){
|
||||
alert('Something went wrong...');
|
||||
},
|
||||
onFailure: function(){
|
||||
alert('Something went wrong...');
|
||||
}
|
||||
};
|
||||
new Ajax.Request('/filelist/sub/', options);
|
||||
var target = event.element();
|
||||
if(target){
|
||||
this.getFiles(target.rel);
|
||||
}
|
||||
|
||||
}
|
||||
}).bind(this));
|
||||
$('window-closer').observe('click',function(){
|
||||
$('window-outter').hide();
|
||||
});
|
||||
},
|
||||
onSubSuccess:function(transport,id){
|
||||
var json = transport.responseText.evalJSON(true);
|
||||
var lis = this.generateLis(json);
|
||||
$('uuid_ol_'+id).update(lis);
|
||||
$('uuid_'+id).show();
|
||||
$('span_'+id).update('-');
|
||||
},
|
||||
onSuccess:function(transport){
|
||||
var json = transport.responseText.evalJSON(true);
|
||||
var lis = this.generateLis(json);
|
||||
$('file-list').update(lis);
|
||||
|
||||
},
|
||||
generateLis:function(json){
|
||||
var lis = "";
|
||||
if(json.length == 0){
|
||||
lis += "<li>暂无数据</li>"
|
||||
} else {
|
||||
json.each((function(file){
|
||||
lis += file['file_name'].endsWith('/')?this.subTemplate.evaluate(file):this.emptySubTemplate.evaluate(file);
|
||||
}).bind(this));
|
||||
}
|
||||
return lis;
|
||||
getFiles: function(uuid){
|
||||
var url = '/filelist/uuid/'+uuid;
|
||||
new Ajax.Request(url, {
|
||||
method: 'get',
|
||||
onSuccess: function(transport) {
|
||||
var json = transport.responseText.evalJSON(true);
|
||||
var liT = new Template("<li><span id='span_#{id}'>+</span> <a href='#' onclick=\" if($('uuid_'+#{id}).getStyle('display')!='none'){$('uuid_'+#{id}).hide();$('span_#{id}').update('+');return false;}; new Ajax.Request('/filelist/sub/', {method: 'get',onSuccess: function(transport){var json = transport.responseText.evalJSON(true);showSubPath(#{id},json);},"
|
||||
+"onFailure:function(transport){ alert('There was an error.');}, parameters:'uuid=#{uuid}&subpath=#{id}&depth=#{depth}'}); return false;\">#{filename}</a><div id='uuid_#{id}' style='display:none;'></div></li>");
|
||||
var liTemplate = new Template("<li>#{filename}</li>");
|
||||
var lis = "";
|
||||
if(json.length == 0){
|
||||
lis = "<li>暂无数据</li>"
|
||||
} else {
|
||||
json.each(function(file){
|
||||
lis += file['filename'].endsWith('/')?liT.evaluate(file):liTemplate.evaluate(file);
|
||||
});
|
||||
}
|
||||
$('file-list').update(lis);
|
||||
},
|
||||
onComplete:function(){
|
||||
$('window-loading').hide();
|
||||
},
|
||||
onException:function(){
|
||||
alert('Something went wrong...');
|
||||
},
|
||||
onFailure: function(){
|
||||
alert('Something went wrong...');
|
||||
}
|
||||
});
|
||||
},
|
||||
getPageSize: function() {
|
||||
|
||||
var xScroll, yScroll;
|
||||
|
||||
if (window.innerHeight && window.scrollMaxY) {
|
||||
xScroll = window.innerWidth + window.scrollMaxX;
|
||||
yScroll = window.innerHeight + window.scrollMaxY;
|
||||
|
@ -104,7 +66,9 @@ Window.prototype = {
|
|||
xScroll = document.body.offsetWidth;
|
||||
yScroll = document.body.offsetHeight;
|
||||
}
|
||||
|
||||
var windowWidth, windowHeight;
|
||||
|
||||
if (self.innerHeight) { // all except Explorer
|
||||
if(document.documentElement.clientWidth){
|
||||
windowWidth = document.documentElement.clientWidth;
|
||||
|
@ -119,21 +83,44 @@ Window.prototype = {
|
|||
windowWidth = document.body.clientWidth;
|
||||
windowHeight = document.body.clientHeight;
|
||||
}
|
||||
|
||||
// for small pages with total height less then height of the viewport
|
||||
if(yScroll < windowHeight){
|
||||
pageHeight = windowHeight;
|
||||
} else {
|
||||
pageHeight = yScroll;
|
||||
}
|
||||
|
||||
// for small pages with total width less then width of the viewport
|
||||
if(xScroll < windowWidth){
|
||||
pageWidth = xScroll;
|
||||
} else {
|
||||
pageWidth = windowWidth;
|
||||
}
|
||||
|
||||
return [pageWidth,pageHeight];
|
||||
}
|
||||
};
|
||||
}
|
||||
function showSubPath(id,json){
|
||||
var liT = new Template("<li><span id='span_#{id}'>+</span> <a href='#' onclick=\"if($('uuid_'+#{id}).getStyle('display')!='none'){$('uuid_'+#{id}).hide();$('span_#{id}').update('+');return false;}; new Ajax.Request('/filelist/sub/', {method: 'get',onSuccess: function(transport){var json = transport.responseText.evalJSON(true);showSubPath(#{id},json);},"
|
||||
+"onFailure:function(transport){ alert('There was an error.');}, parameters:'uuid=#{uuid}&subpath=#{id}&depth=#{depth}'}); return false;\">#{filename}</a><div id='uuid_#{id}' style='display:none;'></div></li>");
|
||||
var liTemplate = new Template("<li>#{filename}</li>");
|
||||
var lis = "<ol>";
|
||||
if(json.length == 0){
|
||||
lis = "<li>暂无数据</li>"
|
||||
} else {
|
||||
json.each(function(file){
|
||||
lis += file['filename'].endsWith('/')?liT.evaluate(file):liTemplate.evaluate(file);
|
||||
});
|
||||
}
|
||||
lis += "</ol>";
|
||||
$('span_'+id).update('-');
|
||||
$('uuid_'+id).update(lis).show();
|
||||
|
||||
}
|
||||
function encodestr(str){
|
||||
return str.replace('/&/g','%26');
|
||||
}
|
||||
document.observe('dom:loaded', function () {
|
||||
w = new Window();
|
||||
new Window();
|
||||
});
|
Loading…
Reference in New Issue