2010-07-06 16:46:04 +00:00
/ *
* To change this template , choose Tools | Templates
* and open the template in the editor .
* /
2010-07-02 03:44:10 +00:00
var Window = Class . create ( ) ;
Window . prototype = {
initialize : function ( ) {
2010-07-06 16:46:04 +00:00
$ ( '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 ) {
this . getFiles ( target . rel ) ;
}
} ) . bind ( this ) ) ;
$ ( 'window-closer' ) . observe ( 'click' , function ( ) {
2010-07-02 03:44:10 +00:00
$ ( 'window-outter' ) . hide ( ) ;
} ) ;
} ,
2010-07-06 16:46:04 +00:00
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 ) ;
} ) ;
2010-07-06 05:58:07 +00:00
}
2010-07-06 16:46:04 +00:00
$ ( 'file-list' ) . update ( lis ) ;
} ,
onComplete : function ( ) {
$ ( 'window-loading' ) . hide ( ) ;
} ,
onException : function ( ) {
alert ( 'Something went wrong...' ) ;
} ,
onFailure : function ( ) {
alert ( 'Something went wrong...' ) ;
}
} ) ;
2010-07-06 05:58:07 +00:00
} ,
getPageSize : function ( ) {
2010-07-06 16:46:04 +00:00
2010-07-06 05:58:07 +00:00
var xScroll , yScroll ;
2010-07-06 16:46:04 +00:00
2010-07-02 03:44:10 +00:00
if ( window . innerHeight && window . scrollMaxY ) {
xScroll = window . innerWidth + window . scrollMaxX ;
yScroll = window . innerHeight + window . scrollMaxY ;
} else if ( document . body . scrollHeight > document . body . offsetHeight ) { // all but Explorer Mac
xScroll = document . body . scrollWidth ;
yScroll = document . body . scrollHeight ;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document . body . offsetWidth ;
yScroll = document . body . offsetHeight ;
}
2010-07-06 16:46:04 +00:00
2010-07-02 03:44:10 +00:00
var windowWidth , windowHeight ;
2010-07-06 16:46:04 +00:00
2010-07-02 03:44:10 +00:00
if ( self . innerHeight ) { // all except Explorer
if ( document . documentElement . clientWidth ) {
windowWidth = document . documentElement . clientWidth ;
} else {
windowWidth = self . innerWidth ;
}
windowHeight = self . innerHeight ;
} else if ( document . documentElement && document . documentElement . clientHeight ) { // Explorer 6 Strict Mode
windowWidth = document . documentElement . clientWidth ;
windowHeight = document . documentElement . clientHeight ;
} else if ( document . body ) { // other Explorers
windowWidth = document . body . clientWidth ;
windowHeight = document . body . clientHeight ;
}
2010-07-06 16:46:04 +00:00
2010-07-02 03:44:10 +00:00
// for small pages with total height less then height of the viewport
if ( yScroll < windowHeight ) {
pageHeight = windowHeight ;
} else {
pageHeight = yScroll ;
}
2010-07-06 16:46:04 +00:00
2010-07-02 03:44:10 +00:00
// for small pages with total width less then width of the viewport
if ( xScroll < windowWidth ) {
pageWidth = xScroll ;
} else {
pageWidth = windowWidth ;
}
2010-07-06 16:46:04 +00:00
2010-07-02 03:44:10 +00:00
return [ pageWidth , pageHeight ] ;
}
2010-07-06 16:46:04 +00:00
}
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' ) ;
}
2010-07-02 03:44:10 +00:00
document . observe ( 'dom:loaded' , function ( ) {
2010-07-06 16:46:04 +00:00
new Window ( ) ;
2010-07-02 04:00:40 +00:00
} ) ;