Refactor post flow, get url info back from server, redirect to final submission form

This commit is contained in:
Nathan Leniz
2015-03-07 17:42:22 +09:00
parent b655cb7532
commit 9bea52d42f
6 changed files with 108 additions and 26 deletions

View File

@@ -53,6 +53,16 @@ exports.recent = function(req, res, next) {
});
};
exports.preSubmit = function(req, res, next) {
var data = req.params.newStory;
debug('got presubmission with info', data.url, data.title);
res.render('stories/index', {
page: 'storySubmission',
storyURL: data.url,
storyTitle: data.title
});
};
exports.returnIndividualStory = function(req, res, next) {
var dashedName = req.params.storyName;
@@ -166,6 +176,26 @@ exports.comments = function(req, res, next) {
});
};
exports.newStory = function(req, res, next) {
var url = req.body.data.url;
debug('Got new story submission, calling resources with', url);
resources.getURLTitle(url, processResponse);
function processResponse(err, storyTitle) {
if (err) {
res.json({
storyURL: url,
storyTitle: ''
});
} else {
storyTitle = storyTitle ? storyTitle : '';
res.json({
storyURL: url,
storyTitle: storyTitle.title
});
}
}
};
exports.storySubmission = function(req, res, next) {
var data = req.body.data;
var storyLink = data.headline