Skip to content

Commit ad9f924

Browse files
committed
Bug 1162854: hitting back after making an edit should keep edit mode open
1 parent 7810a12 commit ad9f924

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<input type="hidden" name="longdesclength" value="[% bug.comments.size FILTER html %]">
131131
<input type="hidden" name="id" id="bug_id" value="[% bug.bug_id FILTER html %]">
132132
<input type="hidden" name="format" value="modal">
133+
<input type="hidden" name="editing" id="editing" value="">
133134
<input type="hidden" name="token" value="[% issue_hash_token([bug.id, bug.delta_ts]) FILTER html %]">
134135
[% END %]
135136

extensions/BugModal/web/bug_modal.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,25 @@ $(function() {
3939
}
4040

4141
// expand/collapse module
42-
function slide_module(module, action) {
42+
function slide_module(module, action, fast) {
43+
if (!module.attr('id'))
44+
return;
4345
var latch = module.find('.module-latch');
4446
var spinner = $(latch.children('.module-spinner')[0]);
4547
var content = $(module.children('.module-content')[0]);
48+
var duration = fast ? 0 : 200;
4649

4750
function slide_done() {
4851
spinner.html(content.is(':visible') ? '&#9662;' : '&#9656;');
4952
}
5053
if (action == 'show') {
51-
content.slideDown(200, 'swing', slide_done);
54+
content.slideDown(duration, 'swing', slide_done);
5255
}
5356
else if (action == 'hide') {
54-
content.slideUp(200, 'swing', slide_done);
57+
content.slideUp(duration, 'swing', slide_done);
5558
}
5659
else {
57-
content.slideToggle(200, 'swing', slide_done);
60+
content.slideToggle(duration, 'swing', slide_done);
5861
}
5962
}
6063

@@ -289,12 +292,9 @@ $(function() {
289292
$('.edit-hide').hide();
290293
$('.edit-show').show();
291294

292-
// expand specific modules
293-
$('#module-details .module-header').each(function() {
294-
if ($(this.parentNode).find('.module-content:visible').length === 0) {
295-
$(this).click();
296-
}
297-
});
295+
// expand specific modules during the initial edit
296+
if (!$('#editing').val())
297+
slide_module($('#module-details'), 'show');
298298

299299
// if there's no current user-story, it's a better experience if it's editable by default
300300
if ($('#cf_user_story').val() === '') {
@@ -384,6 +384,15 @@ $(function() {
384384
return;
385385
$('.save-btn').attr('disabled', true);
386386
this.form.submit();
387+
388+
// remember expanded modules
389+
$('#editing').val(
390+
$('.module .module-content:visible')
391+
.parent()
392+
.map(function(el) { return $(this).attr('id'); })
393+
.toArray()
394+
.join(' ')
395+
);
387396
})
388397
.attr('disabled', false);
389398

@@ -639,8 +648,11 @@ $(function() {
639648
event.preventDefault();
640649
$('#user-story').hide();
641650
$('#user-story-edit-btn').hide();
642-
$('#cf_user_story').show().focus().select();
643651
$('#top-save-btn').show();
652+
$('#cf_user_story').show();
653+
// don't focus the user-story field when restoring edit mode after navigation
654+
if ($('#editing').val() === '')
655+
$('#cf_user_story').focus().select();
644656
});
645657
$('#user-story-reply-btn')
646658
.click(function(event) {
@@ -1006,6 +1018,20 @@ $(function() {
10061018
dirty.val(that.val() === that.data('preselected')[0] ? '' : '1');
10071019
}
10081020
});
1021+
1022+
// finally switch to edit mode if we navigate back to a page that was editing
1023+
if ($('#editing').val()) {
1024+
$('.module')
1025+
.each(function() {
1026+
slide_module($(this), 'hide', true);
1027+
});
1028+
$($('#editing').val().split(' '))
1029+
.each(function() {
1030+
slide_module($('#' + this), 'show', true);
1031+
});
1032+
$('#mode-btn').click();
1033+
$('#editing').val('');
1034+
}
10091035
});
10101036

10111037
function confirmUnsafeURL(url) {

0 commit comments

Comments
 (0)