将prototype框架替换为jquery框架,修改了文件列表、评论分页、在线下载申请表单的ajax功能

This commit is contained in:
Li Jianxuan 2011-11-02 08:13:31 +00:00
parent aec40454af
commit 29c16cc6a0
1 changed files with 92 additions and 37 deletions

View File

@ -9,11 +9,12 @@
$this->breadcrumb('查看元数据');
$this->breadcrumb()->setSeparator(' > ');
$this->headScript()->appendFile('http://maps.google.cn/maps?file=api&v=2&key='.$this->config->google->maps->api);
$this->headScript()->appendFile('/js/prototype.js');
$this->headScript()->appendFile('/js/OpenLayers.js');
$this->headScript()->appendFile('/js/window.js');
$this->headScript()->appendFile('/js/jquery-1.6.4.min.js');
$this->headScript()->appendFile('/static/js/jquery.thickbox.js');
$this->headScript()->appendFile('/js/pubfunc.js');
$this->headLink()->appendStylesheet('/js/theme/default/style.css');
$this->headLink()->appendStylesheet('/static/css/thickbox.css');
?>
<?php $md=$this->metadata;if ($md):?>
<h1><?php echo $this->escape($md->title);
@ -92,13 +93,13 @@ else
}?>">数据说明文档</a></li>
<li>附件:<?php echo $this->attachment;?></li>
<?php endif; ?>
<li id="datatype">数据共享方式:<?php if ($md->datatype) print "离线"; else print "在线(可直接下载)";?> <a href="#" id="show-list" rel="<?php echo $md->uuid;?>">文件列表</a></li>
<li id="datatype">数据共享方式:<?php if ($md->datatype) print "离线"; else print "在线(可直接下载)";?> <a href="javascript:void(0);" id="show-list" onclick="getFileList()" title="">文件列表</a></li>
</ul>
<div id="linkurl">
<?php if ($md->status>0 and $md->status<5) : ?>
<a href="/review/review/uuid/<?php echo $md->uuid; ?>"><img src="/images/review.png" title="此数据正在评审中,我们邀请您对此数据进行评审,以便其能尽快发布!" /></a>
<?php else : if (!$md->datatype) : ?>
<a href="javascript:$('todownload').show();todownload(1);"><img src="/images/download.png" title="直接下载" /></a>
<a href="javascript:$('#todownload').show();todownload(1);"><img src="/images/download.png" title="直接下载" /></a>
<?php endif; ?>
<a href="/data/order/uuid/<?php echo $md->uuid; ?>"><img src="/images/order.png" title="免费!离线申请此数据(在线数据和离线数据都可申请)"/></a>
<?php endif; ?>
@ -148,7 +149,7 @@ endforeach;
</div>
<div id="left">
<div id="ImageViewer"><img src="/service/thumb/id/<?php echo $md->id;?>" onclick="fnCreate('<?php echo $this->thumburl; ?>')" /> </div>
<div id="ImageViewer"><a class="thickbox" title="" href="<?php echo $this->thumburl; ?>"><img src="/service/thumb/id/<?php echo $md->id;?>"/></a></div>
<div id="abstract">
<p>
<?php echo str_replace(array("\r\n", "\n", "\r"),'</p><p>',$md->description);?>
@ -261,11 +262,11 @@ echo '</li>';
<?php echo $this->commentForm; ?>
<?php endif; ?>
</div>
</div>
<div id="window-outter" style="display:none;">
<div id="window-inner">
<div id="window-closer-container">[<a href="#" id="window-closer">关闭</a>]</div>
<div id="window-closer-container">[<a href="#" id="window-closer" onclick="$('#window-outter').hide()">关闭</a>]</div>
<div id="window-content-container">
<div id="window-loading">加载中...</div>
<ol id="file-list">
@ -273,8 +274,9 @@ echo '</li>';
</div>
</div>
</div>
<div id="todownload" style="display:none;">
<div class="closeox"><a href="javascript:void(0);" onclick="$('todownload').hide()">[关闭]</a></div>
<div class="closeox"><a href="javascript:void(0);" onclick="$('#todownload').hide()">[关闭]</a></div>
<div id="returninfo" style="">
</div>
@ -283,40 +285,93 @@ echo '</li>';
//ajax download
function todownload(ft)
{
var request_url = "/data/todownload/uuid/<?php echo $md->uuid;?>/ft/"+ft;
if($('todownloadform')) {var request_pars = $('todownloadform').serialize();}else{var request_pars = '';}
var myAjax = new Ajax.Updater('returninfo', request_url,{
method : 'get',
parameters : request_pars,
onFailure : reportError,
onLoading : loading,
onComplete : done,
evalScripts: true
var url = "/data/todownload/uuid/<?php echo $md->uuid;?>/ft/"+ft;
if($('#todownloadform')) var date = $('#todownloadform').serialize();
$.ajax({
type:"GET",
url:url,
data:date,
success:function(html){
$('#returninfo').html(html);
},
beforeSend:function(){
$('#returninfo').html('<img src="/images/11887177066.gif" />');
}
});
}
//ajax comment
function loading(){$('loading').style.display = 'block';}
function done(){$('loading').style.display = 'none';}
function reportError(request){alert('Sorry. There was an error.');}
function ajaxpage(page){
var request_pars = 'page='+page; //请求参数
var myAjax = new Ajax.Updater('allcomments', '/data/comment/uuid/<?= $md->uuid; ?>',{
method : 'get', // http 请求方法,get or post
parameters : request_pars, // 请求参数
onFailure : reportError, // 失败的时候调用 reportError 函数处理
onLoading : loading, // 加载时
onComplete : done // 读取完毕
});
var url = "/data/comment/uuid/<?= $md->uuid; ?>";
data='page='+page;
$.ajax({
type:"GET",
url:url,
data:data,
success:function(html){$('#allcomments').html(html);},
beforeSend:function(){$('#allcomments').html('<img src="/images/loading.gif" />评论加载中');}
});
};ajaxpage(0);
function getFileList(){
var tw = ($(window).width() - $('#window-outter').width())/2;
$('#window-inner').css('min-height','450px');
$('#window-outter').css({'right':tw});
$('#window-outter').show();
$.getJSON("/filelist/uuid/<?php echo $md->uuid;?>", function(data) {
var items = [];
if(data.length>0)
{
$.each(data, function(key, val) {
if(val['filename'].match(/\/$/))
{
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="li_' + val['id'] + '">' + val['filename'] + '</li>');
}
});
}else{
items.push('<li>暂无数据</li>');
}
$('#file-list').html(items.join(''));
})
.complete(function() {$('#window-loading').hide();});
}
ajaxpage(0);
//google map
var map = new GMap2(document.getElementById("watermap"));
var plotbounds=new GLatLngBounds(new GLatLng(<?= $md->south; ?>,<?= $md->west; ?>),new GLatLng(<?= $md->north; ?>,<?= $md->east; ?>));
var zoomlevel=map.getBoundsZoomLevel(plotbounds);
zoomlevel--;
function getSubFileList(uuid,id,depth){
if($("#div_"+id).length>0)
{
$('#span_'+id).html('+');
$("#div_"+id).remove();
return false;
}
$('<div/>', {
'style':'max-height:400px; overflow:scroll; overflow-x:hidden;',
'id': 'div_'+id,
html: '<li><img src="/images/11887177066.gif" />加载中</li>'
}).appendTo('#li_'+id);
url="/filelist/sub/uuid/"+uuid+"/subpath/"+id+"/depth/"+depth;
$.getJSON(url, function(data) {
var items = [];
$.each(data, function(key, val) {
if(val['filename'].match(/\/$/))
{
items.push('<li id="li_' + val['id'] + '"><span id="span_'+val['id']+'">+</span> <a href="javascript:;" id="taget_'+val['id']+'" onclick="getSubFileList(\'' +val['uuid']+ '\',\''+val['id']+'\',\''+val['depth']+'\')">' + val['filename'] + '</a></li>');
}else{
items.push('<li id="' + key + '">' + val['filename'] + '</li>');
}
});
$("#div_"+id).html(items.join(''));
}).complete(function(){
if($("#div_"+id)){
$('#span_'+id).html('-');
}
});
}
//google map
var map = new GMap2(document.getElementById("watermap"));
var plotbounds=new GLatLngBounds(new GLatLng(<?= $md->south; ?>,<?= $md->west; ?>),new GLatLng(<?= $md->north; ?>,<?= $md->east; ?>));
var zoomlevel=map.getBoundsZoomLevel(plotbounds);
zoomlevel--;
<?php if ($md->north==$md->south) : ?>
zoomlevel=10;
zoomlevel=10;
<?php endif; ?>
if (zoomlevel>16) zoomlevel=16;
map.setCenter(new GLatLng(<?= ($md->south+$md->north)/2; ?>,<?= ($md->east+$md->west)/2; ?>), zoomlevel);