further ux improvements to branch
This commit is contained in:
@ -54,8 +54,10 @@ exports.recent = function(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.preSubmit = function(req, res, next) {
|
exports.preSubmit = function(req, res, next) {
|
||||||
|
|
||||||
var data = req.params.newStory;
|
var data = req.params.newStory;
|
||||||
|
|
||||||
|
|
||||||
data = data.replace(/url=/gi, '').replace(/&title=/gi, ',').split(',');
|
data = data.replace(/url=/gi, '').replace(/&title=/gi, ',').split(',');
|
||||||
var url = data[0];
|
var url = data[0];
|
||||||
var title = data[1];
|
var title = data[1];
|
||||||
@ -177,16 +179,38 @@ exports.comments = function(req, res, next) {
|
|||||||
|
|
||||||
exports.newStory = function(req, res, next) {
|
exports.newStory = function(req, res, next) {
|
||||||
var url = req.body.data.url;
|
var url = req.body.data.url;
|
||||||
|
debug('In pre submit with a url', url);
|
||||||
|
|
||||||
|
Story.find({'link': url}, function(err, story) {
|
||||||
|
debug('Attempting to find a story');
|
||||||
|
if (err) {
|
||||||
|
debug('oops');
|
||||||
|
return res.status(500);
|
||||||
|
}
|
||||||
|
if (story.length) {
|
||||||
|
debug('Found a story already, here\'s the return from find', story);
|
||||||
|
req.flash('errors', {
|
||||||
|
msg: "Someone's already posted that link. Here's the discussion."
|
||||||
|
});
|
||||||
|
debug('Redirecting the user with', story[0].storyLink);
|
||||||
|
res.json({
|
||||||
|
alreadyPosted: true,
|
||||||
|
storyURL: story.pop().storyLink
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
resources.getURLTitle(url, processResponse);
|
resources.getURLTitle(url, processResponse);
|
||||||
function processResponse(err, storyTitle) {
|
function processResponse(err, storyTitle) {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.json({
|
res.json({
|
||||||
|
alreadyPosted: false,
|
||||||
storyURL: url,
|
storyURL: url,
|
||||||
storyTitle: ''
|
storyTitle: ''
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
storyTitle = storyTitle ? storyTitle : '';
|
storyTitle = storyTitle ? storyTitle : '';
|
||||||
res.json({
|
res.json({
|
||||||
|
alreadyPosted: false,
|
||||||
storyURL: url,
|
storyURL: url,
|
||||||
storyTitle: storyTitle.title
|
storyTitle: storyTitle.title
|
||||||
});
|
});
|
||||||
|
@ -42,6 +42,9 @@
|
|||||||
$('#preliminary-story-submit').attr('disabled', false);
|
$('#preliminary-story-submit').attr('disabled', false);
|
||||||
})
|
})
|
||||||
.done(function (data, textStatus, xhr) {
|
.done(function (data, textStatus, xhr) {
|
||||||
|
if (data.alreadyPosted) {
|
||||||
|
window.location = '/stories/' + data.storyURL;
|
||||||
|
}
|
||||||
window.location = '/stories/submit/url=' +
|
window.location = '/stories/submit/url=' +
|
||||||
encodeURIComponent(data.storyURL) +
|
encodeURIComponent(data.storyURL) +
|
||||||
'&title=' + encodeURIComponent(data.storyTitle);
|
'&title=' + encodeURIComponent(data.storyTitle);
|
||||||
|
@ -26,8 +26,7 @@
|
|||||||
.col-xs-12.negative-15
|
.col-xs-12.negative-15
|
||||||
span Posted #{timeAgo}
|
span Posted #{timeAgo}
|
||||||
span by
|
span by
|
||||||
a(href="/" + author.username)
|
a(href="/" + author.username) @#{author.username}
|
||||||
@#{author.username}
|
|
||||||
.col-xs-10.col-xs-offset-1
|
.col-xs-10.col-xs-offset-1
|
||||||
p= description
|
p= description
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
.col-xs-12.col-md-1
|
.col-xs-12.col-md-1
|
||||||
label.control-label.control-label-story-submission(for='name') Title
|
label.control-label.control-label-story-submission(for='name') Title
|
||||||
.col-xs-12.col-md-11
|
.col-xs-12.col-md-11
|
||||||
input#story-title.form-control(placeholder='Type a headline for your link here', name='Title')
|
input#story-title.form-control(placeholder='Type a headline for your link here', name='Title', autofocus)
|
||||||
.form-group
|
.form-group
|
||||||
.col-xs-12.col-md-1
|
.col-xs-12.col-md-1
|
||||||
label.control-label.control-label-story-submission(for='name') Description
|
label.control-label.control-label-story-submission(for='name') Description
|
||||||
|
Reference in New Issue
Block a user