Vulcan/client/templates/post_submit.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2012-09-06 11:09:24 +09:00
Template.post_submit.events = {
'click input[type=submit]': function(e, instance){
2012-09-07 18:17:19 +09:00
e.preventDefault();
if(!Meteor.user()){
throwError('You must be logged in.');
return false;
}
2012-08-31 19:41:54 -04:00
var title= $('#title').val();
var url = $('#url').val();
var body = instance.editor.exportFile();
2012-08-31 19:41:54 -04:00
var postId = Posts.insert({
headline: title
, url: url
, body: body
, userId: Meteor.user()._id
, author: Meteor.user().username
2012-08-31 19:41:54 -04:00
, submitted: new Date().getTime()
, votes: 0
, comments: 0
2012-09-28 17:20:49 +09:00
, baseScore: 0
2012-09-17 12:51:35 +09:00
, score: 0
2012-08-31 19:41:54 -04:00
});
var post = Posts.findOne(postId);
2012-09-20 16:07:29 +09:00
Meteor.call('upvotePost', postId);
2012-08-31 19:41:54 -04:00
trackEvent("new post", {'postId': postId});
2012-09-24 11:31:45 +09:00
Router.navigate('posts/'+postId, {trigger: true});
2012-08-31 19:41:54 -04:00
}
2012-09-07 18:17:19 +09:00
,'click .get-title-link': function(e){
e.preventDefault();
var url=$("#url").val();
$(".get-title-link").addClass("loading");
if(url){
$.get(url, function(response){
if ((suggestedTitle=((/<title>(.*?)<\/title>/m).exec(response.responseText))) != null){
$("#title").val(suggestedTitle[1]);
}else{
alert("Sorry, couldn't find a title...");
}
$(".get-title-link").removeClass("loading");
});
}else{
alert("Please fill in an URL first!");
}
}
2012-09-13 11:05:49 +09:00
};
Template.post_submit.rendered = function(){
this.editor= new EpicEditor(EpicEditorOptions).load();
}