Browse Source

Chat updated.

Martin Edenhofer 9 years ago
parent
commit
66d56ff9e2
3 changed files with 33 additions and 15 deletions
  1. 5 5
      public/assets/chat/chat.css
  2. 28 10
      public/assets/chat/chat.js
  3. 0 0
      public/assets/chat/chat.min.js

+ 5 - 5
public/assets/chat/chat.css

@@ -25,7 +25,7 @@
       height: 100vh;
       height: 100vh;
       border-radius: 0 !important; } }
       border-radius: 0 !important; } }
 
 
-.zammad-chat.zammad-chat-is-open {
+.zammad-chat.zammad-chat-is-visible {
   display: -webkit-flex;
   display: -webkit-flex;
   display: -ms-flexbox;
   display: -ms-flexbox;
   display: flex; }
   display: flex; }
@@ -54,7 +54,7 @@
 .zammad-chat.is-fullscreen .zammad-chat-header {
 .zammad-chat.is-fullscreen .zammad-chat-header {
   border-radius: 0 !important; }
   border-radius: 0 !important; }
 
 
-.zammad-chat.zammad-chat-is-open .zammad-chat-header {
+.zammad-chat.zammad-chat-is-visible .zammad-chat-header {
   cursor: default; }
   cursor: default; }
 
 
 .zammad-chat-welcome-text {
 .zammad-chat-welcome-text {
@@ -80,10 +80,10 @@
   width: 1.3em; }
   width: 1.3em; }
 
 
 .zammad-chat-header-icon-close,
 .zammad-chat-header-icon-close,
-.zammad-chat.zammad-chat-is-open .zammad-chat-header-icon-open {
+.zammad-chat.zammad-chat-is-visible .zammad-chat-header-icon-open {
   display: none; }
   display: none; }
 
 
-.zammad-chat.zammad-chat-is-open .zammad-chat-header-icon-close {
+.zammad-chat.zammad-chat-is-visible .zammad-chat-header-icon-close {
   display: inline; }
   display: inline; }
 
 
 .zammad-chat-agent {
 .zammad-chat-agent {
@@ -105,7 +105,7 @@
   margin: 0 1em;
   margin: 0 1em;
   display: inline-block;
   display: inline-block;
   line-height: 2em;
   line-height: 2em;
-  padding: 0 0.7em;
+  padding: 0 .7em;
   border-radius: 1em;
   border-radius: 1em;
   background: rgba(0, 0, 0, 0.1);
   background: rgba(0, 0, 0, 0.1);
   box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04) inset; }
   box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04) inset; }

+ 28 - 10
public/assets/chat/chat.js

@@ -5,13 +5,13 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
   var ZammadChat, myScript, scriptHost, scripts;
   var ZammadChat, myScript, scriptHost, scripts;
   scripts = document.getElementsByTagName('script');
   scripts = document.getElementsByTagName('script');
   myScript = scripts[scripts.length - 1];
   myScript = scripts[scripts.length - 1];
