2012-10-10 08:32:49 +09:00
|
|
|
Template.post_submit.helpers({
|
|
|
|
categories: function(){
|
|
|
|
return Categories.find();
|
2012-10-23 12:24:38 +09:00
|
|
|
},
|
|
|
|
users: function(){
|
|
|
|
return Meteor.users.find();
|
|
|
|
},
|
|
|
|
userName: function(){
|
|
|
|
return getDisplayName(this);
|
|
|
|
},
|
|
|
|
isSelected: function(){
|
|
|
|
var post=Posts.findOne(Session.get('selectedPostId'));
|
|
|
|
return post && this._id == post.userId;
|
2012-10-10 08:32:49 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-23 12:24:38 +09:00
|
|
|
Template.post_submit.rendered = function(){
|
|
|
|
Session.set('selectedPostId', null);
|
|
|
|
}
|
|
|
|
|
|
|
|
Template.post_submit.rendered = function(){
|
|
|
|
this.editor= new EpicEditor(EpicEditorOptions).load();
|
|
|
|
$('#submitted').datepicker().on('changeDate', function(ev){
|
|
|
|
$('#submitted_hidden').val(moment(ev.date).valueOf());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-06 11:09:24 +09:00
|
|
|
Template.post_submit.events = {
|
2012-09-29 17:48:49 +09:00
|
|
|
'click input[type=submit]': function(e, instance){
|
2012-09-07 18:17:19 +09:00
|
|
|
e.preventDefault();
|
2012-10-01 18:48:46 +09:00
|
|
|
|
|
|
|
$(e.target).addClass('disabled');
|
|
|
|
|
2012-09-20 09:13:48 +09:00
|
|
|
if(!Meteor.user()){
|
|
|
|
throwError('You must be logged in.');
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-31 19:41:54 -04:00
|
|
|
|
2012-09-02 12:33:05 +09:00
|
|
|
var title= $('#title').val();
|
|
|
|
var url = $('#url').val();
|
2012-09-29 17:48:49 +09:00
|
|
|
var body = instance.editor.exportFile();
|
2012-10-10 08:32:49 +09:00
|
|
|
var categories=[];
|
2012-10-23 12:24:38 +09:00
|
|
|
var sticky=!!$('#sticky').attr('checked');
|
|
|
|
var submitted = $('#submitted_hidden').val();
|
|
|
|
var userId = $('#postUser').val();
|
2012-10-10 08:32:49 +09:00
|
|
|
|
|
|
|
$('input[name=category]:checked').each(function() {
|
|
|
|
categories.push($(this).val());
|
|
|
|
});
|
|
|
|
|
2012-10-04 11:45:12 +10:00
|
|
|
Meteor.call('post', {
|
|
|
|
headline: title,
|
|
|
|
body: body,
|
2012-10-10 08:32:49 +09:00
|
|
|
url: url,
|
|
|
|
categories: categories,
|
2012-10-23 12:24:38 +09:00
|
|
|
sticky: sticky,
|
|
|
|
submitted: submitted,
|
|
|
|
userId: userId
|
2012-10-24 11:04:42 +09:00
|
|
|
}, function(error, post) {
|
2012-10-06 13:15:55 +09:00
|
|
|
if(error){
|
|
|
|
console.log(error);
|
|
|
|
throwError(error.reason);
|
2012-10-09 15:34:00 +09:00
|
|
|
clearSeenErrors();
|
|
|
|
$(e.target).removeClass('disabled');
|
2012-10-06 13:15:55 +09:00
|
|
|
}else{
|
2012-10-24 11:04:42 +09:00
|
|
|
trackEvent("new post", {'postId': post.postId});
|
|
|
|
if(post.status === STATUS_PENDING)
|
|
|
|
throwError('Thanks, your post is awaiting approval.')
|
|
|
|
Router.navigate('posts/'+post.postId, {trigger: true});
|
2012-10-06 13:15:55 +09:00
|
|
|
}
|
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-10-23 12:24:38 +09:00
|
|
|
};
|