Merge branch 'AdmitHub-telescope-master-semantic-messages'

This commit is contained in:
Sacha Greif 2014-12-06 17:50:52 +09:00
commit 2def10822a
31 changed files with 101 additions and 96 deletions

View file

@ -1,3 +1,7 @@
## v0.10.0
* Renaming Errors to Messages (thanks @yourcelf!).
## v0.9.11 “FormScope”
* Now using [Autoform](https://github.com/aldeed/meteor-autoform/)'s **quickform** feature to generate post submit and edit forms.

View file

@ -42,7 +42,7 @@ UI.registerHelper('isAdmin', function(showError) {
return true;
}else{
if((typeof showError === "string") && (showError === "true"))
throwError(i18n.t('sorry_you_do_not_have_access_to_this_page'));
flashMessage(i18n.t('sorry_you_do_not_have_access_to_this_page'), "error");
return false;
}
});
@ -78,4 +78,4 @@ UI.registerHelper("sanitize", function(content) {
UI.registerHelper('pluralize', function(count, string) {
string = count === 1 ? string : string + 's';
return i18n.t(string);
});
});

View file

@ -25,7 +25,7 @@ Template[getTemplate('comment_edit')].events({
if(confirm(i18n.t("are_you_sure"))){
Meteor.call('removeComment', comment._id);
Router.go('post_page', {_id: comment.postId});
throwError("Your comment has been deleted.");
flashMessage("Your comment has been deleted.", "success");
}
}
});
});

View file

