text: define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model","mvc/library/library-folderrow-view","mvc/library/library-dataset-view"],function(d,f,g,e,a,c){var b=Backbone.View.extend({el:"#folder_items_element",defaults:{include_deleted:false},progress:0,progressStep:1,modal:null,folderContainer:null,sort:"asc",events:{"click #select-all-checkboxes":"selectAll","click .dataset_row":"selectClickedRow","click .sort-folder-link":"sortColumnClicked"},rowViews:{},initialize:function(h){this.options=_.defaults(this.options||{},h);this.fetchFolder()},fetchFolder:function(h){var h=h||{};this.options.include_deleted=h.include_deleted;var i=this;this.collection=new e.Folder();this.listenTo(this.collection,"add",this.renderOne);this.listenTo(this.collection,"remove",this.removeOne);this.folderContainer=new e.FolderContainer({id:this.options.id});this.folderContainer.url=this.folderContainer.attributes.urlRoot+this.options.id+"/contents";if(this.options.include_deleted){this.folderContainer.url=this.folderContainer.url+"?include_deleted=true"}this.folderContainer.fetch({success:function(j){i.folder_container=j;i.render();i.addAll(j.get("folder").models);if(i.options.dataset_id){row=_.findWhere(i.rowViews,{id:i.options.dataset_id});if(row){row.showDatasetDetails()}else{g.error("Dataset not found. Showing folder instead.")}}},error:function(k,j){if(typeof j.responseJSON!=="undefined"){g.error(j.responseJSON.err_msg+" Click this to go back.","",{onclick:function(){Galaxy.libraries.library_router.back()}})}else{g.error("An error ocurred. Click this to go back.","",{onclick:function(){Galaxy.libraries.library_router.back()}})}}})},render:function(h){this.options=_.defaults(this.options,h);var i=this.templateFolder();$(".tooltip").hide();var j=this.folderContainer.attributes.metadata.full_path;var k;if(j.length===1){k=0}else{k=j[j.length-2][0]}this.$el.html(i({path:this.folderContainer.attributes.metadata.full_path,parent_library_id:this.folderContainer.attributes.metadata.parent_library_id,id:this.options.id,upper_folder_id:k,order:this.sort}));$("#center [data-toggle]").tooltip();$("#center").css("overflow","auto")},postRender:function(){var h=this.folderContainer.attributes.metadata;h.contains_file=typeof this.collection.findWhere({type:"file"})!=="undefined";Galaxy.libraries.folderToolbarView.configureElements(h);$(".library-row").hover(function(){$(this).find(".show_on_hover").show()},function(){$(this).find(".show_on_hover").hide()})},addAll:function(h){_.each(h.reverse(),function(i){Galaxy.libraries.folderListView.collection.add(i)});$("#center [data-toggle]").tooltip();this.checkEmptiness();this.postRender()},renderAll:function(){var h=this;_.each(this.collection.models.reverse(),function(i){h.renderOne(i)});this.postRender()},renderOne:function(i){if(i.get("type")!=="folder"){this.options.contains_file=true}i.set("folder_id",this.id);var h=new a.FolderRowView(i);this.rowViews[i.get("id")]=h;this.$el.find("#first_folder_item").after(h.el);$(".library-row").hover(function(){$(this).find(".show_on_hover").show()},function(){$(this).find(".show_on_hover").hide()})},removeOne:function(h){this.$el.find("#"+h.id).remove()},checkEmptiness:function(){if((this.$el.find(".dataset_row").length===0)&&(this.$el.find(".folder_row").length===0)){this.$el.find(".empty-folder-message").show()}else{this.$el.find(".empty-folder-message").hide()}},sortColumnClicked:function(h){h.preventDefault();if(this.sort==="asc"){this.sortFolder("name","desc");this.sort="desc"}else{this.sortFolder("name","asc");this.sort="asc"}this.render();this.renderAll();this.checkEmptiness()},sortFolder:function(i,h){if(i==="name"){if(h==="asc"){return this.collection.sortByNameAsc()}else{if(h==="desc"){return this.collection.sortByNameDesc()}}}},selectAll:function(i){var h=i.target.checked;that=this;$(":checkbox","#folder_list_body").each(function(){this.checked=h;$row=$(this.parentElement.parentElement);if(h){that.makeDarkRow($row)}else{that.makeWhiteRow($row)}})},selectClickedRow:function(i){var k="";var h;var j;if(i.target.localName==="input"){k=i.target;h=$(i.target.parentElement.parentElement);j="input"}else{if(i.target.localName==="td"){k=$("#"+i.target.parentElement.id).find(":checkbox")[0];h=$(i.target.parentElement);j="td"}}if(k.checked){if(j==="td"){k.checked="";this.makeWhiteRow(h)}else{if(j==="input"){this.makeDarkRow(h)}}}else{if(j==="td"){k.checked="selected";this.makeDarkRow(h)}else{if(j==="input"){this.makeWhiteRow(h)}}}},makeDarkRow:function(h){h.removeClass("light").addClass("dark");h.find("a").removeClass("light").addClass("dark");h.find(".fa-file-o").removeClass("fa-file-o").addClass("fa-file")},makeWhiteRow:function(h){h.removeClass("dark").addClass("light");h.find("a").removeClass("dark").addClass("light");h.find(".fa-file").removeClass("fa-file").addClass("fa-file-o")},templateFolder:function(){var h=[];h.push('<ol class="breadcrumb">');h.push('   <li><a title="Return to the list of libraries" href="#">Libraries</a></li>');h.push("   <% _.each(path, function(path_item) { %>");h.push("   <% if (path_item[0] != id) { %>");h.push('   <li><a title="Return to this folder" href="#/folders/<%- path_item[0] %>"><%- path_item[1] %></a> </li> ');h.push("<% } else { %>");h.push('   <li class="active"><span title="You are in this folder"><%- path_item[1] %></span></li>');h.push("   <% } %>");h.push("   <% }); %>");h.push("</ol>");h.push('<table data-library-id="<%- parent_library_id  %>" id="folder_table" class="grid table table-condensed">');h.push("   <thead>");h.push('       <th class="button_heading"></th>');h.push('       <th style="text-align: center; width: 20px; " title="Check to select all datasets"><input id="select-all-checkboxes" style="margin: 0;" type="checkbox"></th>');h.push('       <th><a class="sort-folder-link" title="Click to reverse order" href="#">name</a> <span title="Sorted alphabetically" class="fa fa-sort-alpha-<%- order %>"></span></th>');h.push('       <th style="width:5%;">data type</th>');h.push('       <th style="width:10%;">size</th>');h.push('       <th style="width:160px;">time updated (UTC)</th>');h.push('       <th style="width:10%;"></th> ');h.push("   </thead>");h.push('   <tbody id="folder_list_body">');h.push('       <tr id="first_folder_item">');h.push('           <td><a href="#<% if (upper_folder_id !== 0){ print("folders/" + upper_folder_id)} %>" title="Go to parent folder" class="btn_open_folder btn btn-default btn-xs">..<a></td>');h.push("           <td></td>");h.push("           <td></td>");h.push("           <td></td>");h.push("           <td></td>");h.push("           <td></td>");h.push("           <td></td>");h.push("       </tr>");h.push("   </tbody>");h.push("</table>");h.push('<div class="empty-folder-message" style="display:none;">This folder is either empty or you do not have proper access permissions to see the contents. If you expected something to show up please consult the <a href="https://wiki.galaxyproject.org/Admin/DataLibraries/LibrarySecurity" target="_blank">library security wikipage</a> or visit the <a href="https://biostar.usegalaxy.org/" target="_blank">Galaxy support site</a>.</div>');return _.template(h.join(""))}});return{FolderListView:b}});