This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/user_invited_controller.js
Robin Ward cf6cbb955b REFACTOR: Introduce Discourse.computed.setting to create a computed
property that links to a `Discourse.SiteSetting`
2014-04-24 18:36:02 -04:00

80 lines
1.8 KiB
JavaScript

/**
This controller handles actions related to a user's invitations
@class UserInvitedController
@extends Ember.ArrayController
@namespace Discourse
@module Discourse
**/
Discourse.UserInvitedController = Ember.ObjectController.extend({
user: null,
init: function() {
this._super();
this.set('searchTerm', '');
},
/**
Observe the search term box with a debouncer and change the results.
@observes searchTerm
**/
_searchTermChanged: Discourse.debounce(function() {
var self = this;
Discourse.Invite.findInvitedBy(self.get('user'), this.get('searchTerm')).then(function (invites) {
self.set('model', invites);
});
}, 250).observes('searchTerm'),
/**
The maximum amount of invites that will be displayed in the view
@property maxInvites
**/
maxInvites: Discourse.computed.setting('invites_shown'),
/**
Can the currently logged in user invite users to the site
@property canInviteToForum
**/
canInviteToForum: function() {
return Discourse.User.currentProp('can_invite_to_forum');
}.property(),
/**
Should the search filter input box be displayed?
@property showSearch
**/
showSearch: function() {
return !(Em.isNone(this.get('searchTerm')) && this.get('invites.length') === 0);
}.property('searchTerm', 'invites.length'),
/**
Were the results limited by our `maxInvites`
@property truncated
**/
truncated: function() {
return this.get('invites.length') === Discourse.SiteSettings.invites_shown;
}.property('invites.length'),
actions: {
/**
Rescind a given invite
@method rescive
@param {Discourse.Invite} invite the invite to rescind.
**/
rescind: function(invite) {
invite.rescind();
return false;
}
}
});