@ -9,7 +9,7 @@ Template[getTemplate('comment_form')].events({
var $commentForm = instance.$('#comment');
e.preventDefault();
$(e.target).addClass('disabled');
clearSeenErrors();
clearSeenMessages();
var content = $commentForm.val();
if(getCurrentTemplate() == 'comment_reply'){
// child comment
@ -17,7 +17,7 @@ Template[getTemplate('comment_form')].events({
Meteor.call('comment', parentComment.postId, parentComment._id, content, function(error, newComment){
if(error){
console.log(error);
throwError(error.reason);
flashMessage(error.reason, "error");
}else{
trackEvent("newComment", newComment);
Router.go('post_page_comment', {
@ -33,7 +33,7 @@ Template[getTemplate('comment_form')].events({
Meteor.call('comment', post._id, null, content, function(error, newComment){
if(error){
console.log(error);
throwError(error.reason);
flashMessage(error.reason, "error");
}else{
trackEvent("newComment", newComment);
Session.set('scrollToCommentId', newComment._id);
@ -42,4 +42,4 @@ Template[getTemplate('comment_form')].events({
});
}
}
});
});

View file

@ -153,7 +153,7 @@ Template[getTemplate('comment_item')].events({
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
throwError(i18n.t("please_log_in_first"));
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('upvoteComment', this, function(error, result){
trackEvent("post upvoted", {'commentId':instance.data._id, 'postId': instance.data.post, 'authorId':instance.data.userId});
@ -163,7 +163,7 @@ Template[getTemplate('comment_item')].events({
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
throwError(i18n.t("please_log_in_first"));
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('cancelUpvoteComment', this, function(error, result){
trackEvent("post upvote cancelled", {'commentId':instance.data._id, 'postId': instance.data.post, 'authorId':instance.data.userId});
@ -173,7 +173,7 @@ Template[getTemplate('comment_item')].events({
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
throwError(i18n.t("please_log_in_first"));
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('downvoteComment', this, function(error, result){
trackEvent("post downvoted", {'commentId':instance.data._id, 'postId': instance.data.post, 'authorId':instance.data.userId});
@ -183,7 +183,7 @@ Template[getTemplate('comment_item')].events({
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
throwError(i18n.t("please_log_in_first"));
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('cancelDownvoteComment', this, function(error, result){
trackEvent("post downvote cancelled", {'commentId':instance.data._id, 'postId': instance.data.post, 'authorId':instance.data.userId});

View file

@ -1,5 +0,0 @@
<template name="error">
{{#each errors}}
{{> UI.dynamic template=error_item}}
{{/each}}
</template>

View file

@ -1,8 +0,0 @@
Template[getTemplate('error')].helpers({
error_item: function () {
return getTemplate('error_item');
},
errors: function(){
return Errors.find({show: true});
}
});

View file

@ -1,10 +0,0 @@
Template[getTemplate('error_item')].helpers({
});
Template[getTemplate('error_item')].created = function(){
var error_id=this.data._id;
Meteor.setTimeout(function(){
Errors.update(error_id, {$set: {seen:true}});
}, 100);
};

View file

@ -6,7 +6,7 @@
<div class="inner-wrapper template-{{pageName}}">
{{> UI.dynamic template=nav}}
<div class="content-wrapper">
{{> UI.dynamic template=error}}
{{> UI.dynamic template=messages}}
{{#each heroModules}}
{{> UI.dynamic template=getTemplate}}
{{/each}}

View file

@ -5,8 +5,8 @@ Template[getTemplate('layout')].helpers({
nav: function () {
return getTemplate('nav');
},
error: function () {
return getTemplate('error');
messages: function () {
return getTemplate('messages');
},
notifications: function () {
return getTemplate('notifications');

View file

@ -1,4 +1,4 @@
<template name="error_item">
<template name="message_item">
{{#if show}}
<div class="grid">
<div class="error {{type}}-message module">

View file

@ -0,0 +1,10 @@
Template[getTemplate('message_item')].helpers({
});
Template[getTemplate('message_item')].created = function(){
var messageId=this.data._id;
Meteor.setTimeout(function(){
Messages.update(messageId, {$set: {seen:true}});
}, 100);
};

View file

@ -0,0 +1,5 @@
<template name="messages">
{{#each messages}}
{{> UI.dynamic template=message_item}}
{{/each}}
</template>

View file

@ -0,0 +1,8 @@
Template[getTemplate('messages')].helpers({
message_item: function () {
return getTemplate('message_item');
},
messages: function(){
return Messages.find({show: true});
}
});

View file

@ -16,7 +16,7 @@ Template[getTemplate('postUpvote')].events({
e.preventDefault();
if(!Meteor.user()){
Router.go(getSigninUrl());
throwError(i18n.t("please_log_in_first"));
flashMessage(i18n.t("please_log_in_first"), "info");
}
Meteor.call('upvotePost', post, function(error, result){
trackEvent("post upvoted", {'_id': post._id});

View file

@ -8,7 +8,7 @@ AutoForm.hooks({
// ------------------------------ Checks ------------------------------ //
if (!Meteor.user()) {
throwError(i18n.t('you_must_be_logged_in'));
flashMessage(i18n.t('you_must_be_logged_in'), "");
return false;
}
@ -45,8 +45,8 @@ AutoForm.hooks({
onError: function(operation, error, template) {
console.log(error)
throwError(error.reason.split('|')[0]); // workaround because error.details returns undefined
clearSeenErrors();
flashMessage(error.reason.split('|')[0], "error"); // workaround because error.details returns undefined
clearSeenMessages();
}
// Called at the beginning and end of submission, respectively.

View file

@ -8,7 +8,7 @@ AutoForm.hooks({
// ------------------------------ Checks ------------------------------ //
if (!Meteor.user()) {
throwError(i18n.t('you_must_be_logged_in'));
flashMessage(i18n.t('you_must_be_logged_in'), 'error');
return false;
}
@ -29,7 +29,7 @@ AutoForm.hooks({
// note: find a way to do this in onSuccess instead?
trackEvent("new post", {'postId': post._id});
if (post.status === STATUS_PENDING) {
throwError('Thanks, your post is awaiting approval.');
flashMessage(i18n.t('thanks_your_post_is_awaiting_approval'), 'success');
}
Router.go('post_page', {_id: post._id});
submit.done();
@ -49,8 +49,8 @@ AutoForm.hooks({
},
onError: function(operation, error, template) {
throwError(error.reason.split('|')[0]); // workaround because error.details returns undefined
clearSeenErrors();
flashMessage(error.message.split('|')[0], 'error'); // workaround because error.details returns undefined
clearSeenMessages();
// $(e.target).removeClass('disabled');
if (error.error == 603) {
var dupePostId = error.reason.split('|')[1];

View file

@ -25,23 +25,23 @@ var scrollUp = function(){
AutoForm.hooks({
inviteForm: {
onSuccess: function(operation, result, template) {
clearSeenErrors();
clearSeenMessages();
if(result && result.newUser){
throwError('An invite has been sent out. Thank you!');
flashMessage('An invite has been sent out. Thank you!', "success");
} else {
throwError('Thank you!');
flashMessage('Thank you!', "info");
}
scrollUp();
},
onError: function(operation, error, template) {
clearSeenErrors();
clearSeenMessages();
if(error && error.reason){
throwError(error.reason);
flashMessage(error.reason, "error");
scrollUp();
}
}
}
});
});

View file

@ -38,9 +38,9 @@ Template[getTemplate('user_edit')].events({
'submit #account-form': function(e){
e.preventDefault();
clearSeenErrors();
clearSeenMessages();
if(!Meteor.user())
throwError(i18n.t('you_must_be_logged_in'));
flashMessage(i18n.t('you_must_be_logged_in'), 'error');
var $target=$(e.target);
var name = $target.find('[name=name]').val();
@ -67,7 +67,7 @@ Template[getTemplate('user_edit')].events({
Accounts.changePassword(old_password, new_password, function(error){
// TODO: interrupt update if there's an error at this point
if(error)
throwError(error.reason);
flashMessage(error.reason, "error");
});
}
@ -79,9 +79,9 @@ Template[getTemplate('user_edit')].events({
$set: update
}, function(error){
if(error){
throwError(error.reason);
flashMessage(error.reason, "error");
} else {
throwError(i18n.t('profile_updated'));
flashMessage(i18n.t('profile_updated'), 'success');
}
Deps.afterFlush(function() {
var element = $('.grid > .error');

View file

@ -10,7 +10,8 @@ Template[getTemplate('user_email')].helpers({
Template[getTemplate('user_email')].events({
'submit form': function(e){
e.preventDefault();
if(!Meteor.user()) throwError(i18n.t('you_must_be_logged_in'));
if(!Meteor.user())
flashMessage(i18n.t('you_must_be_logged_in'), 'error');
var $target=$(e.target);
var user=Session.get('selectedUserId')? Meteor.users.findOne(Session.get('selectedUserId')) : Meteor.user();
var update = {
@ -26,9 +27,9 @@ Template[getTemplate('user_email')].events({
$set: update
}, function(error){
if(error){
throwError(error.reason);
flashMessage(error.reason, "error");
} else {
throwError(i18n.t('thanks_for_signing_up'));
flashMessage(i18n.t('thanks_for_signing_up'), "success");
// Meteor.call('addCurrentUserToMailChimpList');
trackEvent("new sign-up", {'userId': user._id, 'auth':'twitter'});
Router.go('/');

View file

@ -79,7 +79,7 @@ Template[getTemplate('user_profile')].helpers({
Template[getTemplate('user_profile')].events({
'click .invite-link': function(e, instance){
Meteor.call('inviteUser', instance.data.user._id);
throwError('Thanks, user has been invited.');
flashMessage('Thanks, user has been invited.', "success");
},
'click .posts-more': function (e) {
e.preventDefault();
@ -101,4 +101,4 @@ Template[getTemplate('user_profile')].events({
var commentsShown = Session.get('commentsShown');
Session.set('commentsShown', commentsShown + 10);
}
});
});

View file

@ -194,7 +194,7 @@ Meteor.methods({
isDeleted: true
}});
}else{
throwError("You don't have permission to delete this comment.");
flashMessage("You don't have permission to delete this comment.", "error");
}
}
});

View file

@ -1,4 +1,4 @@
if(Meteor.isClient){
// Local (client-only) collection
Errors = new Meteor.Collection(null);
Messages = new Meteor.Collection(null);
}

View file

@ -465,7 +465,7 @@ Meteor.methods({
var now = new Date();
var result = Posts.update(post._id, {$set: {status: 2, postedAt: now}}, {validate: false});
}else{
throwError('You need to be an admin to do that.');
flashMessage('You need to be an admin to do that.', "error");
}
},
@ -473,7 +473,7 @@ Meteor.methods({
if(isAdmin(Meteor.user())){
Posts.update(post._id, {$set: {status: 1}});
}else{
throwError('You need to be an admin to do that.');
flashMessage('You need to be an admin to do that.', "error");
}
},

View file

@ -1,13 +0,0 @@
if(Meteor.isClient){
throwError = function(message, type){
type = (typeof type === 'undefined') ? 'error': type;
// Store errors in the 'Errors' local collection
Errors.insert({message:message, type:type, seen: false, show:true});
};
clearSeenErrors = function(){
Errors.update({seen:true}, {$set: {show:false}}, {multi:true});
};
}

13
lib/messages.js Normal file
View file

@ -0,0 +1,13 @@
if(Meteor.isClient){
flashMessage = function(message, type){
type = (typeof type === 'undefined') ? 'error': type;
// Store errors in the 'Messages' local collection
Messages.insert({message:message, type:type, seen: false, show:true});
};
clearSeenMessages = function(){
Messages.update({seen:true}, {$set: {show:false}}, {multi:true});
};
}

View file

@ -14,8 +14,8 @@ Router._filters = {
}
},
clearSeenErrors: function () {
clearSeenErrors();
clearSeenMessages: function () {
clearSeenMessages();
this.next();
},
@ -73,7 +73,7 @@ Router._filters = {
if(!this.ready() || Meteor.loggingIn()){
this.render(getTemplate('loading'));
} else if(!canPost()) {
throwError(i18n.t("sorry_you_dont_have_permissions_to_add_new_items"));
flashMessage(i18n.t("sorry_you_dont_have_permissions_to_add_new_items"), "error");
this.render(getTemplate('no_rights'));
} else {
this.next();
@ -85,7 +85,7 @@ Router._filters = {
// Already subscribed to this post by route({waitOn: ...})
var post = Posts.findOne(this.params._id);
if(!currentUserCanEdit(post)){
throwError(i18n.t("sorry_you_cannot_edit_this_post"));
flashMessage(i18n.t("sorry_you_cannot_edit_this_post"), "error");
this.render(getTemplate('no_rights'));
} else {
this.next();
@ -97,7 +97,7 @@ Router._filters = {
// Already subscribed to this comment by CommentPageController
var comment = Comments.findOne(this.params._id);
if(!currentUserCanEdit(comment)){
throwError(i18n.t("sorry_you_cannot_edit_this_comment"));
flashMessage(i18n.t("sorry_you_cannot_edit_this_comment"), "error");
this.render(getTemplate('no_rights'));
} else {
this.next();
@ -153,7 +153,7 @@ Meteor.startup( function (){
// Before Hooks
Router.onBeforeAction(filters.isReady);
Router.onBeforeAction(filters.clearSeenErrors);
Router.onBeforeAction(filters.clearSeenMessages);
Router.onBeforeAction(filters.canView, {except: ['atSignIn', 'atSignUp', 'atForgotPwd', 'atResetPwd', 'signOut']});
Router.onBeforeAction(filters.hasCompletedProfile);
Router.onBeforeAction(filters.isLoggedIn, {only: ['post_submit']});

View file

@ -32,12 +32,12 @@ Template.afPostThumbnail.rendered = function () {
var url = $urlField.val();
if (!!url) {
$thumbnailContainer.addClass('loading');
clearSeenErrors();
clearSeenMessages();
console.log('getting embedly data for '+url);
Meteor.call('getEmbedlyData', url, function (error, data) {
if (error) {
console.log(error)
throwError(error.reason);
flashMessage(error.reason, 'error');
$thumbnailContainer.removeClass('loading');
return
}

View file

@ -54,7 +54,7 @@ Meteor.startup(function () {
$banner.removeClass('show-loader');
if(error){
console.log(error);
throwError(error.message);
flashMessage(error.message, "error");
}else{
console.log(result);
confirmSubscription();
@ -71,7 +71,7 @@ Meteor.startup(function () {
$banner.removeClass('show-loader');
if(error){
console.log(error);
throwError(error.message);
flashMessage(error.message, "error");
}else{
console.log(result);
confirmSubscription();
@ -87,4 +87,4 @@ Meteor.startup(function () {
e.preventDefault();
}
});
});
});

View file

@ -24,13 +24,13 @@ Meteor.startup(function () {
}, function(error, categoryName) {
if(error){
console.log(error);
throwError(error.reason);
clearSeenErrors();
flashMessage(error.reason, "error");
clearSeenMessages();
}else{
$('#name').val('');
// throwError('New category "'+categoryName+'" created');
// flashMessage('New category "'+categoryName+'" created', "success");
}
});
}
});
});
});

View file

@ -13,4 +13,4 @@ Meteor.startup(function () {
}
}
});
});
});