2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/67c3ec05a121/ changeset: 67c3ec05a121 user: james_taylor date: 2012-09-17 22:14:52 summary: trackster: misc fixes and reorganization affected #: 3 files diff -r 9deeb2fec6612253de699cc7207ffba09775c88b -r 67c3ec05a12195d30a3fc0ce5247cbc4545027e3 static/scripts/base.js --- a/static/scripts/base.js +++ b/static/scripts/base.js @@ -1,15 +1,15 @@ -define( "libs/backbone", function( backbone ) { +define( ["libs/backbone/backbone"], function( Backbone ) { var Base = function() { if( this.initialize ) { this.initialize.apply(this, arguments); } }; - Base.extend = backbone.Backbone.Model.extend; + Base.extend = Backbone.Model.extend; return { Base: Base, - Backbone: backbone.Backbone + Backbone: Backbone }; }); \ No newline at end of file diff -r 9deeb2fec6612253de699cc7207ffba09775c88b -r 67c3ec05a12195d30a3fc0ce5247cbc4545027e3 static/scripts/viz/trackster_ui.js --- a/static/scripts/viz/trackster_ui.js +++ b/static/scripts/viz/trackster_ui.js @@ -1,4 +1,4 @@ -define( ["libs/underscore","viz/trackster/slotting", "viz/trackster/painters","viz/trackster/tracks"], function( _, slotting, painters, tracks ) { +define( ["base","libs/underscore","viz/trackster/slotting", "viz/trackster/painters","viz/trackster/tracks"], function( base, _, slotting, painters, tracks ) { /************************************************************************ * Functions used for creating and managing the Trackster user interface. @@ -6,139 +6,191 @@ var object_from_template = tracks.object_from_template; -/** - * Add bookmark. - */ -var add_bookmark = function(position, annotation, editable) { - // Create HTML. - var bookmarks_container = $("#bookmarks-container"), - new_bookmark = $("<div/>").addClass("bookmark").appendTo(bookmarks_container); +var TracksterUI = base.Base.extend({ - var position_div = $("<div/>").addClass("position").appendTo(new_bookmark), - position_link = $("<a href=''/>").text(position).appendTo(position_div).click(function() { - view.go_to(position); - return false; - }), - annotation_div = $("<div/>").text(annotation).appendTo(new_bookmark); + initialize: function( baseURL ) { + this.baseURL = baseURL; + }, - // If editable, enable bookmark deletion and annotation editing. - if (editable) { - var delete_icon_container = $("<div/>").addClass("delete-icon-container").prependTo(new_bookmark).click(function (){ - // Remove bookmark. - new_bookmark.slideUp("fast"); - new_bookmark.remove(); - view.has_changes = true; + /** + * Use a popup to select a dataset of create bookmarks from + */ + add_bookmarks: function() { + var baseURL = this.baseURL; + show_modal( "Select dataset for new bookmarks", "progress" ); + $.ajax({ + url: this.baseURL + "/visualization/list_histories", + data: { "f-dbkey": view.dbkey }, + error: function() { alert( "Grid failed" ); }, + success: function(table_html) { + show_modal( + "Select dataset for new bookmarks", + table_html, { + "Cancel": function() { + hide_modal(); + }, + "Insert": function() { + // Just use the first selected + $('input[name=id]:checked,input[name=ldda_ids]:checked').first().each(function(){ + var data, id = $(this).val(); + if ($(this).attr("name") === "id") { + data = { hda_id: id }; + } else { + data = { ldda_id: id}; + } + + $.ajax({ + url: this.baseURL + "/visualization/bookmarks_from_dataset", + data: data, + dataType: "json", + }).then( function(data) { + for( i = 0; i < data.data.length; i++ ) { + var row = data.data[i]; + add_bookmark( row[0], row[1] ); + } + }); + }); + hide_modal(); + } + } + ); + } + }); + }, + + /** + * Add bookmark. + */ + add_bookmark: function(position, annotation, editable) { + // Create HTML. + var bookmarks_container = $("#bookmarks-container"), + new_bookmark = $("<div/>").addClass("bookmark").appendTo(bookmarks_container); + + var position_div = $("<div/>").addClass("position").appendTo(new_bookmark), + position_link = $("<a href=''/>").text(position).appendTo(position_div).click(function() { + view.go_to(position); return false; }), - delete_icon = $("<a href=''/>").addClass("icon-button delete").appendTo(delete_icon_container); - annotation_div.make_text_editable({ - num_rows: 3, - use_textarea: true, - help_text: "Edit bookmark note" - }).addClass("annotation"); + annotation_div = $("<div/>").text(annotation).appendTo(new_bookmark); + + // If editable, enable bookmark deletion and annotation editing. + if (editable) { + var delete_icon_container = $("<div/>").addClass("delete-icon-container").prependTo(new_bookmark).click(function (){ + // Remove bookmark. + new_bookmark.slideUp("fast"); + new_bookmark.remove(); + view.has_changes = true; + return false; + }), + delete_icon = $("<a href=''/>").addClass("icon-button delete").appendTo(delete_icon_container); + annotation_div.make_text_editable({ + num_rows: 3, + use_textarea: true, + help_text: "Edit bookmark note" + }).addClass("annotation"); + } + + view.has_changes = true; + return new_bookmark; + }, + + /** + * Create a complete Trackster visualization. Returns view. + */ + create_visualization: function(view_config, viewport_config, drawables_config, bookmarks_config, editable) { + + // Create view. + view = new tracks.View(view_config); + view.editor = true; + $.when( view.load_chroms_deferred ).then(function() { + // Viewport config. + if (viewport_config) { + var + chrom = viewport_config.chrom, + start = viewport_config.start, + end = viewport_config.end, + overview_drawable_name = viewport_config.overview; + + if (chrom && (start !== undefined) && end) { + view.change_chrom(chrom, start, end); + } + } + + // Add drawables to view. + if (drawables_config) { + // FIXME: can from_dict() be used to create view and add drawables? + var drawable_config, + drawable_type, + drawable; + for (var i = 0; i < drawables_config.length; i++) { + view.add_drawable( object_from_template( drawables_config[i], view, view ) ); + } + } + + // Need to update intro div after drawables have been added. + view.update_intro_div(); + + // Set overview. + var overview_drawable; + for (var i = 0; i < view.drawables.length; i++) { + if (view.drawables[i].name === overview_drawable_name) { + view.set_overview(view.drawables[i]); + break; + } + } + + // Load bookmarks. + if (bookmarks_config) { + var bookmark; + for (var i = 0; i < bookmarks_config.length; i++) { + bookmark = bookmarks_config[i]; + add_bookmark(bookmark['position'], bookmark['annotation'], editable); + } + } + + // View has no changes as of yet. + view.has_changes = false; + }); + + return view; + }, + + /** + * Set up keyboard navigation for a visualization. + */ + init_keyboard_nav: function(view) { + // Keyboard navigation. Scroll ~7% of height when scrolling up/down. + $(document).keydown(function(e) { + // Do not navigate if arrow keys used in input element. + if ($(e.srcElement).is(':input')) { + return; + } + + // Key codes: left == 37, up == 38, right == 39, down == 40 + switch(e.which) { + case 37: + view.move_fraction(0.25); + break + case 38: + var change = Math.round(view.viewport_container.height()/15.0); + view.viewport_container.scrollTop( view.viewport_container.scrollTop() - 20); + break; + case 39: + view.move_fraction(-0.25); + break; + case 40: + var change = Math.round(view.viewport_container.height()/15.0); + view.viewport_container.scrollTop( view.viewport_container.scrollTop() + 20); + break; + } + }); } - view.has_changes = true; - return new_bookmark; -}; - -/** - * Create a complete Trackster visualization. Returns view. - */ -var create_visualization = function(view_config, viewport_config, drawables_config, bookmarks_config, editable) { - - // Create view. - view = new tracks.View(view_config); - view.editor = true; - $.when( view.load_chroms_deferred ).then(function() { - // Viewport config. - if (viewport_config) { - var - chrom = viewport_config.chrom, - start = viewport_config.start, - end = viewport_config.end, - overview_drawable_name = viewport_config.overview; - - if (chrom && (start !== undefined) && end) { - view.change_chrom(chrom, start, end); - } - } - - // Add drawables to view. - if (drawables_config) { - // FIXME: can from_dict() be used to create view and add drawables? - var drawable_config, - drawable_type, - drawable; - for (var i = 0; i < drawables_config.length; i++) { - view.add_drawable( object_from_template( drawables_config[i], view, view ) ); - } - } - - // Need to update intro div after drawables have been added. - view.update_intro_div(); - - // Set overview. - var overview_drawable; - for (var i = 0; i < view.drawables.length; i++) { - if (view.drawables[i].name === overview_drawable_name) { - view.set_overview(view.drawables[i]); - break; - } - } - - // Load bookmarks. - if (bookmarks_config) { - var bookmark; - for (var i = 0; i < bookmarks_config.length; i++) { - bookmark = bookmarks_config[i]; - add_bookmark(bookmark['position'], bookmark['annotation'], editable); - } - } - - // View has no changes as of yet. - view.has_changes = false; - }); - - return view; -}; - -/** - * Set up keyboard navigation for a visualization. - */ - var init_keyboard_nav = function(view) { - // Keyboard navigation. Scroll ~7% of height when scrolling up/down. - $(document).keydown(function(e) { - // Do not navigate if arrow keys used in input element. - if ($(e.srcElement).is(':input')) { - return; - } - - // Key codes: left == 37, up == 38, right == 39, down == 40 - switch(e.which) { - case 37: - view.move_fraction(0.25); - break - case 38: - var change = Math.round(view.viewport_container.height()/15.0); - view.viewport_container.scrollTop( view.viewport_container.scrollTop() - 20); - break; - case 39: - view.move_fraction(-0.25); - break; - case 40: - var change = Math.round(view.viewport_container.height()/15.0); - view.viewport_container.scrollTop( view.viewport_container.scrollTop() + 20); - break; - } - }); -}; +}); return { - add_bookmark: add_bookmark, object_from_template: object_from_template, - create_visualization: create_visualization, - init_keyboard_nav: init_keyboard_nav + TracksterUI: TracksterUI }; }); diff -r 9deeb2fec6612253de699cc7207ffba09775c88b -r 67c3ec05a12195d30a3fc0ce5247cbc4545027e3 templates/tracks/browser.mako --- a/templates/tracks/browser.mako +++ b/templates/tracks/browser.mako @@ -31,12 +31,11 @@ require.config({ baseUrl: "${h.url_for('/static/scripts') }", shim: { - "libs/underscore": { exports: "_" } + "libs/underscore": { exports: "_" }, + "libs/backbone/backbone": { exports: "Backbone" } } }); - require( ["viz/trackster_ui","viz/trackster/util","viz/trackster/tracks"], function( trackster_ui, util, tracks ) { - - var add_bookmark = trackster_ui.add_bookmark + require( ["base", "viz/trackster_ui","viz/trackster/util","viz/trackster/tracks"], function( base, trackster_ui, util, tracks ) { // // Place URLs here so that url_for can be used to generate them. @@ -48,8 +47,9 @@ ${render_trackster_js_vars()} var view, - browser_router; - + browser_router, + ui = new (trackster_ui.TracksterUI)( "${h.url_for('/')}" ); + /** * Set up router. */ @@ -58,51 +58,7 @@ Backbone.history.start(); }; - /** - * Use a popup grid to bookmarks from a dataset. - */ - var add_bookmarks = function() { - show_modal( "Select dataset for new bookmarks", "progress" ); - $.ajax({ - url: "${h.url_for( controller='visualization', action='list_histories' )}", - data: { "f-dbkey": view.dbkey }, - error: function() { alert( "Grid failed" ); }, - success: function(table_html) { - show_modal( - "Select dataset for new bookmarks", - table_html, { - "Cancel": function() { - hide_modal(); - }, - "Insert": function() { - // Just use the first selected - $('input[name=id]:checked,input[name=ldda_ids]:checked').first().each(function(){ - var data, id = $(this).val(); - if ($(this).attr("name") === "id") { - data = { hda_id: id }; - } else { - data = { ldda_id: id}; - } - $.ajax({ - url: "${h.url_for( action='bookmarks_from_dataset' )}", - data: data, - dataType: "json", - }).then( function(data) { - for( i = 0; i < data.data.length; i++ ) { - var row = data.data[i]; - add_bookmark( row[0], row[1] ); - } - }); - }); - hide_modal(); - } - } - ); - } - }); - }; - var browser_router; $(function() { // Create and initialize menu. @@ -192,7 +148,7 @@ $("#right-border").click(function() { view.resize_window(); }); %if config: - view = trackster_ui.create_visualization( { + view = ui.create_visualization( { container: $("#browser-container"), name: "${config.get('title') | h}", vis_id: "${config.get('vis_id')}", @@ -262,7 +218,7 @@ // Add new bookmark. var position = view.chrom + ":" + view.low + "-" + view.high, annotation = "Bookmark description"; - return add_bookmark(position, annotation, true); + return ui.add_bookmark(position, annotation, true); }); // make_popupmenu( $("#bookmarks-more-button"), { @@ -271,7 +227,7 @@ // } // }); - trackster_ui.init_keyboard_nav(view); + ui.init_keyboard_nav(view); }; }); https://bitbucket.org/galaxy/galaxy-central/changeset/6c0bb542d2e0/ changeset: 6c0bb542d2e0 user: james_taylor date: 2012-09-17 22:15:09 summary: pack scripts affected #: 2 files diff -r 67c3ec05a12195d30a3fc0ce5247cbc4545027e3 -r 6c0bb542d2e0cbda209e473db9d77a7076614f0d static/scripts/packed/base.js --- a/static/scripts/packed/base.js +++ b/static/scripts/packed/base.js @@ -1,1 +1,1 @@ -define("libs/backbone",function(b){var a=function(){if(this.initialize){this.initialize.apply(this,arguments)}};a.extend=b.Backbone.Model.extend;return{Base:a,Backbone:b.Backbone}}); \ No newline at end of file +define(["libs/backbone/backbone"],function(b){var a=function(){if(this.initialize){this.initialize.apply(this,arguments)}};a.extend=b.Model.extend;return{Base:a,Backbone:b}}); \ No newline at end of file diff -r 67c3ec05a12195d30a3fc0ce5247cbc4545027e3 -r 6c0bb542d2e0cbda209e473db9d77a7076614f0d static/scripts/packed/viz/trackster_ui.js --- a/static/scripts/packed/viz/trackster_ui.js +++ b/static/scripts/packed/viz/trackster_ui.js @@ -1,1 +1,1 @@ -define(["libs/underscore","viz/trackster/slotting","viz/trackster/painters","viz/trackster/tracks"],function(d,h,g,c){var a=c.object_from_template;var f=function(m,k,i){var o=$("#bookmarks-container"),q=$("<div/>").addClass("bookmark").appendTo(o);var r=$("<div/>").addClass("position").appendTo(q),n=$("<a href=''/>").text(m).appendTo(r).click(function(){view.go_to(m);return false}),l=$("<div/>").text(k).appendTo(q);if(i){var p=$("<div/>").addClass("delete-icon-container").prependTo(q).click(function(){q.slideUp("fast");q.remove();view.has_changes=true;return false}),j=$("<a href=''/>").addClass("icon-button delete").appendTo(p);l.make_text_editable({num_rows:3,use_textarea:true,help_text:"Edit bookmark note"}).addClass("annotation")}view.has_changes=true;return q};var b=function(l,i,k,m,j){view=new c.View(l);view.editor=true;$.when(view.load_chroms_deferred).then(function(){if(i){var v=i.chrom,n=i.start,s=i.end,p=i.overview;if(v&&(n!==undefined)&&s){view.change_chrom(v,n,s)}}if(k){var q,o,r;for(var t=0;t<k.length;t++){view.add_drawable(a(k[t],view,view))}}view.update_intro_div();var w;for(var t=0;t<view.drawables.length;t++){if(view.drawables[t].name===p){view.set_overview(view.drawables[t]);break}}if(m){var u;for(var t=0;t<m.length;t++){u=m[t];f(u.position,u.annotation,j)}}view.has_changes=false});return view};var e=function(i){$(document).keydown(function(j){if($(j.srcElement).is(":input")){return}switch(j.which){case 37:i.move_fraction(0.25);break;case 38:var k=Math.round(i.viewport_container.height()/15);i.viewport_container.scrollTop(i.viewport_container.scrollTop()-20);break;case 39:i.move_fraction(-0.25);break;case 40:var k=Math.round(i.viewport_container.height()/15);i.viewport_container.scrollTop(i.viewport_container.scrollTop()+20);break}})};return{add_bookmark:f,object_from_template:a,create_visualization:b,init_keyboard_nav:e}}); \ No newline at end of file +define(["base","libs/underscore","viz/trackster/slotting","viz/trackster/painters","viz/trackster/tracks"],function(f,c,g,d,b){var a=b.object_from_template;var e=f.Base.extend({initialize:function(h){this.baseURL=h},add_bookmarks:function(){var h=this.baseURL;show_modal("Select dataset for new bookmarks","progress");$.ajax({url:this.baseURL+"/visualization/list_histories",data:{"f-dbkey":view.dbkey},error:function(){alert("Grid failed")},success:function(j){show_modal("Select dataset for new bookmarks",j,{Cancel:function(){hide_modal()},Insert:function(){$("input[name=id]:checked,input[name=ldda_ids]:checked").first().each(function(){var k,l=$(this).val();if($(this).attr("name")==="id"){k={hda_id:l}}else{k={ldda_id:l}}$.ajax({url:this.baseURL+"/visualization/bookmarks_from_dataset",data:k,dataType:"json",}).then(function(m){for(i=0;i<m.data.length;i++){var n=m.data[i];add_bookmark(n[0],n[1])}})});hide_modal()}})}})},add_bookmark:function(m,k,h){var o=$("#bookmarks-container"),q=$("<div/>").addClass("bookmark").appendTo(o);var r=$("<div/>").addClass("position").appendTo(q),n=$("<a href=''/>").text(m).appendTo(r).click(function(){view.go_to(m);return false}),l=$("<div/>").text(k).appendTo(q);if(h){var p=$("<div/>").addClass("delete-icon-container").prependTo(q).click(function(){q.slideUp("fast");q.remove();view.has_changes=true;return false}),j=$("<a href=''/>").addClass("icon-button delete").appendTo(p);l.make_text_editable({num_rows:3,use_textarea:true,help_text:"Edit bookmark note"}).addClass("annotation")}view.has_changes=true;return q},create_visualization:function(l,h,k,m,j){view=new b.View(l);view.editor=true;$.when(view.load_chroms_deferred).then(function(){if(h){var v=h.chrom,n=h.start,s=h.end,p=h.overview;if(v&&(n!==undefined)&&s){view.change_chrom(v,n,s)}}if(k){var q,o,r;for(var t=0;t<k.length;t++){view.add_drawable(a(k[t],view,view))}}view.update_intro_div();var w;for(var t=0;t<view.drawables.length;t++){if(view.drawables[t].name===p){view.set_overview(view.drawables[t]);break}}if(m){var u;for(var t=0;t<m.length;t++){u=m[t];add_bookmark(u.position,u.annotation,j)}}view.has_changes=false});return view},init_keyboard_nav:function(h){$(document).keydown(function(j){if($(j.srcElement).is(":input")){return}switch(j.which){case 37:h.move_fraction(0.25);break;case 38:var k=Math.round(h.viewport_container.height()/15);h.viewport_container.scrollTop(h.viewport_container.scrollTop()-20);break;case 39:h.move_fraction(-0.25);break;case 40:var k=Math.round(h.viewport_container.height()/15);h.viewport_container.scrollTop(h.viewport_container.scrollTop()+20);break}})}});return{object_from_template:a,TracksterUI:e}}); \ No newline at end of file Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.