From b53e710d20136087cdb43a11dcd5cfc13b3a5d50 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 14 Jul 2015 16:53:49 +0100 Subject: [PATCH] Add invite selection to create room dialog --- skins/base/views/molecules/UserSelector.js | 45 +++++++++++++++++ skins/base/views/organisms/CreateRoom.js | 14 ++++++ src/ComponentBroker.js | 1 + src/controllers/molecules/UserSelector.js | 57 ++++++++++++++++++++++ src/controllers/organisms/CreateRoom.js | 18 ++++--- 5 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 skins/base/views/molecules/UserSelector.js create mode 100644 src/controllers/molecules/UserSelector.js diff --git a/skins/base/views/molecules/UserSelector.js b/skins/base/views/molecules/UserSelector.js new file mode 100644 index 00000000..3053bfeb --- /dev/null +++ b/skins/base/views/molecules/UserSelector.js @@ -0,0 +1,45 @@ +/* +Copyright 2015 OpenMarket Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +'use strict'; + +var React = require('react'); + +var UserSelectorController = require("../../../../src/controllers/molecules/UserSelector"); + +module.exports = React.createClass({ + displayName: 'UserSelector', + mixins: [UserSelectorController], + + onAddUserId: function() { + this.addUser(this.refs.user_id_input.getDOMNode().value); + }, + + render: function() { + console.log("Render"); + return ( +
+ + + +
+ ); + } +}); diff --git a/skins/base/views/organisms/CreateRoom.js b/skins/base/views/organisms/CreateRoom.js index 7d91326f..e6115f25 100644 --- a/skins/base/views/organisms/CreateRoom.js +++ b/skins/base/views/organisms/CreateRoom.js @@ -25,17 +25,31 @@ var ComponentBroker = require('../../../../src/ComponentBroker'); var CreateRoomButton = ComponentBroker.get("atoms/create_room/CreateRoomButton"); var RoomNameTextbox = ComponentBroker.get("atoms/create_room/RoomNameTextbox"); var Presets = ComponentBroker.get("atoms/create_room/Presets"); +var UserSelector = ComponentBroker.get("molecules/UserSelector"); module.exports = React.createClass({ displayName: 'CreateRoom', mixins: [CreateRoomController], + getPreset: function() { + return this.refs.presets.getPreset(); + }, + + getName: function() { + return this.refs.name_textbox.getName(); + }, + + getInvitedUsers: function() { + return this.refs.user_selector.getUserIds(); + }, + render: function() { return (
+
); diff --git a/src/ComponentBroker.js b/src/ComponentBroker.js index 935d304d..8f818a65 100644 --- a/src/ComponentBroker.js +++ b/src/ComponentBroker.js @@ -86,4 +86,5 @@ require('../skins/base/views/organisms/RoomView'); require('../skins/base/views/templates/Login'); require('../skins/base/views/organisms/Notifier'); require('../skins/base/views/organisms/CreateRoom'); +require('../skins/base/views/molecules/UserSelector'); } diff --git a/src/controllers/molecules/UserSelector.js b/src/controllers/molecules/UserSelector.js new file mode 100644 index 00000000..e7e05096 --- /dev/null +++ b/src/controllers/molecules/UserSelector.js @@ -0,0 +1,57 @@ +/* +Copyright 2015 OpenMarket Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +'use strict'; + +var React = require('react'); + +module.exports = { + propTypes: { + initially_selected: React.PropTypes.arrayOf(React.PropTypes.string), + }, + + getDefaultProps: function() { + return { + initially_selected: [], + }; + }, + + getInitialState: function() { + return { + selected_users: this.props.initially_selected, + } + }, + + addUser: function(user_id) { + if (this.state.selected_users.indexOf(user_id == -1)) { + this.setState({ + selected_users: this.state.selected_users.concat([user_id]), + }); + } + }, + + removeUser: function(user_id) { + this.setState({ + selected_users: this.state.selected_users.filter(function(e) { + return e != user_id; + }), + }); + }, + + getUserIds: function() { + return this.state.selected_users; + } +}; diff --git a/src/controllers/organisms/CreateRoom.js b/src/controllers/organisms/CreateRoom.js index e24a75cf..d97f2493 100644 --- a/src/controllers/organisms/CreateRoom.js +++ b/src/controllers/organisms/CreateRoom.js @@ -21,17 +21,23 @@ var MatrixClientPeg = require("../../MatrixClientPeg"); module.exports = { onCreateRoom: function() { - var room_name = this.refs.name_textbox.getName(); - console.log("Create room clicked. Name: " + room_name); - - var options = { - preset: this.refs.presets.getPreset(), - }; + var options = {}; + var room_name = this.getName(); if (room_name) { options.name = room_name; } + var preset = this.getPreset(); + if (preset) { + options.preset = preset; + } + + var invited_users = this.getInvitedUsers(); + if (invited_users) { + options.invite = invited_users; + } + var cli = MatrixClientPeg.get(); if (!cli) { // TODO: Error.