define(["galaxy.masthead","mvc/ui/ui-frames"],function(b,c){var a=Backbone.View.extend({el_main:"body",active:false,button_active:null,button_load:null,initialize:function(e){var d=this;this.frames=new c.View({visible:false,});this.button_active=new b.GalaxyMastheadIcon({icon:"fa-th",tooltip:"Enable/Disable Scratchbook",onclick:function(){d._activate()},onunload:function(){if(d.frames.length()>0){return"You opened "+d.frames.length()+" frame(s) which will be lost."}}});Galaxy.masthead.append(this.button_active);this.button_load=new b.GalaxyMastheadIcon({icon:"fa-eye",tooltip:"Show/Hide Scratchbook",onclick:function(f){if(d.frames.visible){d.frames.hide()}else{d.frames.show()}},with_number:true});Galaxy.masthead.append(this.button_load);this.setElement(this.frames.$el);$(this.el_main).append(this.$el);this.frames.setOnChange(function(){d._refresh()});this._refresh()},add_dataset:function(d){var e=this;require(["mvc/data"],function(f){var g=new f.Dataset({id:d});$.when(g.fetch()).then(function(){var h={title:g.get("name")},j=_.find(["tabular","interval"],function(k){return g.get("data_type").indexOf(k)!==-1});if(j){var i=new f.TabularDataset(g.toJSON());_.extend(h,{type:"other",content:function(k){f.createTabularDatasetChunkedView({model:i,parent_elt:k,embedded:true,height:"100%"})}})}else{_.extend(h,{type:"url",content:galaxy_config.root+"datasets/"+g.id+"/display/?preview=True"})}e.add(h)})})},add_trackster_viz:function(e){var d=this;require(["viz/visualization","viz/trackster"],function(g,h){var f=new g.Visualization({id:e});$.when(f.fetch()).then(function(){var j=new h.TracksterUI(galaxy_config.root);var i={title:f.get("name"),type:"other",content:function(l){var n={container:l,name:f.get("title"),id:f.id,dbkey:f.get("dbkey"),stand_alone:false},m=f.get("latest_revision"),k=m.config.view.drawables;_.each(k,function(o){o.dataset={hda_ldda:o.hda_ldda,id:o.dataset_id}});view=j.create_visualization(n,m.config.viewport,m.config.view.drawables,m.config.bookmarks,false)}};d.add(i)})})},add:function(e){if(e.target=="_blank"){window.open(e.content);return}if(e.target=="_top"||e.target=="_parent"||e.target=="_self"){window.location=e.content;return}if(!this.active){var f=$(window.parent.document).find("#galaxy_main");if(e.target=="galaxy_main"||e.target=="center"){if(f.length===0){var d=e.content;if(d.indexOf("?")==-1){d+="?"}else{d+="&"}d+="use_panels=True";window.location=d}else{f.attr("src",e.content)}}else{window.location=e.content}return}this.frames.add(e)},_activate:function(){if(this.active){this.active=false;this.button_active.untoggle();this.frames.hide()}else{this.active=true;this.button_active.toggle()}},_refresh:function(){this.button_load.number(this.frames.length());if(this.frames.length()===0){this.button_load.hide()}else{this.button_load.show()}if(this.frames.visible){this.button_load.toggle()}else{this.button_load.untoggle()}}});return{GalaxyFrame:a}});