This repository has been archived by the owner on Mar 19, 2020. It is now read-only.
forked from mozilla/elmo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
signoffs.js
172 lines (158 loc) · 4.7 KB
/
signoffs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var dropMode = null;
function dropDiff(event, ui) {
$(this).append(ui.draggable);
ui.draggable.css('top', 0);
}
$(document).ready(function() {
$('.diffanchor').draggable({
appendTo: 'body',
axis: 'y',
revert: true,
start: function(event, ui) {
if (dropMode != 'diff') {
$('.ui-droppable').droppable('destroy');
$('.diff').droppable({
drop: dropDiff
});
dropMode = 'diff';
}
}
});
$('.diff').click(function(event) {
event.stopPropagation();
var dfs = $('.diffanchor').parent().prev().find('.shortrev');
if (dfs.length < 2 || dfs[0].textContent == dfs[1].textContent) return;
var params = {
from: dfs[1].textContent,
to: dfs[0].textContent,
repo: $(dfs[0]).data('repo')
};
params = $.param(params);
window.open(diffData.url + "?" + params);
});
function hoverSO(showOrHide) {
return function() {
var q = $('input[data-push=' + this.getAttribute('data-push') + ']')
.not('.suggested')
.not('.clicked');
if (showOrHide === 'hide') {
q.addClass('hidden');
} else {
q.removeClass('hidden');
}
};
}
$('.pushrow').hover(hoverSO('show'), hoverSO('hide'))
.click(function() {
var self = $(this);
var so = $('input[data-push=' + this.getAttribute('data-push') + ']')
.not('.suggested');
if (! so.length) { return; }
var wasClicked = so.hasClass('clicked');
so.toggleClass('clicked');
// XXXX, guess what touch would do
if (wasClicked != so.hasClass('hidden')) {
so.toggleClass('hidden');
}
});
if (permissions && permissions.canAddSignoff) {
$('input.do_signoff').click(doSignoff);
$('#add_signoff').dialog({
autoOpen: false,
width: 600,
minWidth: 300,
title: 'Sign-off'
});
$('#cancel_signoff').dialog({
autoOpen: false,
width: 600,
minWidth: 300,
title: 'Cancel'
});
$('.cancel_signoff').click(function(event) {
var signoff_id = $(this).data('signoff');
var rs = $('#cancel_signoff');
$('input[name="signoff_id"]', rs).val(signoff_id);
rs.dialog('open');
return false;
});
$('#reopen_signoff').dialog({
autoOpen: false,
width: 600,
minWidth: 300,
title: 'Re-open'
});
$('.reopen_signoff').click(function(event) {
var signoff_id = $(this).data('signoff');
var rs = $('#reopen_signoff');
$('input[name="signoff_id"]', rs).val(signoff_id);
rs.dialog('open');
return false;
});
}
if (permissions && permissions.canReviewSignoff) {
$('#review_signoff').dialog({
autoOpen: false,
width: 600,
minWidth: 300,
title: 'Review'
});
$('.review_action').click(function(event) {
var signoff_id = event.target.getAttribute('data-signoff');
var rs = $('#review_signoff');
rs.children('form')[0].signoff_id.value = signoff_id;
rs.dialog('open');
});
}
$('a.load-more').click(function() {
var this_row = $(this).parents('tr');
var min_push_date;
$('tr.pushrow').each(function(i, each) {
if ($(each).data('push_date')) {
min_push_date = $(each).data('push_date');
}
});
var url = location.pathname;
//console.log('URL', url);
console.log('min_push_date', min_push_date);
console.log('# rows before', $('tr.pushrow').length);
var req = $.get(url + '/more/', {push_date: min_push_date});
req.then(function(html) {
$(html).insertBefore(this_row);
console.log('# rows after', $('tr.pushrow').length);
});
return false;
});
});
var Review = {
accept: function(event) {
var frm = event.target.form;
frm.querySelector('[type=submit]').disabled = false;
frm.comment.disabled = true;
frm.clear_old.disabled = true;
},
reject: function(event) {
var frm = event.target.form;
frm.querySelector('[type=submit]').disabled = false;
frm.comment.disabled = false;
frm.clear_old.disabled = false;
frm.comment.focus();
}
};
function showSignoff(details_content) {
$('#signoff_desc').html(details_content);
$('#add_signoff').dialog('open');
}
function doSignoff(event) {
event.stopPropagation();
var t = $(event.target);
var push = t.attr('data-push');
var sf = $('#signoff_form');
sf.children('[name=push]').val(push);
var run = t.attr('data-run');
sf.children('[name=run]').val(run);
$.get(signoffDetailsURL, {push: push, run: run}, showSignoff, 'html');
}