Skip to content

Commit

Permalink
Side-nav CoffeeScript to JavaScript II (#6266)
Browse files Browse the repository at this point in the history
* convert sidenav Coffeescript to Javascript

* fix no unused vars
  • Loading branch information
MartinSchoeler authored and rodrigok committed Mar 23, 2017
1 parent 4b56894 commit 2ffad6d
Show file tree
Hide file tree
Showing 9 changed files with 527 additions and 393 deletions.
122 changes: 0 additions & 122 deletions packages/rocketchat-ui-sidenav/client/chatRoomItem.coffee

This file was deleted.

158 changes: 158 additions & 0 deletions packages/rocketchat-ui-sidenav/client/chatRoomItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/* globals KonchatNotification, menu */

Template.chatRoomItem.helpers({

alert() {
if ((FlowRouter.getParam('_id') !== this.rid) || !document.hasFocus()) {
return this.alert;
}
},

unread() {
if (((FlowRouter.getParam('_id') !== this.rid) || !document.hasFocus()) && (this.unread > 0)) {
return this.unread;
}
},

userStatus() {
const userStatus = RocketChat.roomTypes.getUserStatus(this.t, this.rid);
return `status-${userStatus || 'offline'}`;
},

name() {
return this.name;
},

roomIcon() {
return RocketChat.roomTypes.getIcon(this.t);
},

active() {
if (Session.get('openedRoom') === this.rid) {
return 'active';
}
},

canLeave() {
const roomData = Session.get('roomData' + this.rid);

if (!roomData) { return false; }

if (((roomData.cl != null) && !roomData.cl) || (roomData.t === 'd')) {
return false;
} else {
return true;
}
},

route() {
return RocketChat.roomTypes.getRouteLink(this.t, this);
},

archived() {
return this.archived ? 'archived' : undefined;
}
});

Template.chatRoomItem.rendered = function() {
if (!(FlowRouter.getParam('_id') && (FlowRouter.getParam('_id') === this.data.rid)) && !this.data.ls && (this.data.alert === true)) {
return KonchatNotification.newRoom(this.data.rid);
}
};

Template.chatRoomItem.events({

'click .open-room'() {
return menu.close();
},

'click .hide-room'(e) {
e.stopPropagation();
e.preventDefault();

const { rid } = this;
const { name } = this;

const warnText = (() => {
switch (this.t) {
case 'c': return 'Hide_Room_Warning';
case 'p': return 'Hide_Group_Warning';
case 'd': return 'Hide_Private_Warning';
}
})();

return swal({
title: t('Are_you_sure'),
text: warnText ? t(warnText, name) : '',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes_hide_it'),
cancelButtonText: t('Cancel'),
closeOnConfirm: true,
html: false
}, function() {
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) {
FlowRouter.go('home');
}

return Meteor.call('hideRoom', rid, function(err) {
if (err) {
return handleError(err);
} else if (rid === Session.get('openedRoom')) {
return Session.delete('openedRoom');
}
});
});
},

'click .leave-room'(e) {
e.stopPropagation();
e.preventDefault();

const { rid } = this;
const { name } = this;

const warnText = (() => {
switch (false) {
case this.t !== 'c': return 'Leave_Room_Warning';
case this.t !== 'p': return 'Leave_Group_Warning';
case this.t !== 'd': return 'Leave_Private_Warning';
}
})();
return swal({
title: t('Are_you_sure'),
text: t(warnText, name),
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes_leave_it'),
cancelButtonText: t('Cancel'),
closeOnConfirm: false,
html: false
}, function(isConfirm) {
if (isConfirm) {
return Meteor.call('leaveRoom', rid, function(err) {
if (err) {
return swal({
title: t('Warning'),
text: handleError(err, false),
type: 'warning',
html: false
});

} else {
swal.close();
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) {
FlowRouter.go('home');
}

return RoomManager.close(rid);
}
});
} else {
return swal.close();
}
});
}
});
95 changes: 0 additions & 95 deletions packages/rocketchat-ui-sidenav/client/listChannelsFlex.coffee

This file was deleted.

Loading

0 comments on commit 2ffad6d

Please sign in to comment.