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
|
|
|
.dataTable(); |
159
|
|
|
$('#navigation-list') |
160
|
|
|
.on('preXhr.dt', function ( e, settings, data ) { |
|
|
|
|
161
|
|
|
if(settings.jqXHR) { |
162
|
|
|
settings.jqXHR.abort() |
163
|
|
|
} |
164
|
|
|
}); |
165
|
|
|
}) |
166
|
|
|
|
167
|
|
|
var abeReady = new Event('abeReady') |
168
|
|
|
document.dispatchEvent(abeReady) |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
inject() { |
172
|
|
|
var findComments = function(el) { |
173
|
|
|
var arr = [] |
174
|
|
|
for(var i = 0; i < el.childNodes.length; i++) { |
175
|
|
|
var node = el.childNodes[i] |
176
|
|
|
if(node.nodeType === 8) { |
177
|
|
|
arr.push(node) |
178
|
|
|
} else { |
179
|
|
|
arr.push.apply(arr, findComments(node)) |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
return arr |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
var commentNodes = findComments(document) |
186
|
|
|
|
187
|
|
|
Array.prototype.forEach.call(commentNodes, (comment) => { |
188
|
|
|
if (comment.nodeValue.indexOf('[pageHTML]') > -1) { |
189
|
|
|
var base = comment.data |
190
|
|
|
if(typeof base !== 'undefined' && base !== null) { |
191
|
|
|
base = base.replace(/\[pageHTML\]/g, '') |
192
|
|
|
base = base.replace(/<ABE!--/g, '<!--').replace(/--ABE>/g, '-->') |
193
|
|
|
EditorReload.instance.inject(base) |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
}) |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
_bindEvents() { |
200
|
|
|
|
201
|
|
|
this._blocks.onNewBlock(() => { |
202
|
|
|
this._files.rebind() |
203
|
|
|
this._inputs.rebind() |
204
|
|
|
this._autocomplete.rebind() |
205
|
|
|
}) |
206
|
|
|
|
207
|
|
|
this._manager.remove((el) => { |
|
|
|
|
208
|
|
|
this.table.ajax.reload() |
209
|
|
|
}) |
210
|
|
|
|
211
|
|
|
this._inputs.onReload(() => { |
212
|
|
|
this._save.serializeForm() |
213
|
|
|
EditorReload.instance.reload() |
214
|
|
|
}) |
215
|
|
|
|
216
|
|
|
this._autocomplete.onReload(() => { |
217
|
|
|
EditorReload.instance.reload() |
218
|
|
|
}) |
219
|
|
|
|
220
|
|
|
this._inputs.onBlur(() => { |
221
|
|
|
this._save.serializeForm() |
222
|
|
|
}) |
223
|
|
|
|
224
|
|
|
this._blocks.onRemoveBlock(() => { |
225
|
|
|
this._inputs.rebind() |
226
|
|
|
this._autocomplete.rebind() |
227
|
|
|
this._save.serializeForm() ///**************************************** HOOLA |
228
|
|
|
}) |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
var engine = new Engine() |
233
|
|
|
window.abe = { |
234
|
|
|
save: engine._save, |
235
|
|
|
json: engine.json, |
236
|
|
|
inputs: engine._inputs, |
237
|
|
|
files: engine._files, |
238
|
|
|
manager: engine._manager, |
239
|
|
|
blocks: engine._blocks, |
240
|
|
|
autocomplete: engine._autocomplete, |
241
|
|
|
editorReload: EditorReload |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
245
|
|
|
if(document.querySelector('#page-template')) engine.inject() |
|
|
|
|
246
|
|
|
}) |
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.