summaryrefslogtreecommitdiffstats
path: root/web/react
diff options
context:
space:
mode:
Diffstat (limited to 'web/react')
-rw-r--r--web/react/.eslintrc287
-rw-r--r--web/react/components/get_link_modal.jsx6
-rw-r--r--web/react/components/login.jsx2
-rw-r--r--web/react/components/more_direct_channels.jsx93
-rw-r--r--web/react/components/navbar.jsx272
-rw-r--r--web/react/components/notify_counts.jsx49
-rw-r--r--web/react/components/post.jsx3
-rw-r--r--web/react/components/post_info.jsx171
-rw-r--r--web/react/components/post_list.jsx51
-rw-r--r--web/react/components/post_right.jsx4
-rw-r--r--web/react/components/setting_item_max.jsx4
-rw-r--r--web/react/components/setting_upload.jsx79
-rw-r--r--web/react/components/settings_sidebar.jsx2
-rw-r--r--web/react/components/sidebar.jsx73
-rw-r--r--web/react/components/signup_team_complete.jsx736
-rw-r--r--web/react/components/team_feature_tab.jsx147
-rw-r--r--web/react/components/team_import_tab.jsx68
-rw-r--r--web/react/components/team_settings.jsx181
-rw-r--r--web/react/components/team_settings_modal.jsx42
-rw-r--r--web/react/components/team_signup_allowed_domains_page.jsx98
-rw-r--r--web/react/components/team_signup_display_name_page.jsx72
-rw-r--r--web/react/components/team_signup_email_item.jsx53
-rw-r--r--web/react/components/team_signup_password_page.jsx116
-rw-r--r--web/react/components/team_signup_send_invites_page.jsx121
-rw-r--r--web/react/components/team_signup_url_page.jsx119
-rw-r--r--web/react/components/team_signup_username_page.jsx75
-rw-r--r--web/react/components/team_signup_welcome_page.jsx144
-rw-r--r--web/react/package.json27
-rw-r--r--web/react/stores/post_store.jsx22
-rw-r--r--web/react/utils/client.jsx409
-rw-r--r--web/react/utils/constants.jsx5
-rw-r--r--web/react/utils/utils.jsx945
32 files changed, 2538 insertions, 1938 deletions
diff --git a/web/react/.eslintrc b/web/react/.eslintrc
index d8b36f6ca..cdf96905b 100644
--- a/web/react/.eslintrc
+++ b/web/react/.eslintrc
@@ -1,139 +1,160 @@
{
- "ecmaFeatures": {
- "jsx": true,
- "blockBindings": true,
- "modules": true
- },
- "plugins": [
- "react"
- ],
- "env": {
- "browser": true,
- "node": true,
- "jquery": true,
- "es6": true
- },
- "globals": {
- "React": false
- },
- "rules": {
- "comma-dangle": [2, "never"],
- "no-cond-assign": [2, "except-parens"],
- "no-console": 1,
- "no-constant-condition": 1,
- "no-debugger": 1,
- "no-dupe-args": 2,
- "no-dupe-keys": 2,
- "no-duplicate-case": 2,
- "no-empty": 1,
- "no-ex-assign": 1,
- "no-extra-semi": 2,
- "no-func-assign": 1,
- "no-inner-declarations": 0,
- "no-invalid-regexp": 2,
- "no-irregular-whitespace": 2,
- "no-unreachable": 2,
- "valid-typeof": 2,
- "no-unexpected-multiline": 2,
+ "extends": "eslint:recommended",
+ "ecmaFeatures": {
+ "jsx": true,
+ "blockBindings": true,
+ "modules": true,
+ "classes": true
+ },
+ "plugins": [
+ "react"
+ ],
+ "env": {
+ "browser": true,
+ "node": true,
+ "jquery": true,
+ "es6": true
+ },
+ "globals": {
+ "React": false
+ },
+ "rules": {
+ "comma-dangle": [2, "never"],
+ "no-cond-assign": [2, "except-parens"],
+ "no-console": 1,
+ "no-constant-condition": 1,
+ "no-debugger": 1,
+ "no-dupe-args": 2,
+ "no-dupe-keys": 2,
+ "no-duplicate-case": 2,
+ "no-empty": 1,
+ "no-ex-assign": 1,
+ "no-extra-semi": 2,
+ "no-func-assign": 1,
+ "no-inner-declarations": 0,
+ "no-invalid-regexp": 2,
+ "no-irregular-whitespace": 2,
+ "no-unreachable": 2,
+ "valid-typeof": 2,
+ "no-unexpected-multiline": 2,
- "block-scoped-var": 1,
- "complexity": [1, 8],
- "consistent-return": 2,
- "curly": [2, "all"],
- "dot-notation": 2,
- "dot-location": [2, "object"],
- "eqeqeq": [2, "smart"],
- "guard-for-in": 1,
- "no-alert": 1,
- "no-caller": 2,
- "no-div-regex": 1,
- "no-else-return": 1,
- "no-eval": 2,
- "no-extend-native": 2,
- "no-floating-decimal": 2,
- "no-labels": 2,
- "no-lone-blocks": 1,
- "no-multi-spaces": [2, { "exceptions": { "Property": false } }],
- "no-multi-str": 0,
- "no-param-reassign": 2,
- "no-process-env": 2,
- "no-redeclare": 2,
- "no-return-assign": [2, "always"],
- "no-script-url": 2,
- "no-self-compare": 2,
- "no-sequences": 2,
- "no-throw-literal": 2,
- "no-unused-expressions": 2,
- "no-void": 2,
- "no-warning-comments": 0,
- "no-with": 2,
- "radix": 2,
- "vars-on-top": 0,
- "wrap-iife": [2, "outside"],
- "yoda": [2, "never", {"exceptRange": false, "onlyEquality": false}],
+ "block-scoped-var": 1,
+ "complexity": [1, 8],
+ "consistent-return": 2,
+ "curly": [2, "all"],
+ "dot-notation": 2,
+ "dot-location": [2, "object"],
+ "eqeqeq": [2, "smart"],
+ "guard-for-in": 1,
+ "no-alert": 1,
+ "no-array-constructor": 2,
+ "no-caller": 2,
+ "no-div-regex": 1,
+ "no-else-return": 1,
+ "no-eval": 2,
+ "no-extend-native": 2,
+ "no-extra-bind": 2,
+ "no-floating-decimal": 2,
+ "no-implied-eval": 2,
+ "no-iterator": 2,
+ "no-labels": 2,
+ "no-lone-blocks": 1,
+ "no-loop-func": 2,
+ "no-multi-spaces": [2, { "exceptions": { "Property": false } }],
+ "no-multi-str": 0,
+ "no-native-reassign": 2,
+ "no-new": 2,
+ "no-new-func": 2,
+ "no-new-object": 2,
+ "no-new-wrappers": 2,
+ "no-octal-escape": 2,
+ "no-param-reassign": 2,
+ "no-process-env": 2,
+ "no-process-exit": 2,
+ "no-proto": 2,
+ "no-redeclare": 2,
+ "no-return-assign": [2, "always"],
+ "no-script-url": 2,
+ "no-self-compare": 2,
+ "no-sequences": 2,
+ "no-throw-literal": 2,
+ "no-unused-expressions": 2,
+ "no-undef-init": 2,
+ "no-void": 2,
+ "no-warning-comments": 0,
+ "no-with": 2,
+ "radix": 2,
+ "vars-on-top": 0,
+ "wrap-iife": [2, "outside"],
+ "yoda": [2, "never", {"exceptRange": false, "onlyEquality": false}],
- "no-undefined": 2,
- "no-shadow": [2, {"hoist": "functions"}],
- "no-unused-vars": [2, {"vars": "all", "args": "all"}],
- "no-use-before-define": [2, "nofunc"],
+ "no-undefined": 2,
+ "no-shadow": [2, {"hoist": "functions"}],
+ "no-shadow-restricted-names": 2,
+ "no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
+ "no-use-before-define": [2, "nofunc"],
- // Style
- "array-bracket-spacing": [2, "never"],
- "brace-style": [2, "1tbs", { "allowSingleLine": false }],
- "camelcase": [2, {"properties": "always"}],
- "comma-spacing": [2, {"before": false, "after": true}],
- "comma-style": [2, "last"],
- "computed-property-spacing": [2, "never"],
- "consistent-this": [2, "self"],
- "func-names": 2,
- "func-style": [2, "declaration"],
- "indent": [2, 4, {"indentSwitchCase": false}],
- "key-spacing": [2, {"beforeColon": false, "afterColon": true}],
- "lines-around-comment": [2, { "beforeBlockComment": true, "beforeLineComment": true, "allowBlockStart": true, "allowBlockEnd": true }],
- "linebreak-style": 2,
- "new-cap": 2,
- "new-parens": 2,
- "no-lonely-if": 2,
- "no-mixed-spaces-and-tabs": 2,
- "no-multiple-empty-lines": [2, {"max": 1}],
- "no-spaced-func": 2,
- "no-ternary": 2,
- "no-trailing-spaces": [2, { "skipBlankLines": false }],
- "no-underscore-dangle": 2,
- "no-unneeded-ternary": 2,
- "object-curly-spacing": [2, "never"],
- "one-var": [2, "never"],
- "operator-linebreak": [2, "after"],
- "padded-blocks": [2, "never"],
- "quote-props": [2, "as-needed"],
- "quotes": [2, "single", "avoid-escape"],
- "semi-spacing": [2, {"before": false, "after": true}],
- "semi": [2, "always"],
- "space-after-keywords": [2, "always"],
- "space-before-blocks": [2, "always"],
- "space-before-function-paren": [2, "never"],
- "space-in-parens": [2, "never"],
- "space-infix-ops": 2,
- "space-return-throw-case": 2,
- "space-unary-ops": [2, { "words": true, "nonwords": false }],
- "wrap-regex": 2,
+ // Style
+ "array-bracket-spacing": [2, "never"],
+ "brace-style": [2, "1tbs", { "allowSingleLine": false }],
+ "camelcase": [2, {"properties": "always"}],
+ "comma-spacing": [2, {"before": false, "after": true}],
+ "comma-style": [2, "last"],
+ "computed-property-spacing": [2, "never"],
+ "consistent-this": [2, "self"],
+ "func-names": 2,
+ "func-style": [2, "declaration"],
+ "indent": [2, 4, {"SwitchCase": 0}],
+ "key-spacing": [2, {"beforeColon": false, "afterColon": true}],
+ "lines-around-comment": [2, { "beforeBlockComment": true, "beforeLineComment": true, "allowBlockStart": true, "allowBlockEnd": true }],
+ "linebreak-style": 2,
+ "new-cap": 2,
+ "new-parens": 2,
+ "no-lonely-if": 2,
+ "no-mixed-spaces-and-tabs": 2,
+ "no-multiple-empty-lines": [2, {"max": 1}],
+ "no-spaced-func": 2,
+ "no-ternary": 2,
+ "no-trailing-spaces": [2, { "skipBlankLines": false }],
+ "no-underscore-dangle": 2,
+ "no-unneeded-ternary": 2,
+ "object-curly-spacing": [2, "never"],
+ "one-var": [2, "never"],
+ "operator-linebreak": [2, "after"],
+ "padded-blocks": [2, "never"],
+ "quote-props": [2, "as-needed"],
+ "quotes": [2, "single", "avoid-escape"],
+ "semi-spacing": [2, {"before": false, "after": true}],
+ "semi": [2, "always"],
+ "space-after-keywords": [2, "always"],
+ "space-before-blocks": [2, "always"],
+ "space-before-function-paren": [2, "never"],
+ "space-in-parens": [2, "never"],
+ "space-infix-ops": 2,
+ "space-return-throw-case": 2,
+ "space-unary-ops": [2, { "words": true, "nonwords": false }],
+ "wrap-regex": 2,
- // React Specific
- "react/display-name": [2, { "acceptTranspilerName": true }],
- "react/jsx-boolean-value": [2, "always"],
- "react/jsx-curly-spacing": [2, "never"],
- "react/jsx-no-duplicate-props": [2, { "ignoreCase": false }],
- "react/jsx-no-undef": 2,
- "react/jsx-quotes": [2, "single", "avoid-escape"],
- "react/jsx-uses-react": 2,
- "react/jsx-uses-vars": 2,
- "react/no-danger": 0,
- "react/no-did-mount-set-state": 2,
- "react/no-did-update-set-state": 2,
- "react/no-multi-comp": 2,
- "react/no-unknown-property": 2,
- "react/prop-types": 2,
- "react/sort-comp": 0,
- "react/wrap-multilines": 2
- }
+ // React Specific
+ "react/display-name": [2, { "acceptTranspilerName": true }],
+ "react/jsx-boolean-value": [2, "always"],
+ "react/jsx-curly-spacing": [2, "never"],
+ "react/jsx-max-props-per-line": [2, { "maximum": 1 }],
+ // SOON "react/jsx-indent-props": [2, 4],
+ "react/jsx-no-duplicate-props": [2, { "ignoreCase": false }],
+ "react/jsx-no-literals": 0,
+ "react/jsx-no-undef": 2,
+ "react/jsx-quotes": [2, "single", "avoid-escape"],
+ "react/jsx-uses-react": 2,
+ "react/jsx-uses-vars": 2,
+ "react/no-danger": 0,
+ "react/no-did-mount-set-state": 2,
+ "react/no-did-update-set-state": 2,
+ "react/no-multi-comp": 2,
+ "react/no-unknown-property": 2,
+ "react/prop-types": 2,
+ "react/sort-comp": 0,
+ "react/self-closing-comp": 2,
+ "react/wrap-multilines": 2
+ }
}
diff --git a/web/react/components/get_link_modal.jsx b/web/react/components/get_link_modal.jsx
index a01b57b26..3b10926f5 100644
--- a/web/react/components/get_link_modal.jsx
+++ b/web/react/components/get_link_modal.jsx
@@ -9,6 +9,7 @@ ZeroClipboardMixin.ZeroClipboard.config({
});
module.exports = React.createClass({
+ displayName: 'GetLinkModal',
zeroclipboardElementsSelector: '[data-copy-btn]',
mixins: [ZeroClipboardMixin],
componentDidMount: function() {
@@ -47,7 +48,10 @@ module.exports = React.createClass({
<h4 className='modal-title' id='myModalLabel'>{this.state.title} Link</h4>
</div>
<div className='modal-body'>
- <p>{'The link below is used for open ' + strings.TeamPlural + ' or if you allowed your ' + strings.Team + ' members to sign up using their ' + strings.Company + ' email addresses.'}
+ <p>
+ Send {strings.Team + 'mates'} the link below for them to sign-up to this {strings.Team} site.
+ <br /><br />
+ Be careful not to share this link publicly, since anyone with the link can join your {strings.Team}.
</p>
<textarea className='form-control no-resize' readOnly='true' value={this.state.value}></textarea>
</div>
diff --git a/web/react/components/login.jsx b/web/react/components/login.jsx
index f9eacf094..b61ea931e 100644
--- a/web/react/components/login.jsx
+++ b/web/react/components/login.jsx
@@ -56,7 +56,7 @@ module.exports = React.createClass({
},
function loginFailed(err) {
if (err.message === 'Login failed because email address has not been verified') {
- window.location.href = '/verify_email?name=' + encodeURIComponent(name) + '&email=' + encodeURIComponent(email);
+ window.location.href = '/verify_email?teamname=' + encodeURIComponent(name) + '&email=' + encodeURIComponent(email);
return;
}
state.serverError = err.message;
diff --git a/web/react/components/more_direct_channels.jsx b/web/react/components/more_direct_channels.jsx
index 901cd228f..11ddbcbd1 100644
--- a/web/react/components/more_direct_channels.jsx
+++ b/web/react/components/more_direct_channels.jsx
@@ -3,67 +3,102 @@
var ChannelStore = require('../stores/channel_store.jsx');
var TeamStore = require('../stores/team_store.jsx');
+var Client = require('../utils/client.jsx');
+var AsyncClient = require('../utils/async_client.jsx');
var utils = require('../utils/utils.jsx');
module.exports = React.createClass({
+ displayName: 'MoreDirectChannels',
componentDidMount: function() {
var self = this;
- $(this.refs.modal.getDOMNode()).on('show.bs.modal', function(e) {
+ $(this.refs.modal.getDOMNode()).on('show.bs.modal', function showModal(e) {
var button = e.relatedTarget;
- self.setState({ channels: $(button).data('channels') });
+ self.setState({channels: $(button).data('channels')});
});
},
getInitialState: function() {
- return { channels: [] };
+ return {channels: [], loadingDMChannel: -1};
},
render: function() {
var self = this;
- var directMessageItems = this.state.channels.map(function(channel) {
- var badge = "";
- var titleClass = ""
+ var directMessageItems = this.state.channels.map(function mapActivityToChannel(channel, index) {
+ var badge = '';
+ var titleClass = '';
+ var active = '';
+ var handleClick = null;
if (!channel.fake) {
- var active = channel.id === ChannelStore.getCurrentId() ? "active" : "";
+ if (channel.id === ChannelStore.getCurrentId()) {
+ active = 'active';
+ }
if (channel.unread) {
- badge = <span className="badge pull-right small">{channel.unread}</span>;
- badgesActive = true;
- titleClass = "unread-title"
+ badge = <span className='badge pull-right small'>{channel.unread}</span>;
+ titleClass = 'unread-title';
}
- return (
- <li key={channel.name} className={active}><a className={"sidebar-channel " + titleClass} href="#" onClick={function(e){e.preventDefault(); utils.switchChannel(channel, channel.teammate_username); $(self.refs.modal.getDOMNode()).modal('hide')}}>{badge}{channel.display_name}</a></li>
- );
+
+ handleClick = function clickHandler(e) {
+ e.preventDefault();
+ utils.switchChannel(channel, channel.teammate_username);
+ $(self.refs.modal.getDOMNode()).modal('hide');
+ };
} else {
- return (
- <li key={channel.name} className={active}><a className={"sidebar-channel " + titleClass} href={TeamStore.getCurrentTeamUrl() + "/channels/"+channel.name}>{badge}{channel.display_name}</a></li>
- );
+ // It's a direct message channel that doesn't exist yet so let's create it now
+ var otherUserId = utils.getUserIdFromChannelName(channel);
+
+ if (self.state.loadingDMChannel === index) {
+ badge = <img className='channel-loading-gif pull-right' src='/static/images/load.gif'/>;
+ }
+
+ if (self.state.loadingDMChannel === -1) {
+ handleClick = function clickHandler(e) {
+ e.preventDefault();
+ self.setState({loadingDMChannel: index});
+
+ Client.createDirectChannel(channel, otherUserId,
+ function success(data) {
+ $(self.refs.modal.getDOMNode()).modal('hide');
+ self.setState({loadingDMChannel: -1});
+ AsyncClient.getChannel(data.id);
+ utils.switchChannel(data);
+ },
+ function error() {
+ self.setState({loadingDMChannel: -1});
+ window.location.href = TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name;
+ }
+ );
+ };
+ }
}
+
+ return (
+ <li key={channel.name} className={active}><a className={'sidebar-channel ' + titleClass} href='#' onClick={handleClick}>{badge}{channel.display_name}</a></li>
+ );
});
return (
- <div className="modal fade" id="more_direct_channels" ref="modal" tabIndex="-1" role="dialog" aria-hidden="true">
- <div className="modal-dialog">
- <div className="modal-content">
- <div className="modal-header">
- <button type="button" className="close" data-dismiss="modal">
- <span aria-hidden="true">&times;</span>
- <span className="sr-only">Close</span>
+ <div className='modal fade' id='more_direct_channels' ref='modal' tabIndex='-1' role='dialog' aria-hidden='true'>
+ <div className='modal-dialog'>
+ <div className='modal-content'>
+ <div className='modal-header'>
+ <button type='button' className='close' data-dismiss='modal'>
+ <span aria-hidden='true'>&times;</span>
+ <span className='sr-only'>Close</span>
</button>
- <h4 className="modal-title">More Private Messages</h4>
+ <h4 className='modal-title'>More Private Messages</h4>
</div>
- <div className="modal-body">
- <ul className="nav nav-pills nav-stacked">
+ <div className='modal-body'>
+ <ul className='nav nav-pills nav-stacked'>
{directMessageItems}
</ul>
</div>
- <div className="modal-footer">
- <button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
+ <div className='modal-footer'>
+ <button type='button' className='btn btn-default' data-dismiss='modal'>Close</button>
</div>
</div>
</div>
</div>
-
);
}
});
diff --git a/web/react/components/navbar.jsx b/web/react/components/navbar.jsx
index 6d23c0d9b..3e0a66e92 100644
--- a/web/react/components/navbar.jsx
+++ b/web/react/components/navbar.jsx
@@ -1,111 +1,62 @@
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
-
-var utils = require('../utils/utils.jsx');
var client = require('../utils/client.jsx');
var AsyncClient = require('../utils/async_client.jsx');
var UserStore = require('../stores/user_store.jsx');
var ChannelStore = require('../stores/channel_store.jsx');
var TeamStore = require('../stores/team_store.jsx');
-
-var UserProfile = require('./user_profile.jsx');
var MessageWrapper = require('./message_wrapper.jsx');
+var NotifyCounts = require('./notify_counts.jsx');
var Constants = require('../utils/constants.jsx');
var ActionTypes = Constants.ActionTypes;
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
-function getCountsStateFromStores() {
- var count = 0;
- var channels = ChannelStore.getAll();
- var members = ChannelStore.getAllMembers();
-
- channels.forEach(function(channel) {
- var channelMember = members[channel.id];
- if (channel.type === 'D') {
- count += channel.total_msg_count - channelMember.msg_count;
- } else {
- if (channelMember.mention_count > 0) {
- count += channelMember.mention_count;
- } else if (channelMember.notify_level !== "quiet" && channel.total_msg_count - channelMember.msg_count > 0) {
- count += 1;
- }
- }
- });
-
- return { count: count };
-}
-
-var NotifyCounts = React.createClass({
- componentDidMount: function() {
- ChannelStore.addChangeListener(this._onChange);
- },
- componentWillUnmount: function() {
- ChannelStore.removeChangeListener(this._onChange);
- },
- _onChange: function() {
- var newState = getCountsStateFromStores();
- if (!utils.areStatesEqual(newState, this.state)) {
- this.setState(newState);
- }
- },
- getInitialState: function() {
- return getCountsStateFromStores();
- },
- render: function() {
- if (this.state.count) {
- return <span className="badge badge-notify">{ this.state.count }</span>;
- } else {
- return null;
- }
- }
-});
-
function getStateFromStores() {
- return {
- channel: ChannelStore.getCurrent(),
- member: ChannelStore.getCurrentMember(),
- users: ChannelStore.getCurrentExtraInfo().members
- };
+ return {
+ channel: ChannelStore.getCurrent(),
+ member: ChannelStore.getCurrentMember(),
+ users: ChannelStore.getCurrentExtraInfo().members
+ };
}
module.exports = React.createClass({
displayName: 'Navbar',
-
+ propTypes: {
+ teamDisplayName: React.PropTypes.string
+ },
componentDidMount: function() {
- ChannelStore.addChangeListener(this._onChange);
- ChannelStore.addExtraInfoChangeListener(this._onChange);
+ ChannelStore.addChangeListener(this.onListenerChange);
+ ChannelStore.addExtraInfoChangeListener(this.onListenerChange);
$('.inner__wrap').click(this.hideSidebars);
- $('body').on('click.infopopover', function(e) {
- if ($(e.target).attr('data-toggle') !== 'popover'
- && $(e.target).parents('.popover.in').length === 0) {
+ $('body').on('click.infopopover', function handlePopoverClick(e) {
+ if ($(e.target).attr('data-toggle') !== 'popover' && $(e.target).parents('.popover.in').length === 0) {
$('.info-popover').popover('hide');
}
});
-
},
componentWillUnmount: function() {
- ChannelStore.removeChangeListener(this._onChange);
+ ChannelStore.removeChangeListener(this.onListenerChange);
},
handleSubmit: function(e) {
e.preventDefault();
},
- handleLeave: function(e) {
+ handleLeave: function() {
client.leaveChannel(this.state.channel.id,
- function(data, text, req) {
+ function success() {
AsyncClient.getChannels(true);
window.location.href = TeamStore.getCurrentTeamUrl() + '/channels/town-square';
- }.bind(this),
- function(err) {
- AsyncClient.dispatchError(err, "handleLeave");
+ },
+ function error(err) {
+ AsyncClient.dispatchError(err, 'handleLeave');
}
);
},
hideSidebars: function(e) {
var windowWidth = $(window).outerWidth();
- if(windowWidth <= 768) {
+ if (windowWidth <= 768) {
AppDispatcher.handleServerAction({
type: ActionTypes.RECIEVED_SEARCH,
results: null
@@ -116,7 +67,7 @@ module.exports = React.createClass({
results: null
});
- if (e.target.className != 'navbar-toggle' && e.target.className != 'icon-bar') {
+ if (e.target.className !== 'navbar-toggle' && e.target.className !== 'icon-bar') {
$('.inner__wrap').removeClass('move--right move--left move--left-small');
$('.sidebar--left').removeClass('move--right');
$('.sidebar--right').removeClass('move--left');
@@ -132,27 +83,24 @@ module.exports = React.createClass({
$('.inner__wrap').toggleClass('move--left-small');
$('.sidebar--menu').toggleClass('move--left');
},
- _onChange: function() {
+ onListenerChange: function() {
this.setState(getStateFromStores());
- $("#navbar .navbar-brand .description").popover({placement : 'bottom', trigger: 'click', html: true});
+ $('#navbar .navbar-brand .description').popover({placement: 'bottom', trigger: 'click', html: true});
},
getInitialState: function() {
return getStateFromStores();
},
render: function() {
-
var currentId = UserStore.getCurrentId();
- var popoverContent = "";
+ var popoverContent = '';
var channelTitle = this.props.teamDisplayName;
var isAdmin = false;
var isDirect = false;
- var description = ""
var channel = this.state.channel;
if (channel) {
- description = utils.textToJsx(channel.description, {"singleline": true, "noMentionHighlight": true});
- popoverContent = React.renderToString(<MessageWrapper message={channel.description}/>);
- isAdmin = this.state.member.roles.indexOf("admin") > -1;
+ popoverContent = React.renderToString(<MessageWrapper message={channel.description} options={{singleline: true, noMentionHighlight: true}}/>);
+ isAdmin = this.state.member.roles.indexOf('admin') > -1;
if (channel.type === 'O') {
channelTitle = channel.display_name;
@@ -162,92 +110,112 @@ module.exports = React.createClass({
isDirect = true;
if (this.state.users.length > 1) {
if (this.state.users[0].id === currentId) {
- channelTitle = <UserProfile userId={this.state.users[1].id} />;
+ channelTitle = UserStore.getProfile(this.state.users[1].id).username;
} else {
- channelTitle = <UserProfile userId={this.state.users[0].id} />;
+ channelTitle = UserStore.getProfile(this.state.users[0].id).username;
}
}
}
- if (channel.description.length == 0) {
+ if (channel.description.length === 0) {
popoverContent = React.renderToString(<div>No channel description yet. <br /><a href='#' data-toggle='modal' data-desc={channel.description} data-title={channel.display_name} data-channelid={channel.id} data-target='#edit_channel'>Click here</a> to add one.</div>);
}
}
- var navbar_collapse_button = currentId != null ? null :
- <button type="button" className="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
- <span className="sr-only">Toggle sidebar</span>
- <span className="icon-bar"></span>
- <span className="icon-bar"></span>
- <span className="icon-bar"></span>
- </button>;
- var sidebar_collapse_button = currentId == null ? null :
- <button type="button" className="navbar-toggle" data-toggle="collapse" data-target="#sidebar-nav" onClick={this.toggleLeftSidebar}>
- <span className="sr-only">Toggle sidebar</span>
- <span className="icon-bar"></span>
- <span className="icon-bar"></span>
- <span className="icon-bar"></span>
- <NotifyCounts />
- </button>;
- var right_sidebar_collapse_button= currentId == null ? null :
- <button type="button" className="navbar-toggle menu-toggle pull-right" data-toggle="collapse" data-target="#sidebar-nav" onClick={this.toggleRightSidebar}>
- <span dangerouslySetInnerHTML={{__html: Constants.MENU_ICON }} />
- </button>;
+ var navbarCollapseButton = null;
+ if (currentId == null) {
+ navbarCollapseButton = (<button type='button' className='navbar-toggle' data-toggle='collapse' data-target='#navbar-collapse-1'>
+ <span className='sr-only'>Toggle sidebar</span>
+ <span className='icon-bar'></span>
+ <span className='icon-bar'></span>
+ <span className='icon-bar'></span>
+ </button>);
+ }
+
+ var sidebarCollapseButton = null;
+ if (currentId != null) {
+ sidebarCollapseButton = (<button type='button' className='navbar-toggle' data-toggle='collapse' data-target='#sidebar-nav' onClick={this.toggleLeftSidebar}>
+ <span className='sr-only'>Toggle sidebar</span>
+ <span className='icon-bar'></span>
+ <span className='icon-bar'></span>
+ <span className='icon-bar'></span>
+ <NotifyCounts />
+ </button>);
+ }
+
+ var rightSidebarCollapseButton = null;
+ if (currentId != null) {
+ rightSidebarCollapseButton = (<button type='button' className='navbar-toggle menu-toggle pull-right' data-toggle='collapse' data-target='#sidebar-nav' onClick={this.toggleRightSidebar}>
+ <span dangerouslySetInnerHTML={{__html: Constants.MENU_ICON}} />
+ </button>);
+ }
+
+ var channelMenuDropdown = null;
+ if (channel) {
+ var addMembersOption = null;
+ if (!isDirect && !ChannelStore.isDefault(channel)) {
+ addMembersOption = <li role='presentation'><a role='menuitem' data-toggle='modal' data-target='#channel_invite' href='#'>Add Members</a></li>;
+ }
+
+ var manageMembersOption = null;
+ if (!isDirect && isAdmin && !ChannelStore.isDefault(channel)) {
+ manageMembersOption = <li role='presentation'><a role='menuitem' data-toggle='modal' data-target='#channel_members' href='#'>Manage Members</a></li>;
+ }
+
+ var setChannelDescriptionOption = <li role='presentation'><a role='menuitem' href='#' data-toggle='modal' data-target='#edit_channel' data-desc={channel.description} data-title={channel.display_name} data-channelid={channel.id}>Set Channel Description...</a></li>;
+
+ var notificationPreferenceOption = null;
+ if (!isDirect) {
+ notificationPreferenceOption = <li role='presentation'><a role='menuitem' href='#' data-toggle='modal' data-target='#channel_notifications' data-title={channel.display_name} data-channelid={channel.id}>Notification Preferences</a></li>;
+ }
+
+ var renameChannelOption = null;
+ if (!isDirect && isAdmin && !ChannelStore.isDefault(channel)) {
+ renameChannelOption = <li role='presentation'><a role='menuitem' href='#' data-toggle='modal' data-target='#rename_channel' data-display={channel.display_name} data-name={channel.name} data-channelid={channel.id}>Rename Channel...</a></li>;
+ }
+ var deleteChannelOption = null;
+ if (!isDirect && isAdmin && !ChannelStore.isDefault(channel)) {
+ deleteChannelOption = <li role='presentation'><a role='menuitem' href='#' data-toggle='modal' data-target='#delete_channel' data-title={channel.display_name} data-channelid={channel.id}>Delete Channel...</a></li>;
+ }
+
+ var leaveChannelOption = null;
+ if (!isDirect && !ChannelStore.isDefault(channel)) {
+ leaveChannelOption = <li role='presentation'><a role='menuitem' href='#' onClick={this.handleLeave}>Leave Channel</a></li>;
+ }
+
+ channelMenuDropdown = (<div className='navbar-brand'>
+ <div className='dropdown'>
+ <div data-toggle='popover' data-content={popoverContent} className='description info-popover'></div>
+ <a href='#' className='dropdown-toggle theme' type='button' id='channel_header_dropdown' data-toggle='dropdown' aria-expanded='true'>
+ <span className='heading'>{channelTitle} </span>
+ <span className='glyphicon glyphicon-chevron-down header-dropdown__icon'></span>
+ </a>
+ <ul className='dropdown-menu' role='menu' aria-labelledby='channel_header_dropdown'>
+ {addMembersOption}
+ {manageMembersOption}
+ {setChannelDescriptionOption}
+ {notificationPreferenceOption}
+ {renameChannelOption}
+ {deleteChannelOption}
+ {leaveChannelOption}
+ </ul>
+ </div>
+ </div>);
+ } else {
+ channelMenuDropdown = (<div className='navbar-brand'>
+ <a href='/' className='heading'>{channelTitle}</a>
+ </div>);
+ }
return (
- <nav className="navbar navbar-default navbar-fixed-top" role="navigation">
- <div className="container-fluid theme">
- <div className="navbar-header">
- { navbar_collapse_button }
- { sidebar_collapse_button }
- { right_sidebar_collapse_button }
- { !isDirect && channel ?
- <div className="navbar-brand">
- <div className="dropdown">
- <div data-toggle="popover" data-content={popoverContent} className="description info-popover"></div>
- <a href="#" className="dropdown-toggle theme" type="button" id="channel_header_dropdown" data-toggle="dropdown" aria-expanded="true">
- <span className="heading">{channelTitle} </span>
- <span className="glyphicon glyphicon-chevron-down header-dropdown__icon"></span>
- </a>
- <ul className="dropdown-menu" role="menu" aria-labelledby="channel_header_dropdown">
- { !ChannelStore.isDefault(channel) ?
- <li role="presentation"><a role="menuitem" data-toggle="modal" data-target="#channel_invite" href="#">Add Members</a></li>
- : null
- }
- { isAdmin && !ChannelStore.isDefault(channel) ?
- <li role="presentation"><a role="menuitem" data-toggle="modal" data-target="#channel_members" href="#">Manage Members</a></li>
- : null
- }
- <li role="presentation"><a role="menuitem" href="#" data-toggle="modal" data-target="#edit_channel" data-desc={channel.description} data-title={channel.display_name} data-channelid={channel.id}>Set Channel Description...</a></li>
- <li role="presentation"><a role="menuitem" href="#" data-toggle="modal" data-target="#channel_notifications" data-title={channel.display_name} data-channelid={channel.id}>Notification Preferences</a></li>
- { isAdmin && !ChannelStore.isDefault(channel) ?
- <li role="presentation"><a role="menuitem" href="#" data-toggle="modal" data-target="#rename_channel" data-display={channel.display_name} data-name={channel.name} data-channelid={channel.id}>Rename Channel...</a></li>
- : null
- }
- { isAdmin && !ChannelStore.isDefault(channel) ?
- <li role="presentation"><a role="menuitem" href="#" data-toggle="modal" data-target="#delete_channel" data-title={channel.display_name} data-channelid={channel.id}>Delete Channel...</a></li>
- : null
- }
- { !ChannelStore.isDefault(channel) ?
- <li role="presentation"><a role="menuitem" href="#" onClick={this.handleLeave}>Leave Channel</a></li>
- : null
- }
- </ul>
- </div>
- </div>
- : null
- }
- { isDirect && channel ?
- <div className="navbar-brand">
- <a href="#" className="heading">{ channelTitle }</a>
- </div>
- : null }
- { !channel ?
- <div className="navbar-brand">
- <a href="/" className="heading">{ channelTitle }</a>
- </div>
- : "" }
+ <nav className='navbar navbar-default navbar-fixed-top' role='navigation'>
+ <div className='container-fluid theme'>
+ <div className='navbar-header'>
+ {navbarCollapseButton}
+ {sidebarCollapseButton}
+ {rightSidebarCollapseButton}
+ {channelMenuDropdown}
</div>
</div>
</nav>
diff --git a/web/react/components/notify_counts.jsx b/web/react/components/notify_counts.jsx
new file mode 100644
index 000000000..ebc49882b
--- /dev/null
+++ b/web/react/components/notify_counts.jsx
@@ -0,0 +1,49 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var utils = require('../utils/utils.jsx');
+var ChannelStore = require('../stores/channel_store.jsx');
+
+function getCountsStateFromStores() {
+ var count = 0;
+ var channels = ChannelStore.getAll();
+ var members = ChannelStore.getAllMembers();
+
+ channels.forEach(function setChannelInfo(channel) {
+ var channelMember = members[channel.id];
+ if (channel.type === 'D') {
+ count += channel.total_msg_count - channelMember.msg_count;
+ } else if (channelMember.mention_count > 0) {
+ count += channelMember.mention_count;
+ } else if (channelMember.notify_level !== 'quiet' && channel.total_msg_count - channelMember.msg_count > 0) {
+ count += 1;
+ }
+ });
+
+ return {count: count};
+}
+
+module.exports = React.createClass({
+ displayName: 'NotifyCounts',
+ componentDidMount: function() {
+ ChannelStore.addChangeListener(this.onListenerChange);
+ },
+ componentWillUnmount: function() {
+ ChannelStore.removeChangeListener(this.onListenerChange);
+ },
+ onListenerChange: function() {
+ var newState = getCountsStateFromStores();
+ if (!utils.areStatesEqual(newState, this.state)) {
+ this.setState(newState);
+ }
+ },
+ getInitialState: function() {
+ return getCountsStateFromStores();
+ },
+ render: function() {
+ if (this.state.count) {
+ return <span className='badge badge-notify'>{this.state.count}</span>;
+ }
+ return null;
+ }
+});
diff --git a/web/react/components/post.jsx b/web/react/components/post.jsx
index b798dc7ca..7bc6a8c01 100644
--- a/web/react/components/post.jsx
+++ b/web/react/components/post.jsx
@@ -3,7 +3,6 @@
var PostHeader = require('./post_header.jsx');
var PostBody = require('./post_body.jsx');
-var PostInfo = require('./post_info.jsx');
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var Constants = require('../utils/constants.jsx');
var UserStore = require('../stores/user_store.jsx');
@@ -13,6 +12,8 @@ var client = require('../utils/client.jsx');
var AsyncClient = require('../utils/async_client.jsx');
var ActionTypes = Constants.ActionTypes;
+var PostInfo = require('./post_info.jsx');
+
module.exports = React.createClass({
displayName: "Post",
handleCommentClick: function(e) {
diff --git a/web/react/components/post_info.jsx b/web/react/components/post_info.jsx
index f6ab0ed8a..c96a04c7c 100644
--- a/web/react/components/post_info.jsx
+++ b/web/react/components/post_info.jsx
@@ -6,68 +6,145 @@ var utils = require('../utils/utils.jsx');
var Constants = require('../utils/constants.jsx');
-module.exports = React.createClass({
- getInitialState: function() {
- return { };
- },
- render: function() {
+export default class PostInfo extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {};
+ }
+ shouldShowComment(state, type, isOwner) {
+ if (state === Constants.POST_FAILED || state === Constants.POST_LOADING) {
+ return false;
+ }
+ return isOwner || (this.props.allowReply === 'true' && type !== 'Comment');
+ }
+ createDropdown() {
var post = this.props.post;
var isOwner = UserStore.getCurrentId() === post.user_id;
var isAdmin = UserStore.getCurrentUser().roles.indexOf('admin') > -1;
+ if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING || post.state === Constants.POST_DELETED) {
+ return '';
+ }
+
var type = 'Post';
if (post.root_id && post.root_id.length > 0) {
type = 'Comment';
}
- var comments = '';
- var lastCommentClass = ' comment-icon__container__hide';
- if (this.props.isLastComment) {
- lastCommentClass = ' comment-icon__container__show';
+ if (!this.shouldShowComment(post.state, type, isOwner)) {
+ return '';
}
- if (this.props.commentCount >= 1 && post.state !== Constants.POST_FAILED && post.state !== Constants.POST_LOADING) {
- comments = <a href='#' className={'comment-icon__container theme' + lastCommentClass} onClick={this.props.handleCommentClick}><span className='comment-icon' dangerouslySetInnerHTML={{__html: Constants.COMMENT_ICON}} />{this.props.commentCount}</a>;
+ var dropdownContents = [];
+ var dataComments = 0;
+ if (type === 'Post') {
+ dataComments = this.props.commentCount;
}
- var showDropdown = isOwner || (this.props.allowReply === 'true' && type !== 'Comment');
- if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING) {
- showDropdown = false;
+ if (isOwner) {
+ dropdownContents.push(
+ <li role='presentation'>
+ <a
+ href='#'
+ role='menuitem'
+ data-toggle='modal'
+ data-target='#edit_post'
+ data-title={type}
+ data-message={post.message}
+ data-postid={post.id}
+ data-channelid={post.channel_id}
+ data-comments={dataComments}
+ >
+ Edit
+ </a>
+ </li>
+ );
}
- var dropdownContents = [];
- var dropdown;
- if (showDropdown) {
- var dataComments = 0;
- if (type === 'Post') {
- dataComments = this.props.commentCount;
- }
-
- if (isOwner) {
- dropdownContents.push(<li role='presentation'><a href='#' role='menuitem' data-toggle='modal' data-target='#edit_post' data-title={type} data-message={post.message} data-postid={post.id} data-channelid={post.channel_id} data-comments={dataComments}>Edit</a></li>);
- }
+ if (isOwner || isAdmin) {
+ dropdownContents.push(
+ <li role='presentation'>
+ <a
+ href='#'
+ role='menuitem'
+ data-toggle='modal'
+ data-target='#delete_post'
+ data-title={type}
+ data-postid={post.id}
+ data-channelid={post.channel_id}
+ data-comments={dataComments}
+ >
+ Delete
+ </a>
+ </li>
+ );
+ }
- if (isOwner || isAdmin) {
- dropdownContents.push(<li role='presentation'><a href='#' role='menuitem' data-toggle='modal' data-target='#delete_post' data-title={type} data-postid={post.id} data-channelid={post.channel_id} data-comments={dataComments}>Delete</a></li>);
- }
+ if (this.props.allowReply === 'true') {
+ dropdownContents.push(
+ <li role='presentation'>
+ <a
+ className='reply-link theme'
+ href='#'
+ onClick={this.props.handleCommentClick}
+ >
+ Reply
+ </a>
+ </li>
+ );
+ }
- if (this.props.allowReply === 'true') {
- dropdownContents.push(<li role='presentation'><a className='reply-link theme' href='#' onClick={this.props.handleCommentClick}>Reply</a></li>);
- }
+ return (
+ <div>
+ <a
+ href='#'
+ className='dropdown-toggle theme'
+ type='button'
+ data-toggle='dropdown'
+ aria-expanded='false'
+ />
+ <ul
+ className='dropdown-menu'
+ role='menu'
+ >
+ {dropdownContents}
+ </ul>
+ </div>
+ );
+ }
+ render() {
+ var post = this.props.post;
+ var comments = '';
+ var lastCommentClass = ' comment-icon__container__hide';
+ if (this.props.isLastComment) {
+ lastCommentClass = ' comment-icon__container__show';
+ }
- dropdown = (
- <div>
- <a href='#' className='dropdown-toggle theme' type='button' data-toggle='dropdown' aria-expanded='false' />
- <ul className='dropdown-menu' role='menu'>
- {dropdownContents}
- </ul>
- </div>
+ if (this.props.commentCount >= 1 && post.state !== Constants.POST_FAILED && post.state !== Constants.POST_LOADING) {
+ comments = (
+ <a
+ href='#'
+ className={'comment-icon__container theme' + lastCommentClass}
+ onClick={this.props.handleCommentClick}
+ >
+ <span
+ className='comment-icon'
+ dangerouslySetInnerHTML={{__html: Constants.COMMENT_ICON}}
+ />
+ {this.props.commentCount}
+ </a>
);
}
+ var dropdown = this.createDropdown();
+
return (
<ul className='post-header post-info'>
- <li className='post-header-col'><time className='post-profile-time'>{utils.displayDateTime(post.create_at)}</time></li>
+ <li className='post-header-col'>
+ <time className='post-profile-time'>
+ {utils.displayDateTime(post.create_at)}
+ </time>
+ </li>
<li className='post-header-col post-header__reply'>
<div className='dropdown'>
{dropdown}
@@ -77,4 +154,18 @@ module.exports = React.createClass({
</ul>
);
}
-});
+}
+
+PostInfo.defaultProps = {
+ post: null,
+ commentCount: 0,
+ isLastComment: false,
+ allowReply: false
+};
+PostInfo.propTypes = {
+ post: React.PropTypes.object,
+ commentCount: React.PropTypes.number,
+ isLastComment: React.PropTypes.bool,
+ allowReply: React.PropTypes.string,
+ handleCommentClick: React.PropTypes.func
+};
diff --git a/web/react/components/post_list.jsx b/web/react/components/post_list.jsx
index c210853ac..5fbee99f6 100644
--- a/web/react/components/post_list.jsx
+++ b/web/react/components/post_list.jsx
@@ -23,12 +23,31 @@ function getStateFromStores() {
}
var postList = PostStore.getCurrentPosts();
+ var deletedPosts = PostStore.getUnseenDeletedPosts(channel.id);
+
+ if (deletedPosts && Object.keys(deletedPosts).length > 0) {
+ for (var pid in deletedPosts) {
+ postList.posts[pid] = deletedPosts[pid];
+ postList.order.unshift(pid);
+ }
+
+ postList.order.sort(function postSort(a, b) {
+ if (postList.posts[a].create_at > postList.posts[b].create_at) {
+ return -1;
+ }
+ if (postList.posts[a].create_at < postList.posts[b].create_at) {
+ return 1;
+ }
+ return 0;
+ });
+ }
+
var pendingPostList = PostStore.getPendingPosts(channel.id);
if (pendingPostList) {
postList.order = pendingPostList.order.concat(postList.order);
- for (var pid in pendingPostList.posts) {
- postList.posts[pid] = pendingPostList.posts[pid];
+ for (var ppid in pendingPostList.posts) {
+ postList.posts[ppid] = pendingPostList.posts[ppid];
}
}
@@ -88,7 +107,6 @@ module.exports = React.createClass({
$('.modal-body').css('max-height', $(window).height() * 0.7);
});
- // Timeout exists for the DOM to fully render before making changes
var self = this;
$(window).resize(function resize() {
$(postHolder).perfectScrollbar('update');
@@ -185,6 +203,7 @@ module.exports = React.createClass({
}
}
if (this.state.channel.id !== newState.channel.id) {
+ PostStore.clearUnseenDeletedPosts(this.state.channel.id);
this.scrolledToNew = false;
}
this.setState(newState);
@@ -198,12 +217,6 @@ module.exports = React.createClass({
PostStore.storePost(post);
} else if (msg.action === 'post_edited') {
if (this.state.channel.id === msg.channel_id) {
- this.setState({postList: postList});
- }
-
- PostStore.storePosts(post.channel_id, postList);
- } else if (msg.action === 'post_edited') {
- if (this.state.channel.id === msg.channel_id) {
postList = this.state.postList;
if (!(msg.props.post_id in postList.posts)) {
return;
@@ -226,23 +239,19 @@ module.exports = React.createClass({
activeRootPostId = activeRoot.id;
}
- if (this.state.channel.id === msg.channel_id) {
- postList = this.state.postList;
- if (!(msg.props.post_id in this.state.postList.posts)) {
- return;
- }
+ post = JSON.parse(msg.props.post);
+ postList = this.state.postList;
- delete postList.posts[msg.props.post_id];
- var index = postList.order.indexOf(msg.props.post_id);
+ PostStore.storeUnseenDeletedPost(post);
+
+ if (postList.posts[post.id]) {
+ delete postList.posts[post.id];
+ var index = postList.order.indexOf(post.id);
if (index > -1) {
postList.order.splice(index, 1);
}
- this.setState({postList: postList});
-
PostStore.storePosts(msg.channel_id, postList);
- } else {
- AsyncClient.getPosts(true, msg.channel_id);
}
if (activeRootPostId === msg.props.post_id && UserStore.getCurrentId() !== msg.user_id) {
@@ -324,7 +333,7 @@ module.exports = React.createClass({
var lastViewed = Number.MAX_VALUE;
if (ChannelStore.getCurrentMember() != null) {
- lastViewed = ChannelStore.getCurrentMember().lastViewed_at;
+ lastViewed = ChannelStore.getCurrentMember().last_viewed_at;
}
if (this.state.postList != null) {
diff --git a/web/react/components/post_right.jsx b/web/react/components/post_right.jsx
index 175e1080d..c8c51b0c3 100644
--- a/web/react/components/post_right.jsx
+++ b/web/react/components/post_right.jsx
@@ -120,7 +120,7 @@ RootPost = React.createClass({
<div className='post__content'>
<ul className='post-header'>
<li className='post-header-col'><strong><UserProfile userId={post.user_id} /></strong></li>
- <li className='post-header-col'><time className='post-right-root-time'>{utils.displayDate(post.create_at) + ' ' + utils.displayTime(post.create_at)}</time></li>
+ <li className='post-header-col'><time className='post-right-root-time'>{utils.displayCommentDateTime(post.create_at)}</time></li>
<li className='post-header-col post-header__reply'>
<div className='dropdown'>
{ownerOptions}
@@ -229,7 +229,7 @@ CommentPost = React.createClass({
<div className='post__content'>
<ul className='post-header'>
<li className='post-header-col'><strong><UserProfile userId={post.user_id} /></strong></li>
- <li className='post-header-col'><time className='post-right-comment-time'>{utils.displayDateTime(post.create_at)}</time></li>
+ <li className='post-header-col'><time className='post-right-comment-time'>{utils.displayCommentDateTime(post.create_at)}</time></li>
<li className='post-header-col post-header__reply'>
{ownerOptions}
</li>
diff --git a/web/react/components/setting_item_max.jsx b/web/react/components/setting_item_max.jsx
index 49eb58773..d3d386534 100644
--- a/web/react/components/setting_item_max.jsx
+++ b/web/react/components/setting_item_max.jsx
@@ -3,7 +3,7 @@
module.exports = React.createClass({
render: function() {
- var client_error = this.props.client_error ? <div className='form-group'><label className='col-sm-12 has-error'>{ this.props.client_error }</label></div> : null;
+ var clientError = this.props.clientError ? <div className='form-group'><label className='col-sm-12 has-error'>{ this.props.clientError }</label></div> : null;
var server_error = this.props.server_error ? <div className='form-group'><label className='col-sm-12 has-error'>{ this.props.server_error }</label></div> : null;
var inputs = this.props.inputs;
@@ -19,7 +19,7 @@ module.exports = React.createClass({
<li className="setting-list-item">
<hr />
{ server_error }
- { client_error }
+ { clientError }
{ this.props.submit ? <a className="btn btn-sm btn-primary" onClick={this.props.submit}>Submit</a> : "" }
<a className="btn btn-sm theme" href="#" onClick={this.props.updateSection}>Cancel</a>
</li>
diff --git a/web/react/components/setting_upload.jsx b/web/react/components/setting_upload.jsx
new file mode 100644
index 000000000..870710850
--- /dev/null
+++ b/web/react/components/setting_upload.jsx
@@ -0,0 +1,79 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+module.exports = React.createClass({
+ displayName: 'Setting Upload',
+ propTypes: {
+ title: React.PropTypes.string.isRequired,
+ submit: React.PropTypes.func.isRequired,
+ fileTypesAccepted: React.PropTypes.string.isRequired,
+ clientError: React.PropTypes.string,
+ serverError: React.PropTypes.string
+ },
+ getInitialState: function() {
+ return {
+ clientError: this.props.clientError,
+ serverError: this.props.serverError
+ };
+ },
+ componentWillReceiveProps: function() {
+ this.setState({
+ clientError: this.props.clientError,
+ serverError: this.props.serverError
+ });
+ },
+ doFileSelect: function(e) {
+ e.preventDefault();
+ this.setState({
+ clientError: '',
+ serverError: ''
+ });
+ },
+ doSubmit: function(e) {
+ e.preventDefault();
+ var inputnode = this.refs.uploadinput.getDOMNode();
+ if (inputnode.files && inputnode.files[0]) {
+ this.props.submit(inputnode.files[0]);
+ } else {
+ this.setState({clientError: 'No file selected.'});
+ }
+ },
+ doCancel: function(e) {
+ e.preventDefault();
+ this.refs.uploadinput.getDOMNode().value = '';
+ this.setState({
+ clientError: '',
+ serverError: ''
+ });
+ },
+ render: function() {
+ var clientError = null;
+ if (this.state.clientError) {
+ clientError = (
+ <div className='form-group has-error'><label className='control-label'>{this.state.clientError}</label></div>
+ );
+ }
+ var serverError = null;
+ if (this.state.serverError) {
+ serverError = (
+ <div className='form-group has-error'><label className='control-label'>{this.state.serverError}</label></div>
+ );
+ }
+ return (
+ <ul className='section-max'>
+ <li className='col-xs-12 section-title'>{this.props.title}</li>
+ <li className='col-xs-offset-3 col-xs-8'>
+ <ul className='setting-list'>
+ <li className='setting-list-item'>
+ {serverError}
+ {clientError}
+ <span className='btn btn-sm btn-primary btn-file sel-btn'>SelectFile<input ref='uploadinput' accept={this.props.fileTypesAccepted} type='file' onChange={this.onFileSelect}/></span>
+ <a className={'btn btn-sm btn-primary'} onClick={this.doSubmit}>Import</a>
+ <a className='btn btn-sm theme' href='#' onClick={this.doCancel}>Cancel</a>
+ </li>
+ </ul>
+ </li>
+ </ul>
+ );
+ }
+});
diff --git a/web/react/components/settings_sidebar.jsx b/web/react/components/settings_sidebar.jsx
index b4d291622..d8091ec28 100644
--- a/web/react/components/settings_sidebar.jsx
+++ b/web/react/components/settings_sidebar.jsx
@@ -15,7 +15,7 @@ module.exports = React.createClass({
<div className="">
<ul className="nav nav-pills nav-stacked">
{this.props.tabs.map(function(tab) {
- return <li key={tab.name+'_li'} className={self.props.activeTab == tab.name ? 'active' : ''}><a key={tab.name + '_a'} href="#" onClick={function(){self.updateTab(tab.name);}}><i key={tab.name+'_i'} className={tab.icon}></i>{tab.ui_name}</a></li>
+ return <li key={tab.name+'_li'} className={self.props.activeTab == tab.name ? 'active' : ''}><a key={tab.name + '_a'} href="#" onClick={function(){self.updateTab(tab.name);}}><i key={tab.name+'_i'} className={tab.icon}></i>{tab.uiName}</a></li>
})}
</ul>
</div>
diff --git a/web/react/components/sidebar.jsx b/web/react/components/sidebar.jsx
index 6735bd6e5..d79505e9e 100644
--- a/web/react/components/sidebar.jsx
+++ b/web/react/components/sidebar.jsx
@@ -1,8 +1,8 @@
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
-var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
var ChannelStore = require('../stores/channel_store.jsx');
+var Client = require('../utils/client.jsx');
var AsyncClient = require('../utils/async_client.jsx');
var SocketStore = require('../stores/socket_store.jsx');
var UserStore = require('../stores/user_store.jsx');
@@ -11,9 +11,7 @@ var BrowserStore = require('../stores/browser_store.jsx');
var utils = require('../utils/utils.jsx');
var SidebarHeader = require('./sidebar_header.jsx');
var SearchBox = require('./search_bar.jsx');
-
var Constants = require('../utils/constants.jsx');
-var ActionTypes = Constants.ActionTypes;
function getStateFromStores() {
var members = ChannelStore.getAllMembers();
@@ -70,13 +68,14 @@ function getStateFromStores() {
tempChannel.status = UserStore.getStatus(teammate.id);
tempChannel.last_post_at = 0;
tempChannel.total_msg_count = 0;
+ tempChannel.type = 'D';
readDirectChannels.push(tempChannel);
}
}
// If we don't have MAX_DMS unread channels, sort the read list by last_post_at
if (showDirectChannels.length < Constants.MAX_DMS) {
- readDirectChannels.sort(function(a, b) {
+ readDirectChannels.sort(function sortByLastPost(a, b) {
// sort by last_post_at first
if (a.last_post_at > b.last_post_at) {
return -1;
@@ -124,6 +123,10 @@ function getStateFromStores() {
module.exports = React.createClass({
displayName: 'Sidebar',
+ propTypes: {
+ teamType: React.PropTypes.string,
+ teamDisplayName: React.PropTypes.string
+ },
componentDidMount: function() {
ChannelStore.addChangeListener(this.onChange);
UserStore.addChangeListener(this.onChange);
@@ -244,17 +247,17 @@ module.exports = React.createClass({
var channel = ChannelStore.getCurrent();
if (channel) {
if (channel.type === 'D') {
- var teammate_username = utils.getDirectTeammate(channel.id).username;
- document.title = teammate_username + ' ' + document.title.substring(document.title.lastIndexOf('-'));
+ var teammateUsername = utils.getDirectTeammate(channel.id).username;
+ document.title = teammateUsername + ' ' + document.title.substring(document.title.lastIndexOf('-'));
} else {
document.title = channel.display_name + ' ' + document.title.substring(document.title.lastIndexOf('-'));
}
}
},
- onScroll: function(e) {
+ onScroll: function() {
this.updateUnreadIndicators();
},
- onResize: function(e) {
+ onResize: function() {
this.updateUnreadIndicators();
},
updateUnreadIndicators: function() {
@@ -282,7 +285,10 @@ module.exports = React.createClass({
}
},
getInitialState: function() {
- return getStateFromStores();
+ var newState = getStateFromStores();
+ newState.loadingDMChannel = -1;
+
+ return newState;
},
render: function() {
var members = this.state.members;
@@ -294,8 +300,9 @@ module.exports = React.createClass({
this.firstUnreadChannel = null;
this.lastUnreadChannel = null;
- function createChannelElement(channel) {
+ function createChannelElement(channel, index) {
var channelMember = members[channel.id];
+ var msgCount;
var linkClass = '';
if (channel.id === activeId) {
@@ -304,7 +311,7 @@ module.exports = React.createClass({
var unread = false;
if (channelMember) {
- var msgCount = channel.total_msg_count - channelMember.msg_count;
+ msgCount = channel.total_msg_count - channelMember.msg_count;
unread = (msgCount > 0 && channelMember.notify_level !== 'quiet') || channelMember.mention_count > 0;
}
@@ -322,7 +329,7 @@ module.exports = React.createClass({
if (channelMember) {
if (channel.type === 'D') {
// direct message channels show badges for any number of unread posts
- var msgCount = channel.total_msg_count - channelMember.msg_count;
+ msgCount = channel.total_msg_count - channelMember.msg_count;
if (msgCount > 0) {
badge = <span className='badge pull-right small'>{msgCount}</span>;
badgesActive = true;
@@ -332,6 +339,8 @@ module.exports = React.createClass({
badge = <span className='badge pull-right small'>{channelMember.mention_count}</span>;
badgesActive = true;
}
+ } else if (self.state.loadingDMChannel === index && channel.type === 'D') {
+ badge = <img className='channel-loading-gif pull-right' src='/static/images/load.gif'/>;
}
// set up status icon for direct message channels
@@ -349,39 +358,59 @@ module.exports = React.createClass({
}
// set up click handler to switch channels (or create a new channel for non-existant ones)
- var clickHandler = null;
+ var handleClick = null;
var href = '#';
var teamURL = TeamStore.getCurrentTeamUrl();
+
if (!channel.fake) {
- clickHandler = function(e) {
+ handleClick = function clickHandler(e) {
e.preventDefault();
utils.switchChannel(channel);
};
- }
- if (channel.fake && teamURL){
- href = teamURL + '/channels/' + channel.name;
+ } else if (channel.fake && teamURL) {
+ // It's a direct message channel that doesn't exist yet so let's create it now
+ var otherUserId = utils.getUserIdFromChannelName(channel);
+
+ if (self.state.loadingDMChannel === -1) {
+ handleClick = function clickHandler(e) {
+ e.preventDefault();
+ self.setState({loadingDMChannel: index});
+
+ Client.createDirectChannel(channel, otherUserId,
+ function success(data) {
+ self.setState({loadingDMChannel: -1});
+ AsyncClient.getChannel(data.id);
+ utils.switchChannel(data);
+ },
+ function error() {
+ self.setState({loadingDMChannel: -1});
+ window.location.href = TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name;
+ }
+ );
+ };
+ }
}
return (
<li key={channel.name} ref={channel.name} className={linkClass}>
- <a className={'sidebar-channel ' + titleClass} href={href} onClick={clickHandler}>
+ <a className={'sidebar-channel ' + titleClass} href={href} onClick={handleClick}>
{status}
{channel.display_name}
{badge}
</a>
</li>
);
- };
+ }
// create elements for all 3 types of channels
var channelItems = this.state.channels.filter(
- function(channel) {
+ function filterPublicChannels(channel) {
return channel.type === 'O';
}
).map(createChannelElement);
var privateChannelItems = this.state.channels.filter(
- function(channel) {
+ function filterPrivateChannels(channel) {
return channel.type === 'P';
}
).map(createChannelElement);
@@ -410,7 +439,7 @@ module.exports = React.createClass({
directMessageMore = (
<li>
<a href='#' data-toggle='modal' className='nav-more' data-target='#more_direct_channels' data-channels={JSON.stringify(this.state.hideDirectChannels)}>
- {'More ('+this.state.hideDirectChannels.length+')'}
+ {'More (' + this.state.hideDirectChannels.length + ')'}
</a>
</li>
);
diff --git a/web/react/components/signup_team_complete.jsx b/web/react/components/signup_team_complete.jsx
index e27fcd19d..756aae638 100644
--- a/web/react/components/signup_team_complete.jsx
+++ b/web/react/components/signup_team_complete.jsx
@@ -1,732 +1,22 @@
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
-var utils = require('../utils/utils.jsx');
-var ConfigStore = require('../stores/config_store.jsx');
-var client = require('../utils/client.jsx');
-var UserStore = require('../stores/user_store.jsx');
+var WelcomePage = require('./team_signup_welcome_page.jsx');
+var TeamDisplayNamePage = require('./team_signup_display_name_page.jsx');
+var TeamURLPage = require('./team_signup_url_page.jsx');
+var AllowedDomainsPage = require('./team_signup_allowed_domains_page.jsx');
+var SendInivtesPage = require('./team_signup_send_invites_page.jsx');
+var UsernamePage = require('./team_signup_username_page.jsx');
+var PasswordPage = require('./team_signup_password_page.jsx');
var BrowserStore = require('../stores/browser_store.jsx');
-var constants = require('../utils/constants.jsx');
-
-WelcomePage = React.createClass({
- submitNext: function (e) {
- if (!BrowserStore.isLocalStorageSupported()) {
- this.setState({storageError: 'This service requires local storage to be enabled. Please enable it or exit private browsing.'});
- return;
- }
- e.preventDefault();
- this.props.state.wizard = 'team_display_name';
- this.props.updateParent(this.props.state);
- },
- handleDiffEmail: function (e) {
- e.preventDefault();
- this.setState({useDiff: true});
- },
- handleDiffSubmit: function (e) {
- e.preventDefault();
-
- var state = {useDiff: true, serverError: ''};
-
- var email = this.refs.email.getDOMNode().value.trim().toLowerCase();
- if (!email || !utils.isEmail(email)) {
- state.emailError = 'Please enter a valid email address';
- this.setState(state);
- return;
- } else if (!BrowserStore.isLocalStorageSupported()) {
- state.emailError = 'This service requires local storage to be enabled. Please enable it or exit private browsing.';
- this.setState(state);
- return;
- } else {
- state.emailError = '';
- }
-
- client.signupTeam(email,
- function(data) {
- if (data['follow_link']) {
- window.location.href = data['follow_link'];
- } else {
- this.props.state.wizard = 'finished';
- this.props.updateParent(this.props.state);
- window.location.href = '/signup_team_confirm/?email=' + encodeURIComponent(team.email);
- }
- }.bind(this),
- function(err) {
- this.state.serverError = err.message;
- this.setState(this.state);
- }.bind(this)
- );
- },
- getInitialState: function() {
- return {useDiff: false};
- },
- handleKeyPress: function(event) {
- if (event.keyCode === 13) {
- this.submitNext(event);
- }
- },
- componentWillMount: function() {
- document.addEventListener('keyup', this.handleKeyPress, false);
- },
- componentWillUnmount: function() {
- document.removeEventListener('keyup', this.handleKeyPress, false);
- },
- render: function() {
- client.track('signup', 'signup_team_01_welcome');
-
- var storageError = null;
- if (this.state.storageError) {
- storageError = <label className='control-label'>{this.state.storageError}</label>;
- }
-
- var emailError = null;
- var emailDivClass = 'form-group';
- if (this.state.emailError) {
- emailError = <label className='control-label'>{this.state.emailError}</label>;
- emailDivClass += ' has-error';
- }
-
- var serverError = null;
- if (this.state.serverError) {
- serverError = (
- <div className='form-group has-error'>
- <label className='control-label'>{this.state.serverError}</label>
- </div>
- );
- }
-
- var differentEmailLinkClass = '';
- var emailDivContainerClass = 'hidden';
- if (this.state.useDiff) {
- differentEmailLinkClass = 'hidden';
- emailDivContainerClass = '';
- }
-
- return (
- <div>
- <p>
- <img className='signup-team-logo' src='/static/images/logo.png' />
- <h3 className='sub-heading'>Welcome to:</h3>
- <h1 className='margin--top-none'>{config.SiteName}</h1>
- </p>
- <p className='margin--less'>Let's set up your new team</p>
- <p>
- Please confirm your email address:<br />
- <div className='inner__content'>
- <div className='block--gray'>{this.props.state.team.email}</div>
- </div>
- </p>
- <p className='margin--extra color--light'>
- Your account will administer the new team site. <br />
- You can add other administrators later.
- </p>
- <div className='form-group'>
- <button className='btn-primary btn form-group' type='submit' onClick={this.submitNext}><i className='glyphicon glyphicon-ok'></i>Yes, this address is correct</button>
- {storageError}
- </div>
- <hr />
- <div className={emailDivContainerClass}>
- <div className={emailDivClass}>
- <div className='row'>
- <div className='col-sm-9'>
- <input type='email' ref='email' className='form-control' placeholder='Email Address' maxLength='128' />
- </div>
- </div>
- {emailError}
- </div>
- {serverError}
- <button className='btn btn-md btn-primary' type='button' onClick={this.handleDiffSubmit} type='submit'>Use this instead</button>
- </div>
- <a href='#' onClick={this.handleDiffEmail} className={differentEmailLinkClass}>Use a different email</a>
- </div>
- );
- }
-});
-
-TeamDisplayNamePage = React.createClass({
- submitBack: function (e) {
- e.preventDefault();
- this.props.state.wizard = 'welcome';
- this.props.updateParent(this.props.state);
- },
- submitNext: function (e) {
- e.preventDefault();
-
- var display_name = this.refs.name.getDOMNode().value.trim();
- if (!display_name) {
- this.setState({nameError: 'This field is required'});
- return;
- }
-
- this.props.state.wizard = 'team_url';
- this.props.state.team.display_name = display_name;
- this.props.state.team.name = utils.cleanUpUrlable(display_name);
- this.props.updateParent(this.props.state);
- },
- getInitialState: function() {
- return {};
- },
- handleFocus: function(e) {
- e.preventDefault();
-
- e.currentTarget.select();
- },
- render: function() {
- client.track('signup', 'signup_team_02_name');
-
- var nameError = null;
- var nameDivClass = 'form-group';
- if (this.state.nameError) {
- nameError = <label className='control-label'>{this.state.nameError}</label>;
- nameDivClass += ' has-error';
- }
-
- return (
- <div>
- <form>
- <img className='signup-team-logo' src='/static/images/logo.png' />
-
- <h2>{utils.toTitleCase(strings.Team) + ' Name'}</h2>
- <div className={nameDivClass}>
- <div className='row'>
- <div className='col-sm-9'>
- <input type='text' ref='name' className='form-control' placeholder='' maxLength='128' defaultValue={this.props.state.team.display_name} autoFocus={true} onFocus={this.handleFocus} />
- </div>
- </div>
- {nameError}
- </div>
- <div>{'Name your ' + strings.Team + ' in any language. Your ' + strings.Team + ' name shows in menus and headings.'}</div>
- <button type='submit' className='btn btn-primary margin--extra' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
- <div className='margin--extra'>
- <a href='#' onClick={this.submitBack}>Back to previous step</a>
- </div>
- </form>
- </div>
- );
- }
-});
-
-TeamURLPage = React.createClass({
- submitBack: function (e) {
- e.preventDefault();
- this.props.state.wizard = 'team_display_name';
- this.props.updateParent(this.props.state);
- },
- submitNext: function (e) {
- e.preventDefault();
-
- var name = this.refs.name.getDOMNode().value.trim();
- if (!name) {
- this.setState({nameError: 'This field is required'});
- return;
- }
-
- var cleanedName = utils.cleanUpUrlable(name);
-
- var urlRegex = /^[a-z0-9]+([a-z\-0-9]+|(__)?)[a-z0-9]+$/g;
- if (cleanedName !== name || !urlRegex.test(name)) {
- this.setState({nameError: 'Must be lowercase alphanumeric characters'});
- return;
- } else if (cleanedName.length <= 3 || cleanedName.length > 15) {
- this.setState({nameError: 'Name must be 4 or more characters up to a maximum of 15'});
- return;
- }
-
- for (var index = 0; index < constants.RESERVED_TEAM_NAMES.length; index++) {
- if (cleanedName.indexOf(constants.RESERVED_TEAM_NAMES[index]) === 0) {
- this.setState({nameError: 'This team name is unavailable'});
- return;
- }
- }
-
- client.findTeamByName(name,
- function(data) {
- if (!data) {
- if (config.AllowSignupDomainsWizard) {
- this.props.state.wizard = 'allowed_domains';
- } else {
- this.props.state.wizard = 'send_invites';
- this.props.state.team.type = 'O';
- }
-
- this.props.state.team.name = name;
- this.props.updateParent(this.props.state);
- } else {
- this.state.nameError = 'This URL is unavailable. Please try another.';
- this.setState(this.state);
- }
- }.bind(this),
- function(err) {
- this.state.nameError = err.message;
- this.setState(this.state);
- }.bind(this)
- );
- },
- getInitialState: function() {
- return {};
- },
- handleFocus: function(e) {
- e.preventDefault();
-
- e.currentTarget.select();
- },
- render: function() {
- $('body').tooltip( {selector: '[data-toggle=tooltip]', trigger: 'hover click'} );
-
- client.track('signup', 'signup_team_03_url');
-
- var nameError = null;
- var nameDivClass = 'form-group';
- if (this.state.nameError) {
- nameError = <label className='control-label'>{this.state.nameError}</label>;
- nameDivClass += ' has-error';
- }
-
- return (
- <div>
- <form>
- <img className='signup-team-logo' src='/static/images/logo.png' />
- <h2>{utils.toTitleCase(strings.Team) + ' URL'}</h2>
- <div className={nameDivClass}>
- <div className='row'>
- <div className='col-sm-11'>
- <div className='input-group input-group--limit'>
- <span data-toggle='tooltip' title={utils.getWindowLocationOrigin() + '/'} className='input-group-addon'>{utils.getWindowLocationOrigin() + '/'}</span>
- <input type='text' ref='name' className='form-control' placeholder='' maxLength='128' defaultValue={this.props.state.team.name} autoFocus={true} onFocus={this.handleFocus}/>
- </div>
- </div>
- </div>
- {nameError}
- </div>
- <p>{'Choose the web address of your new ' + strings.Team + ':'}</p>
- <ul className='color--light'>
- <li>Short and memorable is best</li>
- <li>Use lowercase letters, numbers and dashes</li>
- <li>Must start with a letter and can't end in a dash</li>
- </ul>
- <button type='submit' className='btn btn-primary margin--extra' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
- <div className='margin--extra'>
- <a href='#' onClick={this.submitBack}>Back to previous step</a>
- </div>
- </form>
- </div>
- );
- }
-});
-
-AllowedDomainsPage = React.createClass({
- submitBack: function (e) {
- e.preventDefault();
- this.props.state.wizard = 'team_url';
- this.props.updateParent(this.props.state);
- },
- submitNext: function (e) {
- e.preventDefault();
-
- if (this.refs.open_network.getDOMNode().checked) {
- this.props.state.wizard = 'send_invites';
- this.props.state.team.type = 'O';
- this.props.updateParent(this.props.state);
- return;
- }
-
- if (this.refs.allow.getDOMNode().checked) {
- var name = this.refs.name.getDOMNode().value.trim();
- var domainRegex = /^\w+\.\w+$/;
- if (!name) {
- this.setState({nameError: 'This field is required'});
- return;
- }
-
- if (!name.trim().match(domainRegex)) {
- this.setState({nameError: 'The domain doesn\'t appear valid'});
- return;
- }
-
- this.props.state.wizard = 'send_invites';
- this.props.state.team.allowed_domains = name;
- this.props.state.team.type = 'I';
- this.props.updateParent(this.props.state);
- } else {
- this.props.state.wizard = 'send_invites';
- this.props.state.team.type = 'I';
- this.props.updateParent(this.props.state);
- }
- },
- getInitialState: function() {
- return {};
- },
- render: function() {
- client.track('signup', 'signup_team_04_allow_domains');
-
- var nameError = null;
- var nameDivClass = 'form-group';
- if (this.state.nameError) {
- nameError = <label className='control-label'>{this.state.nameError}</label>;
- nameDivClass += ' has-error';
- }
-
- return (
- <div>
- <form>
- <img className='signup-team-logo' src='/static/images/logo.png' />
- <h2>Email Domain</h2>
- <p>
- <div className='checkbox'>
- <label><input type='checkbox' ref='allow' defaultChecked />{' Allow sign up and ' + strings.Team + ' discovery with a ' + strings.Company + ' email address.'}</label>
- </div>
- </p>
- <p>{'Check this box to allow your ' + strings.Team + ' members to sign up using their ' + strings.Company + ' email addresses if you share the same domain--otherwise, you need to invite everyone yourself.'}</p>
- <h4>{'Your ' + strings.Team + '\'s domain for emails'}</h4>
- <div className={nameDivClass}>
- <div className='row'>
- <div className='col-sm-9'>
- <div className='input-group'>
- <span className='input-group-addon'>@</span>
- <input type='text' ref='name' className='form-control' placeholder='' maxLength='128' defaultValue={this.props.state.team.allowed_domains} autoFocus={true} onFocus={this.handleFocus}/>
- </div>
- </div>
- </div>
- {nameError}
- </div>
- <p>To allow signups from multiple domains, separate each with a comma.</p>
- <p>
- <div className='checkbox'>
- <label><input type='checkbox' ref='open_network' defaultChecked={this.props.state.team.type === 'O'} /> Allow anyone to signup to this domain without an invitation.</label>
- </div>
- </p>
- <button type='button' className='btn btn-default' onClick={this.submitBack}><i className='glyphicon glyphicon-chevron-left'></i> Back</button>&nbsp;
- <button type='submit' className='btn-primary btn' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
- </form>
- </div>
- );
- }
-});
-
-EmailItem = React.createClass({
- getInitialState: function() {
- return {};
- },
- getValue: function() {
- return this.refs.email.getDOMNode().value.trim();
- },
- validate: function(teamEmail) {
- var email = this.refs.email.getDOMNode().value.trim().toLowerCase();
-
- if (!email) {
- return true;
- }
-
- if (!utils.isEmail(email)) {
- this.state.emailError = 'Please enter a valid email address';
- this.setState(this.state);
- return false;
- } else if (email === teamEmail) {
- this.state.emailError = 'Please use a different email than the one used at signup';
- this.setState(this.state);
- return false;
- } else {
- this.state.emailError = '';
- this.setState(this.state);
- return true;
- }
- },
- render: function() {
- var emailError = null;
- var emailDivClass = 'form-group';
- if (this.state.emailError) {
- emailError = <label className='control-label'>{ this.state.emailError }</label>;
- emailDivClass += ' has-error';
- }
-
- return (
- <div className={emailDivClass}>
- <input autoFocus={this.props.focus} type='email' ref='email' className='form-control' placeholder='Email Address' defaultValue={this.props.email} maxLength='128' />
- {emailError}
- </div>
- );
- }
-});
-
-SendInivtesPage = React.createClass({
- submitBack: function (e) {
- e.preventDefault();
-
- if (config.AllowSignupDomainsWizard) {
- this.props.state.wizard = 'allowed_domains';
- } else {
- this.props.state.wizard = 'team_url';
- }
-
- this.props.updateParent(this.props.state);
- },
- submitNext: function (e) {
- e.preventDefault();
-
- var valid = true;
-
- if (this.state.emailEnabled) {
- var emails = [];
-
- for (var i = 0; i < this.props.state.invites.length; i++) {
- if (!this.refs['email_' + i].validate(this.props.state.team.email)) {
- valid = false;
- } else {
- emails.push(this.refs['email_' + i].getValue());
- }
- }
-
- if (valid) {
- this.props.state.invites = emails;
- }
- }
-
- if (valid) {
- this.props.state.wizard = 'username';
- this.props.updateParent(this.props.state);
- }
- },
- submitAddInvite: function (e) {
- e.preventDefault();
- this.props.state.wizard = 'send_invites';
- if (!this.props.state.invites) {
- this.props.state.invites = [];
- }
- this.props.state.invites.push('');
- this.props.updateParent(this.props.state);
- },
- submitSkip: function (e) {
- e.preventDefault();
- this.props.state.wizard = 'username';
- this.props.updateParent(this.props.state);
- },
- getInitialState: function() {
- return {
- emailEnabled: !ConfigStore.getSettingAsBoolean('ByPassEmail', false)
- };
- },
- render: function() {
- client.track('signup', 'signup_team_05_send_invites');
-
- var content = null;
- var bottomContent = null;
-
- if (this.state.emailEnabled) {
- var emails = [];
-
- for (var i = 0; i < this.props.state.invites.length; i++) {
- if (i === 0) {
- emails.push(<EmailItem focus={true} key={i} ref={'email_' + i} email={this.props.state.invites[i]} />);
- } else {
- emails.push(<EmailItem focus={false} key={i} ref={'email_' + i} email={this.props.state.invites[i]} />);
- }
- }
-
- content = (
- <div>
- {emails}
- <div className='form-group text-right'><a href='#' onClick={this.submitAddInvite}>Add Invitation</a></div>
- </div>
- );
-
- bottomContent = (
- <p className='color--light'>{'if you prefer, you can invite ' + strings.Team + ' members later'}<br /> and <a href='#' onClick={this.submitSkip}>skip this step</a> for now.</p>
- );
- } else {
- content = (
- <div className='form-group color--light'>Email is currently disabled for your team, and emails cannot be sent. Contact your system administrator to enable email and email invitations.</div>
- );
- }
-
- return (
- <div>
- <form>
- <img className='signup-team-logo' src='/static/images/logo.png' />
- <h2>{'Invite ' + utils.toTitleCase(strings.Team) + ' Members'}</h2>
- {content}
- <div className='form-group'>
- <button type='submit' className='btn-primary btn' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
- </div>
- </form>
- {bottomContent}
- <div className='margin--extra'>
- <a href='#' onClick={this.submitBack}>Back to previous step</a>
- </div>
- </div>
- );
- }
-});
-
-UsernamePage = React.createClass({
- submitBack: function(e) {
- e.preventDefault();
- this.props.state.wizard = 'send_invites';
- this.props.updateParent(this.props.state);
- },
- submitNext: function(e) {
- e.preventDefault();
-
- var name = this.refs.name.getDOMNode().value.trim();
-
- var usernameError = utils.isValidUsername(name);
- if (usernameError === 'Cannot use a reserved word as a username.') {
- this.setState({nameError: 'This username is reserved, please choose a new one.'});
- return;
- } else if (usernameError) {
- this.setState({nameError: 'Username must begin with a letter, and contain 3 to 15 characters in total, which may be numbers, lowercase letters, or any of the symbols \'.\', \'-\', or \'_\''});
- return;
- }
-
- this.props.state.wizard = 'password';
- this.props.state.user.username = name;
- this.props.updateParent(this.props.state);
- },
- getInitialState: function() {
- return {};
- },
- render: function() {
- client.track('signup', 'signup_team_06_username');
-
- var nameError = null;
- var nameDivClass = 'form-group';
- if (this.state.nameError) {
- nameError = <label className='control-label'>{this.state.nameError}</label>;
- nameDivClass += ' has-error';
- }
-
- return (
- <div>
- <form>
- <img className='signup-team-logo' src='/static/images/logo.png' />
- <h2 className='margin--less'>Your username</h2>
- <h5 className='color--light'>{'Select a memorable username that makes it easy for ' + strings.Team + 'mates to identify you:'}</h5>
- <div className='inner__content margin--extra'>
- <div className={nameDivClass}>
- <div className='row'>
- <div className='col-sm-11'>
- <h5><strong>Choose your username</strong></h5>
- <input autoFocus={true} type='text' ref='name' className='form-control' placeholder='' defaultValue={this.props.state.user.username} maxLength='128' />
- <div className='color--light form__hint'>Usernames must begin with a letter and contain 3 to 15 characters made up of lowercase letters, numbers, and the symbols '.', '-' and '_'</div>
- </div>
- </div>
- {nameError}
- </div>
- </div>
- <button type='submit' className='btn btn-primary margin--extra' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
- <div className='margin--extra'>
- <a href='#' onClick={this.submitBack}>Back to previous step</a>
- </div>
- </form>
- </div>
- );
- }
-});
-
-PasswordPage = React.createClass({
- submitBack: function (e) {
- e.preventDefault();
- this.props.state.wizard = 'username';
- this.props.updateParent(this.props.state);
- },
- submitNext: function (e) {
- e.preventDefault();
-
- var password = this.refs.password.getDOMNode().value.trim();
- if (!password || password.length < 5) {
- this.setState({passwordError: 'Please enter at least 5 characters'});
- return;
- }
-
- this.setState({passwordError: null, serverError: null});
- $('#finish-button').button('loading');
- var teamSignup = JSON.parse(JSON.stringify(this.props.state));
- teamSignup.user.password = password;
- teamSignup.user.allow_marketing = true;
- delete teamSignup.wizard;
- var ctl = this;
-
- client.createTeamFromSignup(teamSignup,
- function(data) {
- client.track('signup', 'signup_team_08_complete');
-
- var props = this.props;
-
- $('#sign-up-button').button('reset');
- props.state.wizard = 'finished';
- props.updateParent(props.state, true);
-
- window.location.href = utils.getWindowLocationOrigin() + '/' + props.state.team.name + '/login?email=' + encodeURIComponent(teamSignup.team.email);
-
- // client.loginByEmail(teamSignup.team.domain, teamSignup.team.email, teamSignup.user.password,
- // function(data) {
- // TeamStore.setLastName(teamSignup.team.domain);
- // UserStore.setLastEmail(teamSignup.team.email);
- // UserStore.setCurrentUser(data);
- // window.location.href = '/channels/town-square';
- // }.bind(ctl),
- // function(err) {
- // this.setState({nameError: err.message});
- // }.bind(ctl)
- // );
- }.bind(this),
- function(err) {
- this.setState({serverError: err.message});
- $('#sign-up-button').button('reset');
- }.bind(this)
- );
- },
- getInitialState: function() {
- return {};
- },
- render: function() {
- client.track('signup', 'signup_team_07_password');
-
- var passwordError = null;
- var passwordDivStyle = 'form-group';
- if (this.state.passwordError) {
- passwordError = <div className='form-group has-error'><label className='control-label'>{this.state.passwordError}</label></div>;
- passwordDivStyle = ' has-error';
- }
-
- var serverError = null;
- if (this.state.serverError) {
- serverError = <div className='form-group has-error'><label className='control-label'>{this.state.serverError}</label></div>;
- }
-
- return (
- <div>
- <form>
- <img className='signup-team-logo' src='/static/images/logo.png' />
- <h2 className='margin--less'>Your password</h2>
- <h5 className='color--light'>Select a password that you'll use to login with your email address:</h5>
- <div className='inner__content margin--extra'>
- <h5><strong>Email</strong></h5>
- <div className='block--gray form-group'>{this.props.state.team.email}</div>
- <div className={passwordDivStyle}>
- <div className='row'>
- <div className='col-sm-11'>
- <h5><strong>Choose your password</strong></h5>
- <input autoFocus={true} type='password' ref='password' className='form-control' placeholder='' maxLength='128' />
- <div className='color--light form__hint'>Passwords must contain 5 to 50 characters. Your password will be strongest if it contains a mix of symbols, numbers, and upper and lowercase characters.</div>
- </div>
- </div>
- {passwordError}
- {serverError}
- </div>
- </div>
- <div className='form-group'>
- <button type='submit' className='btn btn-primary margin--extra' id='finish-button' data-loading-text={'<span class=\'glyphicon glyphicon-refresh glyphicon-refresh-animate\'></span> Creating ' + strings.Team + '...'} onClick={this.submitNext}>Finish</button>
- </div>
- <p>By proceeding to create your account and use {config.SiteName}, you agree to our <a href={config.TermsLink}>Terms of Service</a> and <a href={config.PrivacyLink}>Privacy Policy</a>. If you do not agree, you cannot use {config.SiteName}.</p>
- <div className='margin--extra'>
- <a href='#' onClick={this.submitBack}>Back to previous step</a>
- </div>
- </form>
- </div>
- );
- }
-});
module.exports = React.createClass({
+ displayName: 'SignupTeamComplete',
+ propTypes: {
+ hash: React.PropTypes.string,
+ email: React.PropTypes.string,
+ data: React.PropTypes.string
+ },
updateParent: function(state, skipSet) {
BrowserStore.setGlobalItem(this.props.hash, state);
diff --git a/web/react/components/team_feature_tab.jsx b/web/react/components/team_feature_tab.jsx
new file mode 100644
index 000000000..ee0bfa874
--- /dev/null
+++ b/web/react/components/team_feature_tab.jsx
@@ -0,0 +1,147 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var SettingItemMin = require('./setting_item_min.jsx');
+var SettingItemMax = require('./setting_item_max.jsx');
+
+var client = require('../utils/client.jsx');
+var AsyncClient = require('../utils/async_client.jsx');
+
+module.exports = React.createClass({
+ displayName: 'Feature Tab',
+ propTypes: {
+ updateSection: React.PropTypes.func.isRequired,
+ team: React.PropTypes.object.isRequired,
+ activeSection: React.PropTypes.string.isRequired
+ },
+ submitValetFeature: function() {
+ var data = {};
+ data.allowValet = this.state.allowValet;
+
+ client.updateValetFeature(data,
+ function() {
+ this.props.updateSection('');
+ AsyncClient.getMyTeam();
+ }.bind(this),
+ function(err) {
+ var state = this.getInitialState();
+ state.serverError = err;
+ this.setState(state);
+ }.bind(this)
+ );
+ },
+ handleValetRadio: function(val) {
+ this.setState({allowValet: val});
+ this.refs.wrapper.getDOMNode().focus();
+ },
+ componentWillReceiveProps: function(newProps) {
+ var team = newProps.team;
+
+ var allowValet = 'false';
+ if (team && team.allowValet) {
+ allowValet = 'true';
+ }
+
+ this.setState({allowValet: allowValet});
+ },
+ getInitialState: function() {
+ var team = this.props.team;
+
+ var allowValet = 'false';
+ if (team && team.allowValet) {
+ allowValet = 'true';
+ }
+
+ return {allowValet: allowValet};
+ },
+ onUpdateSection: function() {
+ if (this.props.activeSection === 'valet') {
+ self.props.updateSection('valet');
+ } else {
+ self.props.updateSection('');
+ }
+ },
+ render: function() {
+ var clientError = null;
+ var serverError = null;
+ if (this.state.clientError) {
+ clientError = this.state.clientError;
+ }
+ if (this.state.serverError) {
+ serverError = this.state.serverError;
+ }
+
+ var valetSection;
+ var self = this;
+
+ if (this.props.activeSection === 'valet') {
+ var valetActive = ['', ''];
+ if (this.state.allowValet === 'false') {
+ valetActive[1] = 'active';
+ } else {
+ valetActive[0] = 'active';
+ }
+
+ var inputs = [];
+
+ function valetActivate() {
+ self.handleValetRadio('true');
+ }
+
+ function valetDeactivate() {
+ self.handleValetRadio('false');
+ }
+
+ inputs.push(
+ <div>
+ <div className='btn-group' data-toggle='buttons-radio'>
+ <button className={'btn btn-default ' + valetActive[0]} onClick={valetActivate}>On</button>
+ <button className={'btn btn-default ' + valetActive[1]} onClick={valetDeactivate}>Off</button>
+ </div>
+ <div><br/>Valet is a preview feature for enabling a non-user account limited to basic member permissions that can be manipulated by 3rd parties.<br/><br/>IMPORTANT: The preview version of Valet should not be used without a secure connection and a trusted 3rd party, since user credentials are used to connect. OAuth2 will be used in the final release.</div>
+ </div>
+ );
+
+ valetSection = (
+ <SettingItemMax
+ title='Valet (Preview - EXPERTS ONLY)'
+ inputs={inputs}
+ submit={this.submitValetFeature}
+ serverError={serverError}
+ clientError={clientError}
+ updateSection={this.onUpdateSection}
+ />
+ );
+ } else {
+ var describe = '';
+ if (this.state.allowValet === 'false') {
+ describe = 'Off';
+ } else {
+ describe = 'On';
+ }
+
+ valetSection = (
+ <SettingItemMin
+ title='Valet (Preview - EXPERTS ONLY)'
+ describe={describe}
+ updateSection={this.onUpdateSection}
+ />
+ );
+ }
+
+ return (
+ <div>
+ <div className='modal-header'>
+ <button type='button' className='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
+ <h4 className='modal-title' ref='title'><i className='modal-back'></i>Feature Settings</h4>
+ </div>
+ <div ref='wrapper' className='user-settings'>
+ <h3 className='tab-header'>Feature Settings</h3>
+ <div className='divider-dark first'/>
+ {valetSection}
+ <div className='divider-dark'/>
+ </div>
+ </div>
+ );
+ }
+});
diff --git a/web/react/components/team_import_tab.jsx b/web/react/components/team_import_tab.jsx
new file mode 100644
index 000000000..131add999
--- /dev/null
+++ b/web/react/components/team_import_tab.jsx
@@ -0,0 +1,68 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var utils = require('../utils/utils.jsx');
+var SettingUpload = require('./setting_upload.jsx');
+
+module.exports = React.createClass({
+ displayName: 'Import Tab',
+ getInitialState: function() {
+ return {status: 'ready', link: ''};
+ },
+ onImportFailure: function() {
+ this.setState({status: 'fail', link: ''});
+ },
+ onImportSuccess: function(data) {
+ this.setState({status: 'done', link: 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(data)});
+ },
+ doImportSlack: function(file) {
+ this.setState({status: 'in-progress', link: ''});
+ utils.importSlack(file, this.onImportSuccess, this.onImportFailure);
+ },
+ render: function() {
+ var uploadSection = (
+ <SettingUpload
+ title='Import from Slack'
+ submit={this.doImportSlack}
+ fileTypesAccepted='.zip'/>
+ );
+
+ var messageSection;
+ switch (this.state.status) {
+ case 'ready':
+ messageSection = '';
+ break;
+ case 'in-progress':
+ messageSection = (
+ <p>Importing...</p>
+ );
+ break;
+ case 'done':
+ messageSection = (
+ <p>Import sucessfull: <a href={this.state.link} download='MattermostImportSummery.txt'>View Summery</a></p>
+ );
+ break;
+ case 'fail':
+ messageSection = (
+ <p>Import failure: <a href={this.state.link} download='MattermostImportSummery.txt'>View Summery</a></p>
+ );
+ break;
+ }
+
+ return (
+ <div>
+ <div className='modal-header'>
+ <button type='button' className='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
+ <h4 className='modal-title' ref='title'><i className='modal-back'></i>Import</h4>
+ </div>
+ <div ref='wrapper' className='user-settings'>
+ <h3 className='tab-header'>Import</h3>
+ <div className='divider-dark first'/>
+ {uploadSection}
+ {messageSection}
+ <div className='divider-dark'/>
+ </div>
+ </div>
+ );
+ }
+});
diff --git a/web/react/components/team_settings.jsx b/web/react/components/team_settings.jsx
index 3bbb5e892..94d536651 100644
--- a/web/react/components/team_settings.jsx
+++ b/web/react/components/team_settings.jsx
@@ -1,161 +1,62 @@
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
-var UserStore = require('../stores/user_store.jsx');
var TeamStore = require('../stores/team_store.jsx');
-var SettingItemMin = require('./setting_item_min.jsx');
-var SettingItemMax = require('./setting_item_max.jsx');
-var SettingPicture = require('./setting_picture.jsx');
+var ImportTab = require('./team_import_tab.jsx');
+var FeatureTab = require('./team_feature_tab.jsx');
var utils = require('../utils/utils.jsx');
-var client = require('../utils/client.jsx');
-var AsyncClient = require('../utils/async_client.jsx');
-var Constants = require('../utils/constants.jsx');
-
-var FeatureTab = React.createClass({
- submitValetFeature: function() {
- data = {};
- data['allow_valet'] = this.state.allow_valet;
-
- client.updateValetFeature(data,
- function(data) {
- this.props.updateSection("");
- AsyncClient.getMyTeam();
- }.bind(this),
- function(err) {
- state = this.getInitialState();
- state.server_error = err;
- this.setState(state);
- }.bind(this)
- );
- },
- handleValetRadio: function(val) {
- this.setState({ allow_valet: val });
- this.refs.wrapper.getDOMNode().focus();
- },
- componentWillReceiveProps: function(newProps) {
- var team = newProps.team;
-
- var allow_valet = "false";
- if (team && team.allow_valet) {
- allow_valet = "true";
- }
-
- this.setState({ allow_valet: allow_valet });
- },
- getInitialState: function() {
- var team = this.props.team;
-
- var allow_valet = "false";
- if (team && team.allow_valet) {
- allow_valet = "true";
- }
-
- return { allow_valet: allow_valet };
- },
- render: function() {
- var team = this.props.team;
-
- var client_error = this.state.client_error ? this.state.client_error : null;
- var server_error = this.state.server_error ? this.state.server_error : null;
-
- var valetSection;
- var self = this;
-
- if (this.props.activeSection === 'valet') {
- var valetActive = ["",""];
- if (this.state.allow_valet === "false") {
- valetActive[1] = "active";
- } else {
- valetActive[0] = "active";
- }
-
- var inputs = [];
-
- inputs.push(
- <div>
- <div className="btn-group" data-toggle="buttons-radio">
- <button className={"btn btn-default "+valetActive[0]} onClick={function(){self.handleValetRadio("true")}}>On</button>
- <button className={"btn btn-default "+valetActive[1]} onClick={function(){self.handleValetRadio("false")}}>Off</button>
- </div>
- <div><br/>Valet is a preview feature for enabling a non-user account limited to basic member permissions that can be manipulated by 3rd parties.<br/><br/>IMPORTANT: The preview version of Valet should not be used without a secure connection and a trusted 3rd party, since user credentials are used to connect. OAuth2 will be used in the final release.</div>
- </div>
- );
-
- valetSection = (
- <SettingItemMax
- title="Valet (Preview - EXPERTS ONLY)"
- inputs={inputs}
- submit={this.submitValetFeature}
- server_error={server_error}
- client_error={client_error}
- updateSection={function(e){self.props.updateSection("");e.preventDefault();}}
- />
- );
- } else {
- var describe = "";
- if (this.state.allow_valet === "false") {
- describe = "Off";
- } else {
- describe = "On";
- }
-
- valetSection = (
- <SettingItemMin
- title="Valet (Preview - EXPERTS ONLY)"
- describe={describe}
- updateSection={function(){self.props.updateSection("valet");}}
- />
- );
- }
-
- return (
- <div>
- <div className="modal-header">
- <button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
- <h4 className="modal-title" ref="title"><i className="modal-back"></i>Feature Settings</h4>
- </div>
- <div ref="wrapper" className="user-settings">
- <h3 className="tab-header">Feature Settings</h3>
- <div className="divider-dark first"/>
- {valetSection}
- <div className="divider-dark"/>
- </div>
- </div>
- );
- }
-});
-
module.exports = React.createClass({
+ displayName: 'Team Settings',
+ propTypes: {
+ activeTab: React.PropTypes.string.isRequired,
+ activeSection: React.PropTypes.string.isRequired,
+ updateSection: React.PropTypes.func.isRequired
+ },
componentDidMount: function() {
- TeamStore.addChangeListener(this._onChange);
+ TeamStore.addChangeListener(this.onChange);
},
componentWillUnmount: function() {
- TeamStore.removeChangeListener(this._onChange);
+ TeamStore.removeChangeListener(this.onChange);
},
- _onChange: function () {
+ onChange: function() {
var team = TeamStore.getCurrent();
if (!utils.areStatesEqual(this.state.team, team)) {
- this.setState({ team: team });
+ this.setState({team: team});
}
},
getInitialState: function() {
- return { team: TeamStore.getCurrent() };
+ return {team: TeamStore.getCurrent()};
},
render: function() {
- if (this.props.activeTab === 'general') {
- return (
- <div>
- </div>
- );
- } else if (this.props.activeTab === 'feature') {
- return (
- <div>
- <FeatureTab team={this.state.team} activeSection={this.props.activeSection} updateSection={this.props.updateSection} />
- </div>
- );
- } else {
- return <div/>;
+ var result;
+ switch (this.props.activeTab) {
+ case 'general':
+ result = (
+ <div>
+ </div>
+ );
+ break;
+ case 'feature':
+ result = (
+ <div>
+ <FeatureTab team={this.state.team} activeSection={this.props.activeSection} updateSection={this.props.updateSection} />
+ </div>
+ );
+ break;
+ case 'import':
+ result = (
+ <div>
+ <ImportTab team={this.state.team} activeSection={this.props.activeSection} updateSection={this.props.updateSection} />
+ </div>
+ );
+ break;
+ default:
+ result = (
+ <div/>
+ );
+ break;
}
+ return result;
}
});
diff --git a/web/react/components/team_settings_modal.jsx b/web/react/components/team_settings_modal.jsx
index b1c38fd16..c9f479a22 100644
--- a/web/react/components/team_settings_modal.jsx
+++ b/web/react/components/team_settings_modal.jsx
@@ -5,50 +5,52 @@ var SettingsSidebar = require('./settings_sidebar.jsx');
var TeamSettings = require('./team_settings.jsx');
module.exports = React.createClass({
+ displayName: 'Team Settings Modal',
componentDidMount: function() {
- $('body').on('click', '.modal-back', function(){
+ $('body').on('click', '.modal-back', function onClick() {
$(this).closest('.modal-dialog').removeClass('display--content');
});
- $('body').on('click', '.modal-header .close', function(){
- setTimeout(function() {
+ $('body').on('click', '.modal-header .close', function onClick() {
+ setTimeout(function removeContent() {
$('.modal-dialog.display--content').removeClass('display--content');
}, 500);
});
},
updateTab: function(tab) {
- this.setState({ active_tab: tab });
+ this.setState({activeTab: tab});
},
updateSection: function(section) {
- this.setState({ active_section: section });
+ this.setState({activeSection: section});
},
getInitialState: function() {
- return { active_tab: "feature", active_section: "" };
+ return {activeTab: 'feature', activeSection: ''};
},
render: function() {
var tabs = [];
- tabs.push({name: "feature", ui_name: "Features", icon: "glyphicon glyphicon-wrench"});
+ tabs.push({name: 'feature', uiName: 'Features', icon: 'glyphicon glyphicon-wrench'});
+ tabs.push({name: 'import', uiName: 'Import', icon: 'glyphicon glyphicon-upload'});
return (
- <div className="modal fade" ref="modal" id="team_settings" role="dialog" tabIndex="-1" aria-hidden="true">
- <div className="modal-dialog settings-modal">
- <div className="modal-content">
- <div className="modal-header">
- <button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
- <h4 className="modal-title" ref="title">Team Settings</h4>
+ <div className='modal fade' ref='modal' id='team_settings' role='dialog' tabIndex='-1' aria-hidden='true'>
+ <div className='modal-dialog settings-modal'>
+ <div className='modal-content'>
+ <div className='modal-header'>
+ <button type='button' className='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
+ <h4 className='modal-title' ref='title'>Team Settings</h4>
</div>
- <div className="modal-body">
- <div className="settings-table">
- <div className="settings-links">
+ <div className='modal-body'>
+ <div className='settings-table'>
+ <div className='settings-links'>
<SettingsSidebar
tabs={tabs}
- activeTab={this.state.active_tab}
+ activeTab={this.state.activeTab}
updateTab={this.updateTab}
/>
</div>
- <div className="settings-content minimize-settings">
+ <div className='settings-content minimize-settings'>
<TeamSettings
- activeTab={this.state.active_tab}
- activeSection={this.state.active_section}
+ activeTab={this.state.activeTab}
+ activeSection={this.state.activeSection}
updateSection={this.updateSection}
/>
</div>
diff --git a/web/react/components/team_signup_allowed_domains_page.jsx b/web/react/components/team_signup_allowed_domains_page.jsx
new file mode 100644
index 000000000..90c7ff668
--- /dev/null
+++ b/web/react/components/team_signup_allowed_domains_page.jsx
@@ -0,0 +1,98 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var client = require('../utils/client.jsx');
+
+module.exports = React.createClass({
+ displayName: 'TeamSignupAllowedDomainsPage',
+ propTypes: {
+ state: React.PropTypes.object,
+ updateParent: React.PropTypes.func
+ },
+ submitBack: function(e) {
+ e.preventDefault();
+ this.props.state.wizard = 'team_url';
+ this.props.updateParent(this.props.state);
+ },
+ submitNext: function(e) {
+ e.preventDefault();
+
+ if (this.refs.open_network.getDOMNode().checked) {
+ this.props.state.wizard = 'send_invites';
+ this.props.state.team.type = 'O';
+ this.props.updateParent(this.props.state);
+ return;
+ }
+
+ if (this.refs.allow.getDOMNode().checked) {
+ var name = this.refs.name.getDOMNode().value.trim();
+ var domainRegex = /^\w+\.\w+$/;
+ if (!name) {
+ this.setState({nameError: 'This field is required'});
+ return;
+ }
+
+ if (!name.trim().match(domainRegex)) {
+ this.setState({nameError: 'The domain doesn\'t appear valid'});
+ return;
+ }
+
+ this.props.state.wizard = 'send_invites';
+ this.props.state.team.allowed_domains = name;
+ this.props.state.team.type = 'I';
+ this.props.updateParent(this.props.state);
+ } else {
+ this.props.state.wizard = 'send_invites';
+ this.props.state.team.type = 'I';
+ this.props.updateParent(this.props.state);
+ }
+ },
+ getInitialState: function() {
+ return {};
+ },
+ render: function() {
+ client.track('signup', 'signup_team_04_allow_domains');
+
+ var nameError = null;
+ var nameDivClass = 'form-group';
+ if (this.state.nameError) {
+ nameError = <label className='control-label'>{this.state.nameError}</label>;
+ nameDivClass += ' has-error';
+ }
+
+ return (
+ <div>
+ <form>
+ <img className='signup-team-logo' src='/static/images/logo.png' />
+ <h2>Email Domain</h2>
+ <p>
+ <div className='checkbox'>
+ <label><input type='checkbox' ref='allow' defaultChecked={true} />{' Allow sign up and ' + strings.Team + ' discovery with a ' + strings.Company + ' email address.'}</label>
+ </div>
+ </p>
+ <p>{'Check this box to allow your ' + strings.Team + ' members to sign up using their ' + strings.Company + ' email addresses if you share the same domain--otherwise, you need to invite everyone yourself.'}</p>
+ <h4>{'Your ' + strings.Team + '\'s domain for emails'}</h4>
+ <div className={nameDivClass}>
+ <div className='row'>
+ <div className='col-sm-9'>
+ <div className='input-group'>
+ <span className='input-group-addon'>@</span>
+ <input type='text' ref='name' className='form-control' placeholder='' maxLength='128' defaultValue={this.props.state.team.allowed_domains} autoFocus={true} onFocus={this.handleFocus}/>
+ </div>
+ </div>
+ </div>
+ {nameError}
+ </div>
+ <p>To allow signups from multiple domains, separate each with a comma.</p>
+ <p>
+ <div className='checkbox'>
+ <label><input type='checkbox' ref='open_network' defaultChecked={this.props.state.team.type === 'O'} /> Allow anyone to signup to this domain without an invitation.</label>
+ </div>
+ </p>
+ <button type='button' className='btn btn-default' onClick={this.submitBack}><i className='glyphicon glyphicon-chevron-left'></i> Back</button>&nbsp;
+ <button type='submit' className='btn-primary btn' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
+ </form>
+ </div>
+ );
+ }
+});
diff --git a/web/react/components/team_signup_display_name_page.jsx b/web/react/components/team_signup_display_name_page.jsx
new file mode 100644
index 000000000..b5e93de1b
--- /dev/null
+++ b/web/react/components/team_signup_display_name_page.jsx
@@ -0,0 +1,72 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var utils = require('../utils/utils.jsx');
+var client = require('../utils/client.jsx');
+
+module.exports = React.createClass({
+ displayName: 'TeamSignupDisplayNamePage',
+ propTypes: {
+ state: React.PropTypes.object,
+ updateParent: React.PropTypes.func
+ },
+ submitBack: function(e) {
+ e.preventDefault();
+ this.props.state.wizard = 'welcome';
+ this.props.updateParent(this.props.state);
+ },
+ submitNext: function(e) {
+ e.preventDefault();
+
+ var displayName = this.refs.name.getDOMNode().value.trim();
+ if (!displayName) {
+ this.setState({nameError: 'This field is required'});
+ return;
+ }
+
+ this.props.state.wizard = 'team_url';
+ this.props.state.team.display_name = displayName;
+ this.props.state.team.name = utils.cleanUpUrlable(displayName);
+ this.props.updateParent(this.props.state);
+ },
+ getInitialState: function() {
+ return {};
+ },
+ handleFocus: function(e) {
+ e.preventDefault();
+ e.currentTarget.select();
+ },
+ render: function() {
+ client.track('signup', 'signup_team_02_name');
+
+ var nameError = null;
+ var nameDivClass = 'form-group';
+ if (this.state.nameError) {
+ nameError = <label className='control-label'>{this.state.nameError}</label>;
+ nameDivClass += ' has-error';
+ }
+
+ return (
+ <div>
+ <form>
+ <img className='signup-team-logo' src='/static/images/logo.png' />
+
+ <h2>{utils.toTitleCase(strings.Team) + ' Name'}</h2>
+ <div className={nameDivClass}>
+ <div className='row'>
+ <div className='col-sm-9'>
+ <input type='text' ref='name' className='form-control' placeholder='' maxLength='128' defaultValue={this.props.state.team.display_name} autoFocus={true} onFocus={this.handleFocus} />
+ </div>
+ </div>
+ {nameError}
+ </div>
+ <div>{'Name your ' + strings.Team + ' in any language. Your ' + strings.Team + ' name shows in menus and headings.'}</div>
+ <button type='submit' className='btn btn-primary margin--extra' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
+ <div className='margin--extra'>
+ <a href='#' onClick={this.submitBack}>Back to previous step</a>
+ </div>
+ </form>
+ </div>
+ );
+ }
+});
diff --git a/web/react/components/team_signup_email_item.jsx b/web/react/components/team_signup_email_item.jsx
new file mode 100644
index 000000000..11cd17e74
--- /dev/null
+++ b/web/react/components/team_signup_email_item.jsx
@@ -0,0 +1,53 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var utils = require('../utils/utils.jsx');
+
+module.exports = React.createClass({
+ displayName: 'TeamSignupEmailItem',
+ propTypes: {
+ focus: React.PropTypes.bool,
+ email: React.PropTypes.string
+ },
+ getInitialState: function() {
+ return {};
+ },
+ getValue: function() {
+ return this.refs.email.getDOMNode().value.trim();
+ },
+ validate: function(teamEmail) {
+ var email = this.refs.email.getDOMNode().value.trim().toLowerCase();
+
+ if (!email) {
+ return true;
+ }
+
+ if (!utils.isEmail(email)) {
+ this.state.emailError = 'Please enter a valid email address';
+ this.setState(this.state);
+ return false;
+ } else if (email === teamEmail) {
+ this.state.emailError = 'Please use a different email than the one used at signup';
+ this.setState(this.state);
+ return false;
+ }
+ this.state.emailError = '';
+ this.setState(this.state);
+ return true;
+ },
+ render: function() {
+ var emailError = null;
+ var emailDivClass = 'form-group';
+ if (this.state.emailError) {
+ emailError = <label className='control-label'>{this.state.emailError}</label>;
+ emailDivClass += ' has-error';
+ }
+
+ return (
+ <div className={emailDivClass}>
+ <input autoFocus={this.props.focus} type='email' ref='email' className='form-control' placeholder='Email Address' defaultValue={this.props.email} maxLength='128' />
+ {emailError}
+ </div>
+ );
+ }
+});
diff --git a/web/react/components/team_signup_password_page.jsx b/web/react/components/team_signup_password_page.jsx
new file mode 100644
index 000000000..e4f35f100
--- /dev/null
+++ b/web/react/components/team_signup_password_page.jsx
@@ -0,0 +1,116 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var utils = require('../utils/utils.jsx');
+var client = require('../utils/client.jsx');
+
+module.exports = React.createClass({
+ displayName: 'TeamSignupPasswordPage',
+ propTypes: {
+ state: React.PropTypes.object,
+ updateParent: React.PropTypes.func
+ },
+ submitBack: function(e) {
+ e.preventDefault();
+ this.props.state.wizard = 'username';
+ this.props.updateParent(this.props.state);
+ },
+ submitNext: function(e) {
+ e.preventDefault();
+
+ var password = this.refs.password.getDOMNode().value.trim();
+ if (!password || password.length < 5) {
+ this.setState({passwordError: 'Please enter at least 5 characters'});
+ return;
+ }
+
+ this.setState({passwordError: null, serverError: null});
+ $('#finish-button').button('loading');
+ var teamSignup = JSON.parse(JSON.stringify(this.props.state));
+ teamSignup.user.password = password;
+ teamSignup.user.allow_marketing = true;
+ delete teamSignup.wizard;
+
+ // var ctl = this;
+
+ client.createTeamFromSignup(teamSignup,
+ function success() {
+ client.track('signup', 'signup_team_08_complete');
+
+ var props = this.props;
+
+ $('#sign-up-button').button('reset');
+ props.state.wizard = 'finished';
+ props.updateParent(props.state, true);
+
+ window.location.href = utils.getWindowLocationOrigin() + '/' + props.state.team.name + '/login?email=' + encodeURIComponent(teamSignup.team.email);
+
+ // client.loginByEmail(teamSignup.team.domain, teamSignup.team.email, teamSignup.user.password,
+ // function(data) {
+ // TeamStore.setLastName(teamSignup.team.domain);
+ // UserStore.setLastEmail(teamSignup.team.email);
+ // UserStore.setCurrentUser(data);
+ // window.location.href = '/channels/town-square';
+ // }.bind(ctl),
+ // function(err) {
+ // this.setState({nameError: err.message});
+ // }.bind(ctl)
+ // );
+ }.bind(this),
+ function error(err) {
+ this.setState({serverError: err.message});
+ $('#sign-up-button').button('reset');
+ }.bind(this)
+ );
+ },
+ getInitialState: function() {
+ return {};
+ },
+ render: function() {
+ client.track('signup', 'signup_team_07_password');
+
+ var passwordError = null;
+ var passwordDivStyle = 'form-group';
+ if (this.state.passwordError) {
+ passwordError = <div className='form-group has-error'><label className='control-label'>{this.state.passwordError}</label></div>;
+ passwordDivStyle = ' has-error';
+ }
+
+ var serverError = null;
+ if (this.state.serverError) {
+ serverError = <div className='form-group has-error'><label className='control-label'>{this.state.serverError}</label></div>;
+ }
+
+ return (
+ <div>
+ <form>
+ <img className='signup-team-logo' src='/static/images/logo.png' />
+ <h2 className='margin--less'>Your password</h2>
+ <h5 className='color--light'>Select a password that you'll use to login with your email address:</h5>
+ <div className='inner__content margin--extra'>
+ <h5><strong>Email</strong></h5>
+ <div className='block--gray form-group'>{this.props.state.team.email}</div>
+ <div className={passwordDivStyle}>
+ <div className='row'>
+ <div className='col-sm-11'>
+ <h5><strong>Choose your password</strong></h5>
+ <input autoFocus={true} type='password' ref='password' className='form-control' placeholder='' maxLength='128' />
+ <div className='color--light form__hint'>Passwords must contain 5 to 50 characters. Your password will be strongest if it contains a mix of symbols, numbers, and upper and lowercase characters.</div>
+ </div>
+ </div>
+ {passwordError}
+ {serverError}
+ </div>
+ </div>
+ <div className='form-group'>
+ <button type='submit' className='btn btn-primary margin--extra' id='finish-button' data-loading-text={'<span class=\'glyphicon glyphicon-refresh glyphicon-refresh-animate\'></span> Creating ' + strings.Team + '...'} onClick={this.submitNext}>Finish</button>
+ </div>
+ <p>By proceeding to create your account and use {config.SiteName}, you agree to our <a href={config.TermsLink}>Terms of Service</a> and <a href={config.PrivacyLink}>Privacy Policy</a>. If you do not agree, you cannot use {config.SiteName}.</p>
+ <div className='margin--extra'>
+ <a href='#' onClick={this.submitBack}>Back to previous step</a>
+ </div>
+ </form>
+ </div>
+ );
+ }
+});
diff --git a/web/react/components/team_signup_send_invites_page.jsx b/web/react/components/team_signup_send_invites_page.jsx
new file mode 100644
index 000000000..4bc03798b
--- /dev/null
+++ b/web/react/components/team_signup_send_invites_page.jsx
@@ -0,0 +1,121 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var EmailItem = require('./team_signup_email_item.jsx');
+var utils = require('../utils/utils.jsx');
+var ConfigStore = require('../stores/config_store.jsx');
+var client = require('../utils/client.jsx');
+
+module.exports = React.createClass({
+ displayName: 'TeamSignupSendInivtesPage',
+ propTypes: {
+ state: React.PropTypes.object,
+ updateParent: React.PropTypes.func
+ },
+ submitBack: function(e) {
+ e.preventDefault();
+
+ if (config.AllowSignupDomainsWizard) {
+ this.props.state.wizard = 'allowed_domains';
+ } else {
+ this.props.state.wizard = 'team_url';
+ }
+
+ this.props.updateParent(this.props.state);
+ },
+ submitNext: function(e) {
+ e.preventDefault();
+
+ var valid = true;
+
+ if (this.state.emailEnabled) {
+ var emails = [];
+
+ for (var i = 0; i < this.props.state.invites.length; i++) {
+ if (!this.refs['email_' + i].validate(this.props.state.team.email)) {
+ valid = false;
+ } else {
+ emails.push(this.refs['email_' + i].getValue());
+ }
+ }
+
+ if (valid) {
+ this.props.state.invites = emails;
+ }
+ }
+
+ if (valid) {
+ this.props.state.wizard = 'username';
+ this.props.updateParent(this.props.state);
+ }
+ },
+ submitAddInvite: function(e) {
+ e.preventDefault();
+ this.props.state.wizard = 'send_invites';
+ if (!this.props.state.invites) {
+ this.props.state.invites = [];
+ }
+ this.props.state.invites.push('');
+ this.props.updateParent(this.props.state);
+ },
+ submitSkip: function(e) {
+ e.preventDefault();
+ this.props.state.wizard = 'username';
+ this.props.updateParent(this.props.state);
+ },
+ getInitialState: function() {
+ return {
+ emailEnabled: !ConfigStore.getSettingAsBoolean('ByPassEmail', false)
+ };
+ },
+ render: function() {
+ client.track('signup', 'signup_team_05_send_invites');
+
+ var content = null;
+ var bottomContent = null;
+
+ if (this.state.emailEnabled) {
+ var emails = [];
+
+ for (var i = 0; i < this.props.state.invites.length; i++) {
+ if (i === 0) {
+ emails.push(<EmailItem focus={true} key={i} ref={'email_' + i} email={this.props.state.invites[i]} />);
+ } else {
+ emails.push(<EmailItem focus={false} key={i} ref={'email_' + i} email={this.props.state.invites[i]} />);
+ }
+ }
+
+ content = (
+ <div>
+ {emails}
+ <div className='form-group text-right'><a href='#' onClick={this.submitAddInvite}>Add Invitation</a></div>
+ </div>
+ );
+
+ bottomContent = (
+ <p className='color--light'>{'if you prefer, you can invite ' + strings.Team + ' members later'}<br /> and <a href='#' onClick={this.submitSkip}>skip this step</a> for now.</p>
+ );
+ } else {
+ content = (
+ <div className='form-group color--light'>{'Email is currently disabled for your ' + strings.Team + ', and emails cannot be sent. Contact your system administrator to enable email and email invitations.'}</div>
+ );
+ }
+
+ return (
+ <div>
+ <form>
+ <img className='signup-team-logo' src='/static/images/logo.png' />
+ <h2>{'Invite ' + utils.toTitleCase(strings.Team) + ' Members'}</h2>
+ {content}
+ <div className='form-group'>
+ <button type='submit' className='btn-primary btn' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
+ </div>
+ </form>
+ {bottomContent}
+ <div className='margin--extra'>
+ <a href='#' onClick={this.submitBack}>Back to previous step</a>
+ </div>
+ </div>
+ );
+ }
+});
diff --git a/web/react/components/team_signup_url_page.jsx b/web/react/components/team_signup_url_page.jsx
new file mode 100644
index 000000000..beef725e2
--- /dev/null
+++ b/web/react/components/team_signup_url_page.jsx
@@ -0,0 +1,119 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var utils = require('../utils/utils.jsx');
+var client = require('../utils/client.jsx');
+var constants = require('../utils/constants.jsx');
+
+module.exports = React.createClass({
+ displayName: 'TeamSignupURLPage',
+ propTypes: {
+ state: React.PropTypes.object,
+ updateParent: React.PropTypes.func
+ },
+ submitBack: function(e) {
+ e.preventDefault();
+ this.props.state.wizard = 'team_display_name';
+ this.props.updateParent(this.props.state);
+ },
+ submitNext: function(e) {
+ e.preventDefault();
+
+ var name = this.refs.name.getDOMNode().value.trim();
+ if (!name) {
+ this.setState({nameError: 'This field is required'});
+ return;
+ }
+
+ var cleanedName = utils.cleanUpUrlable(name);
+
+ var urlRegex = /^[a-z]+([a-z\-0-9]+|(__)?)[a-z0-9]+$/g;
+ if (cleanedName !== name || !urlRegex.test(name)) {
+ this.setState({nameError: "Use only lower case letters, numbers and dashes. Must start with a letter and can't end in a dash."});
+ return;
+ } else if (cleanedName.length <= 3 || cleanedName.length > 15) {
+ this.setState({nameError: 'Name must be 4 or more characters up to a maximum of 15'});
+ return;
+ }
+
+ for (var index = 0; index < constants.RESERVED_TEAM_NAMES.length; index++) {
+ if (cleanedName.indexOf(constants.RESERVED_TEAM_NAMES[index]) === 0) {
+ this.setState({nameError: 'This team name is unavailable'});
+ return;
+ }
+ }
+
+ client.findTeamByName(name,
+ function success(data) {
+ if (!data) {
+ if (config.AllowSignupDomainsWizard) {
+ this.props.state.wizard = 'allowed_domains';
+ } else {
+ this.props.state.wizard = 'send_invites';
+ this.props.state.team.type = 'O';
+ }
+
+ this.props.state.team.name = name;
+ this.props.updateParent(this.props.state);
+ } else {
+ this.state.nameError = 'This URL is unavailable. Please try another.';
+ this.setState(this.state);
+ }
+ }.bind(this),
+ function error(err) {
+ this.state.nameError = err.message;
+ this.setState(this.state);
+ }.bind(this)
+ );
+ },
+ getInitialState: function() {
+ return {};
+ },
+ handleFocus: function(e) {
+ e.preventDefault();
+
+ e.currentTarget.select();
+ },
+ render: function() {
+ $('body').tooltip({selector: '[data-toggle=tooltip]', trigger: 'hover click'});
+
+ client.track('signup', 'signup_team_03_url');
+
+ var nameError = null;
+ var nameDivClass = 'form-group';
+ if (this.state.nameError) {
+ nameError = <label className='control-label'>{this.state.nameError}</label>;
+ nameDivClass += ' has-error';
+ }
+
+ return (
+ <div>
+ <form>
+ <img className='signup-team-logo' src='/static/images/logo.png' />
+ <h2>{utils.toTitleCase(strings.Team) + ' URL'}</h2>
+ <div className={nameDivClass}>
+ <div className='row'>
+ <div className='col-sm-11'>
+ <div className='input-group input-group--limit'>
+ <span data-toggle='tooltip' title={utils.getWindowLocationOrigin() + '/'} className='input-group-addon'>{utils.getWindowLocationOrigin() + '/'}</span>
+ <input type='text' ref='name' className='form-control' placeholder='' maxLength='128' defaultValue={this.props.state.team.name} autoFocus={true} onFocus={this.handleFocus}/>
+ </div>
+ </div>
+ </div>
+ {nameError}
+ </div>
+ <p>{'Choose the web address of your new ' + strings.Team + ':'}</p>
+ <ul className='color--light'>
+ <li>Short and memorable is best</li>
+ <li>Use lowercase letters, numbers and dashes</li>
+ <li>Must start with a letter and can't end in a dash</li>
+ </ul>
+ <button type='submit' className='btn btn-primary margin--extra' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
+ <div className='margin--extra'>
+ <a href='#' onClick={this.submitBack}>Back to previous step</a>
+ </div>
+ </form>
+ </div>
+ );
+ }
+});
diff --git a/web/react/components/team_signup_username_page.jsx b/web/react/components/team_signup_username_page.jsx
new file mode 100644
index 000000000..56882e6a1
--- /dev/null
+++ b/web/react/components/team_signup_username_page.jsx
@@ -0,0 +1,75 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var utils = require('../utils/utils.jsx');
+var client = require('../utils/client.jsx');
+
+module.exports = React.createClass({
+ displayName: 'TeamSignupUsernamePage',
+ propTypes: {
+ state: React.PropTypes.object,
+ updateParent: React.PropTypes.func
+ },
+ submitBack: function(e) {
+ e.preventDefault();
+ this.props.state.wizard = 'send_invites';
+ this.props.updateParent(this.props.state);
+ },
+ submitNext: function(e) {
+ e.preventDefault();
+
+ var name = this.refs.name.getDOMNode().value.trim();
+
+ var usernameError = utils.isValidUsername(name);
+ if (usernameError === 'Cannot use a reserved word as a username.') {
+ this.setState({nameError: 'This username is reserved, please choose a new one.'});
+ return;
+ } else if (usernameError) {
+ this.setState({nameError: 'Username must begin with a letter, and contain 3 to 15 characters in total, which may be numbers, lowercase letters, or any of the symbols \'.\', \'-\', or \'_\''});
+ return;
+ }
+
+ this.props.state.wizard = 'password';
+ this.props.state.user.username = name;
+ this.props.updateParent(this.props.state);
+ },
+ getInitialState: function() {
+ return {};
+ },
+ render: function() {
+ client.track('signup', 'signup_team_06_username');
+
+ var nameError = null;
+ var nameDivClass = 'form-group';
+ if (this.state.nameError) {
+ nameError = <label className='control-label'>{this.state.nameError}</label>;
+ nameDivClass += ' has-error';
+ }
+
+ return (
+ <div>
+ <form>
+ <img className='signup-team-logo' src='/static/images/logo.png' />
+ <h2 className='margin--less'>Your username</h2>
+ <h5 className='color--light'>{'Select a memorable username that makes it easy for ' + strings.Team + 'mates to identify you:'}</h5>
+ <div className='inner__content margin--extra'>
+ <div className={nameDivClass}>
+ <div className='row'>
+ <div className='col-sm-11'>
+ <h5><strong>Choose your username</strong></h5>
+ <input autoFocus={true} type='text' ref='name' className='form-control' placeholder='' defaultValue={this.props.state.user.username} maxLength='128' />
+ <div className='color--light form__hint'>Usernames must begin with a letter and contain 3 to 15 characters made up of lowercase letters, numbers, and the symbols '.', '-' and '_'</div>
+ </div>
+ </div>
+ {nameError}
+ </div>
+ </div>
+ <button type='submit' className='btn btn-primary margin--extra' onClick={this.submitNext}>Next<i className='glyphicon glyphicon-chevron-right'></i></button>
+ <div className='margin--extra'>
+ <a href='#' onClick={this.submitBack}>Back to previous step</a>
+ </div>
+ </form>
+ </div>
+ );
+ }
+});
diff --git a/web/react/components/team_signup_welcome_page.jsx b/web/react/components/team_signup_welcome_page.jsx
new file mode 100644
index 000000000..f0c680bd8
--- /dev/null
+++ b/web/react/components/team_signup_welcome_page.jsx
@@ -0,0 +1,144 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+var utils = require('../utils/utils.jsx');
+var client = require('../utils/client.jsx');
+var BrowserStore = require('../stores/browser_store.jsx');
+
+module.exports = React.createClass({
+ displayName: 'TeamSignupWelcomePage',
+ propTypes: {
+ state: React.PropTypes.object,
+ updateParent: React.PropTypes.func
+ },
+ submitNext: function(e) {
+ if (!BrowserStore.isLocalStorageSupported()) {
+ this.setState({storageError: 'This service requires local storage to be enabled. Please enable it or exit private browsing.'});
+ return;
+ }
+ e.preventDefault();
+ this.props.state.wizard = 'team_display_name';
+ this.props.updateParent(this.props.state);
+ },
+ handleDiffEmail: function(e) {
+ e.preventDefault();
+ this.setState({useDiff: true});
+ },
+ handleDiffSubmit: function(e) {
+ e.preventDefault();
+
+ var state = {useDiff: true, serverError: ''};
+
+ var email = this.refs.email.getDOMNode().value.trim().toLowerCase();
+ if (!email || !utils.isEmail(email)) {
+ state.emailError = 'Please enter a valid email address';
+ this.setState(state);
+ return;
+ } else if (!BrowserStore.isLocalStorageSupported()) {
+ state.emailError = 'This service requires local storage to be enabled. Please enable it or exit private browsing.';
+ this.setState(state);
+ return;
+ }
+ state.emailError = '';
+
+ client.signupTeam(email,
+ function success(data) {
+ if (data.follow_link) {
+ window.location.href = data.follow_link;
+ } else {
+ this.props.state.wizard = 'finished';
+ this.props.updateParent(this.props.state);
+ window.location.href = '/signup_team_confirm/?email=' + encodeURIComponent(email);
+ }
+ }.bind(this),
+ function error(err) {
+ this.state.serverError = err.message;
+ this.setState(this.state);
+ }.bind(this)
+ );
+ },
+ getInitialState: function() {
+ return {useDiff: false};
+ },
+ handleKeyPress: function(event) {
+ if (event.keyCode === 13) {
+ this.submitNext(event);
+ }
+ },
+ componentWillMount: function() {
+ document.addEventListener('keyup', this.handleKeyPress, false);
+ },
+ componentWillUnmount: function() {
+ document.removeEventListener('keyup', this.handleKeyPress, false);
+ },
+ render: function() {
+ client.track('signup', 'signup_team_01_welcome');
+
+ var storageError = null;
+ if (this.state.storageError) {
+ storageError = <label className='control-label'>{this.state.storageError}</label>;
+ }
+
+ var emailError = null;
+ var emailDivClass = 'form-group';
+ if (this.state.emailError) {
+ emailError = <label className='control-label'>{this.state.emailError}</label>;
+ emailDivClass += ' has-error';
+ }
+
+ var serverError = null;
+ if (this.state.serverError) {
+ serverError = (
+ <div className='form-group has-error'>
+ <label className='control-label'>{this.state.serverError}</label>
+ </div>
+ );
+ }
+
+ var differentEmailLinkClass = '';
+ var emailDivContainerClass = 'hidden';
+ if (this.state.useDiff) {
+ differentEmailLinkClass = 'hidden';
+ emailDivContainerClass = '';
+ }
+
+ return (
+ <div>
+ <p>
+ <img className='signup-team-logo' src='/static/images/logo.png' />
+ <h3 className='sub-heading'>Welcome to:</h3>
+ <h1 className='margin--top-none'>{config.SiteName}</h1>
+ </p>
+ <p className='margin--less'>Let's set up your new team</p>
+ <p>
+ Please confirm your email address:<br />
+ <div className='inner__content'>
+ <div className='block--gray'>{this.props.state.team.email}</div>
+ </div>
+ </p>
+ <p className='margin--extra color--light'>
+ Your account will administer the new team site. <br />
+ You can add other administrators later.
+ </p>
+ <div className='form-group'>
+ <button className='btn-primary btn form-group' type='submit' onClick={this.submitNext}><i className='glyphicon glyphicon-ok'></i>Yes, this address is correct</button>
+ {storageError}
+ </div>
+ <hr />
+ <div className={emailDivContainerClass}>
+ <div className={emailDivClass}>
+ <div className='row'>
+ <div className='col-sm-9'>
+ <input type='email' ref='email' className='form-control' placeholder='Email Address' maxLength='128' />
+ </div>
+ </div>
+ {emailError}
+ </div>
+ {serverError}
+ <button className='btn btn-md btn-primary' type='button' onClick={this.handleDiffSubmit}>Use this instead</button>
+ </div>
+ <a href='#' onClick={this.handleDiffEmail} className={differentEmailLinkClass}>Use a different email</a>
+ </div>
+ );
+ }
+});
diff --git a/web/react/package.json b/web/react/package.json
index 2bba29e2b..c930c4db6 100644
--- a/web/react/package.json
+++ b/web/react/package.json
@@ -3,22 +3,21 @@
"version": "0.0.1",
"private": true,
"dependencies": {
- "flux": "^2.0.0",
- "keymirror": "~0.1.0",
- "object-assign": "^1.0.0",
- "react": "^0.12.0",
- "autolinker": "^0.15.2",
+ "autolinker": "^0.18.1",
+ "flux": "^2.1.1",
+ "keymirror": "^0.1.1",
+ "object-assign": "^3.0.0",
+ "react": "^0.13.3",
"react-zeroclipboard-mixin": "^0.1.0"
},
"devDependencies": {
- "browserify": "^6.2.0",
- "envify": "^3.0.0",
- "jest-cli": "~0.1.17",
- "reactify": "^0.15.2",
- "uglify-js": "~2.4.15",
- "watchify": "^2.1.1",
- "eslint": "^0.24.1",
- "eslint-plugin-react": "^3.0.0"
+ "browserify": "^11.0.1",
+ "envify": "^3.4.0",
+ "babelify": "^6.1.3",
+ "uglify-js": "^2.4.24",
+ "watchify": "^3.3.1",
+ "eslint": "^1.1.0",
+ "eslint-plugin-react": "^3.2.3"
},
"scripts": {
"start": "watchify --extension=jsx -o ../static/js/bundle.js -v -d ./**/*.jsx",
@@ -28,7 +27,7 @@
},
"browserify": {
"transform": [
- "reactify",
+ ["babelify", {"blacklist": ["strict"]}],
"envify"
]
},
diff --git a/web/react/stores/post_store.jsx b/web/react/stores/post_store.jsx
index 3e4fde30a..2fffb17d0 100644
--- a/web/react/stores/post_store.jsx
+++ b/web/react/stores/post_store.jsx
@@ -172,6 +172,28 @@ var PostStore = assign({}, EventEmitter.prototype, {
getPendingPosts: function(channelId) {
return BrowserStore.getItem('pending_posts_' + channelId);
},
+ storeUnseenDeletedPost: function(post) {
+ var posts = this.getUnseenDeletedPosts(post.channel_id);
+
+ if (!posts) {
+ posts = {};
+ }
+
+ post.message = '(message deleted)';
+ post.state = Constants.POST_DELETED;
+
+ posts[post.id] = post;
+ this.storeUnseenDeletedPosts(post.channel_id, posts);
+ },
+ storeUnseenDeletedPosts: function(channelId, posts) {
+ BrowserStore.setItem('deleted_posts_' + channelId, posts);
+ },
+ getUnseenDeletedPosts: function(channelId) {
+ return BrowserStore.getItem('deleted_posts_' + channelId);
+ },
+ clearUnseenDeletedPosts: function(channelId) {
+ BrowserStore.setItem('deleted_posts_' + channelId, {});
+ },
removePendingPost: function(channelId, pendingPostId) {
this._removePendingPost(channelId, pendingPostId);
this.emitChange();
diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx
index ce044457a..103292abf 100644
--- a/web/react/utils/client.jsx
+++ b/web/react/utils/client.jsx
@@ -1,4 +1,3 @@
-// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
var BrowserStore = require('../stores/browser_store.jsx');
@@ -14,73 +13,73 @@ module.exports.trackPage = function() {
global.window.analytics.page();
};
-function handleError(method_name, xhr, status, err) {
- var _LTracker = global.window._LTracker || [];
+function handleError(methodName, xhr, status, err) {
+ var LTracker = global.window.LTracker || [];
var e = null;
try {
e = JSON.parse(xhr.responseText);
- }
- catch(parse_error) {
+ } catch(parseError) {
+ e = null;
}
- var msg = "";
+ var msg = '';
if (e) {
- msg = "error in " + method_name + " msg=" + e.message + " detail=" + e.detailed_error + " rid=" + e.request_id;
- }
- else {
- msg = "error in " + method_name + " status=" + status + " statusCode=" + xhr.status + " err=" + err;
+ msg = 'error in ' + methodName + ' msg=' + e.message + ' detail=' + e.detailed_error + ' rid=' + e.request_id;
+ } else {
+ msg = 'error in ' + methodName + ' status=' + status + ' statusCode=' + xhr.status + ' err=' + err;
- if (xhr.status === 0)
- e = { message: "There appears to be a problem with your internet connection" };
- else
- e = { message: "We received an unexpected status code from the server (" + xhr.status + ")"};
+ if (xhr.status === 0) {
+ e = {message: 'There appears to be a problem with your internet connection'};
+ } else {
+ e = {message: 'We received an unexpected status code from the server (' + xhr.status + ')'};
+ }
}
- console.error(msg)
- console.error(e);
- _LTracker.push(msg);
+ console.error(msg); //eslint-disable-line no-console
+ console.error(e); //eslint-disable-line no-console
+ LTracker.push(msg);
- module.exports.track('api', 'api_weberror', method_name, 'message', msg);
+ module.exports.track('api', 'api_weberror', methodName, 'message', msg);
- if (xhr.status == 401) {
- if (window.location.href.indexOf("/channels") === 0) {
- window.location.pathname = '/login?redirect=' + encodeURIComponent(window.location.pathname+window.location.search);
+ if (xhr.status === 401) {
+ if (window.location.href.indexOf('/channels') === 0) {
+ window.location.pathname = '/login?redirect=' + encodeURIComponent(window.location.pathname + window.location.search);
} else {
var teamURL = window.location.href.split('/channels')[0];
- window.location.href = teamURL + '/login?redirect=' + encodeURIComponent(window.location.pathname+window.location.search);
+ window.location.href = teamURL + '/login?redirect=' + encodeURIComponent(window.location.pathname + window.location.search);
}
}
return e;
}
-module.exports.createTeamFromSignup = function(team_signup, success, error) {
+module.exports.createTeamFromSignup = function(teamSignup, success, error) {
$.ajax({
- url: "/api/v1/teams/create_from_signup",
+ url: '/api/v1/teams/create_from_signup',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
- data: JSON.stringify(team_signup),
+ data: JSON.stringify(teamSignup),
success: success,
- error: function(xhr, status, err) {
- e = handleError("createTeamFromSignup", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('createTeamFromSignup', xhr, status, err);
error(e);
}
});
};
-module.exports.createUser = function(user, data, email_hash, success, error) {
+module.exports.createUser = function(user, data, emailHash, success, error) {
$.ajax({
- url: "/api/v1/users/create?d=" + encodeURIComponent(data) + "&h=" + encodeURIComponent(email_hash),
+ url: '/api/v1/users/create?d=' + encodeURIComponent(data) + '&h=' + encodeURIComponent(emailHash),
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(user),
success: success,
- error: function(xhr, status, err) {
- e = handleError("createUser", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('createUser', xhr, status, err);
error(e);
}
});
@@ -90,14 +89,14 @@ module.exports.createUser = function(user, data, email_hash, success, error) {
module.exports.updateUser = function(user, success, error) {
$.ajax({
- url: "/api/v1/users/update",
+ url: '/api/v1/users/update',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(user),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateUser", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateUser', xhr, status, err);
error(e);
}
});
@@ -107,14 +106,14 @@ module.exports.updateUser = function(user, success, error) {
module.exports.updatePassword = function(data, success, error) {
$.ajax({
- url: "/api/v1/users/newpassword",
+ url: '/api/v1/users/newpassword',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("newPassword", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('newPassword', xhr, status, err);
error(e);
}
});
@@ -124,14 +123,14 @@ module.exports.updatePassword = function(data, success, error) {
module.exports.updateUserNotifyProps = function(data, success, error) {
$.ajax({
- url: "/api/v1/users/update_notify",
+ url: '/api/v1/users/update_notify',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateUserNotifyProps", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateUserNotifyProps', xhr, status, err);
error(e);
}
});
@@ -139,14 +138,14 @@ module.exports.updateUserNotifyProps = function(data, success, error) {
module.exports.updateRoles = function(data, success, error) {
$.ajax({
- url: "/api/v1/users/update_roles",
+ url: '/api/v1/users/update_roles',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateRoles", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateRoles', xhr, status, err);
error(e);
}
});
@@ -155,19 +154,19 @@ module.exports.updateRoles = function(data, success, error) {
};
module.exports.updateActive = function(userId, active, success, error) {
- var data = {};
- data["user_id"] = userId;
- data["active"] = "" + active;
-
+ var data = {};
+ data.user_id = userId;
+ data.active = '' + active;
+
$.ajax({
- url: "/api/v1/users/update_active",
+ url: '/api/v1/users/update_active',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateActive", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateActive', xhr, status, err);
error(e);
}
});
@@ -177,14 +176,14 @@ module.exports.updateActive = function(userId, active, success, error) {
module.exports.sendPasswordReset = function(data, success, error) {
$.ajax({
- url: "/api/v1/users/send_password_reset",
+ url: '/api/v1/users/send_password_reset',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("sendPasswordReset", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('sendPasswordReset', xhr, status, err);
error(e);
}
});
@@ -194,14 +193,14 @@ module.exports.sendPasswordReset = function(data, success, error) {
module.exports.resetPassword = function(data, success, error) {
$.ajax({
- url: "/api/v1/users/reset_password",
+ url: '/api/v1/users/reset_password',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("resetPassword", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('resetPassword', xhr, status, err);
error(e);
}
});
@@ -213,24 +212,24 @@ module.exports.logout = function() {
module.exports.track('api', 'api_users_logout');
var currentTeamUrl = TeamStore.getCurrentTeamUrl();
BrowserStore.clear();
- window.location.href = currentTeamUrl + "/logout";
+ window.location.href = currentTeamUrl + '/logout';
};
module.exports.loginByEmail = function(name, email, password, success, error) {
$.ajax({
- url: "/api/v1/users/login",
+ url: '/api/v1/users/login',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({name: name, email: email, password: password}),
- success: function(data, textStatus, xhr) {
+ success: function onSuccess(data, textStatus, xhr) {
module.exports.track('api', 'api_users_login_success', data.team_id, 'email', data.email);
success(data, textStatus, xhr);
},
- error: function(xhr, status, err) {
+ error: function onError(xhr, status, err) {
module.exports.track('api', 'api_users_login_fail', window.getSubDomain(), 'email', email);
- e = handleError("loginByEmail", xhr, status, err);
+ var e = handleError('loginByEmail', xhr, status, err);
error(e);
}
});
@@ -238,14 +237,14 @@ module.exports.loginByEmail = function(name, email, password, success, error) {
module.exports.revokeSession = function(altId, success, error) {
$.ajax({
- url: "/api/v1/users/revoke_session",
+ url: '/api/v1/users/revoke_session',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({id: altId}),
success: success,
- error: function(xhr, status, err) {
- e = handleError("revokeSession", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('revokeSession', xhr, status, err);
error(e);
}
});
@@ -253,13 +252,13 @@ module.exports.revokeSession = function(altId, success, error) {
module.exports.getSessions = function(userId, success, error) {
$.ajax({
- url: "/api/v1/users/"+userId+"/sessions",
+ url: '/api/v1/users/' + userId + '/sessions',
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success: success,
- error: function(xhr, status, err) {
- e = handleError("getSessions", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getSessions', xhr, status, err);
error(e);
}
});
@@ -267,13 +266,13 @@ module.exports.getSessions = function(userId, success, error) {
module.exports.getAudits = function(userId, success, error) {
$.ajax({
- url: "/api/v1/users/"+userId+"/audits",
+ url: '/api/v1/users/' + userId + '/audits',
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success: success,
- error: function(xhr, status, err) {
- e = handleError("getAudits", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getAudits', xhr, status, err);
error(e);
}
});
@@ -281,10 +280,9 @@ module.exports.getAudits = function(userId, success, error) {
module.exports.getMeSynchronous = function(success, error) {
var currentUser = null;
-
$.ajax({
async: false,
- url: "/api/v1/users/me",
+ url: '/api/v1/users/me',
dataType: 'json',
contentType: 'application/json',
type: 'GET',
@@ -294,14 +292,14 @@ module.exports.getMeSynchronous = function(success, error) {
success(data, textStatus, xhr);
}
},
- error: function(xhr, status, err) {
+ error: function onError(xhr, status, err) {
var ieChecker = window.navigator.userAgent; // This and the condition below is used to check specifically for browsers IE10 & 11 to suppress a 200 'OK' error from appearing on login
- if (xhr.status != 200 || !(ieChecker.indexOf("Trident/7.0") > 0 || ieChecker.indexOf("Trident/6.0") > 0)) {
+ if (xhr.status !== 200 || !(ieChecker.indexOf('Trident/7.0') > 0 || ieChecker.indexOf('Trident/6.0') > 0)) {
if (error) {
- e = handleError('getMeSynchronous', xhr, status, err);
+ var e = handleError('getMeSynchronous', xhr, status, err);
error(e);
- };
- };
+ }
+ }
}
});
@@ -310,14 +308,14 @@ module.exports.getMeSynchronous = function(success, error) {
module.exports.inviteMembers = function(data, success, error) {
$.ajax({
- url: "/api/v1/teams/invite_members",
+ url: '/api/v1/teams/invite_members',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("inviteMembers", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('inviteMembers', xhr, status, err);
error(e);
}
});
@@ -327,14 +325,14 @@ module.exports.inviteMembers = function(data, success, error) {
module.exports.updateTeamDisplayName = function(data, success, error) {
$.ajax({
- url: "/api/v1/teams/update_name",
+ url: '/api/v1/teams/update_name',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateTeamDisplayName", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateTeamDisplayName', xhr, status, err);
error(e);
}
});
@@ -344,14 +342,14 @@ module.exports.updateTeamDisplayName = function(data, success, error) {
module.exports.signupTeam = function(email, success, error) {
$.ajax({
- url: "/api/v1/teams/signup",
+ url: '/api/v1/teams/signup',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({email: email}),
success: success,
- error: function(xhr, status, err) {
- e = handleError("singupTeam", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('singupTeam', xhr, status, err);
error(e);
}
});
@@ -361,14 +359,14 @@ module.exports.signupTeam = function(email, success, error) {
module.exports.createTeam = function(team, success, error) {
$.ajax({
- url: "/api/v1/teams/create",
+ url: '/api/v1/teams/create',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(team),
success: success,
- error: function(xhr, status, err) {
- e = handleError("createTeam", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('createTeam', xhr, status, err);
error(e);
}
});
@@ -376,14 +374,14 @@ module.exports.createTeam = function(team, success, error) {
module.exports.findTeamByName = function(teamName, success, error) {
$.ajax({
- url: "/api/v1/teams/find_team_by_name",
+ url: '/api/v1/teams/find_team_by_name',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({name: teamName}),
success: success,
- error: function(xhr, status, err) {
- e = handleError("findTeamByName", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('findTeamByName', xhr, status, err);
error(e);
}
});
@@ -391,14 +389,14 @@ module.exports.findTeamByName = function(teamName, success, error) {
module.exports.findTeamsSendEmail = function(email, success, error) {
$.ajax({
- url: "/api/v1/teams/email_teams",
+ url: '/api/v1/teams/email_teams',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({email: email}),
success: success,
- error: function(xhr, status, err) {
- e = handleError("findTeamsSendEmail", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('findTeamsSendEmail', xhr, status, err);
error(e);
}
});
@@ -408,14 +406,14 @@ module.exports.findTeamsSendEmail = function(email, success, error) {
module.exports.findTeams = function(email, success, error) {
$.ajax({
- url: "/api/v1/teams/find_teams",
+ url: '/api/v1/teams/find_teams',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify({email: email}),
success: success,
- error: function(xhr, status, err) {
- e = handleError("findTeams", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('findTeams', xhr, status, err);
error(e);
}
});
@@ -423,14 +421,14 @@ module.exports.findTeams = function(email, success, error) {
module.exports.createChannel = function(channel, success, error) {
$.ajax({
- url: "/api/v1/channels/create",
+ url: '/api/v1/channels/create',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(channel),
success: success,
- error: function(xhr, status, err) {
- e = handleError("createChannel", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('createChannel', xhr, status, err);
error(e);
}
});
@@ -438,16 +436,33 @@ module.exports.createChannel = function(channel, success, error) {
module.exports.track('api', 'api_channels_create', channel.type, 'name', channel.name);
};
+module.exports.createDirectChannel = function(channel, userId, success, error) {
+ $.ajax({
+ url: '/api/v1/channels/create_direct',
+ dataType: 'json',
+ contentType: 'application/json',
+ type: 'POST',
+ data: JSON.stringify({user_id: userId}),
+ success: success,
+ error: function(xhr, status, err) {
+ var e = handleError('createDirectChannel', xhr, status, err);
+ error(e);
+ }
+ });
+
+ module.exports.track('api', 'api_channels_create_direct', channel.type, 'name', channel.name);
+};
+
module.exports.updateChannel = function(channel, success, error) {
$.ajax({
- url: "/api/v1/channels/update",
+ url: '/api/v1/channels/update',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(channel),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateChannel", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateChannel', xhr, status, err);
error(e);
}
});
@@ -457,14 +472,14 @@ module.exports.updateChannel = function(channel, success, error) {
module.exports.updateChannelDesc = function(data, success, error) {
$.ajax({
- url: "/api/v1/channels/update_desc",
+ url: '/api/v1/channels/update_desc',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateChannelDesc", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateChannelDesc', xhr, status, err);
error(e);
}
});
@@ -474,14 +489,14 @@ module.exports.updateChannelDesc = function(data, success, error) {
module.exports.updateNotifyLevel = function(data, success, error) {
$.ajax({
- url: "/api/v1/channels/update_notify_level",
+ url: '/api/v1/channels/update_notify_level',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateNotifyLevel", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateNotifyLevel', xhr, status, err);
error(e);
}
});
@@ -489,13 +504,13 @@ module.exports.updateNotifyLevel = function(data, success, error) {
module.exports.joinChannel = function(id, success, error) {
$.ajax({
- url: "/api/v1/channels/" + id + "/join",
+ url: '/api/v1/channels/' + id + '/join',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
success: success,
- error: function(xhr, status, err) {
- e = handleError("joinChannel", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('joinChannel', xhr, status, err);
error(e);
}
});
@@ -505,13 +520,13 @@ module.exports.joinChannel = function(id, success, error) {
module.exports.leaveChannel = function(id, success, error) {
$.ajax({
- url: "/api/v1/channels/" + id + "/leave",
+ url: '/api/v1/channels/' + id + '/leave',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
success: success,
- error: function(xhr, status, err) {
- e = handleError("leaveChannel", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('leaveChannel', xhr, status, err);
error(e);
}
});
@@ -521,13 +536,13 @@ module.exports.leaveChannel = function(id, success, error) {
module.exports.deleteChannel = function(id, success, error) {
$.ajax({
- url: "/api/v1/channels/" + id + "/delete",
+ url: '/api/v1/channels/' + id + '/delete',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
success: success,
- error: function(xhr, status, err) {
- e = handleError("deleteChannel", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('deleteChannel', xhr, status, err);
error(e);
}
});
@@ -537,13 +552,13 @@ module.exports.deleteChannel = function(id, success, error) {
module.exports.updateLastViewedAt = function(channelId, success, error) {
$.ajax({
- url: "/api/v1/channels/" + channelId + "/update_last_viewed_at",
+ url: '/api/v1/channels/' + channelId + '/update_last_viewed_at',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateLastViewedAt", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateLastViewedAt', xhr, status, err);
error(e);
}
});
@@ -556,7 +571,7 @@ function getChannels(success, error) {
type: 'GET',
success: success,
ifModified: true,
- error: function(xhr, status, err) {
+ error: function onError(xhr, status, err) {
var e = handleError('getChannels', xhr, status, err);
error(e);
}
@@ -566,12 +581,12 @@ module.exports.getChannels = getChannels;
module.exports.getChannel = function(id, success, error) {
$.ajax({
- url: "/api/v1/channels/" + id + "/",
+ url: '/api/v1/channels/' + id + '/',
dataType: 'json',
type: 'GET',
success: success,
- error: function(xhr, status, err) {
- e = handleError("getChannel", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getChannel', xhr, status, err);
error(e);
}
});
@@ -581,13 +596,13 @@ module.exports.getChannel = function(id, success, error) {
module.exports.getMoreChannels = function(success, error) {
$.ajax({
- url: "/api/v1/channels/more",
+ url: '/api/v1/channels/more',
dataType: 'json',
type: 'GET',
success: success,
ifModified: true,
- error: function(xhr, status, err) {
- e = handleError("getMoreChannels", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getMoreChannels', xhr, status, err);
error(e);
}
});
@@ -600,7 +615,7 @@ function getChannelCounts(success, error) {
type: 'GET',
success: success,
ifModified: true,
- error: function(xhr, status, err) {
+ error: function onError(xhr, status, err) {
var e = handleError('getChannelCounts', xhr, status, err);
error(e);
}
@@ -610,12 +625,12 @@ module.exports.getChannelCounts = getChannelCounts;
module.exports.getChannelExtraInfo = function(id, success, error) {
$.ajax({
- url: "/api/v1/channels/" + id + "/extra_info",
+ url: '/api/v1/channels/' + id + '/extra_info',
dataType: 'json',
type: 'GET',
success: success,
- error: function(xhr, status, err) {
- e = handleError("getChannelExtraInfo", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getChannelExtraInfo', xhr, status, err);
error(e);
}
});
@@ -623,14 +638,14 @@ module.exports.getChannelExtraInfo = function(id, success, error) {
module.exports.executeCommand = function(channelId, command, suggest, success, error) {
$.ajax({
- url: "/api/v1/command",
+ url: '/api/v1/command',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
- data: JSON.stringify({channelId: channelId, command: command, suggest: "" + suggest}),
+ data: JSON.stringify({channelId: channelId, command: command, suggest: '' + suggest}),
success: success,
- error: function(xhr, status, err) {
- e = handleError("executeCommand", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('executeCommand', xhr, status, err);
error(e);
}
});
@@ -638,18 +653,14 @@ module.exports.executeCommand = function(channelId, command, suggest, success, e
module.exports.getPosts = function(channelId, offset, limit, success, error, complete) {
$.ajax({
- url: "/api/v1/channels/" + channelId + "/posts/" + offset + "/" + limit,
+ url: '/api/v1/channels/' + channelId + '/posts/' + offset + '/' + limit,
dataType: 'json',
type: 'GET',
ifModified: true,
success: success,
- error: function(xhr, status, err) {
- try {
- e = handleError("getPosts", xhr, status, err);
- error(e);
- } catch(er) {
- console.error(er);
- }
+ error: function onError(xhr, status, err) {
+ var e = handleError('getPosts', xhr, status, err);
+ error(e);
},
complete: complete
});
@@ -657,13 +668,13 @@ module.exports.getPosts = function(channelId, offset, limit, success, error, com
module.exports.getPost = function(channelId, postId, success, error) {
$.ajax({
- url: "/api/v1/channels/" + channelId + "/post/" + postId,
+ url: '/api/v1/channels/' + channelId + '/post/' + postId,
dataType: 'json',
type: 'GET',
ifModified: false,
success: success,
- error: function(xhr, status, err) {
- e = handleError("getPost", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getPost', xhr, status, err);
error(e);
}
});
@@ -671,13 +682,13 @@ module.exports.getPost = function(channelId, postId, success, error) {
module.exports.search = function(terms, success, error) {
$.ajax({
- url: "/api/v1/posts/search",
+ url: '/api/v1/posts/search',
dataType: 'json',
type: 'GET',
- data: {"terms": terms},
+ data: {terms: terms},
success: success,
- error: function(xhr, status, err) {
- e = handleError("search", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('search', xhr, status, err);
error(e);
}
});
@@ -687,13 +698,13 @@ module.exports.search = function(terms, success, error) {
module.exports.deletePost = function(channelId, id, success, error) {
$.ajax({
- url: "/api/v1/channels/" + channelId + "/post/" + id + "/delete",
+ url: '/api/v1/channels/' + channelId + '/post/' + id + '/delete',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
success: success,
- error: function(xhr, status, err) {
- e = handleError("deletePost", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('deletePost', xhr, status, err);
error(e);
}
});
@@ -703,14 +714,14 @@ module.exports.deletePost = function(channelId, id, success, error) {
module.exports.createPost = function(post, channel, success, error) {
$.ajax({
- url: "/api/v1/channels/"+ post.channel_id + "/create",
+ url: '/api/v1/channels/' + post.channel_id + '/create',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(post),
success: success,
- error: function(xhr, status, err) {
- e = handleError("createPost", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('createPost', xhr, status, err);
error(e);
}
});
@@ -723,20 +734,20 @@ module.exports.createPost = function(post, channel, success, error) {
// channel_type: channel.type,
// length: post.message.length,
// files: (post.filenames || []).length,
- // mentions: (post.message.match("/<mention>/g") || []).length
+ // mentions: (post.message.match('/<mention>/g') || []).length
// });
};
module.exports.updatePost = function(post, success, error) {
$.ajax({
- url: "/api/v1/channels/"+ post.channel_id + "/update",
+ url: '/api/v1/channels/' + post.channel_id + '/update',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(post),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updatePost", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updatePost', xhr, status, err);
error(e);
}
});
@@ -746,14 +757,14 @@ module.exports.updatePost = function(post, success, error) {
module.exports.addChannelMember = function(id, data, success, error) {
$.ajax({
- url: "/api/v1/channels/" + id + "/add",
+ url: '/api/v1/channels/' + id + '/add',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("addChannelMember", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('addChannelMember', xhr, status, err);
error(e);
}
});
@@ -763,14 +774,14 @@ module.exports.addChannelMember = function(id, data, success, error) {
module.exports.removeChannelMember = function(id, data, success, error) {
$.ajax({
- url: "/api/v1/channels/" + id + "/remove",
+ url: '/api/v1/channels/' + id + '/remove',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("removeChannelMember", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('removeChannelMember', xhr, status, err);
error(e);
}
});
@@ -780,14 +791,14 @@ module.exports.removeChannelMember = function(id, data, success, error) {
module.exports.getProfiles = function(success, error) {
$.ajax({
- url: "/api/v1/users/profiles",
+ url: '/api/v1/users/profiles',
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success: success,
ifModified: true,
- error: function(xhr, status, err) {
- e = handleError("getProfiles", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getProfiles', xhr, status, err);
error(e);
}
});
@@ -795,16 +806,16 @@ module.exports.getProfiles = function(success, error) {
module.exports.uploadFile = function(formData, success, error) {
var request = $.ajax({
- url: "/api/v1/files/upload",
+ url: '/api/v1/files/upload',
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false,
success: success,
- error: function(xhr, status, err) {
+ error: function onError(xhr, status, err) {
if (err !== 'abort') {
- e = handleError("uploadFile", xhr, status, err);
+ var e = handleError('uploadFile', xhr, status, err);
error(e);
}
}
@@ -817,13 +828,13 @@ module.exports.uploadFile = function(formData, success, error) {
module.exports.getPublicLink = function(data, success, error) {
$.ajax({
- url: "/api/v1/files/get_public_link",
+ url: '/api/v1/files/get_public_link',
dataType: 'json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("getPublicLink", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getPublicLink', xhr, status, err);
error(e);
}
});
@@ -831,15 +842,31 @@ module.exports.getPublicLink = function(data, success, error) {
module.exports.uploadProfileImage = function(imageData, success, error) {
$.ajax({
- url: "/api/v1/users/newimage",
+ url: '/api/v1/users/newimage',
type: 'POST',
data: imageData,
cache: false,
contentType: false,
processData: false,
success: success,
- error: function(xhr, status, err) {
- e = handleError("uploadProfileImage", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('uploadProfileImage', xhr, status, err);
+ error(e);
+ }
+ });
+};
+
+module.exports.importSlack = function(fileData, success, error) {
+ $.ajax({
+ url: '/api/v1/teams/import_team',
+ type: 'POST',
+ data: fileData,
+ cache: false,
+ contentType: false,
+ processData: false,
+ success: success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('importTeam', xhr, status, err);
error(e);
}
});
@@ -847,13 +874,13 @@ module.exports.uploadProfileImage = function(imageData, success, error) {
module.exports.getStatuses = function(success, error) {
$.ajax({
- url: "/api/v1/users/status",
+ url: '/api/v1/users/status',
dataType: 'json',
contentType: 'application/json',
type: 'GET',
success: success,
- error: function(xhr, status, err) {
- e = handleError("getStatuses", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getStatuses', xhr, status, err);
error(e);
}
});
@@ -861,13 +888,13 @@ module.exports.getStatuses = function(success, error) {
module.exports.getMyTeam = function(success, error) {
$.ajax({
- url: "/api/v1/teams/me",
+ url: '/api/v1/teams/me',
dataType: 'json',
type: 'GET',
success: success,
ifModified: true,
- error: function(xhr, status, err) {
- e = handleError("getMyTeam", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('getMyTeam', xhr, status, err);
error(e);
}
});
@@ -875,14 +902,14 @@ module.exports.getMyTeam = function(success, error) {
module.exports.updateValetFeature = function(data, success, error) {
$.ajax({
- url: "/api/v1/teams/update_valet_feature",
+ url: '/api/v1/teams/update_valet_feature',
dataType: 'json',
contentType: 'application/json',
type: 'POST',
data: JSON.stringify(data),
success: success,
- error: function(xhr, status, err) {
- e = handleError("updateValetFeature", xhr, status, err);
+ error: function onError(xhr, status, err) {
+ var e = handleError('updateValetFeature', xhr, status, err);
error(e);
}
});
@@ -897,10 +924,10 @@ function getConfig(success, error) {
type: 'GET',
ifModified: true,
success: success,
- error: function(xhr, status, err) {
+ error: function onError(xhr, status, err) {
var e = handleError('getConfig', xhr, status, err);
error(e);
}
});
-};
+}
module.exports.getConfig = getConfig;
diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx
index 41b02c8d6..8239a4a69 100644
--- a/web/react/utils/constants.jsx
+++ b/web/react/utils/constants.jsx
@@ -63,8 +63,9 @@ module.exports = {
GOOGLE_SERVICE: 'google',
POST_CHUNK_SIZE: 60,
MAX_POST_CHUNKS: 3,
- POST_LOADING: "loading",
- POST_FAILED: "failed",
+ POST_LOADING: 'loading',
+ POST_FAILED: 'failed',
+ POST_DELETED: 'deleted',
RESERVED_TEAM_NAMES: [
"www",
"web",
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index 32793809d..c2d250e74 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -2,7 +2,7 @@
// See License.txt for license information.
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
-var ChannelStore = require('../stores/channel_store.jsx')
+var ChannelStore = require('../stores/channel_store.jsx');
var UserStore = require('../stores/user_store.jsx');
var Constants = require('../utils/constants.jsx');
var ActionTypes = Constants.ActionTypes;
@@ -11,8 +11,8 @@ var client = require('./client.jsx');
var Autolinker = require('autolinker');
module.exports.isEmail = function(email) {
- var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
- return regex.test(email);
+ var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
+ return regex.test(email);
};
module.exports.cleanUpUrlable = function(input) {
@@ -23,240 +23,324 @@ module.exports.cleanUpUrlable = function(input) {
};
module.exports.isTestDomain = function() {
-
- if ((/^localhost/).test(window.location.hostname))
+ if ((/^localhost/).test(window.location.hostname)) {
return true;
+ }
- if ((/^dockerhost/).test(window.location.hostname))
+ if ((/^dockerhost/).test(window.location.hostname)) {
return true;
+ }
- if ((/^test/).test(window.location.hostname))
+ if ((/^test/).test(window.location.hostname)) {
return true;
+ }
- if ((/^127.0./).test(window.location.hostname))
+ if ((/^127.0./).test(window.location.hostname)) {
return true;
+ }
- if ((/^192.168./).test(window.location.hostname))
+ if ((/^192.168./).test(window.location.hostname)) {
return true;
+ }
- if ((/^10./).test(window.location.hostname))
+ if ((/^10./).test(window.location.hostname)) {
return true;
+ }
- if ((/^176./).test(window.location.hostname))
+ if ((/^176./).test(window.location.hostname)) {
return true;
+ }
return false;
};
-var getSubDomain = function() {
-
- if (module.exports.isTestDomain())
- return "";
+function getSubDomain() {
+ if (module.exports.isTestDomain()) {
+ return '';
+ }
- if ((/^www/).test(window.location.hostname))
- return "";
+ if ((/^www/).test(window.location.hostname)) {
+ return '';
+ }
- if ((/^beta/).test(window.location.hostname))
- return "";
+ if ((/^beta/).test(window.location.hostname)) {
+ return '';
+ }
- if ((/^ci/).test(window.location.hostname))
- return "";
+ if ((/^ci/).test(window.location.hostname)) {
+ return '';
+ }
- var parts = window.location.hostname.split(".");
+ var parts = window.location.hostname.split('.');
- if (parts.length != 3)
- return "";
+ if (parts.length !== 3) {
+ return '';
+ }
- return parts[0];
+ return parts[0];
}
global.window.getSubDomain = getSubDomain;
module.exports.getSubDomain = getSubDomain;
module.exports.getDomainWithOutSub = function() {
+ var parts = window.location.host.split('.');
- var parts = window.location.host.split(".");
+ if (parts.length === 1) {
+ if (parts[0].indexOf('dockerhost') > -1) {
+ return 'dockerhost:8065';
+ }
- if (parts.length == 1) {
- if (parts[0].indexOf("dockerhost") > -1) {
- return "dockerhost:8065";
- }
- else {
- return "localhost:8065";
+ return 'localhost:8065';
}
- }
- return parts[1] + "." + parts[2];
-}
+ return parts[1] + '.' + parts[2];
+};
module.exports.getCookie = function(name) {
- var value = "; " + document.cookie;
- var parts = value.split("; " + name + "=");
- if (parts.length == 2) return parts.pop().split(";").shift();
-}
-
+ var value = '; ' + document.cookie;
+ var parts = value.split('; ' + name + '=');
+ if (parts.length === 2) {
+ return parts.pop().split(';').shift();
+ }
+};
module.exports.notifyMe = function(title, body, channel) {
- if ("Notification" in window && Notification.permission !== 'denied') {
- Notification.requestPermission(function (permission) {
- if (Notification.permission !== permission) {
- Notification.permission = permission;
- }
-
- if (permission === "granted") {
- var notification = new Notification(title,
- { body: body, tag: body, icon: '/static/images/icon50x50.gif' }
- );
- notification.onclick = function() {
- window.focus();
- if (channel) {
- module.exports.switchChannel(channel);
- } else {
- window.location.href = "/";
- }
- };
- setTimeout(function(){
- notification.close();
- }, 5000);
- }
- });
- }
-}
+ if ('Notification' in window && Notification.permission !== 'denied') {
+ Notification.requestPermission(function onRequestPermission(permission) {
+ if (Notification.permission !== permission) {
+ Notification.permission = permission;
+ }
+
+ if (permission === 'granted') {
+ var notification = new Notification(title, {body: body, tag: body, icon: '/static/images/icon50x50.gif'});
+ notification.onclick = function onClick() {
+ window.focus();
+ if (channel) {
+ module.exports.switchChannel(channel);
+ } else {
+ window.location.href = '/';
+ }
+ };
+ setTimeout(function closeNotificationOnTimeout() {
+ notification.close();
+ }, 5000);
+ }
+ });
+ }
+};
module.exports.ding = function() {
if (!module.exports.isBrowserFirefox()) {
var audio = new Audio('/static/images/ding.mp3');
audio.play();
}
-}
+};
module.exports.getUrlParameter = function(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
- for (var i = 0; i < sURLVariables.length; i++)
- {
+ for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
- if (sParameterName[0] == sParam)
- {
+ if (sParameterName[0] === sParam) {
return sParameterName[1];
}
}
return null;
-}
+};
module.exports.getDateForUnixTicks = function(ticks) {
- return new Date(ticks)
-}
+ return new Date(ticks);
+};
module.exports.displayDate = function(ticks) {
- var d = new Date(ticks);
- var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
+ var d = new Date(ticks);
+ var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
- return m_names[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
-}
+ return monthNames[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear();
+};
module.exports.displayTime = function(ticks) {
- var d = new Date(ticks);
- var hours = d.getHours();
- var minutes = d.getMinutes();
- var ampm = hours >= 12 ? "PM" : "AM";
- hours = hours % 12;
- hours = hours ? hours : "12"
- minutes = minutes > 9 ? minutes : '0'+minutes
- return hours + ":" + minutes + " " + ampm
-}
+ var d = new Date(ticks);
+ var hours = d.getHours();
+ var minutes = d.getMinutes();
+
+ var ampm = 'AM';
+ if (hours >= 12) {
+ ampm = 'AM';
+ }
+
+ hours = hours % 12;
+ if (!hours) {
+ hours = '12';
+ }
+ if (minutes <= 9) {
+ minutes = 0 + minutes;
+ }
+ return hours + ':' + minutes + ' ' + ampm;
+};
module.exports.displayDateTime = function(ticks) {
- var seconds = Math.floor((Date.now() - ticks) / 1000)
+ var seconds = Math.floor((Date.now() - ticks) / 1000);
- interval = Math.floor(seconds / 3600);
+ var interval = Math.floor(seconds / 3600);
- if (interval > 24) {
- return this.displayTime(ticks)
- }
+ if (interval > 24) {
+ return this.displayTime(ticks);
+ }
- if (interval > 1) {
- return interval + " hours ago";
- }
+ if (interval > 1) {
+ return interval + ' hours ago';
+ }
- if (interval == 1) {
- return interval + " hour ago";
- }
+ if (interval === 1) {
+ return interval + ' hour ago';
+ }
- interval = Math.floor(seconds / 60);
- if (interval > 1) {
- return interval + " minutes ago";
- }
+ interval = Math.floor(seconds / 60);
+ if (interval > 1) {
+ return interval + ' minutes ago';
+ }
- return "1 minute ago";
+ return '1 minute ago';
+};
+module.exports.displayCommentDateTime = function(ticks) {
+ return module.exports.displayDate(ticks) + ' ' + module.exports.displayTime(ticks);
}
// returns Unix timestamp in milliseconds
module.exports.getTimestamp = function() {
return Date.now();
-}
+};
-var testUrlMatch = function(text) {
+function testUrlMatch(text) {
var urlMatcher = new Autolinker.matchParser.MatchParser({
- urls: true,
- emails: false,
- twitter: false,
- phone: false,
- hashtag: false,
+ urls: true,
+ emails: false,
+ twitter: false,
+ phone: false,
+ hashtag: false
});
var result = [];
- var replaceFn = function(match) {
- var linkData = {};
- var matchText = match.getMatchedText();
+ function replaceFn(match) {
+ var linkData = {};
+ var matchText = match.getMatchedText();
- linkData.text = matchText;
- linkData.link = matchText.trim().indexOf("http") !== 0 ? "http://" + matchText : matchText;
+ linkData.text = matchText;
+ if (matchText.trim().indexOf('http') !== 0) {
+ linkData.link = 'http://' + matchText;
+ } else {
+ linkData.link = matchText;
+ }
- result.push(linkData);
+ result.push(linkData);
}
- urlMatcher.replace(text,replaceFn,this);
+ urlMatcher.replace(text, replaceFn, this);
return result;
}
module.exports.extractLinks = function(text) {
- var repRegex = new RegExp("<br>", "g");
- var matches = testUrlMatch(text.replace(repRegex, "\n"));
+ var repRegex = new RegExp('<br>', 'g');
+ var matches = testUrlMatch(text.replace(repRegex, '\n'));
- if (!matches.length) return { "links": null, "text": text };
+ if (!matches.length) {
+ return {links: null, text: text};
+ }
var links = [];
for (var i = 0; i < matches.length; i++) {
links.push(matches[i].link);
}
- return { "links": links, "text": text };
-}
+ return {links: links, text: text};
+};
module.exports.escapeRegExp = function(string) {
- return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
+ return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
+};
+
+function getYoutubeEmbed(link) {
+ var regex = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|watch\?(?:[a-zA-Z-_]+=[a-zA-Z0-9-_]+&)+v=)([^#\&\?]*).*/;
+
+ var youtubeId = link.trim().match(regex)[1];
+
+ function onClick(e) {
+ var div = $(e.target).closest('.video-thumbnail__container')[0];
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('src',
+ 'https://www.youtube.com/embed/' +
+ div.id +
+ '?autoplay=1&autohide=1&border=0&wmode=opaque&enablejsapi=1');
+ iframe.setAttribute('width', '480px');
+ iframe.setAttribute('height', '360px');
+ iframe.setAttribute('type', 'text/html');
+ iframe.setAttribute('frameborder', '0');
+
+ div.parentNode.replaceChild(iframe, div);
+ }
+
+ function success(data) {
+ if (!data.items.length || !data.items[0].snippet) {
+ return;
+ }
+ var metadata = data.items[0].snippet;
+ $('.video-uploader.' + youtubeId).html(metadata.channelTitle);
+ $('.video-title.' + youtubeId).find('a').html(metadata.title);
+ $('.post-list-holder-by-time').scrollTop($('.post-list-holder-by-time')[0].scrollHeight);
+ $('.post-list-holder-by-time').perfectScrollbar('update');
+ }
+
+ if (config.GoogleDeveloperKey) {
+ $.ajax({
+ async: true,
+ url: 'https://www.googleapis.com/youtube/v3/videos',
+ type: 'GET',
+ data: {part: 'snippet', id: youtubeId, key:config.GoogleDeveloperKey},
+ success: success
+ });
+ }
+
+ return (
+ <div className='post-comment'>
+ <h4 className='video-type'>YouTube</h4>
+ <h4 className={'video-uploader ' + youtubeId}></h4>
+ <h4 className={'video-title ' + youtubeId}><a href={link}></a></h4>
+ <div className='video-div embed-responsive-item' id={youtubeId} onClick={onClick}>
+ <div className='embed-responsive embed-responsive-4by3 video-div__placeholder'>
+ <div id={youtubeId} className='video-thumbnail__container'>
+ <img className='video-thumbnail' src={'https://i.ytimg.com/vi/' + youtubeId + '/hqdefault.jpg'}/>
+ <div className='block'>
+ <span className='play-button'><span></span></span>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
}
module.exports.getEmbed = function(link) {
-
var ytRegex = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|watch\?(?:[a-zA-Z-_]+=[a-zA-Z0-9-_]+&)+v=)([^#\&\?]*).*/;
var match = link.trim().match(ytRegex);
- if (match && match[1].length==11){
- return getYoutubeEmbed(link);
+ if (match && match[1].length === 11) {
+ return getYoutubeEmbed(link);
}
// Generl embed feature turned off for now
- return;
+ return '';
+ // NEEDS REFACTORING WHEN TURNED BACK ON
+ /*
var id = parseInt((Math.random() * 1000000) + 1);
$.ajax({
type: 'GET',
- url: "https://query.yahooapis.com/v1/public/yql",
+ url: 'https://query.yahooapis.com/v1/public/yql',
data: {
- q: "select * from html where url=\""+link+"\" and xpath='html/head'",
- format: "json"
+ q: 'select * from html where url="' + link + "\" and xpath='html/head'",
+ format: 'json'
},
async: true
}).done(function(data) {
@@ -266,9 +350,9 @@ module.exports.getEmbed = function(link) {
var headerData = data.query.results.head;
- var description = ""
+ var description = ''
for(var i = 0; i < headerData.meta.length; i++) {
- if(headerData.meta[i].name && (headerData.meta[i].name === "description" || headerData.meta[i].name === "Description")){
+ if(headerData.meta[i].name && (headerData.meta[i].name === 'description' || headerData.meta[i].name === 'Description')){
description = headerData.meta[i].content;
break;
}
@@ -279,79 +363,20 @@ module.exports.getEmbed = function(link) {
})
return (
- <div className="post-comment">
- <div className={"web-embed-data"}>
- <p className={"embed-title " + id} />
- <p className={"embed-description " + id} />
- <p className={"embed-link " + id}>{link}</p>
- </div>
- </div>
- );
-}
-
-var getYoutubeEmbed = function(link) {
- var regex = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|watch\?(?:[a-zA-Z-_]+=[a-zA-Z0-9-_]+&)+v=)([^#\&\?]*).*/;
-
- var youtubeId = link.trim().match(regex)[1];
-
- var onclick = function(e) {
- var div = $(e.target).closest('.video-thumbnail__container')[0];
- var iframe = document.createElement("iframe");
- iframe.setAttribute("src",
- "https://www.youtube.com/embed/" + div.id
- + "?autoplay=1&autohide=1&border=0&wmode=opaque&enablejsapi=1");
- iframe.setAttribute("width", "480px");
- iframe.setAttribute("height", "360px");
- iframe.setAttribute("type", "text/html");
- iframe.setAttribute("frameborder", "0");
-
- div.parentNode.replaceChild(iframe, div);
- };
-
- var success = function(data) {
- if(!data.items.length || !data.items[0].snippet) {
- return;
- }
- var metadata = data.items[0].snippet;
- $('.video-uploader.'+youtubeId).html(metadata.channelTitle);
- $('.video-title.'+youtubeId).find('a').html(metadata.title);
- $(".post-list-holder-by-time").scrollTop($(".post-list-holder-by-time")[0].scrollHeight);
- $(".post-list-holder-by-time").perfectScrollbar('update');
- };
-
- if(config.GoogleDeveloperKey) {
- $.ajax({
- async: true,
- url: "https://www.googleapis.com/youtube/v3/videos",
- type: 'GET',
- data: {part:"snippet", id:youtubeId, key:config.GoogleDeveloperKey},
- success: success
- });
- }
-
- return (
- <div className="post-comment">
- <h4 className="video-type">YouTube</h4>
- <h4 className={"video-uploader "+youtubeId}></h4>
- <h4 className={"video-title "+youtubeId}><a href={link}></a></h4>
- <div className="video-div embed-responsive-item" id={youtubeId} onClick={onclick}>
- <div className="embed-responsive embed-responsive-4by3 video-div__placeholder">
- <div id={youtubeId} className="video-thumbnail__container">
- <img className="video-thumbnail" src={"https://i.ytimg.com/vi/" + youtubeId + "/hqdefault.jpg"}/>
- <div className="block">
- <span className="play-button"><span></span></span>
- </div>
- </div>
- </div>
+ <div className='post-comment'>
+ <div className={'web-embed-data'}>
+ <p className={'embed-title ' + id} />
+ <p className={'embed-description ' + id} />
+ <p className={'embed-link ' + id}>{link}</p>
</div>
</div>
);
-
-}
+ */
+};
module.exports.areStatesEqual = function(state1, state2) {
return JSON.stringify(state1) === JSON.stringify(state2);
-}
+};
module.exports.replaceHtmlEntities = function(text) {
var tagsToReplace = {
@@ -359,12 +384,15 @@ module.exports.replaceHtmlEntities = function(text) {
'&lt;': '<',
'&gt;': '>'
};
+ var newtext = text;
for (var tag in tagsToReplace) {
- var regex = new RegExp(tag, "g");
- text = text.replace(regex, tagsToReplace[tag]);
+ if ({}.hasOwnProperty.call(tagsToReplace, tag)) {
+ var regex = new RegExp(tag, 'g');
+ newtext = newtext.replace(regex, tagsToReplace[tag]);
+ }
}
- return text;
-}
+ return newtext;
+};
module.exports.insertHtmlEntities = function(text) {
var tagsToReplace = {
@@ -372,12 +400,15 @@ module.exports.insertHtmlEntities = function(text) {
'<': '&lt;',
'>': '&gt;'
};
+ var newtext = text;
for (var tag in tagsToReplace) {
- var regex = new RegExp(tag, "g");
- text = text.replace(regex, tagsToReplace[tag]);
+ if ({}.hasOwnProperty.call(tagsToReplace, tag)) {
+ var regex = new RegExp(tag, 'g');
+ newtext = newtext.replace(regex, tagsToReplace[tag]);
+ }
}
- return text;
-}
+ return newtext;
+};
module.exports.searchForTerm = function(term) {
AppDispatcher.handleServerAction({
@@ -385,192 +416,192 @@ module.exports.searchForTerm = function(term) {
term: term,
do_search: true
});
-}
+};
-var oldExplicitMentionRegex = /(?:<mention>)([\s\S]*?)(?:<\/mention>)/g;
var puncStartRegex = /^((?![@#])\W)+/g;
var puncEndRegex = /(\W)+$/g;
module.exports.textToJsx = function(text, options) {
if (options && options['singleline']) {
- var repRegex = new RegExp("\n", "g");
- text = text.replace(repRegex, " ");
+ var repRegex = new RegExp('\n', 'g');
+ text = text.replace(repRegex, ' ');
}
- var searchTerm = ""
+ var searchTerm = ''
if (options && options['searchTerm']) {
searchTerm = options['searchTerm'].toLowerCase()
}
- var mentionClass = "mention-highlight";
+ var mentionClass = 'mention-highlight';
if (options && options['noMentionHighlight']) {
- mentionClass = "";
+ mentionClass = '';
}
var inner = [];
// Function specific regex
- var hashRegex = /^href="#[^"]+"|(#[A-Za-z]+[A-Za-z0-9_\-]*[A-Za-z0-9])$/g;
+ var hashRegex = /^href="#[^']+"|(#[A-Za-z]+[A-Za-z0-9_\-]*[A-Za-z0-9])$/g;
var implicitKeywords = UserStore.getCurrentMentionKeys();
- var lines = text.split("\n");
+ var lines = text.split('\n');
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
- var words = line.split(" ");
- var highlightSearchClass = "";
+ var words = line.split(' ');
+ var highlightSearchClass = '';
for (var z = 0; z < words.length; z++) {
var word = words[z];
var trimWord = word.replace(puncStartRegex, '').replace(puncEndRegex, '').trim();
var mentionRegex = /^(?:@)([a-z0-9_]+)$/gi; // looks loop invariant but a weird JS bug needs it to be redefined here
var explicitMention = mentionRegex.exec(trimWord);
- if ((trimWord.toLowerCase().indexOf(searchTerm) > -1 || word.toLowerCase().indexOf(searchTerm) > -1) && searchTerm != "") {
+ if ((trimWord.toLowerCase().indexOf(searchTerm) > -1 || word.toLowerCase().indexOf(searchTerm) > -1) && searchTerm != '') {
- highlightSearchClass = " search-highlight";
+ highlightSearchClass = ' search-highlight';
}
if (explicitMention &&
(UserStore.getProfileByUsername(explicitMention[1]) ||
- Constants.SPECIAL_MENTIONS.indexOf(explicitMention[1]) !== -1))
- {
- var name = explicitMention[1];
- // do both a non-case sensitive and case senstive check
- var mClass = implicitKeywords.indexOf('@'+name.toLowerCase()) !== -1 || implicitKeywords.indexOf('@'+name) !== -1 ? mentionClass : "";
+ Constants.SPECIAL_MENTIONS.indexOf(explicitMention[1]) !== -1))
+ {
+ var name = explicitMention[1];
+ // do both a non-case sensitive and case senstive check
+ var mClass = implicitKeywords.indexOf('@'+name.toLowerCase()) !== -1 || implicitKeywords.indexOf('@'+name) !== -1 ? mentionClass : '';
- var suffix = word.match(puncEndRegex);
- var prefix = word.match(puncStartRegex);
+ var suffix = word.match(puncEndRegex);
+ var prefix = word.match(puncStartRegex);
- if (searchTerm === name) {
- highlightSearchClass = " search-highlight";
- }
+ if (searchTerm === name) {
+ highlightSearchClass = ' search-highlight';
+ }
- inner.push(<span key={name+i+z+"_span"}>{prefix}<a className={mClass + highlightSearchClass + " mention-link"} key={name+i+z+"_link"} href="#" onClick={function(value) { return function() { module.exports.searchForTerm(value); } }(name)}>@{name}</a>{suffix} </span>);
- } else if (testUrlMatch(word).length) {
- var match = testUrlMatch(word)[0];
- var link = match.link;
+ inner.push(<span key={name+i+z+'_span'}>{prefix}<a className={mClass + highlightSearchClass + ' mention-link'} key={name+i+z+'_link'} href='#' onClick={function(value) { return function() { module.exports.searchForTerm(value); } }(name)}>@{name}</a>{suffix} </span>);
+ } else if (testUrlMatch(word).length) {
+ var match = testUrlMatch(word)[0];
+ var link = match.link;
- var prefix = word.substring(0,word.indexOf(match.text));
- var suffix = word.substring(word.indexOf(match.text)+match.text.length);
+ var prefix = word.substring(0,word.indexOf(match.text));
+ var suffix = word.substring(word.indexOf(match.text)+match.text.length);
- inner.push(<span key={word+i+z+"_span"}>{prefix}<a key={word+i+z+"_link"} className={"theme" + highlightSearchClass} target="_blank" href={link}>{match.text}</a>{suffix} </span>);
+ inner.push(<span key={word+i+z+'_span'}>{prefix}<a key={word+i+z+'_link'} className={'theme' + highlightSearchClass} target='_blank' href={link}>{match.text}</a>{suffix} </span>);
- } else if (trimWord.match(hashRegex)) {
- var suffix = word.match(puncEndRegex);
- var prefix = word.match(puncStartRegex);
- var mClass = implicitKeywords.indexOf(trimWord) !== -1 || implicitKeywords.indexOf(trimWord.toLowerCase()) !== -1 ? mentionClass : "";
+ } else if (trimWord.match(hashRegex)) {
+ var suffix = word.match(puncEndRegex);
+ var prefix = word.match(puncStartRegex);
+ var mClass = implicitKeywords.indexOf(trimWord) !== -1 || implicitKeywords.indexOf(trimWord.toLowerCase()) !== -1 ? mentionClass : '';
- if (searchTerm === trimWord.substring(1).toLowerCase() || searchTerm === trimWord.toLowerCase()) {
- highlightSearchClass = " search-highlight";
- }
+ if (searchTerm === trimWord.substring(1).toLowerCase() || searchTerm === trimWord.toLowerCase()) {
+ highlightSearchClass = ' search-highlight';
+ }
- inner.push(<span key={word+i+z+"_span"}>{prefix}<a key={word+i+z+"_hash"} className={"theme " + mClass + highlightSearchClass} href="#" onClick={function(value) { return function() { module.exports.searchForTerm(value); } }(trimWord)}>{trimWord}</a>{suffix} </span>);
+ inner.push(<span key={word+i+z+'_span'}>{prefix}<a key={word+i+z+'_hash'} className={'theme ' + mClass + highlightSearchClass} href='#' onClick={function(value) { return function() { module.exports.searchForTerm(value); } }(trimWord)}>{trimWord}</a>{suffix} </span>);
- } else if (implicitKeywords.indexOf(trimWord) !== -1 || implicitKeywords.indexOf(trimWord.toLowerCase()) !== -1) {
- var suffix = word.match(puncEndRegex);
- var prefix = word.match(puncStartRegex);
+ } else if (implicitKeywords.indexOf(trimWord) !== -1 || implicitKeywords.indexOf(trimWord.toLowerCase()) !== -1) {
+ var suffix = word.match(puncEndRegex);
+ var prefix = word.match(puncStartRegex);
- if (trimWord.charAt(0) === '@') {
- if (searchTerm === trimWord.substring(1).toLowerCase()) {
- highlightSearchClass = " search-highlight";
+ if (trimWord.charAt(0) === '@') {
+ if (searchTerm === trimWord.substring(1).toLowerCase()) {
+ highlightSearchClass = ' search-highlight';
+ }
+ inner.push(<span key={word+i+z+'_span'} key={name+i+z+'_span'}>{prefix}<a className={mentionClass + highlightSearchClass} key={name+i+z+'_link'} href='#'>{trimWord}</a>{suffix} </span>);
+ } else {
+ inner.push(<span key={word+i+z+'_span'}>{prefix}<span className={mentionClass + highlightSearchClass}>{module.exports.replaceHtmlEntities(trimWord)}</span>{suffix} </span>);
}
- inner.push(<span key={word+i+z+"_span"} key={name+i+z+"_span"}>{prefix}<a className={mentionClass + highlightSearchClass} key={name+i+z+"_link"} href="#">{trimWord}</a>{suffix} </span>);
+
+ } else if (word === '') {
+ // if word is empty dont include a span
} else {
- inner.push(<span key={word+i+z+"_span"}>{prefix}<span className={mentionClass + highlightSearchClass}>{module.exports.replaceHtmlEntities(trimWord)}</span>{suffix} </span>);
+ inner.push(<span key={word+i+z+'_span'}><span className={highlightSearchClass}>{module.exports.replaceHtmlEntities(word)}</span> </span>);
}
-
- } else if (word === "") {
- // if word is empty dont include a span
- } else {
- inner.push(<span key={word+i+z+"_span"}><span className={highlightSearchClass}>{module.exports.replaceHtmlEntities(word)}</span> </span>);
- }
- highlightSearchClass = "";
+ highlightSearchClass = '';
}
if (i != lines.length-1)
- inner.push(<br key={"br_"+i+z}/>);
+ inner.push(<br key={'br_'+i+z}/>);
}
return inner;
}
-module.exports.getFileType = function(ext) {
- ext = ext.toLowerCase();
+module.exports.getFileType = function(extin) {
+ var ext = extin.toLowerCase();
if (Constants.IMAGE_TYPES.indexOf(ext) > -1) {
- return "image";
+ return 'image';
}
if (Constants.AUDIO_TYPES.indexOf(ext) > -1) {
- return "audio";
+ return 'audio';
}
if (Constants.VIDEO_TYPES.indexOf(ext) > -1) {
- return "video";
+ return 'video';
}
if (Constants.SPREADSHEET_TYPES.indexOf(ext) > -1) {
- return "spreadsheet";
+ return 'spreadsheet';
}
if (Constants.CODE_TYPES.indexOf(ext) > -1) {
- return "code";
+ return 'code';
}
if (Constants.WORD_TYPES.indexOf(ext) > -1) {
- return "word";
+ return 'word';
}
if (Constants.EXCEL_TYPES.indexOf(ext) > -1) {
- return "excel";
+ return 'excel';
}
if (Constants.PDF_TYPES.indexOf(ext) > -1) {
- return "pdf";
+ return 'pdf';
}
if (Constants.PATCH_TYPES.indexOf(ext) > -1) {
- return "patch";
+ return 'patch';
}
- return "other";
+ return 'other';
};
-module.exports.getPreviewImagePathForFileType = function(fileType) {
- fileType = fileType.toLowerCase();
+module.exports.getPreviewImagePathForFileType = function(fileTypeIn) {
+ var fileType = fileTypeIn.toLowerCase();
var icon;
if (fileType in Constants.ICON_FROM_TYPE) {
icon = Constants.ICON_FROM_TYPE[fileType];
} else {
- icon = Constants.ICON_FROM_TYPE["other"];
+ icon = Constants.ICON_FROM_TYPE.other;
}
- return "/static/images/icons/" + icon + ".png";
+ return '/static/images/icons/' + icon + '.png';
};
-module.exports.getIconClassName = function(fileType) {
- fileType = fileType.toLowerCase();
+module.exports.getIconClassName = function(fileTypeIn) {
+ var fileType = fileTypeIn.toLowerCase();
- if (fileType in Constants.ICON_FROM_TYPE)
+ if (fileType in Constants.ICON_FROM_TYPE) {
return Constants.ICON_FROM_TYPE[fileType];
+ }
- return "glyphicon-file";
-}
+ return 'glyphicon-file';
+};
module.exports.splitFileLocation = function(fileLocation) {
var fileSplit = fileLocation.split('.');
- var ext = "";
+ var ext = '';
if (fileSplit.length > 1) {
ext = fileSplit[fileSplit.length - 1];
fileSplit.splice(fileSplit.length - 1, 1);
}
var filePath = fileSplit.join('.');
- var filename = filePath.split('/')[filePath.split('/').length-1];
+ var filename = filePath.split('/')[filePath.split('/').length - 1];
- return {'ext': ext, 'name': filename, 'path': filePath};
-}
+ return {ext: ext, name: filename, path: filePath};
+};
// Asynchronously gets the size of a file by requesting its headers. If successful, it calls the
// provided callback with the file size in bytes as the argument.
@@ -578,10 +609,10 @@ module.exports.getFileSize = function(url, callback) {
var request = new XMLHttpRequest();
request.open('HEAD', url, true);
- request.onreadystatechange = function() {
- if (request.readyState == 4 && request.status == 200) {
+ request.onreadystatechange = function onReadyStateChange() {
+ if (request.readyState === 4 && request.status === 200) {
if (callback) {
- callback(parseInt(request.getResponseHeader("content-length")));
+ callback(parseInt(request.getResponseHeader('content-length'), 10));
}
}
};
@@ -590,155 +621,154 @@ module.exports.getFileSize = function(url, callback) {
};
module.exports.toTitleCase = function(str) {
- return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
-}
+ function doTitleCase(txt) {
+ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
+ }
+ return str.replace(/\w\S*/g, doTitleCase);
+};
module.exports.changeCss = function(className, classValue) {
// we need invisible container to store additional css definitions
var cssMainContainer = $('#css-modifier-container');
- if (cssMainContainer.length == 0) {
- var cssMainContainer = $('<div id="css-modifier-container"></div>');
- cssMainContainer.hide();
- cssMainContainer.appendTo($('body'));
+ if (cssMainContainer.length === 0) {
+ var cssMainContainer2 = $('<div id="css-modifier-container"></div>');
+ cssMainContainer2.hide();
+ cssMainContainer2.appendTo($('body'));
}
// and we need one div for each class
- classContainer = cssMainContainer.find('div[data-class="' + className + '"]');
- if (classContainer.length == 0) {
+ var classContainer = cssMainContainer.find('div[data-class="' + className + '"]');
+ if (classContainer.length === 0) {
classContainer = $('<div data-class="' + className + '"></div>');
classContainer.appendTo(cssMainContainer);
}
// append additional style
classContainer.html('<style>' + className + ' {' + classValue + '}</style>');
-}
+};
-module.exports.rgb2hex = function(rgb) {
- if (/^#[0-9A-F]{6}$/i.test(rgb)) return rgb;
+module.exports.rgb2hex = function(rgbIn) {
+ if (/^#[0-9A-F]{6}$/i.test(rgbIn)) {
+ return rgbIn;
+ }
- rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
+ var rgb = rgbIn.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
- return ("0" + parseInt(x).toString(16)).slice(-2);
+ return ('0' + parseInt(x, 10).toString(16)).slice(-2);
}
- return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
-}
+ return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
+};
module.exports.placeCaretAtEnd = function(el) {
el.focus();
- if (typeof window.getSelection != "undefined"
- && typeof document.createRange != "undefined") {
+ if (typeof window.getSelection != 'undefined' && typeof document.createRange != 'undefined') {
var range = document.createRange();
range.selectNodeContents(el);
range.collapse(false);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
- } else if (typeof document.body.createTextRange != "undefined") {
+ } else if (typeof document.body.createTextRange != 'undefined') {
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(false);
textRange.select();
}
-}
+};
module.exports.getCaretPosition = function(el) {
if (el.selectionStart) {
- return el.selectionStart;
+ return el.selectionStart;
} else if (document.selection) {
- el.focus();
+ el.focus();
- var r = document.selection.createRange();
- if (r == null) {
- return 0;
- }
+ var r = document.selection.createRange();
+ if (r == null) {
+ return 0;
+ }
- var re = el.createTextRange(),
- rc = re.duplicate();
- re.moveToBookmark(r.getBookmark());
- rc.setEndPoint('EndToStart', re);
+ var re = el.createTextRange();
+ var rc = re.duplicate();
+ re.moveToBookmark(r.getBookmark());
+ rc.setEndPoint('EndToStart', re);
- return rc.text.length;
+ return rc.text.length;
}
return 0;
-}
+};
module.exports.setSelectionRange = function(input, selectionStart, selectionEnd) {
- if (input.setSelectionRange) {
- input.focus();
- input.setSelectionRange(selectionStart, selectionEnd);
- }
- else if (input.createTextRange) {
- var range = input.createTextRange();
- range.collapse(true);
- range.moveEnd('character', selectionEnd);
- range.moveStart('character', selectionStart);
- range.select();
- }
-}
+ if (input.setSelectionRange) {
+ input.focus();
+ input.setSelectionRange(selectionStart, selectionEnd);
+ } else if (input.createTextRange) {
+ var range = input.createTextRange();
+ range.collapse(true);
+ range.moveEnd('character', selectionEnd);
+ range.moveStart('character', selectionStart);
+ range.select();
+ }
+};
-module.exports.setCaretPosition = function (input, pos) {
- module.exports.setSelectionRange(input, pos, pos);
-}
+module.exports.setCaretPosition = function(input, pos) {
+ module.exports.setSelectionRange(input, pos, pos);
+};
module.exports.getSelectedText = function(input) {
- var selectedText;
- if (document.selection != undefined) {
- input.focus();
- var sel = document.selection.createRange();
- selectedText = sel.text;
- } else if (input.selectionStart != undefined) {
- var startPos = input.selectionStart;
- var endPos = input.selectionEnd;
- selectedText = input.value.substring(startPos, endPos)
- }
-
- return selectedText;
-}
-
-module.exports.isValidUsername = function (name) {
-
- var error = ""
- if (!name) {
- error = "This field is required";
+ var selectedText;
+ if (typeof document.selection !== 'undefined') {
+ input.focus();
+ var sel = document.selection.createRange();
+ selectedText = sel.text;
+ } else if (typeof input.selectionStart !== 'undefined') {
+ var startPos = input.selectionStart;
+ var endPos = input.selectionEnd;
+ selectedText = input.value.substring(startPos, endPos);
}
- else if (name.length < 3 || name.length > 15)
- {
- error = "Must be between 3 and 15 characters";
- }
+ return selectedText;
+};
- else if (!/^[a-z0-9\.\-\_]+$/.test(name))
- {
+module.exports.isValidUsername = function(name) {
+ var error = '';
+ if (!name) {
+ error = 'This field is required';
+ } else if (name.length < 3 || name.length > 15) {
+ error = 'Must be between 3 and 15 characters';
+ } else if (!(/^[a-z0-9\.\-\_]+$/).test(name)) {
error = "Must contain only lowercase letters, numbers, and the symbols '.', '-', and '_'.";
- }
-
- else if (!/[a-z]/.test(name.charAt(0)))
- {
- error = "First character must be a letter.";
- }
-
- else
- {
+ } else if (!(/[a-z]/).test(name.charAt(0))) {
+ error = 'First character must be a letter.';
+ } else {
var lowerName = name.toLowerCase().trim();
- for (var i = 0; i < Constants.RESERVED_USERNAMES.length; i++)
- {
- if (lowerName === Constants.RESERVED_USERNAMES[i])
- {
- error = "Cannot use a reserved word as a username.";
+ for (var i = 0; i < Constants.RESERVED_USERNAMES.length; i++) {
+ if (lowerName === Constants.RESERVED_USERNAMES[i]) {
+ error = 'Cannot use a reserved word as a username.';
break;
}
}
}
return error;
+};
+
+function updateTabTitle(name) {
+ document.title = name + ' ' + document.title.substring(document.title.lastIndexOf('-'));
}
+module.exports.updateTabTitle = updateTabTitle;
+
+function updateAddressBar(channelName) {
+ var teamURL = window.location.href.split('/channels')[0];
+ history.replaceState('data', '', teamURL + '/channels/' + channelName);
+}
+module.exports.updateAddressBar = updateAddressBar;
function switchChannel(channel, teammateName) {
AppDispatcher.handleViewAction({
- type: ActionTypes.CLICK_CHANNEL,
- name: channel.name,
- id: channel.id
+ type: ActionTypes.CLICK_CHANNEL,
+ name: channel.name,
+ id: channel.id
});
updateAddressBar(channel.name);
@@ -762,99 +792,104 @@ function switchChannel(channel, teammateName) {
}
module.exports.switchChannel = switchChannel;
-function updateTabTitle(name) {
- document.title = name + ' ' + document.title.substring(document.title.lastIndexOf('-'));
-}
-module.exports.updateTabTitle = updateTabTitle;
-
-function updateAddressBar(channelName) {
- var teamURL = window.location.href.split('/channels')[0];
- history.replaceState('data', '', teamURL + '/channels/' + channelName);
-}
-module.exports.updateAddressBar = updateAddressBar;
-
module.exports.isMobile = function() {
- return screen.width <= 768;
-}
+ return screen.width <= 768;
+};
module.exports.isComment = function(post) {
if ('root_id' in post) {
- return post.root_id != "";
+ return post.root_id !== '';
}
return false;
-}
+};
-module.exports.getDirectTeammate = function(channel_id) {
- var userIds = ChannelStore.get(channel_id).name.split('__');
+module.exports.getDirectTeammate = function(channelId) {
+ var userIds = ChannelStore.get(channelId).name.split('__');
var curUserId = UserStore.getCurrentId();
var teammate = {};
- if(userIds.length != 2 || userIds.indexOf(curUserId) === -1) {
+ if (userIds.length !== 2 || userIds.indexOf(curUserId) === -1) {
return teammate;
}
for (var idx in userIds) {
- if(userIds[idx] !== curUserId) {
+ if (userIds[idx] !== curUserId) {
teammate = UserStore.getProfile(userIds[idx]);
break;
}
}
return teammate;
-}
+};
Image.prototype.load = function(url, progressCallback) {
- var thisImg = this;
+ var self = this;
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.open('GET', url, true);
xmlHTTP.responseType = 'arraybuffer';
- xmlHTTP.onload = function(e) {
- var h = xmlHTTP.getAllResponseHeaders(),
- m = h.match( /^Content-Type\:\s*(.*?)$/mi ),
- mimeType = m[ 1 ] || 'image/png';
+ xmlHTTP.onload = function onLoad() {
+ var h = xmlHTTP.getAllResponseHeaders();
+ var m = h.match(/^Content-Type\:\s*(.*?)$/mi);
+ var mimeType = m[1] || 'image/png';
- var blob = new Blob([this.response], { type: mimeType });
- thisImg.src = window.URL.createObjectURL(blob);
+ var blob = new Blob([this.response], {type: mimeType});
+ self.src = window.URL.createObjectURL(blob);
};
- xmlHTTP.onprogress = function(e) {
- parseInt(thisImg.completedPercentage = (e.loaded / e.total) * 100);
- if (progressCallback) progressCallback();
+ xmlHTTP.onprogress = function onprogress(e) {
+ parseInt(self.completedPercentage = (e.loaded / e.total) * 100, 10);
+ if (progressCallback) {
+ progressCallback();
+ }
};
- xmlHTTP.onloadstart = function() {
- thisImg.completedPercentage = 0;
+ xmlHTTP.onloadstart = function onloadstart() {
+ self.completedPercentage = 0;
};
xmlHTTP.send();
};
Image.prototype.completedPercentage = 0;
-module.exports.changeColor =function(col, amt) {
-
+module.exports.changeColor = function(colourIn, amt) {
var usePound = false;
+ var col = colourIn;
- if (col[0] == "#") {
+ if (col[0] === '#') {
col = col.slice(1);
usePound = true;
}
- var num = parseInt(col,16);
+ var num = parseInt(col, 16);
var r = (num >> 16) + amt;
- if (r > 255) r = 255;
- else if (r < 0) r = 0;
+ if (r > 255) {
+ r = 255;
+ } else if (r < 0) {
+ r = 0;
+ }
var b = ((num >> 8) & 0x00FF) + amt;
- if (b > 255) b = 255;
- else if (b < 0) b = 0;
+ if (b > 255) {
+ b = 255;
+ } else if (b < 0) {
+ b = 0;
+ }
var g = (num & 0x0000FF) + amt;
- if (g > 255) g = 255;
- else if (g < 0) g = 0;
+ if (g > 255) {
+ g = 255;
+ } else if (g < 0) {
+ g = 0;
+ }
- return (usePound?"#":"") + String("000000" + (g | (b << 8) | (r << 16)).toString(16)).slice(-6);
+ var pound = '#';
+ if (!usePound) {
+ pound = '';
+ }
+
+ return pound + String('000000' + (g | (b << 8) | (r << 16)).toString(16)).slice(-6);
};
module.exports.changeOpacity = function(oldColor, opacity) {
@@ -873,53 +908,55 @@ module.exports.changeOpacity = function(oldColor, opacity) {
module.exports.getFullName = function(user) {
if (user.first_name && user.last_name) {
- return user.first_name + " " + user.last_name;
+ return user.first_name + ' ' + user.last_name;
} else if (user.first_name) {
return user.first_name;
} else if (user.last_name) {
return user.last_name;
- } else {
- return "";
}
+
+ return '';
};
module.exports.getDisplayName = function(user) {
if (user.nickname && user.nickname.trim().length > 0) {
return user.nickname;
- } else {
- var fullName = module.exports.getFullName(user);
+ }
+ var fullName = module.exports.getFullName(user);
- if (fullName) {
- return fullName;
- } else {
- return user.username;
- }
+ if (fullName) {
+ return fullName;
}
+
+ return user.username;
};
//IE10 does not set window.location.origin automatically so this must be called instead when using it
module.exports.getWindowLocationOrigin = function() {
var windowLocationOrigin = window.location.origin;
if (!windowLocationOrigin) {
- windowLocationOrigin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
+ windowLocationOrigin = window.location.protocol + '//' + window.location.hostname;
+ if (window.location.port) {
+ windowLocationOrigin += ':' + window.location.port;
+ }
}
return windowLocationOrigin;
-}
+};
-// Converts a file size in bytes into a human-readable string of the form "123MB".
+// Converts a file size in bytes into a human-readable string of the form '123MB'.
module.exports.fileSizeToString = function(bytes) {
// it's unlikely that we'll have files bigger than this
if (bytes > 1024 * 1024 * 1024 * 1024) {
- return Math.floor(bytes / (1024 * 1024 * 1024 * 1024)) + "TB";
+ return Math.floor(bytes / (1024 * 1024 * 1024 * 1024)) + 'TB';
} else if (bytes > 1024 * 1024 * 1024) {
- return Math.floor(bytes / (1024 * 1024 * 1024)) + "GB";
+ return Math.floor(bytes / (1024 * 1024 * 1024)) + 'GB';
} else if (bytes > 1024 * 1024) {
- return Math.floor(bytes / (1024 * 1024)) + "MB";
+ return Math.floor(bytes / (1024 * 1024)) + 'MB';
} else if (bytes > 1024) {
- return Math.floor(bytes / 1024) + "KB";
- } else {
- return bytes + "B";
+ return Math.floor(bytes / 1024) + 'KB';
}
+
+ return bytes + 'B';
};
// Converts a filename (like those attached to Post objects) to a url that can be used to retrieve attachments from the server.
@@ -927,10 +964,10 @@ module.exports.getFileUrl = function(filename) {
var url = filename;
// This is a temporary patch to fix issue with old files using absolute paths
- if (url.indexOf("/api/v1/files/get") != -1) {
- url = filename.split("/api/v1/files/get")[1];
+ if (url.indexOf('/api/v1/files/get') !== -1) {
+ url = filename.split('/api/v1/files/get')[1];
}
- url = module.exports.getWindowLocationOrigin() + "/api/v1/files/get" + url;
+ url = module.exports.getWindowLocationOrigin() + '/api/v1/files/get' + url;
return url;
};
@@ -946,7 +983,7 @@ module.exports.generateId = function() {
// implementation taken from http://stackoverflow.com/a/2117523
var id = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
- id = id.replace(/[xy]/g, function(c) {
+ id = id.replace(/[xy]/g, function replaceRandom(c) {
var r = Math.floor(Math.random() * 16);
var v;
@@ -964,4 +1001,26 @@ module.exports.generateId = function() {
module.exports.isBrowserFirefox = function() {
return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
-}
+};
+
+// Used to get the id of the other user from a DM channel
+module.exports.getUserIdFromChannelName = function(channel) {
+ var ids = channel.name.split('__');
+ var otherUserId = '';
+ if (ids[0] === UserStore.getCurrentId()) {
+ otherUserId = ids[1];
+ } else {
+ otherUserId = ids[0];
+ }
+
+ return otherUserId;
+};
+
+module.exports.importSlack = function(file, success, error) {
+ var formData = new FormData();
+ formData.append('file', file, file.name);
+ formData.append('filesize', file.size);
+ formData.append('importFrom', 'slack');
+
+ client.importSlack(formData, success, error);
+};