From ae737d5dc974445ead45e9ee361c3249b7c186ba Mon Sep 17 00:00:00 2001 From: Jill Tankersley Date: Sat, 3 Dec 2016 19:01:21 -0500 Subject: [PATCH] Updates from private repo --- createroom/createroom.js | 92 ++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/createroom/createroom.js b/createroom/createroom.js index 447f7c6..0bec842 100644 --- a/createroom/createroom.js +++ b/createroom/createroom.js @@ -6,9 +6,6 @@ var CandyShop = (function(self) { return self; }(CandyShop || {})); CandyShop.CreateRoom = (function(self, Candy, $) { - self._options = { - domain: null - } /** Object: about * * Contains: @@ -23,18 +20,16 @@ CandyShop.CreateRoom = (function(self, Candy, $) { /** * Initializes the CreateRoom plugin with the default settings. */ - self.init = function(options){ - // apply the supplied options to the defaults specified - $.extend(true, self._options, options); - + self.init = function(){ $(Candy).on('candy:view.room.after-add', function() { - self.appendButton(); +// self.appendButton(); }); }; self.appendButton = function(){ if ($('#create-group').length === 0) { - $('#chat-tabs').after(self.Template.createButton); + var createRoomHtml = '
+ Create Room
'; + $('#chat-tabs').after(createRoomHtml); $('#create-group').click(function () { self.showModal(); $('#create-group-form').click(function(event) { @@ -48,22 +43,39 @@ CandyShop.CreateRoom = (function(self, Candy, $) { // Add focus to the form element when it's shown. $('#create-group-form-name').focus(); + $('#create-room-link').click(function(){ + $('#create-group-form').submit(); + }); + + // When we press the enter/return key in the form, submit the form. + $('#create-group-form input').keypress(function(event) { + if (event.which === 13 || event.keyCode === 13) { + event.preventDefault(); + $('#create-group-form').submit(); + } + }); + $('#create-group-form').submit(function(event) { event.preventDefault(); if ($('#create-group-form-name').val() === '') { // Notify that group name cannot be blank. - $('.form-group.group-form-name-group').addClass('has-error'); + $('#create-group-form-name').addClass('has-error'); + $('#create-room-error-dialog').html('Room name cannot be blank').removeClass('hide'); // Remove classes after user either starts typing or has pasted in a name. $('#create-group-form-name').focus(function() { - $('.form-group.group-form-name-group').removeClass('has-error'); + $('#create-group-form-name').removeClass('has-error'); + $('#create-room-error-dialog').html('').addClass('hide'); }); } else { var roomName = $('#create-group-form-name').val().trim(); + var roomTopic = $('#create-group-form-topic').val().trim(); + var isPrivate = $('#create-group-form-is_private').prop('checked') ? 1 : 0; + + // Create a valid conference domain. + var conferenceDomain = '@' + Candy.Core.getOptions().conferenceDomain + '.' + Candy.Core.getConnection().domain; + // Create a valid roomjid. - if(!self._options.domain) { // TODO: do this earlier. init() is *too* early because that happens before Candy connects, but maybe we could attach this in a post-connect event handler? That will require more research than I care for at the moment, though. - self._options.domain = "conference" + '.' + Candy.Core.getConnection().domain; - } - var roomJid = roomName.replace(/[^A-Z0-9]+/ig, "_").toLowerCase() + '@' + self._options.domain ; + var roomJid = roomName.replace(/[^A-Z0-9]+/ig, '_').toLowerCase() + conferenceDomain; // Once we've joined the room, send configuration information. $(Candy).on('candy:view.room.after-add', function(ev, obj) { @@ -71,37 +83,65 @@ CandyShop.CreateRoom = (function(self, Candy, $) { // Configuration items for setting room name. var configFormType = $build('field', { 'var': 'FORM_TYPE' }) .c('value').t('http://jabber.org/protocol/muc#roomconfig'); - var configRoomName = $build('field', { 'var': 'muc#roomconfigRoomName' }).c('value').t(roomName); - var config = [configFormType.tree(), configRoomName.tree()]; + var configRoomName = $build('field', { 'var': 'muc#roomconfig_roomname' }).c('value').t(roomName); + var configRoomMembersOnly = $build('field', { 'var': 'much#roomconfig_membersonly' }).c('value').t(isPrivate); + var config = [configFormType.tree(), configRoomName.tree(), configRoomMembersOnly.tree()]; + // Send the configuration form to the server, and on success update our DOM. + Candy.Core.log('[CandyShop CreateRoom] sending new room configuration for ' + roomJid); Candy.Core.getConnection().muc.saveConfiguration(roomJid, config, function(stanza) { var jid = $(stanza).attr('from'); + if (jid === roomJid) { - Candy.View.Pane.Chat.getTab(roomJid).find('.label').html(roomName); + Candy.View.Pane.Chat.getTab(roomJid).find('.room-label').html(roomName); + Candy.Core.Action.Jabber.Room.Admin.SetSubject(roomJid, roomTopic); + } + + if (isPrivate) { + Candy.View.Pane.Chat.getTab(roomJid).find('i.connect-group-chat-icon').removeClass('connect-group-chat-icon').addClass('fa fa-lock'); + } + + // Add it to the roomlist in leftpanehead + if (typeof CandyShop.LeftPaneHead === 'object') { + CandyShop.LeftPaneHead.RoomList.AddRoom(roomJid, roomName, isPrivate); } }); } }); + Candy.Core.log('[CandyShop CreateRoom] joining room created through form: ' + roomJid); // Join the room and close the modal. - Candy.Core.Action.Jabber.Room.Join(roomJid, null); + // Candy.Core.Action.Jabber.Room.Join(roomJid, null); + CandyShop.JoinOnResponse.joinRoom({ roomJid: roomJid, isPrivate: !!isPrivate, topic: roomTopic }, true); Candy.View.Pane.Chat.Modal.hide(); } }); }; self.showModal = function(){ - Candy.View.Pane.Chat.Modal.show(self.Template.modalForm, true, false); + var filterString = $('#candy .room-list-filter').val() + var templateData = { + create_private_room_permission: CONNECT_PERMISSIONS.create_private_room + }; + Candy.View.Pane.Chat.Modal.show(Mustache.to_html(self.Template.modalForm, templateData), true, false); + // Default the new room name to whatever they were looking for + $('#create-group-form-name').val(filterString); self.addFormHandler(); }; self.Template = { - createButton: '
+ Create Room
', - modalForm: '

Create Room

' + - '
' + - '' + - '' + - '
' + modalForm: '' + + '' + + '' }; return self;