FR.components.cartPanel=Ext.extend(Ext.ux.ListPanel,{cls:"cartPanel",locateOnSel:true,errors:[],initComponent:function(){this.store=new Ext.data.ArrayStore({idIndex:0});var emptyText='<img class="illustration" src="'+FR.illustrationsURL+'/empty_cart.svg" /><br>'+FR.T("Add files to the cart.");if(!Ext.isMobile){emptyText+="<br>"+FR.T("Drag them onto the cart button (%1).").replace("%1",'<i class="fa fa-cart-arrow-down"></i>')}this.listViewCfg={emptyText:'<div class="fr-cart-empty">'+emptyText+"</div>",columns:[{cls:"fr-cart-item",tpl:new Ext.XTemplate("{[this.getIconHTML(values)]} {filename}{[this.getDetails(values)]}",{getIconHTML:this.getIconHTML},{getDetails:function(v){var d="";if(v.objectType!="file"){d=v.objectType}else{d=v.nice_filesize}return'<br><span class="filesize">'+d+"</span>"}})}],listeners:{afterrender:function(){if(this.store.getCount()==0){this.store.removeAll()}},contextmenu:function(list,index){this.store.removeAt(index);this.updateUI()},scope:this}};this.total=new Ext.Toolbar.TextItem({cls:"size"});Ext.apply(this,{bbar:[{iconCls:"fa-download",cls:"fr-btn-primary",text:"Download all",handler:function(){this.download()},scope:this},{iconCls:"fa-envelope-o",cls:"fr-btn-default",hidden:!User.perms.email,style:"margin-left:5px",text:"E-mail",handler:function(){this.email()},scope:this},{text:"Clear cart",cls:"fr-btn-default",style:"margin-left:10px;",handler:function(){this.clear()},scope:this},"->",this.total]});FR.components.cartPanel.superclass.initComponent.apply(this,arguments);this.updateUI()},addItem:function(item){if(this.store.getById(item.path)){this.errors.push(FR.T("%1 is already in the cart.").replace("%1",'"'+item.filename+'"'));return false}if(!User.perms.download_folders&&item.objectType!="file"){this.errors.push(FR.T("You cannot add %1 to cart, as you are not allowed to download entire folders.").replace("%1",'"'+item.filename+'"'));return false}this.store.add(new Ext.data.Record(item,item.path));this.updateUI();return true},clear:function(){this.store.suspendEvents();this.store.removeAll();this.listView.refresh();this.store.resumeEvents();this.updateUI()},updateUI:function(){var c=this.store.getCount();this.getBottomToolbar().setVisible(c>0);if(this.attachedTo){var text=c>0?' <div class="bubbleCount">'+c+"</div>":"";this.attachedTo.setText(FR.T("Download cart")+text);this.attachedTo.el.toggleClassIf("withItems",c>0)}this.updateTotal()},download:function(){var paths=[];this.store.each(function(item){paths.push(item.data.path)});FR.actions.download(paths,FR.T("Download cart"))},email:function(){var items=[];this.store.each(function(item){items.push(item.data)});FR.actions.emailFiles(items,true)},updateTotal:function(){var t=0;var hasFolder=false;this.store.each(function(item){if(item.filesize){t+=parseInt(item.filesize)}else{hasFolder=true}});if(t>0){t=Ext.util.Format.fileSize(t);if(hasFolder){t="&gt; "+t}}this.total.setText(t)},attachToComponent:function(cmp){this.attachedTo=cmp;var el=cmp.el;new Ext.dd.DropTarget(el,{ddGroup:"TreeDD",notifyDrop:Ext.createDelegate(function(dragsource,event,data){if(!data.node){if(!FR.UI.gridPanel.target.perms.download){return false}this.addItems(FR.UI.gridPanel.getSelectedFiles())}},this),notifyEnter:function(source,e,data){}})},addItems:function(items){this.errors=[];var countAdded=0,countAll=0;Ext.each(items,function(item){countAll++;if(this.addItem(item)){countAdded++}},this);var feedback=this.errors.length?this.errors:[];if(countAdded==1){if(countAll==1){feedback.push(FR.T("Item added to the download cart"))}else{feedback.push(FR.T("One item added to the download cart"))}}else if(countAdded>1){feedback.push(FR.T("%1 items added to the download cart").replace("%1",countAdded))}FR.UI.feedback(feedback.join("<br>"))}});