Skip to content

Commit

Permalink
Merge pull request #105 from nymag/create-page
Browse files Browse the repository at this point in the history
just get /pages/new and clone it
  • Loading branch information
nelsonpecora committed Jul 28, 2015
2 parents 56c6301 + 80d0cd7 commit 0688624
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
23 changes: 7 additions & 16 deletions controllers/editor-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

var EditorToolbar,
dom = require('../services/dom'),
db = require('../services/db'),
references = require('../services/references'),
forms = require('../services/forms'),
edit = require('../services/edit'),
Expand All @@ -24,19 +23,15 @@ function publish() {

/**
* Create a new page with the same layout as the current page.
* @param {string} layoutName
* currently, this just clones the current page
* (cloning special "new" instances of the page-specific components)
* e.g. /components/article/instances/new
* @returns {Promise}
*/
function createPage(layoutName) {
function createPage() {
// todo: allow users to choose their layout / components

var articlePage = {
layout: '/components/' + layoutName + '/instances/article',
main: '/components/story'
};

db.postToReference('/pages', articlePage).then(function (res) {
location.href = res[references.referenceProperty] + '.html?edit=true';
}).catch(console.error);
return edit.createPage();
}

/**
Expand Down Expand Up @@ -79,11 +74,7 @@ EditorToolbar.prototype = {
/**
* On new page button
*/
onNewPage: function () {
var layoutName = dom.find('[data-layout]').getAttribute('data-layout');

createPage(layoutName);
},
onNewPage: createPage,

/**
* On edit settings button
Expand Down
16 changes: 16 additions & 0 deletions services/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,21 @@ function publishPage() {
});
}

/**
* create a new page, cloning the current page
* @returns {Promise}
*/
function createPage() {
var path = '/pages/new';

return getDataOnly(path).then(function (data) {
delete data._ref;
return db.postToReference('/pages', data).then(function (res) {
location.href = res[references.referenceProperty] + '.html?edit=true';
}).catch(console.error);
});
}

// expose main methods (alphabetical)
module.exports = {
addSchemaToData: addSchemaToData,
Expand All @@ -301,6 +316,7 @@ module.exports = {
removeSchemaFromData: removeSchemaFromData,
removeGroupFieldsFromData: removeGroupFieldsFromData,
publishPage: publishPage,
createPage: createPage,
setSchemaCache: setSchemaCache,
setDataCache: setDataCache,
update: update,
Expand Down

0 comments on commit 0688624

Please sign in to comment.