1
|
|
|
; |
2
|
|
|
/** |
3
|
|
|
* Register the global neon object |
4
|
|
|
* // note: previously used const neon - |
5
|
|
|
* // There is a strange bug in webkit where having a const variable declaration and a dom id selector with the same name breaks! |
6
|
|
|
* @type Object |
7
|
|
|
*/ |
8
|
|
|
window.neon = window.neon || {}; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Log an error |
12
|
|
|
* @param error |
13
|
|
|
* @param context |
14
|
|
|
*/ |
15
|
|
|
neon.error = function(error, context) { |
|
|
|
|
16
|
|
|
if (typeof console !== 'undefined') { |
17
|
|
|
console.error(error, context); |
18
|
|
|
} else { |
19
|
|
|
throw error; |
20
|
|
|
} |
21
|
|
|
}; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Whether we are in debug mode |
25
|
|
|
* @returns {boolean} |
26
|
|
|
*/ |
27
|
|
|
neon.isDebug = function() { |
28
|
|
|
return NEON_DATA.debug ? true : false; |
|
|
|
|
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Alert the user with a message |
33
|
|
|
* @param string type |
34
|
|
|
* @param string message |
35
|
|
|
*/ |
36
|
|
|
neon.alert = function(type, message) { |
37
|
|
|
// TODO - 20180427 - make these do something more interesting than alerts |
38
|
|
|
switch(type) { |
39
|
|
|
case 'error': |
40
|
|
|
alert(message); |
|
|
|
|
41
|
|
|
break; |
42
|
|
|
case 'success': |
43
|
|
|
alert(message); |
44
|
|
|
break; |
45
|
|
|
} |
46
|
|
|
}; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get base url |
50
|
|
|
* @returns string |
51
|
|
|
*/ |
52
|
|
|
neon.base = function(host) { |
53
|
|
|
return host ? NEON_DATA.host : NEON_DATA.base; |
|
|
|
|
54
|
|
|
}; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Create a correct url |
58
|
|
|
* Useage: `neon.url('my/endpoint', {myGetParam:'myGetValue'})` |
59
|
|
|
* |
60
|
|
|
* @param {string} url |
61
|
|
|
* @param {object} params |
62
|
|
|
*/ |
63
|
|
|
neon.url = function(url, params, host) { |
64
|
|
|
host = host || false; |
65
|
|
|
url = (url[0] === '/') ? url.substr(1) : url; |
66
|
|
|
// TODO remove jquery dependancy $.param |
67
|
|
|
let queryPrefix = url.match(/\?/)!==null ? '&' : '?'; |
68
|
|
|
let query = params ? queryPrefix + $.param(params) : ''; |
69
|
|
|
return neon.base(host) + '/' + url + query; |
|
|
|
|
70
|
|
|
}; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get the csrf param |
74
|
|
|
* |
75
|
|
|
* @returns {String} |
76
|
|
|
*/ |
77
|
|
|
neon.csrfParam = function() { |
78
|
|
|
return NEON_DATA.csrfParam; |
|
|
|
|
79
|
|
|
}; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get the csrf token |
83
|
|
|
* |
84
|
|
|
* @returns String |
85
|
|
|
*/ |
86
|
|
|
neon.csrfToken = function() { |
87
|
|
|
// $('meta[name="csrf-token"]').attr('content') |
88
|
|
|
return NEON_DATA.csrfToken; |
|
|
|
|
89
|
|
|
}; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Show a message to flash to the user |
93
|
|
|
* Types include: error | success | info |
94
|
|
|
* ~~~js |
95
|
|
|
* neon.flash('Hey here is a success message', 'success', 10000) |
96
|
|
|
* ~~~ |
97
|
|
|
* @param {string} message - The message body content. |
98
|
|
|
* @param {string} type - 'error' | 'success' | 'info' | 'warning' |
99
|
|
|
* @param {int} duration - The number of milliseconds to show the notification for - if 0 show indefinately |
100
|
|
|
*/ |
101
|
|
|
neon.flash = function(message, type = 'info', duration = 5000, dangerouslyUseHtml = false) { |
102
|
|
|
neon.app.$message({message: message, type: type, duration: duration, showClose: true, dangerouslyUseHTMLString: dangerouslyUseHtml}); |
|
|
|
|
103
|
|
|
}; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Show a message to flash to the user |
107
|
|
|
* Types include: error | success | info |
108
|
|
|
* ~~~js |
109
|
|
|
* neon.notify('Saved', 'Hey here is a success message - the thing saved!', 'success') |
110
|
|
|
* ~~~ |
111
|
|
|
* @param {string} title - The title of the notification - shorter text shown in a bolder style |
112
|
|
|
* @param {string} message - The message body content. |
113
|
|
|
* @param {string} type - 'error' | 'success' | 'info' | 'warning' |
114
|
|
|
* @param {int} duration - The number of milliseconds to show the notification for |
115
|
|
|
*/ |
116
|
|
|
neon.notify = function(title, message, type = 'info', duration = 5000) { |
117
|
|
|
neon.app.$notify({title: title, message: message, type: type, duration: duration}); |
|
|
|
|
118
|
|
|
}; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Take a class path and format into a component string |
122
|
|
|
* For e.g. `neon\\core\\form\\fields\\Text` becomes `neon-core-form-fields-text` |
123
|
|
|
* @param field |
124
|
|
|
* @returns {string} |
125
|
|
|
*/ |
126
|
|
|
neon.classToComponent = function(className) { |
127
|
|
|
return className.replace(/\\/g, '-').replace(/^-/,'') // replace '\' with '-' and remove any leading '-' |
128
|
|
|
.toLowerCase(); |
129
|
|
|
}; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Implements sha1 hashing function |
133
|
|
|
* @param string |
134
|
|
|
* @returns {PromiseLike<string | never>} |
135
|
|
|
* @example neon.sha1(pwd).then(function(hash){ ... }) |
136
|
|
|
*/ |
137
|
|
|
neon.sha1 = function sha1(string){ |
138
|
|
|
var buffer = new TextEncoder("utf-8").encode(string); |
|
|
|
|
139
|
|
|
return crypto.subtle.digest("SHA-1", buffer).then(function (buffer) { |
|
|
|
|
140
|
|
|
// Get the hex code |
141
|
|
|
var hexCodes = []; |
142
|
|
|
var view = new DataView(buffer); |
143
|
|
|
for (var i = 0; i < view.byteLength; i += 4) { |
144
|
|
|
// Using getUint32 reduces the number of iterations needed (we process 4 bytes each time) |
145
|
|
|
var value = view.getUint32(i); |
146
|
|
|
// toString(16) will give the hex representation of the number without padding |
147
|
|
|
var stringValue = value.toString(16); |
148
|
|
|
// We use concatenation and slice for padding |
149
|
|
|
var padding = '00000000'; |
150
|
|
|
var paddedValue = (padding + stringValue).slice(-padding.length); |
151
|
|
|
hexCodes.push(paddedValue); |
152
|
|
|
} |
153
|
|
|
// Join all the hex strings into one |
154
|
|
|
return hexCodes.join(""); |
155
|
|
|
}); |
156
|
|
|
}; |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Have I Been Pwned https://haveibeenpwned.com/ password checker. |
160
|
|
|
* Checks if a password has previously been compromised |
161
|
|
|
* this uses the https://haveibeenpwned.com/API/v2#PwnedPasswords API. |
162
|
|
|
* The function returns a promise that will return the number of times the password has appeared |
163
|
|
|
* in compromised passwords databases. |
164
|
|
|
* Only the first 5 characters of a sha1 hash of the password are ever sent to the service |
165
|
|
|
* keeping it anonymous, this is a technique called k-Anonymity. |
166
|
|
|
* |
167
|
|
|
* @param {String} password |
168
|
|
|
* @returns {Promise<Number>} |
169
|
|
|
* @example |
170
|
|
|
* neon.hibpPasswordCheck().then(function(result) { |
171
|
|
|
* console.log(`This password was found ${result} times in compromised passwords databases!`); |
172
|
|
|
* }) |
173
|
|
|
* @see neon.sha1 - depends on neon.sha1 |
174
|
|
|
*/ |
175
|
|
|
neon.hibpPasswordCheck = function (password){ |
176
|
|
|
var promise = new Promise(function(resolve, reject) { |
|
|
|
|
177
|
|
|
// We hash the pwd first |
178
|
|
|
neon.sha1(password).then(function (hash) { |
|
|
|
|
179
|
|
|
// We send the first 5 chars of the hash to hibp's API |
180
|
|
|
const req = new XMLHttpRequest(); |
181
|
|
|
req.addEventListener("load", function () { |
182
|
|
|
// When we get back a response from the server |
183
|
|
|
// We create an array of lines and loop through them |
184
|
|
|
const resp = this.responseText.split('\n'); |
185
|
|
|
const hashSub = hash.slice(5).toUpperCase(); |
186
|
|
|
for (var index in resp) { |
|
|
|
|
187
|
|
|
// Check if the line matches the rest of the hash |
188
|
|
|
if (resp[index].substring(0, 35) == hashSub) { |
189
|
|
|
return resolve(resp[index].split(':')[1]); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
// Trigger an event with the result |
193
|
|
|
//const event = new CustomEvent('hibpCheck', {detail: result}); |
194
|
|
|
//document.dispatchEvent(event); |
195
|
|
|
resolve(0); |
|
|
|
|
196
|
|
|
}); |
197
|
|
|
req.open('GET', 'https://api.pwnedpasswords.com/range/' + hash.substr(0, 5)); |
198
|
|
|
req.send(); |
199
|
|
|
}); |
200
|
|
|
}); |
201
|
|
|
return promise; |
202
|
|
|
}; |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Returns a function that evaluates statements for various operators. |
206
|
|
|
* This can be used to evaluate filters defined in JSON |
207
|
|
|
* @example |
208
|
|
|
* neon.filters('==')(1, 2); //evaluates as false |
209
|
|
|
* neon.filters('<')(1, 2); //evaluates as true |
210
|
|
|
* @param operator {String} The operator to use in the evaluation. |
211
|
|
|
* @returns Function (x, y) |
212
|
|
|
*/ |
213
|
|
|
neon.filter = function (operator) { |
214
|
|
|
var f = { |
215
|
|
|
'=': function (x, y) { return x == y; }, |
216
|
|
|
'>': function (x, y) { return x > y; }, |
217
|
|
|
'<': function (x, y) { return x < y; }, |
218
|
|
|
'>=': function (x, y) { return x >= y; }, |
219
|
|
|
'<=': function (x, y) { return x <= y; }, |
220
|
|
|
'==': function (x, y) { return x == y; }, |
221
|
|
|
'!=': function (x, y) { return x != y; }, |
222
|
|
|
'===': function (x, y) { return x === y; }, |
223
|
|
|
'!==': function (x, y) { return x !== y; }, |
224
|
|
|
'empty': function (x) { return (x === undefined || x === null || x === '');}, |
225
|
|
|
'!empty': function (x) { return (x !== undefined && x !== null && x !== '');} |
226
|
|
|
}; |
227
|
|
|
|
228
|
|
|
if (! (operator in f)) { |
229
|
|
|
throw 'Not a valid operator.'; |
230
|
|
|
} |
231
|
|
|
return f[operator]; |
232
|
|
|
}; |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Generate a uuid |
236
|
|
|
* @param s |
237
|
|
|
* @returns {string} |
238
|
|
|
*/ |
239
|
|
|
neon.uuid = function(s='-') { |
240
|
|
|
var format = 'XXXXXXXX'+s+'XXXX'+s+'XXXX'+s+'XXXX'+s+'XXXXXXXXXXXX'; |
241
|
|
|
return format.replace(/[X]/g, function(c){ |
|
|
|
|
242
|
|
|
return (Math.floor(Math.random() * 16) + 1).toString(16); |
243
|
|
|
}); |
244
|
|
|
}; |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Generate a uuid64 |
248
|
|
|
* @returns {string} |
249
|
|
|
*/ |
250
|
|
|
neon.uuid64 = function() { |
251
|
|
|
// remove any hyphens |
252
|
|
|
var uuid = neon.uuid(''); |
|
|
|
|
253
|
|
|
uuid += '0'; // 33 hexadecimal characters = 22 64-cimal chars. |
254
|
|
|
// to convert from base-16 to base-64 (not Base64) |
255
|
|
|
// 64 characters |
256
|
|
|
var letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
257
|
|
|
var encoding = '0123456789'+letters+'_Z'; |
258
|
|
|
var uuid64 = ''; |
259
|
|
|
var position = 0; |
260
|
|
|
while (position < 33) { |
261
|
|
|
var snip = uuid.substr(position, 3); |
262
|
|
|
var number = parseInt(snip, 16); |
263
|
|
|
uuid64 += encoding[Math.floor(number/64)] + encoding[Math.floor(number%64)]; |
264
|
|
|
position += 3; |
265
|
|
|
} |
266
|
|
|
return uuid64; |
267
|
|
|
}; |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Flattens an object - this is useful to create string address paths to complex nested structures |
271
|
|
|
* You can use `_.get()` to address complex nested structures in this way |
272
|
|
|
* @example |
273
|
|
|
* neon.flattenObject({ 'a':{ 'b':{ 'b2':2 }, 'c':{ 'c2':2, 'c3':3 } } }); |
274
|
|
|
* // gives => { 'a.b.b2':2, 'a.c.c2':2, 'a.c.c3':3 } |
275
|
|
|
* @param {Object} ob - the object to flatten |
276
|
|
|
* @return {Object} - an object of {}key:value} where the key is a string representing the structure |
277
|
|
|
*/ |
278
|
|
|
neon.flattenObject = function(ob) { |
279
|
|
|
var toReturn = {}; |
280
|
|
|
var flatObject; |
281
|
|
|
for (var i in ob) { |
282
|
|
|
if (!ob.hasOwnProperty(i)) { |
283
|
|
|
continue; |
284
|
|
|
} |
285
|
|
|
if ((typeof ob[i]) === 'object') { |
286
|
|
|
flatObject = neon.flattenObject(ob[i]); |
|
|
|
|
287
|
|
|
for (var x in flatObject) { |
288
|
|
|
if (!flatObject.hasOwnProperty(x)) { |
289
|
|
|
continue; |
290
|
|
|
} |
291
|
|
|
toReturn[i + (!!isNaN(x) ? '.' + x : '')] = flatObject[x]; |
292
|
|
|
} |
293
|
|
|
} else { |
294
|
|
|
toReturn[i] = ob[i]; |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
return toReturn; |
298
|
|
|
}; |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Capitalize the first character of a string |
302
|
|
|
* |
303
|
|
|
* @param {string} stringName |
304
|
|
|
* @returns {string} |
305
|
|
|
*/ |
306
|
|
|
neon.capitalize = function(stringName) { |
307
|
|
|
return stringName[0].toUpperCase() + stringName.substring(1); |
308
|
|
|
}; |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Format a number into a string representing bytes |
312
|
|
|
* @example |
313
|
|
|
* > neon.formatBytes(3452345253) |
314
|
|
|
* < "3.45 GB" |
315
|
|
|
* @param {Number} size |
316
|
|
|
* @returns {string} |
317
|
|
|
*/ |
318
|
|
|
neon.formatBytes = function(size) { |
319
|
|
|
var e = (Math.log(size) / Math.log(1e3)) | 0; |
320
|
|
|
return +(size / Math.pow(1e3, e)).toFixed(2) + ' ' + ('kMGTPEZY' [e - 1] || '') + 'B'; |
321
|
|
|
}; |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Add underscore extensions |
325
|
|
|
*/ |
326
|
|
|
neon._ = { |
327
|
|
|
/** |
328
|
|
|
* A simple inversion of _.isUndefined - can make complex statements easier to read |
329
|
|
|
* @param {*} reference - The value to test |
330
|
|
|
* @returns {boolean} |
331
|
|
|
*/ |
332
|
|
|
isDefined: function(reference) { |
333
|
|
|
return !_.isUndefined(reference); |
|
|
|
|
334
|
|
|
}, |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Validate an object |
338
|
|
|
* |
339
|
|
|
* @param {Object} object - The object containing properties to validate |
340
|
|
|
* @param {string} context - A message to help give context to the error message if validation fails |
341
|
|
|
* @param {Object} definition - The validation definition |
342
|
|
|
* @param {string} definition.type - The data type to test against e.g. String, Object, Array |
343
|
|
|
* @param {boolean} definition.required - Whether the item is required |
344
|
|
|
*/ |
345
|
|
|
validate: function(object, context, definition) { |
346
|
|
|
_.each(definition, function(prop, name) { |
|
|
|
|
347
|
|
|
// check the property exists if it is required |
348
|
|
|
if (_.isUndefined(object[name])) { |
|
|
|
|
349
|
|
|
if (prop.required) |
350
|
|
|
_.error('Missing required property: "' + name + '"', context); |
|
|
|
|
351
|
|
|
return; |
352
|
|
|
} |
353
|
|
|
// check the type |
354
|
|
|
var validType = _.assertType(object[name], prop.type); |
355
|
|
|
if (!validType.valid) { |
356
|
|
|
_.error('Invalid property: type check failed for property "' + name + '".' + |
357
|
|
|
' Expected ' + validType.expectedType + |
358
|
|
|
', got ' + Object.prototype.toString.call(object[name]).slice(8, -1) + '.', context); |
359
|
|
|
} |
360
|
|
|
}); |
361
|
|
|
}, |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Assert that a value is of type |
365
|
|
|
* |
366
|
|
|
* ```js |
367
|
|
|
* _.assertType('is string', String); // => true |
368
|
|
|
* ``` |
369
|
|
|
* |
370
|
|
|
* @param {*} value - The value to test |
371
|
|
|
* @param {*} type - The type to assert e.g. String | Number | Array |
372
|
|
|
* @returns {{valid: boolean, expectedType: *}} |
373
|
|
|
*/ |
374
|
|
|
assertType: function(value, type) { |
375
|
|
|
var simpleCheckRE = /^(String|Number|Boolean|Function|Symbol)$/; |
376
|
|
|
var valid; |
377
|
|
|
var expectedType = _.getType(type); |
|
|
|
|
378
|
|
|
if (simpleCheckRE.test(expectedType)) { |
379
|
|
|
valid = typeof value === expectedType.toLowerCase(); |
380
|
|
|
} else if (expectedType === 'Object') { |
381
|
|
|
valid = _.isObject(value); |
382
|
|
|
} else if (expectedType === 'Array') { |
383
|
|
|
valid = _.isArray(value); |
384
|
|
|
} else { |
385
|
|
|
valid = value instanceof type; |
386
|
|
|
} |
387
|
|
|
return { |
388
|
|
|
valid: valid, |
389
|
|
|
expectedType: expectedType |
390
|
|
|
}; |
391
|
|
|
}, |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Use the string name of the data type function check built-in types, |
395
|
|
|
* because a simple equality check will fail when running |
396
|
|
|
* across different vms / iframes. |
397
|
|
|
* @param {*} fn - The data type function e.g. String | Number | Array | Object etc |
398
|
|
|
* @returns {string} the data type string |
399
|
|
|
*/ |
400
|
|
|
getType: function(fn) { |
401
|
|
|
var match = fn && fn.toString().match(/^\s*function (\w+)/); |
402
|
|
|
return match ? match[1] : ''; |
403
|
|
|
}, |
404
|
|
|
|
405
|
|
|
error: neon.error, |
406
|
|
|
capitalize: neon.capitalize, |
407
|
|
|
formatBytes: neon.formatBytes, |
408
|
|
|
uuid: neon.uuid, |
409
|
|
|
flattenObject: neon.flattenObject |
410
|
|
|
}; |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* Add neon "_" helpers to the underscore / lodash library if it exists |
414
|
|
|
* Thus functions become accessible via "_." |
415
|
|
|
*/ |
416
|
|
|
if (typeof _ != "undefined") { |
|
|
|
|
417
|
|
|
_.mixin(neon._); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* Create a new global Vuex Store |
422
|
|
|
*/ |
423
|
|
|
neon.Store = new Vuex.Store({ |
|
|
|
|
424
|
|
|
|
425
|
|
|
strict: NEON_DATA.debug, |
|
|
|
|
426
|
|
|
|
427
|
|
|
state: { |
428
|
|
|
modals: [] |
429
|
|
|
}, |
430
|
|
|
|
431
|
|
|
getters: { |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* Whether a modal should be displayed |
435
|
|
|
* |
436
|
|
|
* @return boolean |
437
|
|
|
*/ |
438
|
|
|
getShowModal: (state, getters) => () => { |
|
|
|
|
439
|
|
|
// do we have any modals to show on the stack |
440
|
|
|
return state.modals.length !== 0; |
441
|
|
|
}, |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* Get the string name of the component that the modal should render |
445
|
|
|
* |
446
|
|
|
* @return {string} The component name |
447
|
|
|
*/ |
448
|
|
|
getModalComponent: (state, getters) => () => { |
|
|
|
|
449
|
|
|
var last = _.last(state.modals); |
|
|
|
|
450
|
|
|
if (_.isUndefined(last)) { |
451
|
|
|
return ''; |
452
|
|
|
} |
453
|
|
|
return last.component; |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
}, |
457
|
|
|
mutations: { |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* @param {Object} state |
461
|
|
|
* @param {Object} payload |
462
|
|
|
* @param {String} payload.form the form id |
463
|
|
|
* @param {Object} payload.fields the form data object where key is the field name and the value is the field value |
464
|
|
|
*/ |
465
|
|
|
CREATE_FORM: function(state, payload) { |
466
|
|
|
Vue.set(state.forms, payload.form, payload.fields); |
|
|
|
|
467
|
|
|
}, |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* Show a modal |
471
|
|
|
* @param state |
472
|
|
|
* @param {Object} payload |
473
|
|
|
* @param {Object} payload.component - The component to show in the model e.g. 'firefly-picker-modal' |
474
|
|
|
* the component specified should be wrapped by 'neon-modal-wrap' component |
475
|
|
|
* @param {Object} payload.props - The properties to pass to the component |
476
|
|
|
*/ |
477
|
|
|
SHOW_MODAL: function(state, payload) { |
478
|
|
|
_.validate(payload, 'in neon.Store_MODAL', { |
|
|
|
|
479
|
|
|
component: {type: String, required: true}, |
480
|
|
|
props: {type: Object, required: false} |
481
|
|
|
}); |
482
|
|
|
|
483
|
|
|
state.modals.push({ |
484
|
|
|
component: { |
485
|
|
|
name: payload.component, |
486
|
|
|
props: payload.props |
487
|
|
|
} |
488
|
|
|
}); |
489
|
|
|
}, |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Close the current active modal |
493
|
|
|
* |
494
|
|
|
* @param state |
495
|
|
|
* @constructor |
496
|
|
|
*/ |
497
|
|
|
CLOSE_MODAL: function(state) { |
498
|
|
|
// pop the last modal off the stack |
499
|
|
|
state.modals.pop(); |
500
|
|
|
} |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
}); |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* This needs to be the last bit of script to run |
507
|
|
|
*/ |
508
|
|
|
neon.app = new Vue({ |
|
|
|
|
509
|
|
|
store: neon.Store, |
510
|
|
|
computed: Vuex.mapGetters(['getShowModal', 'getModalComponent']), |
511
|
|
|
methods: Vuex.mapMutations([ |
512
|
|
|
{closeModal: 'CLOSE_MODAL'} |
513
|
|
|
]) |
514
|
|
|
}); |
515
|
|
|
|
516
|
|
|
if (jQuery) { |
517
|
|
|
$.ajaxSetup({ |
518
|
|
|
headers: {'X-CSRF-Token': neon.csrfToken()} |
519
|
|
|
}); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
/** |
523
|
|
|
* Mount a vue object - factory for creating new mountable vue instances |
524
|
|
|
* @param {string} selector |
525
|
|
|
* @return Vue |
526
|
|
|
*/ |
527
|
|
|
neon.mount = function(selector) { |
528
|
|
|
return (new Vue({ |
|
|
|
|
529
|
|
|
store: neon.Store |
|
|
|
|
530
|
|
|
}).$mount(selector)); |
531
|
|
|
}; |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Set up Vue |
535
|
|
|
*/ |
536
|
|
|
if (Vue) { |
|
|
|
|
537
|
|
|
Vue.config.performance = neon.isDebug; |
538
|
|
|
} |
539
|
|
|
|
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.