Skip to content
Snippets Groups Projects
Commit 2ddcf2c5 authored by Marcelo Schmidt's avatar Marcelo Schmidt
Browse files

Redesign

parent 1a514fb4
No related branches found
No related tags found
No related merge requests found
Showing
with 99 additions and 122 deletions
Meteor.startup ->
roomNameChangedCallback = (msg) ->
Tracker.nonreactive ->
if msg.t is 'r'
if Session.get('openedRoom') is msg.rid
type = if FlowRouter.current().route.name is 'channel' then 'c' else 'p'
RoomManager.close type + FlowRouter.getParam('name')
FlowRouter.go FlowRouter.current().route.name, name: msg.msg
return msg
RocketChat.callbacks.add 'streamMessage', roomNameChangedCallback, RocketChat.callbacks.priority.HIGH
......@@ -329,18 +329,6 @@ Template.room.events
$('#room-title-field').focus().select()
, 10
'keydown #room-title-field': (event) ->
if event.keyCode is 27 # esc
Session.set('editRoomTitle', false)
else if event.keyCode is 13 # enter
renameRoom @_id, $(event.currentTarget).val()
'blur #room-title-field': (event) ->
# TUDO: create a configuration to select the desired behaviour
# renameRoom this._id, $(event.currentTarget).val()
Session.set('editRoomTitle', false)
$(".fixed-title").removeClass "visible"
"click .flex-tab .user-image > a" : (e) ->
RocketChat.TabBar.openFlex()
Session.set('showUserInfo', $(e.currentTarget).data('username'))
......@@ -613,36 +601,3 @@ Template.room.onRendered ->
if webrtc.localUrl.get()?
RocketChat.TabBar.setTemplate 'membersList'
RocketChat.TabBar.openFlex()
renameRoom = (rid, name) ->
name = name?.toLowerCase().trim()
console.log 'room renameRoom' if window.rocketDebug
room = Session.get('roomData' + rid)
if room.name is name
Session.set('editRoomTitle', false)
return false
Meteor.call 'saveRoomName', rid, name, (error, result) ->
if result
Session.set('editRoomTitle', false)
# If room was renamed then close current room and send user to the new one
RoomManager.close room.t + room.name
switch room.t
when 'c'
FlowRouter.go 'channel', name: name
when 'p'
FlowRouter.go 'group', name: name
toastr.success t('Room_name_changed_successfully')
if error
if error.error is 'name-invalid'
toastr.error t('Invalid_room_name', name)
return
if error.error is 'duplicate-name'
if room.t is 'c'
toastr.error t('Duplicate_channel_name', name)
else
toastr.error t('Duplicate_private_group_name', name)
return
toastr.error error.reason
......@@ -6,7 +6,7 @@ Meteor.startup ->
RocketChat.TabBar.addButton
id: 'channel-settings'
i18nTitle: 'Channel_Settings'
icon: 'octicon octicon-gear'
icon: 'octicon octicon-info'
template: 'channelSettings'
order: 0
, RocketChat.callbacks.priority.MEDIUM, 'enter-room-tabbar-channel-settings'
......@@ -13,3 +13,15 @@ Meteor.startup ->
return msg
RocketChat.callbacks.add 'streamMessage', roomSettingsChangedCallback, RocketChat.callbacks.priority.HIGH
roomNameChangedCallback = (msg) ->
Tracker.nonreactive ->
if msg.t is 'r'
if Session.get('openedRoom') is msg.rid
type = if FlowRouter.current().route.name is 'channel' then 'c' else 'p'
RoomManager.close type + FlowRouter.getParam('name')
FlowRouter.go FlowRouter.current().route.name, name: msg.msg
return msg
RocketChat.callbacks.add 'streamMessage', roomNameChangedCallback, RocketChat.callbacks.priority.HIGH
......@@ -15,3 +15,15 @@
}
}
}
.input-line.double-col {
div {
line-height: 15px;
padding: 10px 20px 10px 0;
i.octicon {
font-size: 13px;
opacity: 0.4;
vertical-align: top;
}
}
}
Template.channelSettings.helpers
canEdit: ->
return true
editing: (field) ->
return false
notDirect: ->
return ChatRoom.findOne(@rid)?.t isnt 'd'
roomType: ->
return ChatRoom.findOne(@rid)?.t
roomTypeDescription: ->
return if ChatRoom.findOne(@rid)?.t is 'c' then t('Channel') else t('Private_Group')
roomName: ->
return ChatRoom.findOne(@rid)?.name
roomTopic: ->
......
......@@ -9,31 +9,40 @@
<fieldset>
{{#if notDirect}}
<div class="input-line double-col">
<label>{{_ "Room_Name"}}</label>
<label>{{_ "Name"}}</label>
<div>
<input type="text" name="roomName" value="{{roomName}}" />
{{#if editing 'roomName'}}
<input type="text" name="roomName" value="{{roomName}}" />
{{else}}
{{roomName}}{{#if canEdit}} <i class="octicon octicon-pencil"></i>{{/if}}
{{/if}}
</div>
</div>
{{/if}}
<div class="input-line double-col">
<label>{{_ "Room_Topic"}}</label>
<label>{{_ "Topic"}}</label>
<div>
<input type="text" name="roomTopic" value="{{roomTopic}}" />
{{#if editing 'roomTopic'}}
<input type="text" name="roomTopic" value="{{roomTopic}}" />
{{else}}
{{roomTopic}}{{#if canEdit}} <i class="octicon octicon-pencil"></i>{{/if}}
{{/if}}
</div>
</div>
{{#if notDirect}}
<div class="input-line double-col">
<label>{{_ "Room_Type"}}</label>
<label>{{_ "Type"}}</label>
<div>
<label><input type="radio" name="roomType" value="c" checked="{{$eq roomType 'c'}}" /> {{_ "Channel"}}</label>
<label><input type="radio" name="roomType" value="p" checked="{{$eq roomType 'p'}}" /> {{_ "Private_Group"}}</label>
{{#if editing 'roomType'}}
<label><input type="radio" name="roomType" value="c" checked="{{$eq roomType 'c'}}" /> {{_ "Channel"}}</label>
<label><input type="radio" name="roomType" value="p" checked="{{$eq roomType 'p'}}" /> {{_ "Private_Group"}}</label>
{{else}}
{{roomTypeDescription}}{{#if canEdit}} <i class="octicon octicon-pencil"></i>{{/if}}
{{/if}}
</div>
</div>
{{/if}}
</fieldset>
<div class="submit">
<button class="button save"><i class="icon-send"></i><span>{{_ "Save_changes"}}</span></button>
</div>
</form>
</div>
</template>
{
"Channel": "Channel",
"Private_Group": "Private Group",
"Room_Name": "Room Name",
"Room_Topic": "Room Topic",
"Room_Type": "Room Type",
"Name": "Name",
"Topic": "Topic",
"Type": "Type",
"Room_Settings": "Room Settings",
"room_changed_privacy": "Room type changed to: <em>__room_type__</em> by <em>__user_by__</em>",
"room_changed_topic": "Room topic changed to: <em>__room_topic__</em> by <em>__user_by__</em>"
......
......@@ -25,9 +25,9 @@ Package.onUse(function(api) {
], 'client');
api.addFiles([
'server/functions/changeRoomType.coffee',
'server/functions/changeRoomTopic.coffee',
'server/methods/saveRoomName.coffee',
'server/functions/saveRoomType.coffee',
'server/functions/saveRoomTopic.coffee',
'server/functions/saveRoomName.coffee',
'server/methods/saveRoomSettings.coffee',
'server/models/Messages.coffee'
], 'server');
......
RocketChat.saveRoomName = (rid, name) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] sendMessage -> Invalid user")
room = RocketChat.models.Rooms.findOneById rid
if room.t not in ['c', 'p']
throw new Meteor.Error 403, 'Not allowed'
unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid)
#if room.u._id isnt Meteor.userId() and not hasPermission
throw new Meteor.Error 403, 'Not allowed'
if not /^[0-9a-z-_]+$/.test name
throw new Meteor.Error 'name-invalid', 'Invalid_room_name', { channelName: name }
name = _.slugify name
if name is room.name
return
# avoid duplicate names
if RocketChat.models.Rooms.findOneByName name
throw new Meteor.Error 'duplicate-name', 'Duplicate_channel_name', { channelName: name }
RocketChat.models.Rooms.setNameById rid, name
RocketChat.models.Subscriptions.updateNameByRoomId rid, name
return name
RocketChat.changeRoomTopic = (rid, roomTopic) ->
RocketChat.saveRoomTopic = (rid, roomTopic) ->
unless Match.test rid, String
throw new Meteor.Error 'invalid-rid'
console.log '[function] RocketChat.changeRoomTopic'.green, rid, roomTopic
console.log '[function] RocketChat.saveRoomTopic'.green, rid, roomTopic
return RocketChat.models.Rooms.setTopicById(rid, roomTopic)
RocketChat.changeRoomType = (rid, roomType) ->
console.log '[function] RocketChat.changeRoomType'.green, rid, roomType
RocketChat.saveRoomType = (rid, roomType) ->
console.log '[function] RocketChat.saveRoomType'.green, rid, roomType
unless Match.test rid, String
throw new Meteor.Error 'invalid-rid'
......
Meteor.methods
saveRoomName: (rid, name) ->
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] sendMessage -> Invalid user")
room = RocketChat.models.Rooms.findOneById rid
if room.t not in ['c', 'p']
throw new Meteor.Error 403, 'Not allowed'
unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid)
#if room.u._id isnt Meteor.userId() and not hasPermission
throw new Meteor.Error 403, 'Not allowed'
if not /^[0-9a-z-_]+$/.test name
throw new Meteor.Error 'name-invalid', 'Invalid_room_name', { channelName: name }
name = _.slugify name
if name is room.name
return
# avoid duplicate names
if RocketChat.models.Rooms.findOneByName name
throw new Meteor.Error 'duplicate-name', 'Duplicate_channel_name', { channelName: name }
RocketChat.models.Rooms.setNameById rid, name
RocketChat.models.Subscriptions.updateNameByRoomId rid, name
RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser rid, name, Meteor.user()
return name
......@@ -13,8 +13,12 @@ Meteor.methods
room = RocketChat.models.Rooms.findOneById rid
if room?
if settings.roomName isnt room.name
name = RocketChat.saveRoomName rid, settings.roomName
RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser rid, name, Meteor.user()
if settings.roomType isnt room.t
RocketChat.changeRoomType(rid, settings.roomType)
RocketChat.saveRoomType(rid, settings.roomType)
if settings.roomType is 'c'
message = TAPi18n.__('Channel')
......@@ -23,12 +27,8 @@ Meteor.methods
RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_privacy', rid, message, Meteor.user()
if settings.roomName isnt room.name
name = Meteor.call 'saveRoomName', rid, settings.roomName
if settings.roomTopic isnt room.topic
RocketChat.changeRoomTopic(rid, settings.roomTopic)
message = settings.roomTopic
RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_topic', rid, message, Meteor.user()
RocketChat.saveRoomTopic(rid, settings.roomTopic)
RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_topic', rid, settings.roomTopic, Meteor.user()
return true
RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser = (type, roomId, message, user, extraData) ->
return @createWithTypeRoomIdMessageAndUser type, roomId, message, user, extraData
RocketChat.models.Messages.createRoomRenamedWithRoomIdRoomNameAndUser = (roomId, roomName, user, extraData) ->
return @createWithTypeRoomIdMessageAndUser 'r', roomId, roomName, user, extraData
......@@ -258,10 +258,6 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base
message = user.username
return @createWithTypeRoomIdMessageAndUser 'au', roomId, message, user, extraData
createRoomRenamedWithRoomIdRoomNameAndUser: (roomId, roomName, user, extraData) ->
return @createWithTypeRoomIdMessageAndUser 'r', roomId, roomName, user, extraData
# REMOVE
removeById: (_id) ->
query =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment