From ed52cdf6dfd81f77593deb6a326b725e0f8002f7 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 14 Jul 2015 15:14:26 +0100 Subject: [PATCH] Add basic CreateRoom organism. Supports setting room name and selecting preset --- .../atoms/create_room/CreateRoomButton.js | 32 +++++++++++++ skins/base/views/atoms/create_room/Presets.js | 35 +++++++++++++++ .../atoms/create_room/RoomNameTextbox.js | 32 +++++++++++++ skins/base/views/organisms/CreateRoom.js | 43 ++++++++++++++++++ src/ComponentBroker.js | 4 ++ .../atoms/create_room/CreateRoomButton.js | 35 +++++++++++++++ src/controllers/atoms/create_room/Presets.js | 45 +++++++++++++++++++ .../atoms/create_room/RoomNameTextbox.js | 45 +++++++++++++++++++ src/controllers/organisms/CreateRoom.js | 44 ++++++++++++++++++ 9 files changed, 315 insertions(+) create mode 100644 skins/base/views/atoms/create_room/CreateRoomButton.js create mode 100644 skins/base/views/atoms/create_room/Presets.js create mode 100644 skins/base/views/atoms/create_room/RoomNameTextbox.js create mode 100644 skins/base/views/organisms/CreateRoom.js create mode 100644 src/controllers/atoms/create_room/CreateRoomButton.js create mode 100644 src/controllers/atoms/create_room/Presets.js create mode 100644 src/controllers/atoms/create_room/RoomNameTextbox.js create mode 100644 src/controllers/organisms/CreateRoom.js diff --git a/skins/base/views/atoms/create_room/CreateRoomButton.js b/skins/base/views/atoms/create_room/CreateRoomButton.js new file mode 100644 index 00000000..2f9ccae0 --- /dev/null +++ b/skins/base/views/atoms/create_room/CreateRoomButton.js @@ -0,0 +1,32 @@ +/* +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 CreateRoomButtonController = require("../../../../../src/controllers/atoms/create_room/CreateRoomButton"); + +module.exports = React.createClass({ + displayName: 'CreateRoomButton', + mixins: [CreateRoomButtonController], + + render: function() { + return ( + + ); + } +}); diff --git a/skins/base/views/atoms/create_room/Presets.js b/skins/base/views/atoms/create_room/Presets.js new file mode 100644 index 00000000..66cbcc32 --- /dev/null +++ b/skins/base/views/atoms/create_room/Presets.js @@ -0,0 +1,35 @@ +/* +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 PresetsController = require("../../../../../src/controllers/atoms/create_room/Presets"); + +module.exports = React.createClass({ + displayName: 'CreateRoomPresets', + mixins: [PresetsController], + + render: function() { + return ( + + ); + } +}); diff --git a/skins/base/views/atoms/create_room/RoomNameTextbox.js b/skins/base/views/atoms/create_room/RoomNameTextbox.js new file mode 100644 index 00000000..e8a87736 --- /dev/null +++ b/skins/base/views/atoms/create_room/RoomNameTextbox.js @@ -0,0 +1,32 @@ +/* +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 RoomNameTextboxController = require("../../../../../src/controllers/atoms/create_room/RoomNameTextbox"); + +module.exports = React.createClass({ + displayName: 'CreateRoomButton', + mixins: [RoomNameTextboxController], + + render: function() { + return ( + + ); + } +}); diff --git a/skins/base/views/organisms/CreateRoom.js b/skins/base/views/organisms/CreateRoom.js new file mode 100644 index 00000000..7d91326f --- /dev/null +++ b/skins/base/views/organisms/CreateRoom.js @@ -0,0 +1,43 @@ +/* +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 CreateRoomController = require("../../../../src/controllers/organisms/CreateRoom"); + +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"); + + +module.exports = React.createClass({ + displayName: 'CreateRoom', + mixins: [CreateRoomController], + + render: function() { + return ( +
+ + + +
+ ); + } +}); diff --git a/src/ComponentBroker.js b/src/ComponentBroker.js index 32b07a03..935d304d 100644 --- a/src/ComponentBroker.js +++ b/src/ComponentBroker.js @@ -61,6 +61,9 @@ if (0) { require('../skins/base/views/atoms/LogoutButton'); require('../skins/base/views/atoms/EnableNotificationsButton'); require('../skins/base/views/atoms/MessageTimestamp'); +require('../skins/base/views/atoms/create_room/CreateRoomButton'); +require('../skins/base/views/atoms/create_room/RoomNameTextbox'); +require('../skins/base/views/atoms/create_room/Presets'); require('../skins/base/views/molecules/MatrixToolbar'); require('../skins/base/views/molecules/RoomTile'); require('../skins/base/views/molecules/MessageTile'); @@ -82,4 +85,5 @@ require('../skins/base/views/organisms/RoomList'); require('../skins/base/views/organisms/RoomView'); require('../skins/base/views/templates/Login'); require('../skins/base/views/organisms/Notifier'); +require('../skins/base/views/organisms/CreateRoom'); } diff --git a/src/controllers/atoms/create_room/CreateRoomButton.js b/src/controllers/atoms/create_room/CreateRoomButton.js new file mode 100644 index 00000000..f03dd56c --- /dev/null +++ b/src/controllers/atoms/create_room/CreateRoomButton.js @@ -0,0 +1,35 @@ +/* +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: { + onCreateRoom: React.PropTypes.func, + }, + + getDefaultProps: function() { + return { + onCreateRoom: function() {}, + }; + }, + + onClick: function() { + this.props.onCreateRoom(); + }, +}; diff --git a/src/controllers/atoms/create_room/Presets.js b/src/controllers/atoms/create_room/Presets.js new file mode 100644 index 00000000..0ae0ffb4 --- /dev/null +++ b/src/controllers/atoms/create_room/Presets.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'); + +module.exports = { + propTypes: { + default_preset: React.PropTypes.string + }, + + onValueChanged: function(ev) { + this.setState({preset: ev.target.value}) + }, + + getDefaultProps: function() { + return { + default_preset: 'private_chat', + }; + }, + + getInitialState: function() { + return { + preset: this.props.default_preset, + } + }, + + getPreset: function() { + return this.state.preset; + }, +}; diff --git a/src/controllers/atoms/create_room/RoomNameTextbox.js b/src/controllers/atoms/create_room/RoomNameTextbox.js new file mode 100644 index 00000000..a5017c89 --- /dev/null +++ b/src/controllers/atoms/create_room/RoomNameTextbox.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'); + +module.exports = { + propTypes: { + default_name: React.PropTypes.string + }, + + onValueChanged: function(ev) { + this.setState({room_name: ev.target.value}) + }, + + getDefaultProps: function() { + return { + default_name: '', + }; + }, + + getInitialState: function() { + return { + room_name: this.props.default_name, + } + }, + + getName: function() { + return this.state.room_name; + }, +}; diff --git a/src/controllers/organisms/CreateRoom.js b/src/controllers/organisms/CreateRoom.js new file mode 100644 index 00000000..e24a75cf --- /dev/null +++ b/src/controllers/organisms/CreateRoom.js @@ -0,0 +1,44 @@ +/* +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 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(), + }; + + if (room_name) { + options.name = room_name; + } + + var cli = MatrixClientPeg.get(); + if (!cli) { + // TODO: Error. + console.error("Cannot create room: No matrix client."); + return; + } + + var deferred = MatrixClientPeg.get().createRoom(options); + } +};