forked from ljay79/jira-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialogIssuesFromFilter.html
148 lines (120 loc) · 5.65 KB
/
dialogIssuesFromFilter.html
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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<style>
.error-container { display: none; margin-bottom: 16px; padding: 5px 10px; text-align: center; color: #fff; }
.filter-select { border: 1px solid #dfdfdf; height: 224px; overflow-y: auto; line-height: 28px; }
.filter-select > div { padding-left: 3px; padding-right: 24px; }
.filter-select > div:nth-child(even) { background: #f7f8f9; }
.is-loading { text-align: center; animation: blink .5s infinite; }
@keyframes blink { 0% { color: #fff; } 50% { color: #777; } 100% { color: #fff; } }
.is-favourite label { font-weight: bold; }
.filter-cols { display: flex; flex-direction: row; flex-wrap: wrap; align-items: left; justify-content: left; }
.filter-cols .label { flex: 0 0 100%; font-weight: bold; }
.filter-cols .item { position: relative; flex: 0 0 25%; padding-left: 20px; box-sizing: border-box; }
.filter-cols .item input[type="checkbox"] { position: absolute; }
</style>
</head>
<body>
<div id="response-message" class="error-container" role="dialog"></div>
<form name="issue-filter" action="" method="post">
<input type="hidden" name="filter_id" id="filter-id" value="" />
<div class="block filter-select is-loading">loading filters ...</div>
<div class="block filter-cols">
<label class="label">Columns</label>
<? for (var id in columns) { ?>
<div class="item">
<input type="checkbox" id="column-<?= id ?>" name="columns[]" value="<?= id ?>"<? if (defaultColumns.indexOf(id) > -1) { ?> checked="checked"<? } ?>>
<label for="column-<?= id ?>"><?= columns[id] ?></label>
</div>
<? } ?>
</div>
<div class="block">
<button type="submit" class="action" disabled>Insert</button>
<button type="button" onclick="google.script.host.close()">Cancel</button>
</div>
</form>
<script>
var filter = document.forms['issue-filter'];
var valid = false;
var timeout = null;
var alert = document.getElementById('response-message');
var input = Array.prototype.slice.call(filter.elements).filter(function(el){ return el.nodeName === 'INPUT'; });
var columns = input.filter(function(el){ return el.type === 'checkbox'; });
var action = filter.querySelector('[type=submit]');
var filters = [];
function hideAlert(){
if(timeout) timeout = clearTimeout(timeout);
alert.style.display = 'none';
}
function showAlert(text,type,time) {
alert.innerText = text;
alert.style.backgroundColor = type ? 'rgb(139,195,74)' : 'rgb(213,0,0)';
alert.style.display = 'block';
if (time) timeout = setTimeout(hideAlert,time);
}
function inputValidatyHandler() {
if (this.name === 'filter' && this.checked) filter.elements['filter_id'].value = this.value;
valid = columns.filter(function(el){ return el.checked; }).length > 0 && filter.elements['filter_id'].value.length > 0;
action.disabled = valid ? false : 'disabled';
}
function onInitFilter(response) {
var filterSelect = filter.querySelector('.filter-select');
filterSelect.innerText = '';
filterSelect.classList.remove('is-loading');
if (!response.length) {
showAlert('No filters available!')
return;
}
response.forEach(function(option) {
var radio = document.createElement('div');
var radioInput = document.createElement('input');
var radioLabel = document.createElement('label');
radioInput.setAttribute('type', 'radio');
radioInput.setAttribute('name', 'filter');
radioInput.setAttribute('id', 'filter-id-'+option.id);
radioInput.setAttribute('value', option.id);
radioLabel.setAttribute('for', 'filter-id-'+option.id);
radioLabel.innerText = option.name + ' ('+option.owner+')';
if (option.favourite) radio.className = 'is-favourite';
radio.appendChild(radioInput);
radio.appendChild(radioLabel);
radioInput.addEventListener('change', inputValidatyHandler);
filters.push(radioInput);
filterSelect.appendChild(radio);
});
filters[0].checked = true;
filter.elements['filter_id'].value = filters[0].value;
window.dispatchEvent(new Event('load'));
}
function formSubmitHandler(event) {
if (event) event.preventDefault();
hideAlert();
if (!valid) return;
showAlert('inserting ...', 1);
var formData = {
filter_id: filter.elements['filter_id'].value,
columns: columns.filter(function(el){ return el.checked; }).map(function(el) { return el.value; })
};
google.script.run
.withSuccessHandler(onResponse)
.withFailureHandler(onResponse)
.insertIssuesFromFilter(formData);
}
function onResponse(response) {
var done = response.status === true;
hideAlert();
if(done) google.script.host.close();
showAlert(response.message, done, 10000);
}
google.script.run
.withSuccessHandler(onInitFilter)
.getMyFilters(true);
filter.addEventListener('submit', formSubmitHandler);
input.forEach(function(el){ el.addEventListener('change', inputValidatyHandler); });
window.addEventListener('load', inputValidatyHandler);
</script>
</body>
</html>