Merge branch 'develop' of github.com:martini/zammad into develop
This commit is contained in:
commit
50cf1fa018
9 changed files with 87 additions and 90 deletions
|
@ -119,7 +119,6 @@ class App.CustomerChat extends App.Controller
|
||||||
type: 'error'
|
type: 'error'
|
||||||
msg: App.i18n.translateContent('To be able to chat you need to select min. one chat topic in settings!')
|
msg: App.i18n.translateContent('To be able to chat you need to select min. one chat topic in settings!')
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
@meta.active = state
|
@meta.active = state
|
||||||
|
|
||||||
|
@ -148,7 +147,6 @@ class App.CustomerChat extends App.Controller
|
||||||
if @meta.active_sessions
|
if @meta.active_sessions
|
||||||
for session in @meta.active_sessions
|
for session in @meta.active_sessions
|
||||||
@addChat(session)
|
@addChat(session)
|
||||||
console.log('updateMeta aC', session)
|
|
||||||
@meta.active_sessions = false
|
@meta.active_sessions = false
|
||||||
|
|
||||||
@updateNavMenu()
|
@updateNavMenu()
|
||||||
|
@ -281,7 +279,8 @@ class ChatWindow extends App.Controller
|
||||||
if preferences.chat && preferences.chat.phrase
|
if preferences.chat && preferences.chat.phrase
|
||||||
phrases = preferences.chat.phrase[@session.chat_id]
|
phrases = preferences.chat.phrase[@session.chat_id]
|
||||||
if phrases
|
if phrases
|
||||||
@sendMessage phrases
|
@input.html(phrases)
|
||||||
|
@sendMessage()
|
||||||
|
|
||||||
focus: =>
|
focus: =>
|
||||||
@input.focus()
|
@input.focus()
|
||||||
|
@ -352,12 +351,10 @@ class ChatWindow extends App.Controller
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@sendMessage()
|
@sendMessage()
|
||||||
|
|
||||||
sendMessage: (content) =>
|
sendMessage: =>
|
||||||
if !content
|
|
||||||
content = @input.html()
|
content = @input.html()
|
||||||
return if !content
|
return if !content
|
||||||
|
|
||||||
console.log('send', content, @session.session_id)
|
|
||||||
App.WebSocket.send(
|
App.WebSocket.send(
|
||||||
event:'chat_session_message'
|
event:'chat_session_message'
|
||||||
data:
|
data:
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Chat < ApplicationModel
|
||||||
chat_user = User.find(chat_session.user_id)
|
chat_user = User.find(chat_session.user_id)
|
||||||
url = nil
|
url = nil
|
||||||
if chat_user.image && chat_user.image != 'none'
|
if chat_user.image && chat_user.image != 'none'
|
||||||
url = "/api/v1/users/image/#{chat_user.image}"
|
url = "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/api/v1/users/image/#{chat_user.image}"
|
||||||
end
|
end
|
||||||
user = {
|
user = {
|
||||||
name: chat_user.fullname,
|
name: chat_user.fullname,
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Sessions::Event::ChatSessionStart < Sessions::Event::ChatBase
|
||||||
chat_user = User.find(chat_session.user_id)
|
chat_user = User.find(chat_session.user_id)
|
||||||
url = nil
|
url = nil
|
||||||
if chat_user.image && chat_user.image != 'none'
|
if chat_user.image && chat_user.image != 'none'
|
||||||
url = "/api/v1/users/image/#{chat_user.image}"
|
url = "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/api/v1/users/image/#{chat_user.image}"
|
||||||
end
|
end
|
||||||
user = {
|
user = {
|
||||||
name: chat_user.fullname,
|
name: chat_user.fullname,
|
||||||
|
|
|
@ -8,7 +8,7 @@ do($ = window.jQuery, window) ->
|
||||||
class ZammadChat
|
class ZammadChat
|
||||||
|
|
||||||
defaults:
|
defaults:
|
||||||
chat_id: undefined
|
chatId: undefined
|
||||||
show: true
|
show: true
|
||||||
target: $('body')
|
target: $('body')
|
||||||
host: ''
|
host: ''
|
||||||
|
@ -73,6 +73,7 @@ do($ = window.jQuery, window) ->
|
||||||
return window.zammadChatTemplates[name](options)
|
return window.zammadChatTemplates[name](options)
|
||||||
|
|
||||||
constructor: (options) ->
|
constructor: (options) ->
|
||||||
|
@options = $.extend {}, @defaults, options
|
||||||
|
|
||||||
# check prerequisites
|
# check prerequisites
|
||||||
if !window.WebSocket or !sessionStorage
|
if !window.WebSocket or !sessionStorage
|
||||||
|
@ -80,12 +81,11 @@ do($ = window.jQuery, window) ->
|
||||||
@log 'notice', 'Chat: Browser not supported!'
|
@log 'notice', 'Chat: Browser not supported!'
|
||||||
return
|
return
|
||||||
|
|
||||||
if !options.chat_id
|
if !@options.chatId
|
||||||
@state = 'unsupported'
|
@state = 'unsupported'
|
||||||
@log 'error', 'Chat: need chat id as option!'
|
@log 'error', 'Chat: need chatId as option!'
|
||||||
return
|
return
|
||||||
|
|
||||||
@options = $.extend {}, @defaults, options
|
|
||||||
@el = $(@view('chat')(
|
@el = $(@view('chat')(
|
||||||
title: @options.title
|
title: @options.title
|
||||||
))
|
))
|
||||||
|
@ -111,7 +111,7 @@ do($ = window.jQuery, window) ->
|
||||||
@sendMessage()
|
@sendMessage()
|
||||||
|
|
||||||
send: (event, data = {}) =>
|
send: (event, data = {}) =>
|
||||||
data.chat_id = @options.chat_id
|
data.chat_id = @options.chatId
|
||||||
@log 'debug', 'ws:send', event, data
|
@log 'debug', 'ws:send', event, data
|
||||||
pipe = JSON.stringify
|
pipe = JSON.stringify
|
||||||
event: event
|
event: event
|
||||||
|
@ -447,12 +447,12 @@ do($ = window.jQuery, window) ->
|
||||||
protocol = 'ws://'
|
protocol = 'ws://'
|
||||||
if window.location.protocol is 'https:'
|
if window.location.protocol is 'https:'
|
||||||
protocol = 'wss://'
|
protocol = 'wss://'
|
||||||
@options.host = "#{ protocol }#{ scriptHost }"
|
@options.host = "#{ protocol }#{ scriptHost }/ws"
|
||||||
|
|
||||||
wsConnect: =>
|
wsConnect: =>
|
||||||
@detectHost() if !@options.host
|
@detectHost() if !@options.host
|
||||||
|
|
||||||
@log 'notice', "Connecting to #{@options.host}"
|
@log 'debug', "Connecting to #{@options.host}"
|
||||||
@ws = new window.WebSocket("#{@options.host}")
|
@ws = new window.WebSocket("#{@options.host}")
|
||||||
@ws.onopen = @onWebSocketOpen
|
@ws.onopen = @onWebSocketOpen
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
scriptHost = myScript.src.match('.*://([^:/]*).*')[1];
|
scriptHost = myScript.src.match('.*://([^:/]*).*')[1];
|
||||||
ZammadChat = (function() {
|
ZammadChat = (function() {
|
||||||
ZammadChat.prototype.defaults = {
|
ZammadChat.prototype.defaults = {
|
||||||
chat_id: void 0,
|
chatId: void 0,
|
||||||
show: true,
|
show: true,
|
||||||
target: $('body'),
|
target: $('body'),
|
||||||
host: '',
|
host: '',
|
||||||
|
@ -134,17 +134,17 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
this.view = bind(this.view, this);
|
this.view = bind(this.view, this);
|
||||||
this.log = bind(this.log, this);
|
this.log = bind(this.log, this);
|
||||||
this.T = bind(this.T, this);
|
this.T = bind(this.T, this);
|
||||||
|
this.options = $.extend({}, this.defaults, options);
|
||||||
if (!window.WebSocket || !sessionStorage) {
|
if (!window.WebSocket || !sessionStorage) {
|
||||||
this.state = 'unsupported';
|
this.state = 'unsupported';
|
||||||
this.log('notice', 'Chat: Browser not supported!');
|
this.log('notice', 'Chat: Browser not supported!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!options.chat_id) {
|
if (!this.options.chatId) {
|
||||||
this.state = 'unsupported';
|
this.state = 'unsupported';
|
||||||
this.log('error', 'Chat: need chat id as option!');
|
this.log('error', 'Chat: need chatId as option!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.options = $.extend({}, this.defaults, options);
|
|
||||||
this.el = $(this.view('chat')({
|
this.el = $(this.view('chat')({
|
||||||
title: this.options.title
|
title: this.options.title
|
||||||
}));
|
}));
|
||||||
|
@ -173,7 +173,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
data = {};
|
data = {};
|
||||||
}
|
}
|
||||||
data.chat_id = this.options.chat_id;
|
data.chat_id = this.options.chatId;
|
||||||
this.log('debug', 'ws:send', event, data);
|
this.log('debug', 'ws:send', event, data);
|
||||||
pipe = JSON.stringify({
|
pipe = JSON.stringify({
|
||||||
event: event,
|
event: event,
|
||||||
|
@ -551,14 +551,14 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
if (window.location.protocol === 'https:') {
|
if (window.location.protocol === 'https:') {
|
||||||
protocol = 'wss://';
|
protocol = 'wss://';
|
||||||
}
|
}
|
||||||
return this.options.host = "" + protocol + scriptHost;
|
return this.options.host = "" + protocol + scriptHost + "/ws";
|
||||||
};
|
};
|
||||||
|
|
||||||
ZammadChat.prototype.wsConnect = function() {
|
ZammadChat.prototype.wsConnect = function() {
|
||||||
if (!this.options.host) {
|
if (!this.options.host) {
|
||||||
this.detectHost();
|
this.detectHost();
|
||||||
}
|
}
|
||||||
this.log('notice', "Connecting to " + this.options.host);
|
this.log('debug', "Connecting to " + this.options.host);
|
||||||
this.ws = new window.WebSocket("" + this.options.host);
|
this.ws = new window.WebSocket("" + this.options.host);
|
||||||
this.ws.onopen = this.onWebSocketOpen;
|
this.ws.onopen = this.onWebSocketOpen;
|
||||||
this.ws.onmessage = this.onWebSocketMessage;
|
this.ws.onmessage = this.onWebSocketMessage;
|
||||||
|
@ -683,67 +683,6 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
|
||||||
return window.ZammadChat = ZammadChat;
|
return window.ZammadChat = ZammadChat;
|
||||||
})(window.jQuery, window);
|
})(window.jQuery, window);
|
||||||
|
|
||||||
if (!window.zammadChatTemplates) {
|
|
||||||
window.zammadChatTemplates = {};
|
|
||||||
}
|
|
||||||
window.zammadChatTemplates["agent"] = function (__obj) {
|
|
||||||
if (!__obj) __obj = {};
|
|
||||||
var __out = [], __capture = function(callback) {
|
|
||||||
var out = __out, result;
|
|
||||||
__out = [];
|
|
||||||
callback.call(this);
|
|
||||||
result = __out.join('');
|
|
||||||
__out = out;
|
|
||||||
return __safe(result);
|
|
||||||
}, __sanitize = function(value) {
|
|
||||||
if (value && value.ecoSafe) {
|
|
||||||
return value;
|
|
||||||
} else if (typeof value !== 'undefined' && value != null) {
|
|
||||||
return __escape(value);
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
|
|
||||||
__safe = __obj.safe = function(value) {
|
|
||||||
if (value && value.ecoSafe) {
|
|
||||||
return value;
|
|
||||||
} else {
|
|
||||||
if (!(typeof value !== 'undefined' && value != null)) value = '';
|
|
||||||
var result = new String(value);
|
|
||||||
result.ecoSafe = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (!__escape) {
|
|
||||||
__escape = __obj.escape = function(value) {
|
|
||||||
return ('' + value)
|
|
||||||
.replace(/&/g, '&')
|
|
||||||
.replace(/</g, '<')
|
|
||||||
.replace(/>/g, '>')
|
|
||||||
.replace(/"/g, '"');
|
|
||||||
};
|
|
||||||
}
|
|
||||||
(function() {
|
|
||||||
(function() {
|
|
||||||
if (this.agent.avatar) {
|
|
||||||
__out.push('\n<img class="zammad-chat-agent-avatar" src="');
|
|
||||||
__out.push(__sanitize(this.agent.avatar));
|
|
||||||
__out.push('">\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
__out.push('\n<span class="zammad-chat-agent-sentence">\n <span class="zammad-chat-agent-name">');
|
|
||||||
|
|
||||||
__out.push(__sanitize(this.agent.name));
|
|
||||||
|
|
||||||
__out.push('</span>\n</span>');
|
|
||||||
|
|
||||||
}).call(this);
|
|
||||||
|
|
||||||
}).call(__obj);
|
|
||||||
__obj.safe = __objSafe, __obj.escape = __escape;
|
|
||||||
return __out.join('');
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||||
|
@ -821,6 +760,67 @@ jQuery.fn.autoGrow = function(options) {
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
if (!window.zammadChatTemplates) {
|
||||||
|
window.zammadChatTemplates = {};
|
||||||
|
}
|
||||||
|
window.zammadChatTemplates["agent"] = function (__obj) {
|
||||||
|
if (!__obj) __obj = {};
|
||||||
|
var __out = [], __capture = function(callback) {
|
||||||
|
var out = __out, result;
|
||||||
|
__out = [];
|
||||||
|
callback.call(this);
|
||||||
|
result = __out.join('');
|
||||||
|
__out = out;
|
||||||
|
return __safe(result);
|
||||||
|
}, __sanitize = function(value) {
|
||||||
|
if (value && value.ecoSafe) {
|
||||||
|
return value;
|
||||||
|
} else if (typeof value !== 'undefined' && value != null) {
|
||||||
|
return __escape(value);
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
|
||||||
|
__safe = __obj.safe = function(value) {
|
||||||
|
if (value && value.ecoSafe) {
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
if (!(typeof value !== 'undefined' && value != null)) value = '';
|
||||||
|
var result = new String(value);
|
||||||
|
result.ecoSafe = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (!__escape) {
|
||||||
|
__escape = __obj.escape = function(value) {
|
||||||
|
return ('' + value)
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"');
|
||||||
|
};
|
||||||
|
}
|
||||||
|
(function() {
|
||||||
|
(function() {
|
||||||
|
if (this.agent.avatar) {
|
||||||
|
__out.push('\n<img class="zammad-chat-agent-avatar" src="');
|
||||||
|
__out.push(__sanitize(this.agent.avatar));
|
||||||
|
__out.push('">\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
__out.push('\n<span class="zammad-chat-agent-sentence">\n <span class="zammad-chat-agent-name">');
|
||||||
|
|
||||||
|
__out.push(__sanitize(this.agent.name));
|
||||||
|
|
||||||
|
__out.push('</span>\n</span>');
|
||||||
|
|
||||||
|
}).call(this);
|
||||||
|
|
||||||
|
}).call(__obj);
|
||||||
|
__obj.safe = __objSafe, __obj.escape = __escape;
|
||||||
|
return __out.join('');
|
||||||
|
};
|
||||||
|
|
||||||
if (!window.zammadChatTemplates) {
|
if (!window.zammadChatTemplates) {
|
||||||
window.zammadChatTemplates = {};
|
window.zammadChatTemplates = {};
|
||||||
}
|
}
|
||||||
|
|
2
public/assets/chat/chat.min.js
vendored
2
public/assets/chat/chat.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -138,7 +138,7 @@
|
||||||
-->
|
-->
|
||||||
<script>
|
<script>
|
||||||
var chat = new ZammadChat({
|
var chat = new ZammadChat({
|
||||||
chat_id: 1,
|
chatId: 1,
|
||||||
host: 'ws://localhost:6042',
|
host: 'ws://localhost:6042',
|
||||||
debug: true
|
debug: true
|
||||||
});
|
});
|
||||||
|
|
|
@ -105,7 +105,7 @@
|
||||||
<script src="chat.js"></script>
|
<script src="chat.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var chat = new ZammadChat({
|
var chat = new ZammadChat({
|
||||||
chat_id: 1,
|
chatId: 1,
|
||||||
host: 'ws://localhost:6042',
|
host: 'ws://localhost:6042',
|
||||||
debug: true,
|
debug: true,
|
||||||
background: '#494d52',
|
background: '#494d52',
|
||||||
|
|
|
@ -200,7 +200,7 @@ class ChatTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
# check customer state
|
# check customer state
|
||||||
assert_equal('no_seats_available', chat.customer_state[:state])
|
assert_equal('no_seats_available', chat.customer_state[:state])
|
||||||
assert_equal(0, chat.customer_state[:queue])
|
assert_equal(5, chat.customer_state[:queue])
|
||||||
|
|
||||||
# check agent1 state
|
# check agent1 state
|
||||||
agent_state = Chat.agent_state(agent1.id)
|
agent_state = Chat.agent_state(agent1.id)
|
||||||
|
@ -225,7 +225,7 @@ class ChatTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
# check customer state
|
# check customer state
|
||||||
assert_equal('no_seats_available', chat.customer_state[:state])
|
assert_equal('no_seats_available', chat.customer_state[:state])
|
||||||
assert_equal(-2, chat.customer_state[:queue])
|
assert_equal(5, chat.customer_state[:queue])
|
||||||
|
|
||||||
# check agent1 state
|
# check agent1 state
|
||||||
agent_state = Chat.agent_state(agent1.id)
|
agent_state = Chat.agent_state(agent1.id)
|
||||||
|
@ -250,7 +250,7 @@ class ChatTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
# check customer state
|
# check customer state
|
||||||
assert_equal('no_seats_available', chat.customer_state[:state])
|
assert_equal('no_seats_available', chat.customer_state[:state])
|
||||||
assert_equal(-1, chat.customer_state[:queue])
|
assert_equal(5, chat.customer_state[:queue])
|
||||||
|
|
||||||
# check agent1 state
|
# check agent1 state
|
||||||
agent_state = Chat.agent_state(agent1.id)
|
agent_state = Chat.agent_state(agent1.id)
|
||||||
|
|
Loading…
Reference in a new issue