diff --git a/app/assets/javascripts/app/controllers/_channel/chat.coffee b/app/assets/javascripts/app/controllers/_channel/chat.coffee index f4daca886..e09f0afb0 100644 --- a/app/assets/javascripts/app/controllers/_channel/chat.coffee +++ b/app/assets/javascripts/app/controllers/_channel/chat.coffee @@ -6,6 +6,11 @@ class App.ChannelChat extends App.ControllerTabs @title 'Chat', true @tabs = [ + { + name: 'Chat Channels', + target: 'channels', + controller: App.ChannelChatOverview + }, { name: 'Settings', target: 'setting', @@ -15,28 +20,125 @@ class App.ChannelChat extends App.ControllerTabs @render() -# enable/disable +class App.ChannelChatOverview extends App.Controller + events: + 'click .js-new': 'new' + 'click .js-edit': 'edit' + 'click .js-delete': 'delete' + 'click .js-widget': 'widget' -# show also if nobody is online / leave a message + constructor: -> + super + @interval(@load, 30000) + #@load() -# channels - # sales - en / authentication needed - # sales - de / authentication needed + load: => + @startLoading() + @ajax( + id: 'chat_index' + type: 'GET' + url: @apiPath + '/chats' + processData: true + success: (data, status, xhr) => + App.Collection.loadAssets(data.assets) + @stopLoading() + @render(data) + ) + render: (data = {}) => + chats = [] + for chat_id in data.chat_ids + chats.push App.Chat.find(chat_id) -# agent - # channes I'm work for + @html App.view('channel/chat_overview')( + chats: chats + ) - # x sales - de / greeting - # o sales - en / greeting + new: (e) => + new App.ControllerGenericNew( + pageData: + title: 'Chats' + object: 'Chat' + objects: 'Chats' + genericObject: 'Chat' + callback: @load + container: @el.closest('.content') + large: true + ) -# concurent chats + edit: (e) => + e.preventDefault() + id = $(e.target).closest('.action').data('id') + new App.ControllerGenericEdit( + id: id + genericObject: 'Chat' + pageData: + object: 'Chat' + container: @el.closest('.content') + callback: @load + ) -# active chats - # name, email, location/ip, age + delete: (e) => + e.preventDefault() + id = $(e.target).closest('.action').data('id') + item = App.Chat.find(id) + new App.ControllerGenericDestroyConfirm( + item: item + container: @el.closest('.content') + callback: @load + ) + widget: (e) => + e.preventDefault() + id = $(e.target).closest('.action').data('id') + new Widget( + permanent: + id: id + ) -# chat history +class Widget extends App.ControllerModal + events: + 'change .js-params': 'updateParams' + 'keyup .js-params': 'updateParams' + + constructor: -> + super + @head = 'Widget' + @close = true + @render() + @show() + + render: -> + @content = $( App.view('channel/chat_js_widget')( + baseurl: window.location.origin + )) + + onShown: => + @updateParams() + + updateParams: => + console.log('id', @id) + + quote = (value) -> + if value.replace + value = value.replace('\'', '\\\'') + .replace(/\/g, '>') + value + params = @formParam(@$('.js-params')) + if @permanent + for key, value of @permanent + params[key] = value + paramString = '' + for key, value of params + if value != '' + if paramString != '' + paramString += ",\n" + if value == 'true' || value == 'false' || _.isNumber(value) + paramString += " #{key}: #{value}" + else + paramString += " #{key}: '#{quote(value)}'" + @$('.js-modal-params').html(paramString) App.Config.set( 'Chat', { prio: 4000, name: 'Chat', parent: '#channels', target: '#channels/chat', controller: App.ChannelChat, role: ['Admin'] }, 'NavBarAdmin' ) diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index 7bd2133c1..80815b094 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -81,7 +81,10 @@ class App.CustomerChat extends App.Controller # play on changes if @lastWaitingChatCount isnt counter - @sounds.chat_new.play() + + # do not play sound on initial load + if counter > 0 && @lastWaitingChatCount isnt undefined + @sounds.chat_new.play() @lastWaitingChatCount = counter # collect chat window messages diff --git a/app/assets/javascripts/app/models/chat.coffee b/app/assets/javascripts/app/models/chat.coffee new file mode 100644 index 000000000..b80361ce0 --- /dev/null +++ b/app/assets/javascripts/app/models/chat.coffee @@ -0,0 +1,16 @@ +class App.Chat extends App.Model + @configure 'Chat', 'name', 'active', 'public', 'max_queue', 'note' + @extend Spine.Model.Ajax + @url: @apiPath + '/chats' + + @configure_attributes = [ + { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false }, + { name: 'note', display: 'Note', tag: 'textarea', limit: 250, null: true }, + { name: 'public', display: 'Public', tag: 'boolean', default: true }, + { name: 'max_queue', display: 'Max. Queue', tag: 'input', default: 5 }, + { name: 'active', display: 'Active', tag: 'active', default: true }, + { name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 }, + { name: 'created_at', display: 'Created', tag: 'datetime', readonly: 1 }, + { name: 'updated_by_id', display: 'Updated by', relation: 'User', readonly: 1 }, + { name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 }, + ] diff --git a/app/assets/javascripts/app/views/channel/chat_js_widget.jst.eco b/app/assets/javascripts/app/views/channel/chat_js_widget.jst.eco new file mode 100644 index 000000000..915a90c46 --- /dev/null +++ b/app/assets/javascripts/app/views/channel/chat_js_widget.jst.eco @@ -0,0 +1,66 @@ +
<%- @T('Option') %> | +
---|
+ + |
+ + |
<%- @T('You need to add the following Java Script code snipped to your web page') %>: + +
+<script id="zammad_form_script" src="<%= @baseurl %>/assets/chat/chat.min.js"></script> + +<script> +$(function() { + new ZammadChat({({ + + }); +}); +</script>diff --git a/app/assets/javascripts/app/views/channel/chat_overview.jst.eco b/app/assets/javascripts/app/views/channel/chat_overview.jst.eco new file mode 100644 index 000000000..0d30c8ce5 --- /dev/null +++ b/app/assets/javascripts/app/views/channel/chat_overview.jst.eco @@ -0,0 +1,44 @@ + +
<%- @T('You have no configured chat\'s right now.') %>
+<% else: %> + <% for chat in @chats: %> +