|
1
|
|
|
/*global document, window, $, Event */ |
|
2
|
|
|
|
|
3
|
|
|
import {Devtool} from './devtool/Devtool' |
|
4
|
|
|
|
|
5
|
|
|
import EditorInputs from './modules/EditorInputs' |
|
6
|
|
|
import EditorBlock from './modules/EditorBlock' |
|
7
|
|
|
import EditorFiles from './modules/EditorFiles' |
|
8
|
|
|
import EditorSave from './modules/EditorSave' |
|
9
|
|
|
import EditorJson from './modules/EditorJson' |
|
10
|
|
|
import EditorManager from './modules/EditorManager' |
|
11
|
|
|
import EditorAutocomplete from './modules/EditorAutocomplete' |
|
12
|
|
|
import EditorReload from './modules/EditorReload' |
|
13
|
|
|
import EditorReferences from './modules/EditorReferences' |
|
14
|
|
|
import EditorStructures from './modules/EditorStructures' |
|
15
|
|
|
|
|
16
|
|
|
var htmlTag = document.querySelector('html') |
|
17
|
|
|
window.CONFIG = JSON.parse(htmlTag.getAttribute('data-config')) |
|
18
|
|
|
// window.json = JSON.parse(unescape(htmlTag.getAttribute('data-json').replace(/"/g, '\"'))) |
|
19
|
|
|
var j = htmlTag.getAttribute('data-json') |
|
20
|
|
|
if (j != null) { |
|
21
|
|
|
j = j.replace(/"/g, '"') |
|
22
|
|
|
j = unescape(j) |
|
23
|
|
|
j = j.replace(/\%27/g, '\'') |
|
24
|
|
|
window.json = JSON.parse(j) |
|
25
|
|
|
}else { |
|
26
|
|
|
window.json = {} |
|
27
|
|
|
} |
|
28
|
|
|
var l = htmlTag.getAttribute('data-locales') |
|
29
|
|
|
if (l != null) { |
|
30
|
|
|
|
|
31
|
|
|
window.Locales = JSON.parse(l) |
|
32
|
|
|
}else { |
|
33
|
|
|
window.Locales = {} |
|
34
|
|
|
} |
|
35
|
|
|
var s = htmlTag.getAttribute('data-slugs') |
|
36
|
|
|
if (s != null) { |
|
37
|
|
|
window.slugs = JSON.parse(s) |
|
38
|
|
|
}else { |
|
39
|
|
|
window.slugs = {} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
class Engine { |
|
43
|
|
|
|
|
44
|
|
|
constructor() { |
|
45
|
|
|
this._blocks = new EditorBlock() |
|
46
|
|
|
this._inputs = new EditorInputs() |
|
47
|
|
|
this._files = new EditorFiles() |
|
48
|
|
|
this._save = new EditorSave() |
|
49
|
|
|
this._manager = new EditorManager() |
|
50
|
|
|
this._autocomplete = new EditorAutocomplete() |
|
51
|
|
|
this._dev = new Devtool() |
|
52
|
|
|
this.reference = new EditorReferences() |
|
53
|
|
|
this.structure = new EditorStructures() |
|
54
|
|
|
|
|
55
|
|
|
this.json = EditorJson.instance |
|
56
|
|
|
|
|
57
|
|
|
this._bindEvents() |
|
58
|
|
|
|
|
59
|
|
|
this.table = null |
|
60
|
|
|
this.columns = [ |
|
61
|
|
|
{ |
|
62
|
|
|
'data': null, |
|
63
|
|
|
'defaultContent': '', |
|
64
|
|
|
'orderable': false |
|
65
|
|
|
}, |
|
66
|
|
|
{ |
|
67
|
|
|
'data': 'abe_meta.link' |
|
68
|
|
|
}, |
|
69
|
|
|
{ |
|
70
|
|
|
'data': 'abe_meta.template' |
|
71
|
|
|
}, |
|
72
|
|
|
{ |
|
73
|
|
|
'data': null, |
|
74
|
|
|
'defaultContent': '' |
|
75
|
|
|
} |
|
76
|
|
|
] |
|
77
|
|
|
|
|
78
|
|
|
Array.prototype.forEach.call(workflow, (flow) => { |
|
|
|
|
|
|
79
|
|
|
this.columns.push( |
|
80
|
|
|
{ 'data': null, |
|
81
|
|
|
'defaultContent': '', |
|
82
|
|
|
'orderable': false |
|
83
|
|
|
} |
|
84
|
|
|
) |
|
85
|
|
|
}) |
|
86
|
|
|
|
|
87
|
|
|
this.columns.push( |
|
88
|
|
|
{ |
|
89
|
|
|
'data': null, |
|
90
|
|
|
'defaultContent': '', |
|
91
|
|
|
'orderable': false |
|
92
|
|
|
} |
|
93
|
|
|
) |
|
94
|
|
|
|
|
95
|
|
|
$(document).ready(() => { |
|
96
|
|
|
this.table = $('#navigation-list').DataTable( { |
|
97
|
|
|
'pageLength': 50, |
|
98
|
|
|
'processing': true, |
|
99
|
|
|
'serverSide': true, |
|
100
|
|
|
'ajax': '/abe/paginate', |
|
101
|
|
|
'columns': this.columns, |
|
102
|
|
|
'order': [[ 3, 'desc' ]], |
|
103
|
|
|
'stateSave': true, |
|
104
|
|
|
'drawCallback': function(settings) { |
|
|
|
|
|
|
105
|
|
|
window.abe.manager.rebind() |
|
106
|
|
|
}, |
|
107
|
|
|
stateSaveCallback: function(settings,data) { |
|
108
|
|
|
localStorage.setItem( 'DataTables_' + settings.sInstance, JSON.stringify(data) ) |
|
|
|
|
|
|
109
|
|
|
}, |
|
110
|
|
|
stateLoadCallback: function(settings) { |
|
111
|
|
|
return JSON.parse( localStorage.getItem( 'DataTables_' + settings.sInstance ) ) |
|
|
|
|
|
|
112
|
|
|
}, |
|
113
|
|
|
'createdRow': function (row, data, index) { |
|
114
|
|
|
var actions = '<div class="row icons-action">' |
|
115
|
|
|
if(data.publish != null) { |
|
116
|
|
|
actions += `<a href="/abe/operations/unpublish${data.abe_meta.link}" |
|
117
|
|
|
title="Unpublish" |
|
118
|
|
|
class="icon" data-unpublish="true" data-text="Are you sure you want to unpublish : ${data.abe_meta.link}" |
|
119
|
|
|
title="unpublish"> |
|
120
|
|
|
<span class="glyphicon glyphicon-eye-close"></span> |
|
121
|
|
|
</a>` |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
actions += `<a href="/abe/operations/delete/${data.abe_meta.status}${data.abe_meta.link}" |
|
125
|
|
|
title="Delete" |
|
126
|
|
|
class="icon" |
|
127
|
|
|
data-delete="true" |
|
128
|
|
|
data-text="Are you sure you want to delete : ${data.abe_meta.link}" |
|
129
|
|
|
title="remove"> |
|
130
|
|
|
<span class="glyphicon glyphicon-trash"></span> |
|
131
|
|
|
</a></div>` |
|
132
|
|
|
|
|
133
|
|
|
var i = 4 |
|
134
|
|
|
Array.prototype.forEach.call(workflow, (flow) => { |
|
|
|
|
|
|
135
|
|
|
var wkf = '' |
|
136
|
|
|
if(typeof data[flow] !== 'undefined' && flow === 'publish') { |
|
137
|
|
|
wkf = `<a href="/abe/editor${data[flow].html}" class="checkmark label-published" title="${data[flow].cleanDate}">✔</a>` |
|
138
|
|
|
} |
|
139
|
|
|
if(data.abe_meta.status == flow && flow !== 'publish') { |
|
140
|
|
|
wkf = `<a href="/abe/editor${data[flow].html}" class="label label-default label-draft" title="${data[flow].cleanDate}">${flow}</a>` |
|
141
|
|
|
} |
|
142
|
|
|
$('td', row).eq(i).html(wkf) |
|
143
|
|
|
++i |
|
144
|
|
|
}) |
|
145
|
|
|
|
|
146
|
|
|
$('td', row).eq(0).html(index + 1) |
|
147
|
|
|
$('td', row).eq(1).html('<a href="/abe/editor'+data.abe_meta.link+'" class="file-path">'+data.abe_meta.link+'</a>') |
|
148
|
|
|
$('td', row).eq(3).html(moment(data.date).format('YYYY/MM/DD')) |
|
149
|
|
|
$('td', row).eq(i).html(actions) |
|
150
|
|
|
} |
|
151
|
|
|
}) |
|
152
|
|
|
$('#navigation-list') |
|
153
|
|
|
.on('processing.dt', function ( e, settings, processing ) { |
|
154
|
|
|
$('#navigation-list_processing') |
|
155
|
|
|
.css( 'display', processing ? 'block' : 'none' ) |
|
156
|
|
|
.css( {top:'150px'}) |
|
157
|
|
|
}) |
|
158
|
|
|
|
|
159
|
|
|
$('#navigation-list') |
|
160
|
|
|
.on('preXhr.dt', function ( e, settings, data ) { |
|
|
|
|
|
|
161
|
|
|
if(settings.jqXHR) { |
|
162
|
|
|
settings.jqXHR.abort() |
|
163
|
|
|
} |
|
164
|
|
|
}) |
|
165
|
|
|
}) |
|
166
|
|
|
|
|
167
|
|
|
$('#navigation-list') |
|
168
|
|
|
.on('processing.dt', function ( e, settings, processing ) { |
|
169
|
|
|
$('#navigation-list_processing') |
|
170
|
|
|
.css( 'display', processing ? 'block' : 'none' ) |
|
171
|
|
|
.css( {top:'150px'}); |
|
172
|
|
|
}); |
|
173
|
|
|
|
|
174
|
|
|
$('#navigation-list') |
|
175
|
|
|
.on('preXhr.dt', function ( e, settings, data ) { |
|
|
|
|
|
|
176
|
|
|
if(settings.jqXHR) { |
|
177
|
|
|
settings.jqXHR.abort() |
|
178
|
|
|
} |
|
179
|
|
|
}); |
|
180
|
|
|
|
|
181
|
|
|
var abeReady = new Event('abeReady') |
|
182
|
|
|
document.dispatchEvent(abeReady) |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
inject() { |
|
186
|
|
|
var findComments = function(el) { |
|
187
|
|
|
var arr = [] |
|
188
|
|
|
for(var i = 0; i < el.childNodes.length; i++) { |
|
189
|
|
|
var node = el.childNodes[i] |
|
190
|
|
|
if(node.nodeType === 8) { |
|
191
|
|
|
arr.push(node) |
|
192
|
|
|
} else { |
|
193
|
|
|
arr.push.apply(arr, findComments(node)) |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
return arr |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
var commentNodes = findComments(document) |
|
200
|
|
|
|
|
201
|
|
|
Array.prototype.forEach.call(commentNodes, (comment) => { |
|
202
|
|
|
if (comment.nodeValue.indexOf('[pageHTML]') > -1) { |
|
203
|
|
|
var base = comment.data |
|
204
|
|
|
if(typeof base !== 'undefined' && base !== null) { |
|
205
|
|
|
base = base.replace(/\[pageHTML\]/g, '') |
|
206
|
|
|
base = base.replace(/<ABE!--/g, '<!--').replace(/--ABE>/g, '-->') |
|
207
|
|
|
EditorReload.instance.inject(base) |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
}) |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
_bindEvents() { |
|
214
|
|
|
|
|
215
|
|
|
this._blocks.onNewBlock(() => { |
|
216
|
|
|
this._files.rebind() |
|
217
|
|
|
this._inputs.rebind() |
|
218
|
|
|
this._autocomplete.rebind() |
|
219
|
|
|
}) |
|
220
|
|
|
|
|
221
|
|
|
this._manager.remove((el) => { |
|
|
|
|
|
|
222
|
|
|
this.table.ajax.reload() |
|
223
|
|
|
}) |
|
224
|
|
|
|
|
225
|
|
|
this._inputs.onReload(() => { |
|
226
|
|
|
this._save.serializeForm() |
|
227
|
|
|
EditorReload.instance.reload() |
|
228
|
|
|
}) |
|
229
|
|
|
|
|
230
|
|
|
this._autocomplete.onReload(() => { |
|
231
|
|
|
EditorReload.instance.reload() |
|
232
|
|
|
}) |
|
233
|
|
|
|
|
234
|
|
|
this._inputs.onBlur(() => { |
|
235
|
|
|
this._save.serializeForm() |
|
236
|
|
|
}) |
|
237
|
|
|
|
|
238
|
|
|
this._blocks.onRemoveBlock(() => { |
|
239
|
|
|
this._inputs.rebind() |
|
240
|
|
|
this._autocomplete.rebind() |
|
241
|
|
|
this._save.serializeForm() ///**************************************** HOOLA |
|
242
|
|
|
}) |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
var engine = new Engine() |
|
247
|
|
|
window.abe = { |
|
248
|
|
|
save: engine._save, |
|
249
|
|
|
json: engine.json, |
|
250
|
|
|
inputs: engine._inputs, |
|
251
|
|
|
files: engine._files, |
|
252
|
|
|
manager: engine._manager, |
|
253
|
|
|
blocks: engine._blocks, |
|
254
|
|
|
autocomplete: engine._autocomplete, |
|
255
|
|
|
editorReload: EditorReload |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
259
|
|
|
if(document.querySelector('#page-template')) engine.inject() |
|
|
|
|
|
|
260
|
|
|
}) |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.