Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AdFabConnect/abejs
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Oct 25, 2016
2 parents 3da7022 + 7c5d193 commit 3b09fad
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/cli/cms/operations/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export function reject(filePath, tplPath, json) {
error: resSave.error
}
} else if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){
resSave.success = 1
result = resSave
} else if(typeof resSave.json !== 'undefined' && resSave.json !== null){
result = {
Expand Down
4 changes: 3 additions & 1 deletion src/cli/cms/operations/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ export function save(url, tplPath, json = null, text = '', type = '', previousSa
export function saveJsonAndHtml(templateId, obj, html) {
var page = new Page(templateId, html, obj.json.content, true)

saveHtml(obj.html.path, page.html)
if (obj.json.content.abe_meta.status === 'publish') {
saveHtml(obj.html.path, page.html)
}
saveJson(obj.json.path, obj.json.content)

return {
Expand Down
8 changes: 4 additions & 4 deletions src/server/public/scripts/modules/EditorJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export default class Json {
alert(jsonRes.error)
return
}
if(typeof jsonRes.reject !== 'undefined' && jsonRes.reject !== null) {
location.reload()
return
}
// if(typeof jsonRes.reject !== 'undefined' && jsonRes.reject !== null) {
// location.reload()
// return
// }
this.data = jsonRes.json
}
catch(e){
Expand Down
10 changes: 9 additions & 1 deletion src/server/public/scripts/modules/EditorSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import {IframeNode} from '../utils/iframe'
import EditorUtils from './EditorUtils'
import Json from '../modules/EditorJson'
import on from 'on'

export default class EditorSave {
constructor() {
this._json = Json.instance
this._saveType = 'draft'

this.onFileSaved = on(this)

this._abeForm = document.querySelector('#abeForm')
this._abeDisplayStatus = document.querySelector('[data-display-status]')
this._abeFormSubmit = document.querySelector('#abeForm button[type=submit]')

this._handleSubmitClick = this._submitClick.bind(this)
Expand Down Expand Up @@ -137,7 +141,11 @@ export default class EditorSave {
target.classList.remove('done')
target.removeAttribute('disabled')

if(result.success === 1) location.reload()
this._abeDisplayStatus.innerHTML = result.json.abe_meta.status
if(result.success === 1) {
json = result.json
}
this.onFileSaved._fire()
}).catch(function(e) {
console.error(e)
})
Expand Down
4 changes: 4 additions & 0 deletions src/server/public/scripts/template-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class Engine {
'autoWidth': false
})
})

var abeReady = new Event('abeReady');
document.dispatchEvent(abeReady);
}

inject() {
Expand Down Expand Up @@ -107,6 +110,7 @@ class Engine {

var engine = new Engine()
window.abe = {
save: engine._save,
json: engine.json,
inputs: engine._inputs,
files: engine._files,
Expand Down
30 changes: 4 additions & 26 deletions src/server/routes/get-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,18 @@ var route = function(req, res, next) {

var filePathTest = cmsData.revision.getDocumentRevision(req.query.filePath)
if(typeof filePathTest !== 'undefined' && filePathTest !== null) {
// filePath = filePathTest.path
jsonPath = filePathTest.path
linkPath = filePathTest.abe_meta.link
}

if(jsonPath === null || !coreUtils.file.exist(jsonPath)) {
res.redirect('/abe/')
return
}
}

editor(templatePath, jsonPath, linkPath)
.then((result) => {
var manager = {}
var revisionFilePath = coreUtils.file.changePath(filePath, config.draft.url)
var dirPath = path.dirname(revisionFilePath)
var allDraft = cmsData.file.getFiles(dirPath, true, 99, new RegExp('\\.' + config.files.templates.extension))

allDraft = cmsData.metas.get(allDraft, 'draft')
var breadcrumb = req.params[0].split('/')
manager.file = {
revision: cmsData.revision.getFilesRevision(allDraft, cmsData.fileAttr.delete(revisionFilePath))
,template: breadcrumb
,path: (req.query.filePath) ? path.resolve(req.query.filePath).replace(/^\//, '') : ''
}
if(manager.file.revision.length > 0){
var publishPath = cmsData.fileAttr.delete(manager.file.revision[0].path.replace(new RegExp(`/${config.draft.url}/`), `/${config.publish.url}/`))
manager.file.isPublished = coreUtils.file.exist(publishPath)
}

resolve({
obj: result,
manager: manager
})
resolve(result)
}).catch(function(e) {
console.error(e)
})
Expand All @@ -97,9 +76,8 @@ var route = function(req, res, next) {
})

p.then((result) => {
var obj = result.obj
var manager = result.manager
// let tplUrl = result.tplUrl
var obj = result
var manager = {}

manager.home = {
files: Manager.instance.getList()
Expand Down
2 changes: 1 addition & 1 deletion src/server/views/partials/engine.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div class="abeform-wrapper">
<form class="text-i18n status-{{@root.json.abe_meta.status}}" id="abeForm">
<div class="display-status">
current status : {{@root.json.abe_meta.status}}
current status : <span data-display-status="true">{{@root.json.abe_meta.status}}</span>
</div>

<ul class="nav nav-tabs" role="tablist">
Expand Down

0 comments on commit 3b09fad

Please sign in to comment.