From ad9f924253079bdd95721dcede870eae4c07dc61 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 27 May 2015 12:18:43 +0800 Subject: Bug 1162854: hitting back after making an edit should keep edit mode open --- .../template/en/default/bug_modal/edit.html.tmpl | 1 + extensions/BugModal/web/bug_modal.js | 48 +++++++++++++++++----- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl index 67c94f499..ba3973bcf 100644 --- a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl @@ -130,6 +130,7 @@ + [% END %] diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js index 32949828f..4c4d83ad8 100644 --- a/extensions/BugModal/web/bug_modal.js +++ b/extensions/BugModal/web/bug_modal.js @@ -39,22 +39,25 @@ $(function() { } // expand/collapse module - function slide_module(module, action) { + function slide_module(module, action, fast) { + if (!module.attr('id')) + return; var latch = module.find('.module-latch'); var spinner = $(latch.children('.module-spinner')[0]); var content = $(module.children('.module-content')[0]); + var duration = fast ? 0 : 200; function slide_done() { spinner.html(content.is(':visible') ? '▾' : '▸'); } if (action == 'show') { - content.slideDown(200, 'swing', slide_done); + content.slideDown(duration, 'swing', slide_done); } else if (action == 'hide') { - content.slideUp(200, 'swing', slide_done); + content.slideUp(duration, 'swing', slide_done); } else { - content.slideToggle(200, 'swing', slide_done); + content.slideToggle(duration, 'swing', slide_done); } } @@ -289,12 +292,9 @@ $(function() { $('.edit-hide').hide(); $('.edit-show').show(); - // expand specific modules - $('#module-details .module-header').each(function() { - if ($(this.parentNode).find('.module-content:visible').length === 0) { - $(this).click(); - } - }); + // expand specific modules during the initial edit + if (!$('#editing').val()) + slide_module($('#module-details'), 'show'); // if there's no current user-story, it's a better experience if it's editable by default if ($('#cf_user_story').val() === '') { @@ -384,6 +384,15 @@ $(function() { return; $('.save-btn').attr('disabled', true); this.form.submit(); + + // remember expanded modules + $('#editing').val( + $('.module .module-content:visible') + .parent() + .map(function(el) { return $(this).attr('id'); }) + .toArray() + .join(' ') + ); }) .attr('disabled', false); @@ -639,8 +648,11 @@ $(function() { event.preventDefault(); $('#user-story').hide(); $('#user-story-edit-btn').hide(); - $('#cf_user_story').show().focus().select(); $('#top-save-btn').show(); + $('#cf_user_story').show(); + // don't focus the user-story field when restoring edit mode after navigation + if ($('#editing').val() === '') + $('#cf_user_story').focus().select(); }); $('#user-story-reply-btn') .click(function(event) { @@ -1006,6 +1018,20 @@ $(function() { dirty.val(that.val() === that.data('preselected')[0] ? '' : '1'); } }); + + // finally switch to edit mode if we navigate back to a page that was editing + if ($('#editing').val()) { + $('.module') + .each(function() { + slide_module($(this), 'hide', true); + }); + $($('#editing').val().split(' ')) + .each(function() { + slide_module($('#' + this), 'show', true); + }); + $('#mode-btn').click(); + $('#editing').val(''); + } }); function confirmUnsafeURL(url) { -- cgit v1.2.3-24-g4f1b