Merge pull request #1743 from RocketChat/livechat-form-improvements
Livechat registration form improvementspull/1747/head
commit
31779bccfa
@ -1,60 +1,62 @@ |
||||
Template.room.helpers({ |
||||
title: function() { |
||||
Template.livechatWindow.helpers({ |
||||
title() { |
||||
var ref; |
||||
if (!Template.instance().subscriptionsReady()) { |
||||
return ''; |
||||
} |
||||
return ((ref = Settings.findOne('Livechat_title')) != null ? ref.value : void 0) || 'Rocket.Chat'; |
||||
}, |
||||
color: function() { |
||||
color() { |
||||
var ref; |
||||
if (!Template.instance().subscriptionsReady()) { |
||||
return 'transparent'; |
||||
} |
||||
return ((ref = Settings.findOne('Livechat_title_color')) != null ? ref.value : void 0) || '#C1272D'; |
||||
}, |
||||
popoutActive: function() { |
||||
popoutActive() { |
||||
return FlowRouter.getQueryParam('mode') === 'popout'; |
||||
}, |
||||
showMessages: function() { |
||||
return Session.get('triggered') || Meteor.userId(); |
||||
showRegisterForm() { |
||||
if (Session.get('triggered') || Meteor.userId()) { |
||||
return false; |
||||
} |
||||
var form = Settings.findOne('Livechat_registration_form'); |
||||
return form.value; |
||||
}, |
||||
livechatStartedEnabled: function() { |
||||
livechatStartedEnabled() { |
||||
return Template.instance().startedEnabled.get() !== null; |
||||
}, |
||||
livechatEnabled: function() { |
||||
livechatEnabled() { |
||||
return Template.instance().startedEnabled.get(); |
||||
} |
||||
}); |
||||
|
||||
Template.room.events({ |
||||
'click .title': function() { |
||||
Template.livechatWindow.events({ |
||||
'click .title'() { |
||||
parentCall('toggleWindow'); |
||||
}, |
||||
'click .popout': function(event) { |
||||
'click .popout'(event) { |
||||
event.stopPropagation(); |
||||
parentCall('openPopout'); |
||||
} |
||||
}); |
||||
|
||||
Template.room.onCreated(function() { |
||||
self = this; |
||||
|
||||
self.startedEnabled = new ReactiveVar(null); |
||||
Template.livechatWindow.onCreated(function() { |
||||
this.startedEnabled = new ReactiveVar(null); |
||||
|
||||
self.subscribe('settings', ['Livechat_title', 'Livechat_title_color', 'Livechat_enabled']); |
||||
this.subscribe('settings', ['Livechat_title', 'Livechat_title_color', 'Livechat_enabled', 'Livechat_registration_form']); |
||||
|
||||
var initialCheck = true; |
||||
|
||||
self.autorun(function() { |
||||
if (self.subscriptionsReady()) { |
||||
this.autorun(() => { |
||||
if (this.subscriptionsReady()) { |
||||
var enabled = Settings.findOne('Livechat_enabled'); |
||||
if (enabled !== undefined) { |
||||
if (!enabled.value && initialCheck) { |
||||
parentCall('removeWidget'); |
||||
} |
||||
initialCheck = false; |
||||
self.startedEnabled.set(enabled.value); |
||||
this.startedEnabled.set(enabled.value); |
||||
} |
||||
} |
||||
}); |
@ -1,50 +0,0 @@ |
||||
Template.register.helpers |
||||
error: -> |
||||
return Template.instance().error.get() |
||||
|
||||
title: -> |
||||
return '' unless Template.instance().subscriptionsReady() |
||||
return Settings.findOne('Livechat_title')?.value or 'Rocket.Chat' |
||||
|
||||
color: -> |
||||
return 'transparent' unless Template.instance().subscriptionsReady() |
||||
return Settings.findOne('Livechat_title_color')?.value or '#C1272D' |
||||
|
||||
welcomeMessage: -> |
||||
return "" |
||||
|
||||
Template.register.events |
||||
'submit #livechat-registration': (e, instance) -> |
||||
e.preventDefault() |
||||
|
||||
$name = instance.$('input[name=name]') |
||||
$email = instance.$('input[name=email]') |
||||
|
||||
unless $name.val().trim() and $email.val().trim() |
||||
return instance.showError TAPi18n.__('Please_fill_name_and_email') |
||||
else |
||||
Meteor.call 'registerGuest', visitor.getToken(), $name.val(), $email.val(), (error, result) -> |
||||
if error? |
||||
return instance.showError error.reason |
||||
|
||||
Meteor.loginWithToken result.token, (error) -> |
||||
if error |
||||
return instance.showError error.reason |
||||
|
||||
'click .error': (e, instance) -> |
||||
instance.hideError() |
||||
|
||||
Template.register.onCreated -> |
||||
@subscribe 'settings', ['Livechat_title', 'Livechat_title_color'] |
||||
@error = new ReactiveVar |
||||
|
||||
@showError = (msg) => |
||||
$('.error').addClass('show') |
||||
@error.set msg |
||||
return |
||||
|
||||
@hideError = => |
||||
$('.error').removeClass('show') |
||||
@error.set() |
||||
return |
||||
|
@ -0,0 +1,68 @@ |
||||
Template.register.helpers({ |
||||
error() { |
||||
return Template.instance().error.get(); |
||||
}, |
||||
welcomeMessage() { |
||||
return ""; |
||||
}, |
||||
hasDepartments() { |
||||
return Department.find().count() > 1; |
||||
}, |
||||
departments() { |
||||
return Department.find(); |
||||
} |
||||
}); |
||||
|
||||
Template.register.events({ |
||||
'submit #livechat-registration' (e, instance) { |
||||
var $email, $name; |
||||
e.preventDefault(); |
||||
$name = instance.$('input[name=name]'); |
||||
$email = instance.$('input[name=email]'); |
||||
if (!($name.val().trim() && $email.val().trim())) { |
||||
return instance.showError(TAPi18n.__('Please_fill_name_and_email')); |
||||
} else { |
||||
var departmentId = instance.$('select[name=department]').val(); |
||||
if (!departmentId) { |
||||
var department = Department.findOne(); |
||||
if (department) { |
||||
departmentId = department._id; |
||||
} |
||||
} |
||||
|
||||
var guest = { |
||||
token: visitor.getToken(), |
||||
name: $name.val(), |
||||
email: $email.val(), |
||||
department: departmentId |
||||
}; |
||||
Meteor.call('livechat:registerGuest', guest, function(error, result) { |
||||
if (error != null) { |
||||
return instance.showError(error.reason); |
||||
} |
||||
Meteor.loginWithToken(result.token, function(error) { |
||||
if (error) { |
||||
return instance.showError(error.reason); |
||||
} |
||||
}); |
||||
}); |
||||
} |
||||
}, |
||||
'click .error' (e, instance) { |
||||
return instance.hideError(); |
||||
} |
||||
}); |
||||
|
||||
Template.register.onCreated(function() { |
||||
this.subscribe('livechat:availableDepartments'); |
||||
|
||||
this.error = new ReactiveVar; |
||||
this.showError = (msg) => { |
||||
$('.error').addClass('show'); |
||||
this.error.set(msg); |
||||
}; |
||||
this.hideError = () => { |
||||
$('.error').removeClass('show'); |
||||
this.error.set(); |
||||
}; |
||||
}); |
@ -0,0 +1,3 @@ |
||||
Meteor.publish('livechat:availableDepartments', function() { |
||||
return RocketChat.models.LivechatDepartment.findEnabledWithAgents(); |
||||
}); |
Loading…
Reference in new issue