import Parse from './parse';
import ParseItem from './parseItem';
var extendAction = _.extend(Parse,ParseItem);
export default ClassBase.extend(extendAction).extend({
init:function(){
this.$el = this.$('.tab-group-pan .panel-log');
this.pathInfo = {};
this.listenTo(this.parent,'tabChange.panel-log',this.reloadView);
this.bindEvent();
},
reloadView:function(pathInfo,listData,isClick){
if(this.pathInfo.path == pathInfo.path) return;
isClick && this.$('.content').html('');
this.serverData = false;
this.pathInfo = pathInfo;
this.initViewList(this.pathInfo);
},
bindEvent: function(){
var self = this;
this.$el.delegate('.data-path','click',function(e){
var param = {
path:$(this).attr('file-path'),
type:$(this).attr('file-type'),
name:$(this).attr('file-name'),
};
// 文件夹则打开; 文件则打开所在位置;
if(param.type == 'folder'){
self.root.pathAction.open(param);
}else{
self.root.pathAction.openFatherSelect(param.path);
}
// 移动端提示进入;
if($.isWindowSmall()){
Tips.tips(LNG['explorer.openPathFinished']);
}
}).delegate('.toggle-item','click',function(e){
var $item = $(this).parent();
var $itemGroup = $item.find('.group-item-more');
var $btnShow = $item.find('.toggle-show');
var $btnHide = $item.find('.toggle-hide');
// 默认收起; 显示展开按钮;
if($(this).hasClass('toggle-show')){ // 显示;
$itemGroup.addClass('show-all');
$btnShow.addClass('hidden');
$btnHide.removeClass('hidden');
}else{
$itemGroup.removeClass('show-all');
$btnShow.removeClass('hidden');
$btnHide.addClass('hidden');
}
self.parent.$('.perfectScroll').perfectScroll();
});
},
// 请求历史记录列表,并初始化界面;
initViewList:function(pathInfo,page,pageNum){
var self = this;
var param = {path:pathInfo.path,page:page || 1,pageNum:pageNum || 200};
var pageInfo = _.get(this.serverData,'pageInfo');
if( !page && pageInfo){
param.page = pageInfo.page;
param.pageNum = pageInfo.pageNum;
}
var tips = Tips.loadingMask(this.$el,false,0.2);
this.pathModel.pathLog(param,function(data){
tips.close();
if(!data || !data.code) return Tips.tips(data);
self.renderView(data.data,pathInfo);
});
},
renderView:function(serverData,pathInfo){
var tpl = require('./list.html');
serverData.list = this.dataParseMain(pathInfo,serverData.list);
this.serverData = serverData;
var assign = {data:serverData,userInfo:this.root.path.userInfo};
this.renderHtml(tpl,assign,this.$('.content'));
this.pageLoad(serverData.pageInfo,pathInfo);
this.parent.resetTop();
if(!this.initViewFinished){
this.initViewFinished = true;
this.$('.content').hide().delay(50).fadeIn(250);
}
},
pageLoad:function(pageInfo,pathInfo){
var self = this;
var $page = this.$(".list-page");
var pageSizeArray = [50,100,200,500];
if(!pageInfo || pageInfo.totalNum <= pageSizeArray[0]){
this.$el.addClass('page-empty');
return $page.html('');
}
this.$el.removeClass('page-empty');
$page.pageBox({
totalNum: pageInfo.totalNum, //总条数
pageTotal: pageInfo.pageTotal, //总页数
pageShow: 1, //显示页数
pageCurrent: pageInfo.page, //当前页数
pageSize:pageInfo.pageNum, //每页条数
pageSizeArray:pageSizeArray, //每页条数选择 条/页
callback:function(page,pageSize){
self.initViewList(pathInfo,page,pageSize);
}
});
},
});