-  scriptHost = myScript.src.match(".*://([^:/]*).*")[1];
+  scriptHost = myScript.src.match('.*://([^:/]*).*')[1];
   ZammadChat = (function() {
   ZammadChat = (function() {
     ZammadChat.prototype.defaults = {
     ZammadChat.prototype.defaults = {
+      chat_id: void 0,
       show: true,
       show: true,
       target: $('body'),
       target: $('body'),
       host: '',
       host: '',
-      port: 6042,
       debug: false,
       debug: false,
       flat: false,
       flat: false,
       fontSize: void 0,
       fontSize: void 0,
@@ -119,7 +119,6 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
       this.onCloseAnimationEnd = bind(this.onCloseAnimationEnd, this);
       this.onCloseAnimationEnd = bind(this.onCloseAnimationEnd, this);
       this.closeWindow = bind(this.closeWindow, this);
       this.closeWindow = bind(this.closeWindow, this);
       this.close = bind(this.close, this);
       this.close = bind(this.close, this);
-      this.onOpenAnimationEnd = bind(this.onOpenAnimationEnd, this);
       this.open = bind(this.open, this);
       this.open = bind(this.open, this);
       this.renderMessage = bind(this.renderMessage, this);
       this.renderMessage = bind(this.renderMessage, this);
       this.receiveMessage = bind(this.receiveMessage, this);
       this.receiveMessage = bind(this.receiveMessage, this);
@@ -140,6 +139,11 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
         this.log('notice', 'Chat: Browser not supported!');
         this.log('notice', 'Chat: Browser not supported!');
         return;
         return;
       }
       }
+      if (!options.chat_id) {
+        this.state = 'unsupported';
+        this.log('error', 'Chat: need chat id as option!');
+        return;
+      }
       this.options = $.extend({}, this.defaults, options);
       this.options = $.extend({}, this.defaults, options);
       this.el = $(this.view('chat')({
       this.el = $(this.view('chat')({
         title: this.options.title
         title: this.options.title
@@ -166,6 +170,10 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
 
 
     ZammadChat.prototype.send = function(event, data) {
     ZammadChat.prototype.send = function(event, data) {
       var pipe;
       var pipe;
+      if (data == null) {
+        data = {};
+      }
+      data.chat_id = this.options.chat_id;
       this.log('debug', 'ws:send', event, data);
       this.log('debug', 'ws:send', event, data);
       pipe = JSON.stringify({
       pipe = JSON.stringify({
         event: event,
         event: event,
@@ -181,6 +189,9 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
         pipe = pipes[i];
         pipe = pipes[i];
         this.log('debug', 'ws:onmessage', pipe);
         this.log('debug', 'ws:onmessage', pipe);
         switch (pipe.event) {
         switch (pipe.event) {
+          case 'chat_error':
+            this.log('error', pipe.data);
+            break;
           case 'chat_session_message':
           case 'chat_session_message':
             if (pipe.data.self_written) {
             if (pipe.data.self_written) {
               return;
               return;
@@ -225,7 +236,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
                 this.wsClose();
                 this.wsClose();
                 break;
                 break;
               case 'no_seats_available':
               case 'no_seats_available':
-                this.onError('Zammad Chat: Too many clients in queue. Clients in queue: ', pipe.data.queue);
+                this.onError("Zammad Chat: Too many clients in queue. Clients in queue: " + pipe.data.queue);
                 this.state = 'off';
                 this.state = 'off';
                 this.hide();
                 this.hide();
                 this.wsClose();
                 this.wsClose();
@@ -351,7 +362,7 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
       var ref, unread;
       var ref, unread;
       this.lastAddedType = "message--" + data.from;
       this.lastAddedType = "message--" + data.from;
       unread = (ref = document.hidden) != null ? ref : {
       unread = (ref = document.hidden) != null ? ref : {
-        " zammad-chat-message--unread": ""
+        ' zammad-chat-message--unread': ''
       };
       };
       this.el.find('.zammad-chat-body').append(this.view('message')(data));
       this.el.find('.zammad-chat-body').append(this.view('message')(data));
       return this.scrollToBottom();
       return this.scrollToBottom();
@@ -535,15 +546,20 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
     };
     };
 
 
     ZammadChat.prototype.detectHost = function() {
     ZammadChat.prototype.detectHost = function() {
-      return this.options.host = "ws://" + scriptHost;
+      var protocol;
+      protocol = 'ws://';
+      if (window.location.protocol === 'https:') {
+        protocol = 'wss://';
+      }
+      return this.options.host = "" + protocol + scriptHost;
     };
     };
 
 
     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.options.port);
-      this.ws = new window.WebSocket(this.options.host + ":" + this.options.port);
+      this.log('notice', "Connecting to " + 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;
       this.ws.onclose = (function(_this) {
       this.ws.onclose = (function(_this) {
@@ -599,7 +615,8 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
 
 
     ZammadChat.prototype.onSessionClosed = function(data) {
     ZammadChat.prototype.onSessionClosed = function(data) {
       this.addStatus(this.T('Chat closed by %s', data.realname));
       this.addStatus(this.T('Chat closed by %s', data.realname));
-      return this.disableInput();
+      this.disableInput();
+      return this.setAgentOnlineState('offline');
     };
     };
 
 
     ZammadChat.prototype.disconnect = function() {
     ZammadChat.prototype.disconnect = function() {
@@ -637,7 +654,8 @@ var bind = function(fn, me){ return function(){ return fn.apply(me, arguments);
       this.el.find('.zammad-chat-welcome').addClass('zammad-chat-is-hidden');
       this.el.find('.zammad-chat-welcome').addClass('zammad-chat-is-hidden');
       this.el.find('.zammad-chat-agent').removeClass('zammad-chat-is-hidden');
       this.el.find('.zammad-chat-agent').removeClass('zammad-chat-is-hidden');
       this.el.find('.zammad-chat-agent-status').removeClass('zammad-chat-is-hidden');
       this.el.find('.zammad-chat-agent-status').removeClass('zammad-chat-is-hidden');
-      return this.input.focus();
+      this.input.focus();
+      return this.setAgentOnlineState('online');
     };
     };
 
 
     ZammadChat.prototype.showTimeout = function() {
     ZammadChat.prototype.showTimeout = function() {

File diff suppressed because it is too large
+ 0 - 0
public/assets/chat/chat.min.js


Some files were not shown because too many files changed in this diff