2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('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);
|
|
|
|
},
|
2014-07-03 10:28:27 +09:00
|
|
|
isSelected: function(user){
|
|
|
|
return user._id == Meteor.userId() ? "selected" : "";
|
2014-07-03 13:15:23 +09:00
|
|
|
},
|
|
|
|
showPostedAt: function () {
|
|
|
|
if(Session.get('currentPostStatus') == STATUS_APPROVED){
|
|
|
|
return 'visible'
|
|
|
|
}else{
|
|
|
|
return 'hidden'
|
|
|
|
}
|
2014-07-03 14:13:47 +09:00
|
|
|
// return (Session.get('currentPostStatus') || STATUS_APPROVED) == STATUS_APPROVED; // default to approved
|
2012-10-10 08:32:49 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('post_submit')].rendered = function(){
|
2014-08-01 09:07:58 +09:00
|
|
|
// run all post submit rendered callbacks
|
|
|
|
var instance = this;
|
|
|
|
postSubmitRenderedCallbacks.forEach(function(callback) {
|
|
|
|
callback(instance);
|
|
|
|
});
|
|
|
|
|
2014-07-03 13:15:23 +09:00
|
|
|
Session.set('currentPostStatus', STATUS_APPROVED);
|
2012-10-23 12:24:38 +09:00
|
|
|
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();
|
2014-07-03 13:15:23 +09:00
|
|
|
|
|
|
|
$('#postedAtDate').datepicker();
|
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
|
|
|
|
2014-09-16 15:13:42 -04:00
|
|
|
};
|
2012-10-23 12:24:38 +09:00
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('post_submit')].events({
|
2014-07-03 13:15:23 +09:00
|
|
|
'change input[name=status]': function (e, i) {
|
|
|
|
Session.set('currentPostStatus', e.currentTarget.value);
|
|
|
|
},
|
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');
|
|
|
|
|
2014-07-03 13:15:23 +09:00
|
|
|
// ------------------------------ Checks ------------------------------ //
|
|
|
|
|
2012-09-20 09:13:48 +09:00
|
|
|
if(!Meteor.user()){
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
flashMessage(i18n.t('You must be logged in.'), "error");
|
2012-09-20 09:13:48 +09:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-31 19:41:54 -04:00
|
|
|
|
2014-07-03 13:15:23 +09:00
|
|
|
// ------------------------------ Properties ------------------------------ //
|
2012-10-10 08:32:49 +09:00
|
|
|
|
2014-07-03 13:15:23 +09:00
|
|
|
// Basic Properties
|
2012-10-10 08:32:49 +09:00
|
|
|
|
2013-01-13 08:52:35 +09:00
|
|
|
var properties = {
|
2014-07-03 13:15:23 +09:00
|
|
|
title: $('#title').val(),
|
|
|
|
body: instance.editor.exportFile(),
|
|
|
|
sticky: $('#sticky').is(':checked'),
|
|
|
|
userId: $('#postUser').val(),
|
|
|
|
status: parseInt($('input[name=status]:checked').val())
|
2013-01-13 08:52:35 +09:00
|
|
|
};
|
2014-06-22 09:55:34 +09:00
|
|
|
|
2014-07-03 13:15:23 +09:00
|
|
|
// PostedAt
|
|
|
|
|
2014-09-16 15:13:42 -04:00
|
|
|
var $postedAtDate = $('#postedAtDate');
|
|
|
|
var $postedAtTime = $('#postedAtTime');
|
2014-07-03 13:15:23 +09:00
|
|
|
var setPostedAt = false;
|
|
|
|
var postedAt = new Date(); // default to current browser date and time
|
2014-09-16 15:13:42 -04:00
|
|
|
var postedAtDate = $postedAtDate.datepicker('getDate');
|
|
|
|
var postedAtTime = $postedAtTime.val();
|
2014-07-03 13:15:23 +09:00
|
|
|
|
2014-09-16 15:13:42 -04:00
|
|
|
if ($postedAtDate.exists() && postedAtDate != "Invalid Date"){ // if custom date is set, use it
|
2014-07-03 13:15:23 +09:00
|
|
|
postedAt = postedAtDate;
|
|
|
|
setPostedAt = true;
|
|
|
|
}
|
|
|
|
|
2014-09-16 15:13:42 -04:00
|
|
|
if ($postedAtTime.exists() && postedAtTime.split(':').length==2){ // if custom time is set, use it
|
2014-07-03 14:13:47 +09:00
|
|
|
var hours = postedAtTime.split(':')[0];
|
|
|
|
var minutes = postedAtTime.split(':')[1];
|
2014-07-03 13:15:23 +09:00
|
|
|
postedAt = moment(postedAt).hour(hours).minute(minutes).toDate();
|
|
|
|
setPostedAt = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(setPostedAt) // if either custom date or time has been set, pass result to properties
|
2014-09-16 15:13:42 -04:00
|
|
|
properties.postedAt = postedAt;
|
2014-07-03 13:15:23 +09:00
|
|
|
|
|
|
|
|
|
|
|
// URL
|
|
|
|
|
|
|
|
var url = $('#url').val();
|
2014-06-22 09:55:34 +09:00
|
|
|
if(!!url){
|
2013-02-20 10:27:45 +09:00
|
|
|
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;
|
|
|
|
}
|
2014-06-22 09:55:34 +09:00
|
|
|
|
2014-07-05 18:06:28 +09:00
|
|
|
// ------------------------------ Callbacks ------------------------------ //
|
2014-07-03 13:15:23 +09:00
|
|
|
|
2014-07-05 18:06:28 +09:00
|
|
|
// run all post submit client callbacks on properties object successively
|
|
|
|
properties = postSubmitClientCallbacks.reduce(function(result, currentFunction) {
|
|
|
|
return currentFunction(result);
|
|
|
|
}, properties);
|
2014-07-03 13:15:23 +09:00
|
|
|
|
2014-07-03 14:13:47 +09:00
|
|
|
// console.log(properties)
|
2014-07-03 13:15:23 +09:00
|
|
|
|
|
|
|
// ------------------------------ Insert ------------------------------ //
|
2014-08-11 12:09:20 +02:00
|
|
|
if (properties) {
|
|
|
|
Meteor.call('post', properties, function(error, post) {
|
|
|
|
if(error){
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
flashMessage(error.reason, "error");
|
|
|
|
clearSeenMessages();
|
2014-08-11 12:09:20 +02:00
|
|
|
$(e.target).removeClass('disabled');
|
|
|
|
if(error.error == 603)
|
|
|
|
Router.go('/posts/'+error.details);
|
|
|
|
}else{
|
|
|
|
trackEvent("new post", {'postId': post._id});
|
|
|
|
if(post.status === STATUS_PENDING)
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
flashMessage('Thanks, your post is awaiting approval.', "success");
|
2014-08-11 12:09:20 +02:00
|
|
|
Router.go('/posts/'+post._id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$(e.target).removeClass('disabled');
|
|
|
|
}
|
2014-07-03 13:15:23 +09: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();
|
2014-09-16 15:13:42 -04:00
|
|
|
var $getTitleLink = $(".get-title-link");
|
|
|
|
$getTitleLink.addClass("loading");
|
2012-09-07 18:17:19 +09:00
|
|
|
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
|
|
|
}
|
2014-09-16 15:13:42 -04:00
|
|
|
$getTitleLink.removeClass("loading");
|
2013-01-09 23:50:26 -03:00
|
|
|
});
|
2012-09-07 18:17:19 +09:00
|
|
|
}else{
|
|
|
|
alert("Please fill in an URL first!");
|
2014-09-16 15:13:42 -04:00
|
|
|
$getTitleLink.removeClass("loading");
|
2012-09-07 18:17:19 +09:00
|
|
|
}
|
|
|
|
}
|
2013-07-04 11:16:11 +09:00
|
|
|
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
});
|