Enable default chat in preferences automatically if only one exists.
This commit is contained in:
parent
ed88660938
commit
7ba6f6a54d
2 changed files with 44 additions and 21 deletions
|
@ -127,11 +127,31 @@ class App.CustomerChat extends App.Controller
|
||||||
if state
|
if state
|
||||||
@startPushState()
|
@startPushState()
|
||||||
preferences = @Session.get('preferences')
|
preferences = @Session.get('preferences')
|
||||||
if !preferences || !preferences.chat || !preferences.chat.active || _.isEmpty(preferences.chat.active)
|
if App.Chat.first() && !preferences || !preferences.chat || !preferences.chat.active || _.isEmpty(preferences.chat.active)
|
||||||
@notify(
|
|
||||||
type: 'error'
|
# if we only have one chat, avtice it automatically
|
||||||
msg: App.i18n.translateContent('To be able to chat you need to select min. one chat topic in settings!')
|
if App.Chat.count() < 2
|
||||||
)
|
preferences.chat = {}
|
||||||
|
preferences.chat.active = {}
|
||||||
|
preferences.chat.active[App.Chat.first().id] = 'on'
|
||||||
|
|
||||||
|
# update user preferences
|
||||||
|
@ajax(
|
||||||
|
id: 'preferences'
|
||||||
|
type: 'PUT'
|
||||||
|
url: "#{@apiPath}/users/preferences"
|
||||||
|
data: JSON.stringify(user: {chat: preferences.chat})
|
||||||
|
processData: true
|
||||||
|
success: @success
|
||||||
|
error: @error
|
||||||
|
)
|
||||||
|
|
||||||
|
# if we have more chats, let decide the user
|
||||||
|
else
|
||||||
|
msg = 'To be able to chat you need to select min. one chat topic below!'
|
||||||
|
|
||||||
|
# open modal settings
|
||||||
|
@settings(settings: msg)
|
||||||
else
|
else
|
||||||
@stopPushState()
|
@stopPushState()
|
||||||
@pushState()
|
@pushState()
|
||||||
|
@ -191,9 +211,10 @@ class App.CustomerChat extends App.Controller
|
||||||
return if @windowCount() >= @maxChatWindows
|
return if @windowCount() >= @maxChatWindows
|
||||||
App.WebSocket.send(event:'chat_session_start')
|
App.WebSocket.send(event:'chat_session_start')
|
||||||
|
|
||||||
settings: ->
|
settings: (errors = {}) ->
|
||||||
new Setting(
|
new Setting(
|
||||||
maxChatWindows: @maxChatWindows
|
maxChatWindows: @maxChatWindows
|
||||||
|
errors: errors
|
||||||
)
|
)
|
||||||
|
|
||||||
class CustomerChatRouter extends App.ControllerPermanent
|
class CustomerChatRouter extends App.ControllerPermanent
|
||||||
|
@ -536,6 +557,7 @@ class Setting extends App.ControllerModal
|
||||||
App.view('customer_chat/setting')(
|
App.view('customer_chat/setting')(
|
||||||
chats: App.Chat.all()
|
chats: App.Chat.all()
|
||||||
preferences: preferences
|
preferences: preferences
|
||||||
|
errors: @errors
|
||||||
)
|
)
|
||||||
|
|
||||||
submit: (e) =>
|
submit: (e) =>
|
||||||
|
@ -544,7 +566,7 @@ class Setting extends App.ControllerModal
|
||||||
|
|
||||||
@formDisable(e)
|
@formDisable(e)
|
||||||
|
|
||||||
# get data
|
# update user preferences
|
||||||
@ajax(
|
@ajax(
|
||||||
id: 'preferences'
|
id: 'preferences'
|
||||||
type: 'PUT'
|
type: 'PUT'
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
<div class="select form-group">
|
||||||
|
<label for="a"><%- @T('Max. concurrent chats') %></label>
|
||||||
|
<div class="u-positionOrigin">
|
||||||
|
<select id="a" class="form-control" name="chat::max_windows">
|
||||||
|
<% for count in [1..20]: %>
|
||||||
|
<option value="<%- count %>" <% if parseInt(@preferences.chat.max_windows) is count: %>selected<% end %>><%- count %></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
<%- @Icon('arrow-down', 'dropdown-arrow') %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% if @errors.settings: %>
|
||||||
|
<div class="alert alert--danger"><%- @T(@errors.settings) %></div>
|
||||||
|
<% end %>
|
||||||
<table class="settings-list">
|
<table class="settings-list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -18,17 +32,4 @@
|
||||||
</label>
|
</label>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
</table>
|
||||||
<div class="select form-group">
|
|
||||||
<label for="a"><%- @T('Max. concurrent chats') %></label>
|
|
||||||
<div class="u-positionOrigin">
|
|
||||||
<select id="a" class="form-control" name="chat::max_windows">
|
|
||||||
<% for count in [1..20]: %>
|
|
||||||
<option value="<%- count %>" <% if parseInt(@preferences.chat.max_windows) is count: %>selected<% end %>><%- count %></option>
|
|
||||||
<% end %>
|
|
||||||
</select>
|
|
||||||
<%- @Icon('arrow-down', 'dropdown-arrow') %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
Loading…
Reference in a new issue