-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProcessChangelog.js
183 lines (162 loc) · 7.35 KB
/
ProcessChangelog.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
173
174
175
176
177
178
179
180
181
182
183
$(document).ready(function() {
var resetFilterOptions = function() {
var $filters = $('form#filters');
var $when = $filters.find('select[name=when]');
if ($when.length && $when.prop('value') != "between") {
$filters.find('.log-datepicker')
.val('')
.parent('div')
.addClass('disabled')
.end()
.attr('title', $filters.find('input[name=date_from]').attr('data-disabled-title'))
.attr('disabled', 'disabled');
if (window.location.search.match(/date_from=/) || window.location.search.match(/date_until=/)) {
history.replaceState(null, null, '?' + $filters.serialize());
}
}
}
var initLog = function() {
var $info = $('#info');
var $table = $('table.log');
var $filters = $('form#filters');
// more/less links
var moreColumnIndex = $table.find('> tbody > tr:first > td:has(.details-table)').index();
if (moreColumnIndex > -1) {
$table.find('> tbody > tr').each(function() {
$(this)
.find('> td:eq(' + moreColumnIndex + ')')
.wrapInner('<span hidden></span>')
.append('<a class="more" tabindex="0" role="button"><span class="text">' + config.log.i18n.more + '</span><i class="icon" aria-hidden="true"></i></a>');
});
// more/less functionality
$table.on('click keyup', 'a.more', function(e, noFocus) {
if (e.type == 'click' || e.type == 'keyup' && (e.keyCode == 32 || e.keyCode == 40 || e.keyCode == 38|| e.keyCode == 13)) {
e.preventDefault();
var $tr = $(this).parents('tr:first');
if ($table.hasClass('open-all') && $tr.next('tr.more').length) return;
$tr.toggleClass('open');
$(this).children('.text:first').text(config.log.i18n[$tr.hasClass('open') ? 'less' : 'more']);
if (($table.hasClass('open-all') || $tr.hasClass('open')) || e.type == 'keyup' && e.keyCode == 38) {
var colspan = $tr.find('> td').length;
var details = $(this).prev('[hidden]').html();
$tr.after('<tr class="more"><td colspan="' + colspan + '">' + details + '</td></tr>');
if (!$table.hasClass('no-focus')) {
$tr.next('tr.more').find('.details:first').focus();
}
} else {
$tr.next('tr.more').remove();
}
}
});
}
// more/less open/collapse all toggle
var $moreToggleAll = $('<a class="more-toggle-all" tabindex="0" role="button"><span class="text">' + config.log.i18n.openAll + '</span><i class="icon" aria-hidden="true"></i></a>');
$info.append($moreToggleAll);
$info.on('click keyup', 'a.more-toggle-all', function(e) {
if (e.type == 'click' || e.type == 'keyup' && (e.keyCode == 32 || e.keyCode == 13)) {
e.preventDefault();
$table.addClass('no-focus');
$table.toggleClass('open-all');
$table.find('a.more').trigger('click');
$moreToggleAll.find('.text').text(config.log.i18n[$table.hasClass('open-all') ? 'collapseAll' : 'openAll']);
console.log($table.hasClass('open-all'));
$table.removeClass('no-focus');
}
});
// remove link
$table.on('click', 'a.remove-row', function() {
if (confirm(config.log.i18n.areYouSure)) {
var $link = $(this);
$.get($link.attr('href'), function(data) {
data = $.parseJSON(data);
if (data && !data.error) {
$link.parents('tr:first').fadeOut('500');
} else {
alert(config.log.i18n.removeFailed);
}
});
}
return false;
});
// hide extra info when ordering data
$table.on('click', 'th.tablesorter-header', function() {
$table.find('tr.open a.more').trigger('click');
});
// when data is filtered by id and only one row exists, show info by default
if ($table.find('a.more').length == 1 && window.location.search.match(/[?&]id=/)) {
$table.find('a.more').trigger('click');
}
// display JS-only icons
$('.js-icon').addClass('icon').removeClass('js-icon');
// AJAX filter form
$filters.on('change', 'select, input', function() {
resetFilterOptions();
updateContent('?' + $filters.serialize());
});
// AJAX links
$table.parent().off('click.ajax').on('click.ajax', 'a.ajax', function(event) {
event.preventDefault();
resetFilterOptions();
updateContent($(this).attr('href'));
});
// AJAX pagination
$('.MarkupPagerNavCustom').on('click', 'a', function(event) {
event.preventDefault();
var params = $(this).attr('href');
$('html, body').animate({
scrollTop: $info.offset().top
}, 500, function() {
updateContent(params);
});
});
// hide irrelevant options in filter form
resetFilterOptions();
// init datepicker
$('.log-datepicker').each(function() {
var options = {
dateFormat: $(this).attr('data-dateformat'),
minDate: $(this).attr('data-mindate'),
maxDate: $(this).attr('data-maxdate')
};
$(this).datepicker(options);
});
// layout fix for filter fieldset label (required when content is updated via AJAX)
$(".Inputfield:not(.collapsed9) > .InputfieldHeader").addClass("InputfieldStateToggle");
}
// update content via AJAX
var $info = $('#info');
var $contentContainer = $info.parent();
var isUikit = $contentContainer.find('.uk-select:first').length > 0;
var updateXHR;
var updateContent = function(params) {
var $spinner = $info.find('h2 .fa-spinner');
if (!$spinner.length || $spinner.data('params') != params) {
if ($spinner.length && updateXHR) {
updateXHR.abort();
}
$spinner = $('<i class="fa fa-spinner fa-spin"></i>').data('params', params);
$info.find('h2').append($spinner);
history.replaceState(null, null, params);
updateXHR = $.ajax({
url: params,
error: function(xhr, textStatus, errorThrown) {
alert(textStatus);
},
success: function(data, textStatus) {
$contentContainer.html(data);
if (isUikit) {
$contentContainer.find('select').addClass('uk-select');
}
},
complete: function(xhr, textStatus) {
initLog();
if (typeof AdminDataTable !== 'undefined') {
AdminDataTable.init();
}
}
});
}
}
// init
initLog();
});