further ux improvements to branch

This commit is contained in:
Michael Q Larson
2015-03-07 17:38:47 -08:00
parent 87ac659038
commit 0a741f0e54
4 changed files with 29 additions and 3 deletions

View File

@ -54,8 +54,10 @@ exports.recent = function(req, res, next) {
};
exports.preSubmit = function(req, res, next) {
var data = req.params.newStory;
data = data.replace(/url=/gi, '').replace(/&title=/gi, ',').split(',');
var url = data[0];
var title = data[1];
@ -177,16 +179,38 @@ exports.comments = function(req, res, next) {
exports.newStory = function(req, res, next) {
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);
function processResponse(err, storyTitle) {
if (err) {
res.json({
alreadyPosted: false,
storyURL: url,
storyTitle: ''
});
} else {
storyTitle = storyTitle ? storyTitle : '';
res.json({
alreadyPosted: false,
storyURL: url,
storyTitle: storyTitle.title
});

View File

@ -42,6 +42,9 @@
$('#preliminary-story-submit').attr('disabled', false);
})
.done(function (data, textStatus, xhr) {
if (data.alreadyPosted) {
window.location = '/stories/' + data.storyURL;
}
window.location = '/stories/submit/url=' +
encodeURIComponent(data.storyURL) +
'&title=' + encodeURIComponent(data.storyTitle);

View File

@ -26,8 +26,7 @@
.col-xs-12.negative-15
span Posted #{timeAgo}
span  by 
a(href="/" + author.username)
@#{author.username}
a(href="/" + author.username) @#{author.username}
.col-xs-10.col-xs-offset-1
p= description

View File

@ -14,7 +14,7 @@
.col-xs-12.col-md-1
label.control-label.control-label-story-submission(for='name') Title
.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
.col-xs-12.col-md-1
label.control-label.control-label-story-submission(for='name') Description