Sha256: e34f4e386d4deaa28544eda46a7edb8233eb3b337efe2f2684606b8b1e1db3f5

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 KB

Contents

import { isBlank } from '@/misc/utils'

export default (services) => ({
  // Fetch a page from an id (or a path)
  fetchPage({ commit, state: { site } }, id) {
    setTimeout(
      () =>
        services.page
          .findById(site, id)
          .then((page) => commit('SET_PAGE', page)),
      100,
    )
  },
  // Persist the content of a page (including or not the site content)
  async persistPage({
    commit,
    dispatch,
    state: { page, site, style },
    getters: { content, defaultPageAttributes },
  }) {
    commit('SET_SAVE_BUTTON_STATE', 'inProgress')

    const pageAttributes = {
      sections: content.pageSections,
      lockVersion: page.lockVersion,
      ...defaultPageAttributes,
    }
    const siteAttributes = isBlank(content.siteSections)
      ? { style }
      : {
          sections: content.siteSections,
          lockVersion: site.lockVersion,
          style,
        }

    return services.page
      .update(page.id, pageAttributes, siteAttributes)
      .then(() => {
        commit('SET_SAVE_BUTTON_STATE', 'success')
        commit('RESET_TOUCHED_SECTIONS')
        Promise.all([dispatch('fetchPage', page.id), dispatch('fetchSite')])
      })
      .catch(({ response: { status } }) => {
        commit('SET_SAVE_BUTTON_STATE', 'fail')
        console.log('[Maglev] could not save the page', status)
        if (status === 409) commit('OPEN_ERROR_MODAL', 'staleRecord')
      })
  },
  setCurrentPageSettings({ commit }, pageSettings) {
    commit('SET_PAGE_SETTINGS', pageSettings)
  },
})

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
maglevcms-1.1.5 app/frontend/editor/store/actions/page.js
maglevcms-1.1.4 app/frontend/editor/store/actions/page.js
maglevcms-1.1.3 app/frontend/editor/store/actions/page.js
maglevcms-1.1.2 app/frontend/editor/store/actions/page.js
maglevcms-1.1.1 app/frontend/editor/store/actions/page.js
maglevcms-1.1.0 app/frontend/editor/store/actions/page.js