Skip to content

Commit

Permalink
bug; variable meta
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Dec 14, 2016
1 parent ccf79d6 commit bf26625
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/cli/cms/editor/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class Form {
}

obj = extend(true, defaultValues, obj)
obj.key = obj.key.replace(/\./, '-')
obj.key = obj.key//.replace(/\./, '-')

if(obj.key.indexOf('[') < 0 && obj.key.indexOf('.') > -1) {
obj.block = obj.key.split('.')[0]
Expand Down
1 change: 1 addition & 0 deletions src/cli/cms/operations/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var create = function(template, pathCreate, name, req, forceJson = {}, duplicate
var resHook = abeExtend.hooks.instance.trigger('beforeFirstSave', postUrl, req.body, json)
postUrl = resHook.postUrl
json = resHook.json

var p2 = cmsOperations.post.draft(
postUrl,
json,
Expand Down
30 changes: 16 additions & 14 deletions src/server/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,25 @@ function addToForm(match, text, json, util, arrayBlock, keyArray = null, i = 0)
obj = cmsData.attributes.getAll(v, json)

var realKey
if(typeof keyArray !== 'undefined' && keyArray !== null) {
realKey = obj.key.replace(/[^\.]+?\./, '')

if(obj.key.indexOf(keyArray + '.') >= 0 && realKey.length > 0){
obj.keyArray = keyArray
obj.realKey = realKey
obj.key = keyArray + '[' + i + '].' + realKey
obj.desc = obj.desc + ' ' + i,
insertAbeEach(obj, text, json, util, arrayBlock)
// if(typeof keyArray !== 'undefined' && keyArray !== null) {
// realKey = obj.key.replace(/[^\.]+?\./, '')

}else if(util.dontHaveKey(obj.key)) {
obj.value = json[getDataIdWithNoSlash(obj.key)]
json[getDataIdWithNoSlash(obj.key)] = add(obj, json, text, util)
}
// if(obj.key.indexOf(keyArray + '.') >= 0 && realKey.length > 0){
// obj.keyArray = keyArray
// obj.realKey = realKey
// obj.key = keyArray + '[' + i + '].' + realKey
// obj.desc = obj.desc + ' ' + i,
// insertAbeEach(obj, text, json, util, arrayBlock)

// }else if(util.dontHaveKey(obj.key)) {
// obj.value = json[getDataIdWithNoSlash(obj.key)]
// json[getDataIdWithNoSlash(obj.key)] = add(obj, json, text, util)
// }

}else if(util.dontHaveKey(obj.key) && cmsData.regex.isSingleAbe(v, text)) {
realKey = obj.key.replace(/\./g, '-')
// }else
if(util.dontHaveKey(obj.key) && cmsData.regex.isSingleAbe(v, text)) {
realKey = obj.key//.replace(/\./g, '-')
obj.value = json[getDataIdWithNoSlash(realKey)]
json[getDataIdWithNoSlash(obj.key)] = add(obj, json, text, util)
}
Expand Down
48 changes: 43 additions & 5 deletions src/server/public/abejs/scripts/admin-compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4774,6 +4774,8 @@ var _FolderSelect = require('./FolderSelect');

var _FolderSelect2 = _interopRequireDefault(_FolderSelect);

var _jsonObject = require('../utils/jsonObject');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand All @@ -4795,7 +4797,7 @@ var FormCreate = function () {
this._formInputs = [].slice.call(this._form.querySelectorAll('input, select'));
this._precontribTemplate = [].slice.call(this._form.querySelectorAll('[data-precontrib-templates]'));

this._selectTemplate = this._form.querySelector('[data-id="selectTemplate"]');
this._selectTemplate = this._form.querySelector('[data-id="abe_meta.template"]');
this._showHideSelect(this._selectTemplate);
this._handleBtnSelectTemplate = this._btnSelectTemplate.bind(this);

Expand Down Expand Up @@ -4907,7 +4909,8 @@ var FormCreate = function () {
if (resultValue.indexOf('{') > -1) {
try {
var jsonValue = JSON.parse(resultValue);
values[id].push(jsonValue);
(0, _jsonObject.setObjByString)(values, id, jsonValue);
// values[id].push(jsonValue)
} catch (e) {
// values[id].push(value)
}
Expand All @@ -4921,7 +4924,8 @@ var FormCreate = function () {
if (value.indexOf('{') > -1) {
try {
var jsonValue = JSON.parse(value);
values[id] = [jsonValue];
// values[id] = [jsonValue]
(0, _jsonObject.setObjByString)(values, id, [jsonValue]);

if (required && values[id].length == 0) {
isValid = false;
Expand All @@ -4931,7 +4935,8 @@ var FormCreate = function () {
// values[id].push(value)
}
} else {
values[id] = value;
// values[id] = value
(0, _jsonObject.setObjByString)(values, id, value);
if (required && values[id] == '') {
isValid = false;
if (showErrors) parentNode.classList.add('has-error');
Expand Down Expand Up @@ -5047,7 +5052,7 @@ var FormCreate = function () {

exports.default = FormCreate;

},{"./FolderSelect":18,"limax":3,"nanoajax":4,"qs":11}],20:[function(require,module,exports){
},{"../utils/jsonObject":21,"./FolderSelect":18,"limax":3,"nanoajax":4,"qs":11}],20:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
Expand Down Expand Up @@ -5109,4 +5114,37 @@ var FormList = function () {

exports.default = FormList;

},{}],21:[function(require,module,exports){
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setObjByString = setObjByString;
function setObjByString(obj, str, val) {
var keys, key;
//make sure str is a string with length
if (!str || !str.length || Object.prototype.toString.call(str) !== "[object String]") {
return false;
}
if (obj !== Object(obj)) {
//if it's not an object, make it one
obj = {};
}
keys = str.split(".");
while (keys.length > 1) {
key = keys.shift();
if (obj !== Object(obj)) {
//if it's not an object, make it one
obj = {};
}
if (!(key in obj)) {
//if obj doesn't contain the key, add it and set it to an empty object
obj[key] = {};
}
obj = obj[key];
}
return obj[keys[0]] = val;
}

},{}]},{},[17]);
7 changes: 5 additions & 2 deletions src/server/public/abejs/scripts/modules/EditorSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {IframeNode} from '../utils/iframe'
import EditorUtils from './EditorUtils'
import Json from '../modules/EditorJson'
import on from 'on'
import {setObjByString} from '../utils/jsonObject'

export default class EditorSave {
constructor() {
Expand Down Expand Up @@ -53,6 +54,7 @@ export default class EditorSave {

Array.prototype.forEach.call(inputs, (input) => {
var dataId = input.getAttribute('data-id')
var maxlength = input.getAttribute('data-maxlength')
if(input.type === 'file') return
if(typeof dataId !== 'undefined' && dataId !== null) {
if(dataId.indexOf('[') > -1){
Expand All @@ -72,7 +74,7 @@ export default class EditorSave {
}else {
var value

if (input.nodeName === 'SELECT') {
if (input.nodeName === 'SELECT' && maxlength != "1") {
var checked = input.querySelectorAll('option:checked')
value = []
Array.prototype.forEach.call(checked, (check) => {
Expand Down Expand Up @@ -100,7 +102,8 @@ export default class EditorSave {
}else {
value = input.value.replace(/\"/g, '\&quot;') + ''
}
this._json.data[dataId] = value
setObjByString(this._json.data, dataId, value);
// this._json.data[dataId] = value
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/server/public/abejs/scripts/modules/EditorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class EditorUtils {
if (visible === 'false' || visible === false) {
return
}
var id = target.getAttribute('data-id')
var id = target.getAttribute('data-id').replace(/\./g, '-')
var nodes = IframeNode('#page-template', '[data-abe-' + id + ']')

if(typeof nodes === 'undefined' || nodes === null || nodes.length === 0) {
Expand Down Expand Up @@ -77,7 +77,7 @@ export default class EditorUtils {
}

static getAttr(target) {
var id = target.getAttribute('data-id')
var id = target.getAttribute('data-id').replace(/\./g, '-')

return {
abe: 'data-abe-' + id.replace(/\[([0-9]*)\]/g, '$1'),
Expand Down
12 changes: 8 additions & 4 deletions src/server/public/abejs/scripts/modules/FormCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import limax from 'limax'
import Nanoajax from 'nanoajax'
import qs from 'qs'
import FolderSelect from './FolderSelect'
import {setObjByString} from '../utils/jsonObject'

export default class FormCreate {
constructor(parentForm) {
Expand All @@ -20,7 +21,7 @@ export default class FormCreate {
this._formInputs = [].slice.call(this._form.querySelectorAll('input, select'))
this._precontribTemplate = [].slice.call(this._form.querySelectorAll('[data-precontrib-templates]'))

this._selectTemplate = this._form.querySelector('[data-id="selectTemplate"]')
this._selectTemplate = this._form.querySelector('[data-id="abe_meta.template"]')
this._showHideSelect(this._selectTemplate)
this._handleBtnSelectTemplate = this._btnSelectTemplate.bind(this)

Expand Down Expand Up @@ -126,7 +127,8 @@ export default class FormCreate {
if (resultValue.indexOf('{') > -1) {
try {
var jsonValue = JSON.parse(resultValue)
values[id].push(jsonValue)
setObjByString(values, id, jsonValue);
// values[id].push(jsonValue)
}catch(e) {
// values[id].push(value)
}
Expand All @@ -140,7 +142,8 @@ export default class FormCreate {
if (value.indexOf('{') > -1) {
try {
var jsonValue = JSON.parse(value)
values[id] = [jsonValue]
// values[id] = [jsonValue]
setObjByString(values, id, [jsonValue]);

if (required && values[id].length == 0) {
isValid = false
Expand All @@ -150,7 +153,8 @@ export default class FormCreate {
// values[id].push(value)
}
}else {
values[id] = value
// values[id] = value
setObjByString(values, id, value);
if (required && values[id] == '') {
isValid = false
if(showErrors) parentNode.classList.add('has-error')
Expand Down
25 changes: 25 additions & 0 deletions src/server/public/abejs/scripts/utils/jsonObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export function setObjByString(obj, str, val) {
var keys, key;
//make sure str is a string with length
if (!str || !str.length || Object.prototype.toString.call(str) !== "[object String]") {
return false;
}
if (obj !== Object(obj)) {
//if it's not an object, make it one
obj = {};
}
keys = str.split(".");
while (keys.length > 1) {
key = keys.shift();
if (obj !== Object(obj)) {
//if it's not an object, make it one
obj = {};
}
if (!(key in obj)) {
//if obj doesn't contain the key, add it and set it to an empty object
obj[key] = {};
}
obj = obj[key];
}
return obj[keys[0]] = val;
}
2 changes: 1 addition & 1 deletion src/server/routes/post-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var route = function(req, res, next) {
var postName = folderName.pop()
folderName = folderName.join('/')

var p = cmsOperations.create(req.body.selectTemplate, folderName, postName, req, req.body)
var p = cmsOperations.create(req.body.abe_meta.template, folderName, postName, req, req.body)

p.then((resSave) => {
var result = {
Expand Down
5 changes: 4 additions & 1 deletion src/server/routes/post-duplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ var route = function(req, res, next) {
var postName = folderName.pop()
folderName = folderName.join('/')

var p = cmsOperations.duplicate(req.body.oldFilePath, req.body.selectTemplate, folderName, postName, req)
var oldFilePath = req.body.oldFilePath
delete req.body.oldFilePath

var p = cmsOperations.duplicate(oldFilePath, req.body.abe_meta.template, folderName, postName, req)

p.then((resSave) => {
var result = {
Expand Down
5 changes: 4 additions & 1 deletion src/server/routes/post-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ var route = function(req, res, next) {
var postName = folderName.pop()
folderName = folderName.join('/')

var p = cmsOperations.duplicate(req.body.oldFilePath, req.body.selectTemplate, folderName, postName, req, true)
var oldFilePath = req.body.oldFilePath
delete req.body.oldFilePath

var p = cmsOperations.duplicate(oldFilePath, req.body.abe_meta.template, folderName, postName, req, true)

p.then((resSave) => {
var result = {
Expand Down
2 changes: 1 addition & 1 deletion src/server/views/partials/create-form-template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="form-group">
<label for="selectTemplate" class="control-label">{{@root.text.template}} *</label>
<select class="form-control" id="selectTemplate" data-id="selectTemplate" data-required="true" name="selectTemplate" data-type-template-abe="true">
<select class="form-control" id="selectTemplate" data-id="abe_meta.template" data-required="true" data-maxlength="1" name="selectTemplate" data-type-template-abe="true">
<option></option>
{{#each @root.manager.list.templates}}
{{#ifCond @root.json.abe_meta.template name}}
Expand Down

0 comments on commit bf26625

Please sign in to comment.