commit/galaxy-central: 4 new changesets
4 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/518d296e4ed8/ Changeset: 518d296e4ed8 User: jgoecks Date: 2014-07-15 17:07:41 Summary: Trackster: readd long lost code to detect unsaved changes and prompt to save on exit. Affected #: 1 file diff -r 7c5d92187dfd5b92fd05e0fcab163a8a0ef89ffa -r 518d296e4ed8646b9e738e5293dab9f77834bf17 static/scripts/viz/trackster_ui.js --- a/static/scripts/viz/trackster_ui.js +++ b/static/scripts/viz/trackster_ui.js @@ -35,9 +35,62 @@ }, /** + * Save visualization, returning a Deferred object for the remote call to save. + */ + save_viz: function() { + // show dialog + Galaxy.modal.show({title: "Saving...", body: "progress" }); + + // Save bookmarks. + var bookmarks = []; + $(".bookmark").each(function() { + bookmarks.push({ + position: $(this).children(".position").text(), + annotation: $(this).children(".annotation").text() + }); + }); + + // FIXME: give unique IDs to Drawables and save overview as ID. + var overview_track_name = (view.overview_drawable ? view.overview_drawable.config.get_value('name') : null), + viz_config = { + 'view': view.to_dict(), + 'viewport': { 'chrom': view.chrom, 'start': view.low , 'end': view.high, 'overview': overview_track_name }, + 'bookmarks': bookmarks + }; + + // Make call to save visualization. + return $.ajax({ + url: galaxy_config.root + "visualization/save", + type: "POST", + dataType: "json", + data: { + 'id' : view.vis_id, + 'title' : view.config.get_value('name'), + 'dbkey' : view.dbkey, + 'type' : 'trackster', + 'vis_json' : JSON.stringify(viz_config) + } + }).success(function(vis_info) { + Galaxy.modal.hide(); + view.vis_id = vis_info.vis_id; + view.has_changes = false; + + // Needed to set URL when first saving a visualization. + window.history.pushState({}, "", vis_info.url + window.location.hash); + }).error(function() { + // show dialog + Galaxy.modal.show({ + title : "Could Not Save", + body : "Could not save visualization. Please try again later.", + buttons : { "Cancel": function() { Galaxy.modal.hide(); } } + }); + }); + }, + + /** * Create button menu */ - createButtonMenu: function() { + createButtonMenu: function() { var self = this, menu = create_icon_buttons_menu([ { icon_class: 'plus-button', title: 'Add tracks', on_click: function() { @@ -62,58 +115,13 @@ } }, { icon_class: 'disk--arrow', title: 'Save', on_click: function() { - // show dialog - Galaxy.modal.show({title: "Saving...", body: "progress" }); - - // Save bookmarks. - var bookmarks = []; - $(".bookmark").each(function() { - bookmarks.push({ - position: $(this).children(".position").text(), - annotation: $(this).children(".annotation").text() - }); - }); - - // FIXME: give unique IDs to Drawables and save overview as ID. - var overview_track_name = (view.overview_drawable ? view.overview_drawable.config.get_value('name') : null), - viz_config = { - 'view': view.to_dict(), - 'viewport': { 'chrom': view.chrom, 'start': view.low , 'end': view.high, 'overview': overview_track_name }, - 'bookmarks': bookmarks - }; - - $.ajax({ - url: galaxy_config.root + "visualization/save", - type: "POST", - dataType: "json", - data: { - 'id' : view.vis_id, - 'title' : view.config.get_value('name'), - 'dbkey' : view.dbkey, - 'type' : 'trackster', - 'vis_json' : JSON.stringify(viz_config) - } - }).success(function(vis_info) { - Galaxy.modal.hide(); - view.vis_id = vis_info.vis_id; - view.has_changes = false; - - // Needed to set URL when first saving a visualization. - window.history.pushState({}, "", vis_info.url + window.location.hash); - }).error(function() { - // show dialog - Galaxy.modal.show({ - title : "Could Not Save", - body : "Could not save visualization. Please try again later.", - buttons : { "Cancel": function() { Galaxy.modal.hide() } } - }); - }); + self.save_viz(); } }, { icon_class: 'cross-circle', title: 'Close', on_click: function() { - window.location = galaxy_config.root + 'visualization'; + self.handle_unsaved_changes(view); } } ], @@ -302,7 +310,7 @@ /** * Set up keyboard navigation for a visualization. */ - init_keyboard_nav: function(view) { + init_keyboard_nav: function(view) { // Keyboard navigation. Scroll ~7% of height when scrolling up/down. $(document).keyup(function(e) { // Do not navigate if arrow keys used in input element. @@ -328,6 +336,35 @@ break; } }); + }, + + /** + * Handle unsaved changes in visualization. + */ + handle_unsaved_changes: function(view) { + if (view.has_changes) { + var self = this; + Galaxy.modal.show({ + title: "Close visualization", + body: "There are unsaved changes to your visualization which will be lost if you do not save them.", + buttons: { + "Cancel": function() { Galaxy.modal.hide(); }, + "Leave without Saving" : function() { + window.onbeforeunload = undefined; + window.location = galaxy_config.root + 'visualization'; + }, + "Save" : function() { + $.when(self.save_viz()).then(function() { + window.location = galaxy_config.root + 'visualization'; + }); + } + } + }); + + } + else { + window.location = galaxy_config.root + 'visualization'; + } } }); https://bitbucket.org/galaxy/galaxy-central/commits/08a1e9d70ebc/ Changeset: 08a1e9d70ebc User: jgoecks Date: 2014-07-15 18:19:47 Summary: Trackster: add dialog to indicate changes will be lost if navigating away from the viz. Affected #: 1 file diff -r 518d296e4ed8646b9e738e5293dab9f77834bf17 -r 08a1e9d70ebcf08bd8ec850e678a6a5a79cf9f5f static/scripts/viz/trackster.js --- a/static/scripts/viz/trackster.js +++ b/static/scripts/viz/trackster.js @@ -211,6 +211,10 @@ // initialize keyboard ui.init_keyboard_nav(view); + + $(window).on('beforeunload', function() { + return "There are unsaved changes to your visualization that will be lost if you leave this page."; + }); } }); https://bitbucket.org/galaxy/galaxy-central/commits/a34d766b17c7/ Changeset: a34d766b17c7 User: jgoecks Date: 2014-07-15 18:33:54 Summary: Trackster: bug fixes for managing state. Affected #: 2 files diff -r 08a1e9d70ebcf08bd8ec850e678a6a5a79cf9f5f -r a34d766b17c7f3a7e6683e6b2d7aa6cb2a3b7215 static/scripts/viz/trackster.js --- a/static/scripts/viz/trackster.js +++ b/static/scripts/viz/trackster.js @@ -213,7 +213,9 @@ ui.init_keyboard_nav(view); $(window).on('beforeunload', function() { - return "There are unsaved changes to your visualization that will be lost if you leave this page."; + if (view.has_changes) { + return "There are unsaved changes to your visualization that will be lost if you leave this page."; + } }); } }); diff -r 08a1e9d70ebcf08bd8ec850e678a6a5a79cf9f5f -r a34d766b17c7f3a7e6683e6b2d7aa6cb2a3b7215 static/scripts/viz/trackster_ui.js --- a/static/scripts/viz/trackster_ui.js +++ b/static/scripts/viz/trackster_ui.js @@ -267,9 +267,6 @@ } } - // 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++) { https://bitbucket.org/galaxy/galaxy-central/commits/893a727a7b7c/ Changeset: 893a727a7b7c User: jgoecks Date: 2014-07-15 18:41:06 Summary: Trackster: mark visualization changed when tracks change. Affected #: 1 file diff -r a34d766b17c7f3a7e6683e6b2d7aa6cb2a3b7215 -r 893a727a7b7cc83355bc977d034622da50af16e5 static/scripts/viz/trackster/tracks.js --- a/static/scripts/viz/trackster/tracks.js +++ b/static/scripts/viz/trackster/tracks.js @@ -1380,6 +1380,14 @@ drawable.init(); this.changed(); this.update_intro_div(); + + // When drawable config changes, mark view as changed. This + // captures most (all?) state change that needs to be saved. + var self = this; + drawable.config.on('change', function() { + console.log(drawable.config.get_value('name') + " changed"); + self.changed(); + }); }, add_label_track: function (label_track) { 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.
participants (1)
-
commits-noreply@bitbucket.org