2012-10-02 10:54:04 +09:00
|
|
|
// Template.post_edit.preserve(['#title', '#url', '#editor', '#sticky']);
|
|
|
|
|
|
|
|
// Template.post_edit.preserve({
|
|
|
|
// // 'input[id]': function (node) { return node.id; }
|
|
|
|
// '[name]': function(node) { return node.getAttribute('name');}
|
|
|
|
// });
|
2012-09-29 17:48:49 +09:00
|
|
|
|
|
|
|
Template.post_edit.helpers({
|
|
|
|
post: function(){
|
2012-10-18 13:40:11 +11:00
|
|
|
return Posts.findOne(Session.get('selectedPostId'));
|
2012-10-10 08:32:49 +09:00
|
|
|
},
|
|
|
|
categories: function(){
|
|
|
|
return Categories.find();
|
|
|
|
},
|
|
|
|
isChecked: function(){
|
|
|
|
var post= Posts.findOne(Session.get('selectedPostId'));
|
|
|
|
return $.inArray( this.name, post.categories) != -1;
|
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(){
|
|
|
|
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-24 11:04:42 +09:00
|
|
|
},
|
|
|
|
statusPending: function(){
|
|
|
|
return this.status == STATUS_PENDING;
|
|
|
|
},
|
|
|
|
statusApproved: function(){
|
|
|
|
return this.status == STATUS_APPROVED;
|
|
|
|
},
|
|
|
|
statusRejected: function(){
|
|
|
|
return this.status == STATUS_REJECTED;
|
|
|
|
},
|
2012-09-29 17:48:49 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
Template.post_edit.rendered = function(){
|
2012-10-01 10:59:08 +09:00
|
|
|
var post= Posts.findOne(Session.get('selectedPostId'));
|
2012-09-29 17:48:49 +09:00
|
|
|
if(post && !this.editor){
|
2012-11-19 11:03:15 +09:00
|
|
|
|
2012-09-29 17:48:49 +09:00
|
|
|
this.editor= new EpicEditor(EpicEditorOptions).load();
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2012-09-13 11:05:49 +09:00
|
|
|
|
2012-09-06 11:09:24 +09:00
|
|
|
Template.post_edit.events = {
|
2012-09-29 17:48:49 +09:00
|
|
|
'click input[type=submit]': function(e, instance){
|
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-10-01 10:59:08 +09:00
|
|
|
var selectedPostId=Session.get('selectedPostId');
|
2012-09-06 11:09:24 +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');
|
2012-11-19 11:03:15 +09:00
|
|
|
var submitted = parseInt(moment($('#submitted_date').val()+$('#submitted_time').val(), "MM/DD/YYYY HH:mm").valueOf());
|
2012-10-23 12:24:38 +09:00
|
|
|
var userId = $('#postUser').val();
|
2012-10-24 16:48:30 +09:00
|
|
|
var status = parseInt($('input[name=status]:checked').val());
|
2012-10-10 08:32:49 +09:00
|
|
|
|
|
|
|
$('input[name=category]:checked').each(function() {
|
|
|
|
categories.push($(this).val());
|
2012-10-24 11:04:42 +09:00
|
|
|
});
|
2012-10-10 08:32:49 +09:00
|
|
|
|
2012-10-01 10:59:08 +09:00
|
|
|
Posts.update(selectedPostId,
|
2012-09-29 17:48:49 +09:00
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
headline: title
|
|
|
|
, url: url
|
|
|
|
, body: body
|
2012-10-10 08:32:49 +09:00
|
|
|
, categories: categories
|
2012-11-19 11:03:15 +09:00
|
|
|
, submitted: submitted
|
2012-10-23 12:24:38 +09:00
|
|
|
, sticky: sticky
|
|
|
|
, userId: userId
|
2012-10-24 11:04:42 +09:00
|
|
|
, status: status
|
2012-09-29 17:48:49 +09:00
|
|
|
}
|
|
|
|
}
|
2012-10-10 10:48:14 +09:00
|
|
|
,function(error){
|
|
|
|
if(error){
|
|
|
|
throwError(error.reason);
|
|
|
|
}else{
|
|
|
|
trackEvent("edit post", {'postId': selectedPostId});
|
2012-11-21 14:28:18 +11:00
|
|
|
Meteor.Router.to("/posts/"+selectedPostId);
|
2012-10-10 10:48:14 +09:00
|
|
|
}
|
|
|
|
}
|
2012-09-06 11:09:24 +09:00
|
|
|
);
|
2012-09-06 10:14:03 +09:00
|
|
|
}
|
2012-09-07 10:57:57 +09:00
|
|
|
|
|
|
|
, 'click .delete-link': function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
if(confirm("Are you sure?")){
|
2012-10-01 10:59:08 +09:00
|
|
|
var selectedPostId=Session.get('selectedPostId');
|
|
|
|
Posts.remove(selectedPostId);
|
2012-11-21 14:28:18 +11:00
|
|
|
Meteor.Router.to("posts/deleted");
|
2012-09-07 10:57:57 +09:00
|
|
|
}
|
|
|
|
}
|
2012-09-29 17:48:49 +09:00
|
|
|
};
|