-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathadmin-page-columns.ts
141 lines (114 loc) · 5.89 KB
/
admin-page-columns.ts
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
import {Form} from "./admin/columns/form";
import {EventConstants} from "./constants";
import {initAcServices} from "./helpers/admin-columns";
import $ from 'jquery';
import ColumnConfigurator from "./admin/columns/column-configurator";
import Modal from "./modules/modal";
import Feedback from "./admin/columns/feedback";
import InfoScreenOption from "./admin/columns/screen-options";
import {initAcTooltips} from "./plugin/tooltip";
import {initPointers} from "./modules/ac-pointer";
import {initUninitializedListScreens} from "./admin/columns/listscreen-initialize";
import Modals from "./modules/modals";
import {Column} from "./admin/columns/column";
import {LocalizedAcColumnSettings} from "./types/admin-columns";
declare let AC: LocalizedAcColumnSettings
declare const jQuery: any;
let AcServices = initAcServices();
AcServices.registerService('Modals', new Modals());
new ColumnConfigurator(AcServices);
document.addEventListener('DOMContentLoaded', () => {
initSaveHandlers();
// Init the form
document.querySelectorAll<HTMLFormElement>('#listscreen_settings').forEach((formElement: HTMLElement) => {
AcServices.registerService('Form', new Form(formElement, AcServices))
});
// Init the Pro promotion Modal
if (AcServices.hasService('Modals')) {
document.querySelectorAll<HTMLElement>('#ac-modal-pro').forEach(proModal => {
AcServices.getService<Modals>('Modals')?.register(new Modal(proModal), 'pro');
});
}
const matchStart = (params: any, data: any) => {
if (jQuery.trim(params.term) === '') {
return data;
}
if (typeof data.children === 'undefined') {
return null;
}
let filteredChildren: any[] = [];
jQuery.each(data.children, (idx: any, child: any) => {
if (child.text.toUpperCase().indexOf(params.term.toUpperCase()) > -1) {
filteredChildren.push(child);
}
});
if (filteredChildren.length) {
let d = Object.assign({}, data);
d.children = filteredChildren;
return d;
}
return null;
}
document.querySelectorAll<HTMLSelectElement>('#ac_list_screen').forEach(select => {
(<any>jQuery(select)).ac_select2({
theme: 'acs2',
matcher: matchStart,
width: '250px',
dropdownCssClass: '-listkeys',
}).on('select2:select', () => {
document.querySelectorAll<HTMLElement>('.view-link').forEach(link => link.style.display = 'none');
select.closest<HTMLFormElement>('form')?.submit();
select.disabled = true;
(select.nextElementSibling as HTMLElement).style.display = 'inline-block';
});
})
document.querySelectorAll<HTMLElement>('#direct-feedback').forEach(feedbackElement => new Feedback(feedbackElement));
if (AC.hasOwnProperty('uninitialized_list_screens')) {
initUninitializedListScreens(AC.uninitialized_list_screens);
}
// Screen Options
document.querySelectorAll<HTMLInputElement>('[data-ac-screen-option="show_column_id"] input').forEach(el => new InfoScreenOption('show_column_id', el, 'show-column-id', document.querySelector('.ac-boxes')!));
document.querySelectorAll<HTMLInputElement>('[data-ac-screen-option="show_column_type"] input').forEach(el => new InfoScreenOption('show_column_type', el, 'show-column-type', document.querySelector('.ac-boxes')!));
document.querySelectorAll<HTMLInputElement>('[data-ac-screen-option="show_list_screen_id"] input').forEach(el => new InfoScreenOption('show_list_screen_id', el, 'show-list-screen-id', document.querySelector('.ac-admin')!));
document.querySelectorAll<HTMLInputElement>('[data-ac-screen-option="show_list_screen_type"] input').forEach(el => new InfoScreenOption('show_list_screen_type', el, 'show-list-screen-type', document.querySelector('.ac-admin')!));
});
AcServices.addListener(EventConstants.SETTINGS.FORM.LOADED, (form: Form) => {
document.querySelectorAll('.add_column').forEach(el => el.addEventListener('click', () => form.createNewColumn()));
document.querySelectorAll('a[data-clear-columns]').forEach(el => el.addEventListener('click', () => form.resetColumns()));
if (!form.getElement().classList.contains('-disabled')) {
// Make column settings sortable
let $form = $(form.getElement()) as any;
$form.hasClass('ui-sortable')
? $form.sortable('refresh')
: $form.sortable({
axis: 'y',
items: '.ac-column',
handle: '[data-sort-handle]',
containment: $form
});
}
});
AcServices.addListener(EventConstants.SETTINGS.FORM.SAVING, () => {
document.querySelector('#cpac .ac-admin')?.classList.add('saving');
});
AcServices.addListener(EventConstants.SETTINGS.FORM.SAVED, () => {
document.querySelector('#cpac .ac-admin')?.classList.remove('saving');
document.querySelector('#cpac .ac-admin')?.classList.add('stored');
});
AcServices.addListener(EventConstants.SETTINGS.COLUMN.INIT, (column: Column) => {
initAcTooltips();
initPointers(column.getElement().querySelectorAll('.ac-pointer'));
});
const initSaveHandlers = () => {
const elements = document.querySelectorAll<HTMLElement>('.sidebox a.submit, .column-footer a.submit');
AcServices.addListener(EventConstants.SETTINGS.FORM.READY, (form: Form) => {
elements.forEach(el => {
el.addEventListener('click', e => {
e.preventDefault();
elements.forEach(el => el.setAttribute('disabled', 'disabled'));
form.submitForm();
});
})
});
AcServices.addListener(EventConstants.SETTINGS.FORM.SAVED, () => elements.forEach(el => el.removeAttribute('disabled')));
}