2012-09-29 17:48:49 +09:00
|
|
|
Template.post_edit.helpers({
|
2013-01-13 08:52:35 +09:00
|
|
|
created: function(){
|
2013-10-06 09:17:37 +09:00
|
|
|
return moment(this.createdAt).format("MMMM Do, h:mm:ss a");
|
2013-01-13 08:52:35 +09:00
|
|
|
},
|
2012-10-10 08:32:49 +09:00
|
|
|
categories: function(){
|
2013-02-20 10:27:45 +09:00
|
|
|
var post = this;
|
|
|
|
return Categories.find().map(function(category) {
|
2013-04-06 13:44:52 +09:00
|
|
|
category.checked = _.contains(_.pluck(post.categories, '_id'), category._id) ? 'checked' : '';
|
2013-02-20 10:27:45 +09:00
|
|
|
return category;
|
|
|
|
});
|
2012-10-18 11:26:42 +09:00
|
|
|
},
|
2014-01-30 19:12:57 +00:00
|
|
|
categoriesEnabled: function(){
|
|
|
|
return Categories.find().count();
|
|
|
|
},
|
2013-01-13 08:52:35 +09:00
|
|
|
isApproved: function(){
|
2013-01-13 09:13:25 +09:00
|
|
|
return this.status == STATUS_APPROVED;
|
2013-01-13 08:52:35 +09:00
|
|
|
},
|
2013-01-13 09:13:25 +09:00
|
|
|
isSticky: function(){
|
|
|
|
return this.sticky ? 'checked' : '';
|
|
|
|
},
|
2014-05-01 19:58:56 -07:00
|
|
|
isSelected: function(parentPost){
|
|
|
|
return parentPost && this._id == parentPost.userId ? 'selected' : '';
|
2013-07-19 14:30:39 +03:00
|
|
|
},
|
2012-10-18 11:26:42 +09:00
|
|
|
submittedDate: function(){
|
2012-11-19 11:03:15 +09:00
|
|
|
return moment(this.submitted).format("MM/DD/YYYY");
|
|
|
|
},
|
|
|
|
submittedTime: function(){
|
|
|
|
return moment(this.submitted).format("HH:mm");
|
2012-10-23 12:24:38 +09:00
|
|
|
},
|
|
|
|
users: function(){
|
2013-02-10 08:15:31 +09:00
|
|
|
return Meteor.users.find().fetch();
|
2012-10-23 12:24:38 +09:00
|
|
|
},
|
|
|
|
userName: function(){
|
|
|
|
return getDisplayName(this);
|
|
|
|
},
|
2013-01-13 09:13:25 +09:00
|
|
|
hasStatusPending: function(){
|
|
|
|
return this.status == STATUS_PENDING ? 'checked' : '';
|
2012-10-24 11:04:42 +09:00
|
|
|
},
|
2013-01-13 09:13:25 +09:00
|
|
|
hasStatusApproved: function(){
|
|
|
|
return this.status == STATUS_APPROVED ? 'checked' : '';
|
2012-10-24 11:04:42 +09:00
|
|
|
},
|
2013-01-13 09:13:25 +09:00
|
|
|
hasStatusRejected: function(){
|
|
|
|
return this.status == STATUS_REJECTED ? 'checked' : '';
|
2013-07-04 12:05:09 +09:00
|
|
|
},
|
|
|
|
shorten: function(){
|
|
|
|
return !!getSetting('bitlyToken');
|
|
|
|
}
|
2012-09-29 17:48:49 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
Template.post_edit.rendered = function(){
|
2014-05-19 09:09:39 +09:00
|
|
|
var post = this.data.post;
|
2012-09-29 17:48:49 +09:00
|
|
|
if(post && !this.editor){
|
2013-07-19 14:30:39 +03:00
|
|
|
this.editor= new EpicEditor(EpicEditorOptions).load();
|
2014-05-19 09:09:39 +09:00
|
|
|
this.editor.importFile('editor', post.body);
|
2012-11-19 11:03:15 +09:00
|
|
|
|
|
|
|
$('#submitted_date').datepicker();
|
|
|
|
|
2012-09-29 17:48:49 +09:00
|
|
|
}
|
2013-07-19 12:17:49 +09:00
|
|
|
|
2014-05-01 19:58:56 -07:00
|
|
|
// $("#postUser").selectToAutocomplete(); // XXX
|
2013-07-19 14:30:39 +03:00
|
|
|
|
2012-09-29 17:48:49 +09:00
|
|
|
}
|
2012-09-13 11:05:49 +09:00
|
|
|
|
2013-11-24 16:13:53 +02:00
|
|
|
Template.post_edit.events({
|
2012-09-29 17:48:49 +09:00
|
|
|
'click input[type=submit]': function(e, instance){
|
2013-10-09 12:39:05 +09:00
|
|
|
var post = this;
|
|
|
|
var categories = [];
|
|
|
|
var url = $('#url').val();
|
|
|
|
var shortUrl = $('#short-url').val();
|
|
|
|
var status = parseInt($('input[name=status]:checked').val());
|
|
|
|
|
2012-09-06 10:14:03 +09:00
|
|
|
e.preventDefault();
|
2012-10-10 10:48:14 +09:00
|
|
|
if(!Meteor.user()){
|
|
|
|
throwError('You must be logged in.');
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-06 10:14:03 +09:00
|
|
|
|
2012-11-26 17:39:23 +09:00
|
|
|
$('input[name=category]:checked').each(function() {
|
2013-04-06 13:44:52 +09:00
|
|
|
var categoryId = $(this).val();
|
|
|
|
if(category = Categories.findOne(categoryId))
|
2013-03-15 15:17:44 +09:00
|
|
|
categories.push(category);
|
2012-11-26 17:39:23 +09:00
|
|
|
});
|
2013-07-19 14:30:39 +03:00
|
|
|
|
2012-11-26 17:37:47 +09:00
|
|
|
var properties = {
|
2012-12-20 17:30:54 +01:00
|
|
|
headline: $('#title').val(),
|
2013-07-19 14:30:39 +03:00
|
|
|
shortUrl: shortUrl,
|
2012-11-26 17:37:47 +09:00
|
|
|
body: instance.editor.exportFile(),
|
2012-11-26 17:39:23 +09:00
|
|
|
categories: categories,
|
2012-11-26 17:37:47 +09:00
|
|
|
};
|
2013-07-19 14:30:39 +03:00
|
|
|
|
2013-01-13 09:13:25 +09:00
|
|
|
if(url){
|
|
|
|
properties.url = (url.substring(0, 7) == "http://" || url.substring(0, 8) == "https://") ? url : "http://"+url;
|
|
|
|
}
|
|
|
|
|
2012-11-26 17:37:47 +09:00
|
|
|
if(isAdmin(Meteor.user())){
|
2013-01-13 08:52:35 +09:00
|
|
|
if(status == STATUS_APPROVED){
|
2013-03-04 10:55:46 +09:00
|
|
|
if(!post.submitted){
|
2013-01-13 09:52:40 +09:00
|
|
|
// this is the first time we are approving the post
|
2013-02-27 16:50:41 +09:00
|
|
|
properties.submitted = new Date().getTime();
|
2013-01-13 12:34:29 +09:00
|
|
|
}else if($('#submitted_date').exists()){
|
2013-01-13 09:52:40 +09:00
|
|
|
properties.submitted = parseInt(moment($('#submitted_date').val()+$('#submitted_time').val(), "MM/DD/YYYY HH:mm").valueOf());
|
|
|
|
}
|
2013-01-13 08:52:35 +09:00
|
|
|
}
|
2012-11-26 17:37:47 +09:00
|
|
|
adminProperties = {
|
|
|
|
sticky: !!$('#sticky').attr('checked'),
|
|
|
|
userId: $('#postUser').val(),
|
2013-01-13 10:21:09 +09:00
|
|
|
status: status,
|
2012-11-26 17:37:47 +09:00
|
|
|
};
|
|
|
|
properties = _.extend(properties, adminProperties);
|
|
|
|
}
|
|
|
|
|
2013-10-09 12:39:05 +09:00
|
|
|
Posts.update(post._id,{
|
|
|
|
$set: properties
|
|
|
|
}, function(error){
|
2012-10-10 10:48:14 +09:00
|
|
|
if(error){
|
2013-07-05 07:09:15 +09:00
|
|
|
console.log(error);
|
2012-10-10 10:48:14 +09:00
|
|
|
throwError(error.reason);
|
|
|
|
}else{
|
2013-10-06 09:17:37 +09:00
|
|
|
trackEvent("edit post", {'postId': post._id});
|
|
|
|
Router.go("/posts/"+post._id);
|
2012-10-10 10:48:14 +09:00
|
|
|
}
|
2013-10-09 12:39:05 +09:00
|
|
|
});
|
2013-07-19 14:30:39 +03:00
|
|
|
},
|
|
|
|
'click .delete-link': function(e){
|
2013-10-09 12:39:05 +09:00
|
|
|
var post = this;
|
|
|
|
|
2012-09-07 10:57:57 +09:00
|
|
|
e.preventDefault();
|
2013-10-09 12:39:05 +09:00
|
|
|
|
2012-09-07 10:57:57 +09:00
|
|
|
if(confirm("Are you sure?")){
|
2014-03-20 23:00:15 +05:30
|
|
|
Router.go("/");
|
2013-10-06 09:17:37 +09:00
|
|
|
Meteor.call("deletePostById", post._id, function(error) {
|
2013-07-19 14:30:39 +03:00
|
|
|
if (error) {
|
|
|
|
console.log(error);
|
|
|
|
throwError(error.reason);
|
|
|
|
} else {
|
2014-03-20 23:00:15 +05:30
|
|
|
throwError('Your post has been deleted.');
|
2013-07-19 14:30:39 +03:00
|
|
|
}
|
|
|
|
});
|
2012-09-07 10:57:57 +09:00
|
|
|
}
|
|
|
|
}
|
2013-11-24 16:13:53 +02:00
|
|
|
});
|