/** @jsx React.DOM */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ /* jshint newcap:false */ /* global loop:true, React */ var loop = loop || {}; loop.roomViews = (function(mozL10n) { "use strict"; var sharedActions = loop.shared.actions; var sharedMixins = loop.shared.mixins; var ROOM_STATES = loop.store.ROOM_STATES; var SCREEN_SHARE_STATES = loop.shared.utils.SCREEN_SHARE_STATES; var sharedViews = loop.shared.views; /** * ActiveRoomStore mixin. * @type {Object} */ var ActiveRoomStoreMixin = { mixins: [Backbone.Events], propTypes: { roomStore: React.PropTypes.instanceOf(loop.store.RoomStore).isRequired }, componentWillMount: function() { this.listenTo(this.props.roomStore, "change:activeRoom", this._onActiveRoomStateChanged); this.listenTo(this.props.roomStore, "change:error", this._onRoomError); }, componentWillUnmount: function() { this.stopListening(this.props.roomStore); }, _onActiveRoomStateChanged: function() { // Only update the state if we're mounted, to avoid the problem where // stopListening doesn't nuke the active listeners during a event // processing. if (this.isMounted()) { this.setState(this.props.roomStore.getStoreState("activeRoom")); } }, _onRoomError: function() { // Only update the state if we're mounted, to avoid the problem where // stopListening doesn't nuke the active listeners during a event // processing. if (this.isMounted()) { this.setState({error: this.props.roomStore.getStoreState("error")}); } }, getInitialState: function() { var storeState = this.props.roomStore.getStoreState("activeRoom"); return _.extend({ // Used by the UI showcase. roomState: this.props.roomState || storeState.roomState }, storeState); } }; var SocialShareDropdown = React.createClass({ propTypes: { dispatcher: React.PropTypes.instanceOf(loop.Dispatcher).isRequired, roomUrl: React.PropTypes.string, show: React.PropTypes.bool.isRequired, socialShareButtonAvailable: React.PropTypes.bool, socialShareProviders: React.PropTypes.array }, handleToolbarAddButtonClick: function(event) { event.preventDefault(); this.props.dispatcher.dispatch(new sharedActions.AddSocialShareButton()); }, handleAddServiceClick: function(event) { event.preventDefault(); this.props.dispatcher.dispatch(new sharedActions.AddSocialShareProvider()); }, handleProviderClick: function(event) { event.preventDefault(); var origin = event.currentTarget.dataset.provider; var provider = this.props.socialShareProviders.filter(function(provider) { return provider.origin == origin; })[0]; this.props.dispatcher.dispatch(new sharedActions.ShareRoomUrl({ provider: provider, roomUrl: this.props.roomUrl, previews: [] })); }, render: function() { // Don't render a thing when no data has been fetched yet. if (!this.props.socialShareProviders) { return null; } var cx = React.addons.classSet; var shareDropdown = cx({ "share-service-dropdown": true, "dropdown-menu": true, "share-button-unavailable": !this.props.socialShareButtonAvailable, "hide": !this.props.show }); // When the button is not yet available, we offer to put it in the navbar // for the user. if (!this.props.socialShareButtonAvailable) { return (
{mozL10n.get("share_panel_header")}
{ mozL10n.get("share_panel_body", { brandShortname: mozL10n.get("brandShortname"), clientSuperShortname: mozL10n.get("clientSuperShortname"), }) }
); } return ( ); } }); /** * Desktop room invitation view (overlay). */ var DesktopRoomInvitationView = React.createClass({ mixins: [React.addons.LinkedStateMixin, sharedMixins.DropdownMenuMixin], propTypes: { dispatcher: React.PropTypes.instanceOf(loop.Dispatcher).isRequired, error: React.PropTypes.object, // This data is supplied by the activeRoomStore. roomData: React.PropTypes.object.isRequired, show: React.PropTypes.bool.isRequired, showContext: React.PropTypes.bool.isRequired }, getInitialState: function() { return { copiedUrl: false, newRoomName: "" }; }, handleTextareaKeyDown: function(event) { // Submit the form as soon as the user press Enter in that field // Note: We're using a textarea instead of a simple text input to display // placeholder and entered text on two lines, to circumvent l10n // rendering/UX issues for some locales. if (event.which === 13) { this.handleFormSubmit(event); } }, handleFormSubmit: function(event) { event.preventDefault(); this.props.dispatcher.dispatch(new sharedActions.RenameRoom({ roomToken: this.props.roomData.roomToken, newRoomName: this.state.newRoomName })); }, handleEmailButtonClick: function(event) { event.preventDefault(); this.props.dispatcher.dispatch( new sharedActions.EmailRoomUrl({roomUrl: this.props.roomData.roomUrl})); }, handleCopyButtonClick: function(event) { event.preventDefault(); this.props.dispatcher.dispatch( new sharedActions.CopyRoomUrl({roomUrl: this.props.roomData.roomUrl})); this.setState({copiedUrl: true}); }, handleShareButtonClick: function(event) { event.preventDefault(); this.toggleDropdownMenu(); }, render: function() { if (!this.props.show) { return null; } var cx = React.addons.classSet; return (

{mozL10n.get("rooms_name_change_failed_label")}