From d94399ec7fca2246427b2f511e3157ba1c9ec1d1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 17 Nov 2015 16:39:46 +0100 Subject: [PATCH] Added chat tabs based on database. Added chat.preferences store. --- .../app/controllers/_channel/chat.coffee | 34 +++++++++++-------- app/models/chat.rb | 1 + db/migrate/20151117000001_update3_chat.rb | 5 +++ 3 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20151117000001_update3_chat.rb diff --git a/app/assets/javascripts/app/controllers/_channel/chat.coffee b/app/assets/javascripts/app/controllers/_channel/chat.coffee index 5f0a9c59a..13dc61e3d 100644 --- a/app/assets/javascripts/app/controllers/_channel/chat.coffee +++ b/app/assets/javascripts/app/controllers/_channel/chat.coffee @@ -7,21 +7,27 @@ class App.ChannelChat extends App.ControllerTabs @title @header, true - @tabs = [ - { - name: 'company.com/sales', - target: 'company-com-sales', - controller: App.ChannelChatDesigner, - }, - { - name: 'company.com', - target: 'company-com', - controller: App.ChannelChatDesigner, - } - ] - - @render() + @load() + load: => + @tabs = [] + @ajax( + id: 'chat_index' + type: 'GET' + url: @apiPath + '/chats' + processData: true + success: (data, status, xhr) => + App.Collection.loadAssets(data.assets) + for chat in App.Chat.all() + tab = + name: chat.name + target: "chat-#{chat.id}" + controller: App.ChannelChatDesigner + params: + model: chat + @tabs.push tab + @render() + ) class App.ChannelChatDesigner extends App.Controller events: diff --git a/app/models/chat.rb b/app/models/chat.rb index b9d6d7d99..356da3aa0 100644 --- a/app/models/chat.rb +++ b/app/models/chat.rb @@ -2,6 +2,7 @@ class Chat < ApplicationModel validates :name, presence: true + store :preferences def customer_state(session_id = nil) return { state: 'chat_disabled' } if !Setting.get('chat') diff --git a/db/migrate/20151117000001_update3_chat.rb b/db/migrate/20151117000001_update3_chat.rb new file mode 100644 index 000000000..44aa95fe9 --- /dev/null +++ b/db/migrate/20151117000001_update3_chat.rb @@ -0,0 +1,5 @@ +class Update3Chat < ActiveRecord::Migration + def up + add_column :chats, :preferences, :string, limit: 5000, null: true + end +end