discourse/app/assets/javascripts/discourse/controllers/invite.js.es6
Régis Hanol 0947191060 UX: improved our footer handling
- new "show-footer" mixins
- converted most of the routes to ES6
- FIX: handling of "indexStream" in user pages

There will now be a footer on all the following pages
- /exception
- /about
- /latest
- /new
- /unread
- /starred
- /top
- /categories
- /c/:category
- /c/:category/l/latest
- /c/:category/l/new
- /c/:category/l/unread
- /c/:category/l/top
- /t/:topic/:id
- /groups/:name/members
- /user/activity
- /user/activity/topics
- /user/activity/posts
- /user/activity/replies
- /user/activity/likes-given
- /user/activity/likes-received
- /user/activity/bookmarks
- /user/activity/starred
- /user/badges
- /user/notifications
- /user/flagged-posts
- /user/deleted-posts
- /user/private-messages
- /user/private-messages/mine
- /user/private-messages/unread
- /user/invited
- /user/:username/preferences
- /faq (static pages)
- /badges
- /badges/:id/:badge
2014-11-19 20:37:43 +01:00

145 lines
3.8 KiB
JavaScript

import ModalFunctionality from 'discourse/mixins/modal-functionality';
import ObjectController from 'discourse/controllers/object';
export default ObjectController.extend(ModalFunctionality, {
needs: ['user-invited'],
// If this isn't defined, it will proxy to the user model on the preferences
// page which is wrong.
email: null,
isAdmin: function(){
return Discourse.User.currentProp("admin");
}.property(),
/**
Can we submit the form?
@property disabled
**/
disabled: function() {
if (this.get('saving')) return true;
if (this.blank('email')) return true;
if (!Discourse.Utilities.emailValid(this.get('email'))) return true;
if (this.get('isPrivateTopic') && this.blank('groupNames')) return true;
return false;
}.property('email', 'isPrivateTopic', 'groupNames', 'saving'),
/**
The current text for the invite button
@property buttonTitle
**/
buttonTitle: function() {
if (this.get('saving')) return I18n.t('topic.inviting');
return I18n.t('topic.invite_reply.action');
}.property('saving'),
/**
We are inviting to a topic if the model isn't the current user. The current user would
mean we are inviting to the forum in general.
@property invitingToTopic
**/
invitingToTopic: function() {
return this.get('model') !== Discourse.User.current();
}.property('model'),
/**
Is Private Topic? (i.e. visible only to specific group members)
@property isPrivateTopic
**/
isPrivateTopic: Em.computed.and('invitingToTopic', 'model.category.read_restricted'),
/**
Instructional text for the modal.
@property inviteInstructions
**/
inviteInstructions: function() {
if (this.get('invitingToTopic')) {
return I18n.t('topic.invite_reply.to_topic');
} else {
return I18n.t('topic.invite_reply.to_forum');
}
}.property('invitingToTopic'),
/**
Instructional text for the group selection.
@property groupInstructions
**/
groupInstructions: function() {
if (this.get('isPrivateTopic')) {
return I18n.t('topic.automatically_add_to_groups_required');
} else {
return I18n.t('topic.automatically_add_to_groups_optional');
}
}.property('isPrivateTopic'),
/**
Function to find groups.
**/
groupFinder: function(term) {
return Discourse.Group.findAll({search: term, ignore_automatic: true});
},
/**
The "success" text for when the invite was created.
@property successMessage
**/
successMessage: function() {
return I18n.t('topic.invite_reply.success', { email: this.get('email') });
}.property('email'),
/**
Reset the modal to allow a new user to be invited.
@method reset
**/
reset: function() {
this.setProperties({
email: null,
groupNames: null,
error: false,
saving: false,
finished: false
});
},
actions: {
/**
Create the invite and update the modal accordingly.
@method createInvite
**/
createInvite: function() {
if (this.get('disabled')) { return; }
var self = this;
var groupNames = this.get('groupNames');
var userInvitedController = this.get('controllers.user-invited');
this.setProperties({ saving: true, error: false });
this.get('model').createInvite(this.get('email'), groupNames).then(function() {
self.setProperties({ saving: false, finished: true });
if (!self.get('invitingToTopic')) {
Discourse.Invite.findInvitedBy(Discourse.User.current()).then(function (invite_model) {
userInvitedController.set('model', invite_model);
userInvitedController.set('totalInvites', invite_model.invites.length);
});
}
}).catch(function() {
self.setProperties({ saving: false, error: true });
});
return false;
}
}
});