Skip to content

Commit

Permalink
refactoring: precontribution 33
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Nov 17, 2016
1 parent 46c1b56 commit 5f12f59
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 147 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 @@ -56,7 +56,7 @@ export default class Form {
type: 'text',
value: '',
visible: true,
precontribTemplate: ""
precontribTemplate: ''
}

obj = extend(true, defaultValues, obj)
Expand Down
6 changes: 3 additions & 3 deletions src/cli/cms/editor/handlebars/printBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function printBlock (ctx, obj) {
<label class="title">${ctx[0].block}</label>
<div class='single-block well well-sm'>`
Array.prototype.forEach.call(ctx, (item) => {
if (precontrib) item.value = ""
if (precontrib) item.value = ''
res += printInput(item)
})
res += '</div></div>'
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function printBlock (ctx, obj) {
<div id="${key}${i}" class="collapse" >
`
Array.prototype.forEach.call(arrItem[i], (item) => {
if (precontrib) item.value = ""
if (precontrib) item.value = ''
res += printInput(item)
})
res += '</div></div>'
Expand All @@ -65,7 +65,7 @@ export default function printBlock (ctx, obj) {
</div>
</div>`
}else {
if (precontrib) ctx[0].value = ""
if (precontrib) ctx[0].value = ''
res += printInput(ctx[0])
}
return res
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cms/editor/handlebars/printInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function printInput () {
last-values='${lastValues}'>`

if (!params.required) {
res += `<option value=''></option>`
res += '<option value=\'\'></option>'
}

if(typeof params.source === 'object' && Object.prototype.toString.call(params.source) === '[object Array]') {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/cms/templates/handlebars/setVariable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* Handlebars helper, to add variable inside template file
*/
export default function setVariable(varName, varValue, options){
options.data.root[varName] = varValue;
};
options.data.root[varName] = varValue
}
2 changes: 1 addition & 1 deletion src/cli/cms/templates/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export function setAbePrecontribDefaultValueIfDoesntExist(templateText) {

export function getAbePrecontribFromTemplates(templatesList) {
var fields = []
var precontributionTemplate = ""
var precontributionTemplate = ''
Array.prototype.forEach.call(templatesList, (file) => {
var templateText = setAbePrecontribDefaultValueIfDoesntExist(file.template)

Expand Down
1 change: 0 additions & 1 deletion src/server/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import path from 'path'
import {
cmsData,
cmsEditor,
coreUtils,
abeEngine,
cmsTemplates,
abeExtend
Expand Down
2 changes: 1 addition & 1 deletion src/server/helpers/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
coreUtils
} from '../../cli'

var page = function (req, res, next) {
var page = function (req, res) {
var html = (req.query.html) ? true : false
var json = null
var editor = false
Expand Down
1 change: 0 additions & 1 deletion src/server/middlewares/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fse from 'fs-extra'

import {
coreUtils,
cmsData,
config,
abeExtend
} from '../../cli'
Expand Down
4 changes: 2 additions & 2 deletions src/server/public/scripts/modules/EditorAutocomplete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global document */
/*global document, json */

import EditorUtils from '../modules/EditorUtils'
import Json from '../modules/EditorJson'
Expand Down Expand Up @@ -250,7 +250,7 @@ export default class EditorAutocomplete {
var match
while (match = /\{\{(.*?)\}\}/.exec(dataVal)) {
var selector = target.form.querySelector('[data-id="' + match[1] + '"]')
if(selector != null) dataVal = dataVal.replace('{{' + match[1] + '}}', selector.value);
if(selector != null) dataVal = dataVal.replace('{{' + match[1] + '}}', selector.value)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/public/scripts/modules/EditorManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global document, top, $, location, confirm, window */
/*global document, top, $, location, confirm, window, alert */

import Nanoajax from 'nanoajax'
import qs from 'qs'
Expand Down
2 changes: 1 addition & 1 deletion src/server/public/scripts/modules/EditorReload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global document, window */
/*global document, window, json */

import Handlebars from 'handlebars'
import Nanoajax from 'nanoajax'
Expand Down
2 changes: 1 addition & 1 deletion src/server/public/scripts/modules/EditorSave.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global document, CONFIG, window, json, alert, location */
/*global document, window, json, alert */

import {IframeNode} from '../utils/iframe'
import EditorUtils from './EditorUtils'
Expand Down
21 changes: 9 additions & 12 deletions src/server/public/scripts/modules/FolderSelect.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*global document */

export default class FolderSelect {
constructor() {

constructor(form) {
this._form = form
// constante variable
this._selectTemplate = document.querySelector('#selectTemplate')
this._selectsWebsite = document.querySelector('#level-1')
this._selectsCreate = [].slice.call(document.querySelectorAll('select[id*="level-"]'))
this._selectTemplate = this._form.querySelector('#selectTemplate')
this._selectsWebsite = this._form.querySelector('#level-1')
this._selectsCreate = [].slice.call(this._form.querySelectorAll('select[id*="level-"]'))

// constante methode
this._handleChangeSelectsCreate = this._changeSelectsCreate.bind(this)
Expand Down Expand Up @@ -41,7 +40,7 @@ export default class FolderSelect {
}

_hideSubLevels(i) {
var levels = [].slice.call(document.querySelectorAll('.level-' + i))
var levels = [].slice.call(this._form.querySelectorAll('.level-' + i))
while(levels.length > 0){
levels.forEach((level) => {
var options = [].slice.call(level.querySelectorAll('option'))
Expand All @@ -51,18 +50,16 @@ export default class FolderSelect {
})
level.classList.add('hidden')
})
levels = [].slice.call(document.querySelectorAll('.level-' + i++))
levels = [].slice.call(this._form.querySelectorAll('.level-' + i++))
}
}

_showSubLevels(i, dataShow) {
var levels = [].slice.call(document.querySelectorAll('.level-' + i))
var level1selected = document.querySelector('.level-1 select').value
var levels = [].slice.call(this._form.querySelectorAll('.level-' + i))
levels.forEach((level) => {
level.classList.add('hidden')

// console.log([].slice.call(document.querySelectorAll(`[data-shown=${dataShow}][data-parent=${level1selected}]`)))
var childs = [].slice.call(document.querySelectorAll(`[data-shown=${dataShow}]`))
var childs = [].slice.call(this._form.querySelectorAll(`[data-shown=${dataShow}]`))
if(childs) {
childs.forEach(function (child) {
var options = [].slice.call(child.querySelectorAll('option'))
Expand Down
44 changes: 19 additions & 25 deletions src/server/public/scripts/modules/FormCreate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/*global document, window, alert */
/*global document, window, alert, slugs, CONFIG */

import limax from 'limax'
import Nanoajax from 'nanoajax'
import qs from 'qs'
import FolderSelect from './FolderSelect'
import TemplateSelect from './TemplateSelect'

export default class FormCreate {
constructor(parentForm) {
Expand Down Expand Up @@ -34,7 +33,7 @@ export default class FormCreate {
this._handleBlurEvent = this._blurEvent.bind(this)

// // init modules
new FolderSelect()
new FolderSelect(this._form)

this._bindEvents()

Expand Down Expand Up @@ -64,7 +63,7 @@ export default class FormCreate {
}.bind(this))
}

_blurEvent(e) {
_blurEvent() {
this._setSlug(false)
}

Expand Down Expand Up @@ -93,10 +92,9 @@ export default class FormCreate {

_setSlug(showErrors) {
var values = {}
var postName = ""
var postPath = ""
var postPath = ''
var isValid = true
if (this._selectedTemplate != null && this._selectedTemplate != "") {
if (this._selectedTemplate != null && this._selectedTemplate != '') {

Array.prototype.forEach.call(this._formInputs, function(input) {
var parentNode = input.parentNode
Expand All @@ -108,16 +106,15 @@ export default class FormCreate {
input.parentNode.classList.remove('error')
if (linkedTpl == null || linkedTpl == this._selectedTemplate) {
var id = input.getAttribute('data-id')
var autocomplete = input.getAttribute('data-autocomplete') == "true" ? true : false
var required = input.getAttribute('data-required') == "true" ? true : false
var autocomplete = input.getAttribute('data-autocomplete') == 'true' ? true : false
var required = input.getAttribute('data-required') == 'true' ? true : false
var value = input.value

if (autocomplete) {
var results = input.parentNode.querySelectorAll('.autocomplete-result')
var autocompleteValue = ""
values[id] = []
Array.prototype.forEach.call(results, function(result) {
var resultValue = result.getAttribute("value")
var resultValue = result.getAttribute('value')
if (resultValue.indexOf('{') > -1) {
try {
var jsonValue = JSON.parse(resultValue)
Expand Down Expand Up @@ -146,15 +143,14 @@ export default class FormCreate {
}
}else {
values[id] = value
if (required && values[id] == "") {
if (required && values[id] == '') {
isValid = false
if(showErrors) parentNode.classList.add('has-error')
}
}
}
}
}.bind(this))
var filePath = postPath + postName

var slug = slugs[this._selectedTemplate]
var slugMatches = slug.match(/{{.*?}}/g)
Expand All @@ -171,10 +167,9 @@ export default class FormCreate {
}
}.bind(this))

var postPath = ""
var slugPaths = document.querySelectorAll('[data-slug-type=path]')
Array.prototype.forEach.call(slugPaths, function(slugPath) {
if (slugPath.value != null && slugPath.value != "") {
if (slugPath.value != null && slugPath.value != '') {
postPath += slugPath.value + '/'
}
})
Expand All @@ -183,22 +178,22 @@ export default class FormCreate {
isValid = false
}

var breadcrumbs = postPath.split('/');
var breadcrumbsHtml = "";
var breadcrumbs = postPath.split('/')
var breadcrumbsHtml = ''
Array.prototype.forEach.call(breadcrumbs, function(breadcrumb) {
var breadcrumbNames = breadcrumb.split('-')
breadcrumbsHtml += '<li>';
breadcrumbsHtml += '<li>'
Array.prototype.forEach.call(breadcrumbNames, function(breadcrumbName) {
if (breadcrumbName == "" && showErrors) {
breadcrumbsHtml += '<a href="#" class="btn-danger">...</a>-';
if (breadcrumbName == '' && showErrors) {
breadcrumbsHtml += '<a href="#" class="btn-danger">...</a>-'
}else {
breadcrumbsHtml += '<a href="#">' + breadcrumbName + '</a>-';
breadcrumbsHtml += '<a href="#">' + breadcrumbName + '</a>-'
}
}.bind(this))
breadcrumbsHtml = breadcrumbsHtml.replace(/-$/, '')
breadcrumbsHtml += '</li>';
breadcrumbsHtml += '</li>'
})
breadcrumbsHtml += '<span>.' + CONFIG.EXTENSION + '</span>';
breadcrumbsHtml += '<span>.' + CONFIG.EXTENSION + '</span>'
this._previewPostPath.innerHTML = breadcrumbsHtml

return {
Expand All @@ -208,7 +203,7 @@ export default class FormCreate {
}
}

_submit(type, target) {
_submit(type) {
var res = this._setSlug(true)
var toSave = qs.stringify(res.values)

Expand All @@ -226,7 +221,6 @@ export default class FormCreate {
window.location.href = window.location.origin + '/abe' + jsonRes.json.abe_meta.link
}else {
alert('error')
btn.classList.remove('disable')
}
})
}
Expand Down
29 changes: 0 additions & 29 deletions src/server/public/scripts/modules/TemplateSelect.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/server/public/scripts/template-engine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global document, window, $ */
/*global document, window, $, Event */

import {Devtool} from './devtool/Devtool'

Expand Down
Loading

0 comments on commit 5f12f59

Please sign in to comment.