Skip to content

Commit

Permalink
Merge pull request #258 from nicolaslabbe/feature/abe-data-variable-d…
Browse files Browse the repository at this point in the history
…ynamique-precontrib

Feature abe type data
  • Loading branch information
gregorybesson committed Oct 31, 2017
2 parents fbf7465 + baca931 commit 9c5a3dc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cli/cms/data/attributes.js
Expand Up @@ -65,10 +65,10 @@ export function sanitizeSourceAttribute(obj, jsonPage) {

try {
val = eval('jsonPage.' + val)
obj.sourceString = obj.sourceString.replace(match, val)
} catch (e) {
val = ''
}
obj.sourceString = obj.sourceString.replace(match, val)
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/cli/cms/data/source.js
Expand Up @@ -171,12 +171,12 @@ export function nextDataList(jsonPage, match) {
}

var obj = cmsData.attributes.getAll(match, jsonPage)
obj = cmsData.attributes.sanitizeSourceAttribute(obj, jsonPage)

var type = cmsData.sql.getSourceType(obj.sourceString)

switch (type) {
case 'request':
obj = cmsData.attributes.sanitizeSourceAttribute(obj, jsonPage)
requestList(obj, match, jsonPage)
.then(jsonPage => {
resolve(jsonPage)
Expand All @@ -186,6 +186,7 @@ export function nextDataList(jsonPage, match) {
})
break
case 'value':
obj = cmsData.attributes.sanitizeSourceAttribute(obj, jsonPage)
valueList(obj, match, jsonPage)
.then(() => {
resolve()
Expand All @@ -204,6 +205,7 @@ export function nextDataList(jsonPage, match) {
})
break
case 'file':
obj = cmsData.attributes.sanitizeSourceAttribute(obj, jsonPage)
fileList(obj, match, jsonPage)
.then(() => {
resolve()
Expand Down
Expand Up @@ -425,6 +425,8 @@ export default class EditorAutocomplete {
this._previousValue = val
}
var dataVal = target.getAttribute('data-value').replace(/&quote;/g, "'")
var template = Handlebars.compile(dataVal, {noEscape: true})
dataVal = template(this._json.data)

if (dataVal.indexOf('{{') > -1) {
var match
Expand Down
2 changes: 1 addition & 1 deletion src/server/public/abecms/scripts/modules/EditorInputs.js
Expand Up @@ -41,7 +41,7 @@ export default class EditorInputs {
this._reloads = [].slice.call(
document.querySelectorAll('[reload=true]:not([data-multiple="multiple"])')
)
this._inputs = [].slice.call(document.querySelectorAll('input.form-abe'))
this._inputs = [].slice.call(document.querySelectorAll('.form-abe'))
this._inputs = this._inputs.concat(
[].slice.call(document.querySelectorAll('textarea.form-abe'))
)
Expand Down
14 changes: 11 additions & 3 deletions src/server/public/abecms/scripts/modules/EditorSave.js
Expand Up @@ -41,7 +41,7 @@ export default class EditorSave {
* @return {Object} json
*/
serializeForm() {
var abeForm = document.querySelector('.abeform-wrapper')
var abeForm = document.querySelector('.abeform-wrapper') || document.querySelector('.form-create')
if (abeForm == null) return
var e = document.getElementById('selectTemplate')
var selectedTemplate = e.options[e.selectedIndex].value
Expand Down Expand Up @@ -109,7 +109,11 @@ export default class EditorSave {
input.value.indexOf('{') > -1 ||
input.value.indexOf('[') > -1
) {
value = JSON.parse(input.value)
try {
value = JSON.parse(input.value)
}catch(e) {
value = null
}
} else {
value = input.value
}
Expand Down Expand Up @@ -166,7 +170,11 @@ export default class EditorSave {
input.value.indexOf('{') > -1 &&
!input.classList.contains('abe-keep-format')
) {
value = JSON.parse(input.value)
try {
value = JSON.parse(input.value)
}catch(e) {
value = null
}
} else {
value = input.value
}
Expand Down

0 comments on commit 9c5a3dc

Please sign in to comment.