2012-10-10 08:32:49 +09:00
|
|
|
Template.post_submit.helpers({
|
2014-01-30 19:12:57 +00:00
|
|
|
categoriesEnabled: function(){
|
|
|
|
return Categories.find().count();
|
|
|
|
},
|
2012-10-10 08:32:49 +09:00
|
|
|
categories: function(){
|
|
|
|
return Categories.find();
|
2012-10-23 12:24:38 +09:00
|
|
|
},
|
|
|
|
users: function(){
|
2014-06-22 08:57:20 +09:00
|
|
|
return Meteor.users.find({}, {sort: {'profile.name': 1}});
|
2012-10-23 12:24:38 +09:00
|
|
|
},
|
|
|
|
userName: function(){
|
|
|
|
return getDisplayName(this);
|
|
|
|
},
|
|
|
|
isSelected: function(){
|
|
|
|
var post=Posts.findOne(Session.get('selectedPostId'));
|
2014-04-30 16:58:11 -07:00
|
|
|
return (post && this._id == post.userId) ? 'selected' : '';
|
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);
|
2012-11-19 12:03:06 +09:00
|
|
|
if(!this.editor && $('#editor').exists())
|
2012-11-01 10:27:34 +09:00
|
|
|
this.editor= new EpicEditor(EpicEditorOptions).load();
|
2012-10-23 12:24:38 +09:00
|
|
|
$('#submitted').datepicker().on('changeDate', function(ev){
|
|
|
|
$('#submitted_hidden').val(moment(ev.date).valueOf());
|
|
|
|
});
|
2013-07-19 12:17:49 +09:00
|
|
|
|
2014-05-01 19:58:56 -07:00
|
|
|
// $("#postUser").selectToAutocomplete(); // XXX
|
2013-07-19 12:17:49 +09:00
|
|
|
|
2012-10-23 12:24:38 +09:00
|
|
|
}
|
|
|
|
|
2013-11-24 16:13:53 +02: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()){
|
2013-11-04 18:45:03 +01:00
|
|
|
throwError(i18n.t('You must be logged in.'));
|
2012-09-20 09:13:48 +09:00
|
|
|
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();
|
2013-07-04 11:16:11 +09:00
|
|
|
var shortUrl = $('#short-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-30 13:33:52 +09:00
|
|
|
var status = parseInt($('input[name=status]:checked').val());
|
2012-10-10 08:32:49 +09:00
|
|
|
|
|
|
|
$('input[name=category]:checked').each(function() {
|
2013-02-18 13:38:15 +09:00
|
|
|
categories.push(Categories.findOne($(this).val()));
|
2012-10-10 08:32:49 +09:00
|
|
|
});
|
|
|
|
|
2013-01-13 08:52:35 +09:00
|
|
|
var properties = {
|
2014-05-16 09:19:35 +09:00
|
|
|
title: title
|
2012-10-30 13:33:52 +09:00
|
|
|
, body: body
|
2013-07-04 11:16:11 +09:00
|
|
|
, shortUrl: shortUrl
|
2012-10-30 13:33:52 +09:00
|
|
|
, categories: categories
|
|
|
|
, sticky: sticky
|
|
|
|
, submitted: submitted
|
|
|
|
, userId: userId
|
|
|
|
, status: status
|
2013-01-13 08:52:35 +09:00
|
|
|
};
|
2013-02-20 10:27:45 +09:00
|
|
|
if(url){
|
|
|
|
var cleanUrl = (url.substring(0, 7) == "http://" || url.substring(0, 8) == "https://") ? url : "http://"+url;
|
2013-01-13 08:52:35 +09:00
|
|
|
properties.url = cleanUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.call('post', properties, function(error, post) {
|
2012-10-06 13:15:55 +09:00
|
|
|
if(error){
|
|
|
|
throwError(error.reason);
|
2012-10-09 15:34:00 +09:00
|
|
|
clearSeenErrors();
|
|
|
|
$(e.target).removeClass('disabled');
|
2012-10-30 12:01:11 +09:00
|
|
|
if(error.error == 603)
|
2013-10-09 21:49:02 +09:00
|
|
|
Router.go('/posts/'+error.details);
|
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.')
|
2013-10-09 21:49:02 +09:00
|
|
|
Router.go('/posts/'+post.postId);
|
2012-10-06 13:15:55 +09:00
|
|
|
}
|
2012-08-31 19:41:54 -04:00
|
|
|
});
|
2013-11-24 16:13:53 +02:00
|
|
|
},
|
|
|
|
'click .get-title-link': function(e){
|
2012-09-07 18:17:19 +09:00
|
|
|
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...");
|
2013-01-09 22:48:23 -03:00
|
|
|
}
|
2013-01-09 23:50:26 -03:00
|
|
|
$(".get-title-link").removeClass("loading");
|
|
|
|
});
|
2012-09-07 18:17:19 +09:00
|
|
|
}else{
|
|
|
|
alert("Please fill in an URL first!");
|
2013-01-09 23:50:26 -03:00
|
|
|
$(".get-title-link").removeClass("loading");
|
2012-09-07 18:17:19 +09:00
|
|
|
}
|
|
|
|
}
|
2013-07-04 11:16:11 +09:00
|
|
|
|
2013-11-24 16:13:53 +02:00
|
|
|
});
|