fixes #9688 and harmonizes actions from channelSettings and the channel popover

Introduces a re-use-library for the channel related actions.
pull/9697/head
Oliver Jägle 8 years ago
parent 7213440400
commit 6dc96f30e0
  1. 109
      packages/rocketchat-channel-settings/client/views/channelSettings.js
  2. 93
      packages/rocketchat-lib/client/lib/ChannelActions.js
  3. 7
      packages/rocketchat-lib/client/lib/index.js
  4. 78
      packages/rocketchat-ui/client/views/app/popover.js

@ -1,6 +1,7 @@
import toastr from 'toastr';
import s from 'underscore.string';
import { RocketChat, RoomSettingsEnum } from 'meteor/rocketchat:lib';
import { hide, leave, erase } from 'meteor/rocketchat:lib';
const common = {
canLeaveRoom() {
const { cl: canLeave, t: roomType } = Template.instance().room;
@ -27,7 +28,7 @@ const common = {
};
const call = (method, ...params) => {
return new Promise((resolve, reject) => {
Meteor.call(method, ...params, (err, result)=> {
Meteor.call(method, ...params, (err, result) => {
if (err) {
handleError(err);
return reject(err);
@ -46,11 +47,11 @@ Template.channelSettingsEditing.events({
this.value.set(e.currentTarget.checked);
},
'click .js-reset'(e, t) {
const {settings} = t;
const { settings } = t;
Object.keys(settings).forEach(key => settings[key].value.set(settings[key].default.get()));
},
async 'click .js-save'(e, t) {
const {settings} = t;
const { settings } = t;
Object.keys(settings).forEach(async name => {
const setting = settings[name];
const value = setting.value.get();
@ -201,7 +202,7 @@ Template.channelSettingsEditing.onCreated(function() {
};
if (room['default']) {
if (RocketChat.authz.hasRole(Meteor.userId(), 'admin')) {
return new Promise((resolve, reject)=> {
return new Promise((resolve, reject) => {
modal.open({
title: t('Room_default_change_to_private_will_be_default_no_more'),
type: 'warning',
@ -269,7 +270,7 @@ Template.channelSettingsEditing.onCreated(function() {
return RocketChat.authz.hasAtLeastOnePermission(['archive-room', 'unarchive-room'], room._id);
},
save(value) {
return new Promise((resolve, reject)=>{
return new Promise((resolve, reject) => {
modal.open({
title: t('Are_you_sure'),
type: 'warning',
@ -347,7 +348,7 @@ Template.channelSettingsEditing.onCreated(function() {
};
Object.keys(this.settings).forEach(key => {
const setting = this.settings[key];
const def =setting.getValue ? setting.getValue(this.room): this.room[key];
const def = setting.getValue ? setting.getValue(this.room) : this.room[key];
setting.default = new ReactiveVar(def || false);
setting.value = new ReactiveVar(def || false);
});
@ -368,7 +369,7 @@ Template.channelSettingsEditing.helpers({
return this.value.get();// ? '' : 'checked';
},
modified(text = '') {
const {settings} = Template.instance();
const { settings } = Template.instance();
return !Object.keys(settings).some(key => settings[key].default.get() !== settings[key].value.get()) ? text : '';
},
equal(text = '', text2 = '', ret = '*') {
@ -385,7 +386,7 @@ Template.channelSettingsEditing.helpers({
return 'hashtag';
case 'l':
return 'livechat';
default :
default:
return null;
}
},
@ -420,96 +421,20 @@ Template.channelSettings.events({
t.editing.set(true);
},
'click .js-leave'(e, instance) {
let warnText;
const { rid, name, t : type } = instance.room;
switch (type) {
case 'c': warnText = 'Leave_Room_Warning'; break;
case 'p': warnText = 'Leave_Group_Warning'; break;
case 'd': warnText = 'Leave_Private_Warning'; break;
case 'l': warnText = 'Leave_Livechat_Warning'; break;
}
modal.open({
title: t('Are_you_sure'),
text: warnText ? t(warnText, name) : '',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes_leave_it'),
cancelButtonText: t('Cancel'),
closeOnConfirm: true,
html: false
}, async function() {
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) {
FlowRouter.go('home');
}
await call('leaveRoom', rid);
if (rid === Session.get('openedRoom')) {
Session.delete('openedRoom');
}
});
const { name, t: type } = instance.room;
const rid = instance.room._id;
leave(type, rid, name);
},
'click .js-hide'(e, instance) {
let warnText;
const { rid, name, t: type } = instance.room;
switch (type) {
case 'c': warnText = 'Hide_Room_Warning'; break;
case 'p': warnText = 'Hide_Group_Warning'; break;
case 'd': warnText = 'Hide_Private_Warning'; break;
case 'l': warnText = 'Hide_Livechat_Warning'; break;
}
modal.open({
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
}, async function() {
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) {
FlowRouter.go('home');
}
await call('hideRoom', rid);
if (rid === Session.get('openedRoom')) {
Session.delete('openedRoom');
}
});
const { name, t: type } = instance.room;
const rid = instance.room._id;
hide(type, rid, name);
},
'click .js-cancel'(e, t) {
t.editing.set(false);
},
'click .js-delete'() {
return modal.open({
title: t('Are_you_sure'),
text: t('Delete_Room_Warning'),
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes_delete_it'),
cancelButtonText: t('Cancel'),
closeOnConfirm: false,
html: false
}, () => {
call('eraseRoom', this.rid).then(() => {
modal.open({
title: t('Deleted'),
text: t('Room_has_been_deleted'),
type: 'success',
timer: 2000,
showConfirmButton: false
});
});
});
return erase(this.rid);
}
});
@ -558,7 +483,7 @@ Template.channelSettingsInfo.helpers({
return 'hashtag';
case 'l':
return 'livechat';
default :
default:
return null;
}
}

@ -0,0 +1,93 @@
import { UiTextContext } from 'meteor/rocketchat:lib';
export function hide(type, rid, name) {
const warnText = RocketChat.roomTypes.roomTypes[type].getUiText(UiTextContext.HIDE_WARNING);
modal.open({
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');
}
Meteor.call('hideRoom', rid, function(err) {
if (err) {
handleError(err);
} else if (rid === Session.get('openedRoom')) {
Session.delete('openedRoom');
}
});
});
return false;
}
export function leave(type, rid, name) {
const warnText = RocketChat.roomTypes.roomTypes[type].getUiText(UiTextContext.LEAVE_WARNING);
modal.open({
title: t('Are_you_sure'),
text: warnText ? 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) {
Meteor.call('leaveRoom', rid, function(err) {
if (err) {
modal.open({
title: t('Warning'),
text: handleError(err, false),
type: 'warning',
html: false
});
} else {
modal.close();
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) {
FlowRouter.go('home');
}
RoomManager.close(rid);
}
});
}
});
return false;
}
export function erase(rid) {
modal.open({
title: t('Are_you_sure'),
text: t('Delete_Room_Warning'),
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes_delete_it'),
cancelButtonText: t('Cancel'),
closeOnConfirm: false,
html: false
}, () => {
call('eraseRoom', rid).then(() => {
modal.open({
title: t('Deleted'),
text: t('Room_has_been_deleted'),
type: 'success',
timer: 2000,
showConfirmButton: false
});
});
});
}

@ -8,12 +8,15 @@
import { RocketChatTabBar } from './RocketChatTabBar';
import { RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig, UiTextContext } from '../../lib/RoomTypeConfig';
import {hide, leave, erase} from './ChannelActions';
export {
RocketChatTabBar,
RoomSettingsEnum,
RoomTypeConfig,
RoomTypeRouteConfig,
UiTextContext
UiTextContext,
hide,
leave,
erase
};

@ -1,7 +1,7 @@
/* globals popover isRtl */
import _ from 'underscore';
import {UiTextContext} from 'meteor/rocketchat:lib';
import { hide, leave } from 'meteor/rocketchat:lib';
this.popover = {
renderedPopover: null,
@ -41,7 +41,7 @@ Template.popover.onRendered(function() {
const activeElement = this.data.activeElement;
const popoverContent = this.firstNode.children[0];
const position = _.throttle(() => {
const position = typeof this.data.position === 'function'? this.data.position() : this.data.position;
const position = typeof this.data.position === 'function' ? this.data.position() : this.data.position;
const customCSSProperties = typeof this.data.customCSSProperties === 'function' ? this.data.customCSSProperties() : this.data.customCSSProperties;
const mousePosition = typeof this.data.mousePosition === 'function' ? this.data.mousePosition() : this.data.mousePosition;
if (position) {
@ -114,7 +114,7 @@ Template.popover.events({
const id = event.currentTarget.dataset.id;
const action = RocketChat.messageBox.actions.getById(id);
if ((action[0] != null ? action[0].action : undefined) != null) {
action[0].action({rid: t.data.data.rid, messageBox: document.querySelector('.rc-message-box'), element: event.currentTarget, event});
action[0].action({ rid: t.data.data.rid, messageBox: document.querySelector('.rc-message-box'), element: event.currentTarget, event });
if (id !== 'audio-message') {
popover.close();
}
@ -210,77 +210,11 @@ Template.popover.events({
const action = e.currentTarget.dataset.id;
if (action === 'hide') {
const warnText = RocketChat.roomTypes.roomTypes[template].getUiText(UiTextContext.HIDE_WARNING);
modal.open({
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');
}
Meteor.call('hideRoom', rid, function(err) {
if (err) {
handleError(err);
} else if (rid === Session.get('openedRoom')) {
Session.delete('openedRoom');
}
});
});
return false;
hide(template, rid, name);
}
if (action === 'leave') {
let warnText;
switch (template) {
case 'c': warnText = 'Leave_Room_Warning'; break;
case 'p': warnText = 'Leave_Group_Warning'; break;
case 'd': warnText = 'Leave_Private_Warning'; break;
case 'l': warnText = 'Hide_Livechat_Warning'; break;
}
modal.open({
title: t('Are_you_sure'),
text: warnText ? 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) {
Meteor.call('leaveRoom', rid, function(err) {
if (err) {
modal.open({
title: t('Warning'),
text: handleError(err, false),
type: 'warning',
html: false
});
} else {
modal.close();
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName()) && (Session.get('openedRoom') === rid)) {
FlowRouter.go('home');
}
RoomManager.close(rid);
}
});
}
});
return false;
leave(template, rid, name);
}
if (action === 'read') {
@ -294,7 +228,7 @@ Template.popover.events({
return handleError(error);
}
const subscription = ChatSubscription.findOne({rid});
const subscription = ChatSubscription.findOne({ rid });
if (subscription == null) {
return;
}

Loading…
Cancel
Save