2015-04-13 14:52:03 +09:00
|
|
|
Template.userInvites.created = function () {
|
2014-12-08 22:17:43 +09:00
|
|
|
|
|
|
|
var user = this.data;
|
|
|
|
var instance = this;
|
|
|
|
|
|
|
|
instance.invites = new ReactiveVar({});
|
|
|
|
|
|
|
|
Meteor.autorun(function () {
|
|
|
|
coreSubscriptions.subscribe('invites', user._id);
|
|
|
|
var invites = Invites.find({invitingUserId: user._id});
|
|
|
|
instance.invites.set(invites);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-04-13 14:52:03 +09:00
|
|
|
Template.userInvites.helpers({
|
2014-12-08 22:17:43 +09:00
|
|
|
canCurrentUserInvite: function () {
|
2014-07-31 01:18:17 +02:00
|
|
|
var currentUser = Meteor.user();
|
2015-01-07 08:22:46 +01:00
|
|
|
return currentUser && (currentUser.inviteCount > 0 && can.invite(currentUser));
|
2014-07-31 01:18:17 +02:00
|
|
|
},
|
2014-12-08 22:17:43 +09:00
|
|
|
invitesLeft: function () {
|
2014-07-31 01:18:17 +02:00
|
|
|
var currentUser = Meteor.user();
|
|
|
|
return currentUser ? currentUser.inviteCount : 0;
|
|
|
|
},
|
2014-12-08 22:17:43 +09:00
|
|
|
invitesSchema: function () {
|
2015-01-07 08:22:46 +01:00
|
|
|
// expose schema for Invites (used by AutoForm)
|
2014-07-31 01:18:17 +02:00
|
|
|
return InviteSchema;
|
2014-12-08 22:17:43 +09:00
|
|
|
},
|
|
|
|
invites: function () {
|
|
|
|
return Template.instance().invites.get();
|
2014-07-31 01:18:17 +02:00
|
|
|
}
|
2014-08-01 13:16:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var scrollUp = function(){
|
|
|
|
Deps.afterFlush(function() {
|
|
|
|
var element = $('.grid > .error');
|
|
|
|
$('html, body').animate({scrollTop: element.offset().top});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
AutoForm.hooks({
|
|
|
|
inviteForm: {
|
|
|
|
onSuccess: function(operation, result, template) {
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.clearSeen();
|
2014-08-01 14:21:33 +02:00
|
|
|
|
2014-08-01 13:16:40 +02:00
|
|
|
if(result && result.newUser){
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash('An invite has been sent out. Thank you!', "success");
|
2014-08-01 13:16:40 +02:00
|
|
|
} else {
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash('Thank you!', "info");
|
2014-08-01 13:16:40 +02:00
|
|
|
}
|
|
|
|
scrollUp();
|
|
|
|
},
|
|
|
|
|
|
|
|
onError: function(operation, error, template) {
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.clearSeen();
|
2015-01-07 08:22:46 +01:00
|
|
|
|
2014-08-01 13:16:40 +02:00
|
|
|
if(error && error.reason){
|
2015-03-27 16:24:21 +08:00
|
|
|
Messages.flash(error.reason, "error");
|
2014-08-01 13:16:40 +02:00
|
|
|
scrollUp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
});
|