From c734a5224073c530f8c8c181ce9985e6dbdbf3a0 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 28 Jun 2017 19:19:19 +0200 Subject: [PATCH] Implemented issue #1206 - Feedback Form Channel - Ability to set a target group for incoming tickets. --- .../app/controllers/_channel/form.coffee | 34 +++++- .../app/views/channel/form.jst.eco | 14 ++- app/controllers/form_controller.rb | 7 +- .../20170628000001_form_group_selection.rb | 103 ++++++++++++++++++ db/seeds/settings.rb | 95 ++++++++++++++++ 5 files changed, 244 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20170628000001_form_group_selection.rb diff --git a/app/assets/javascripts/app/controllers/_channel/form.coffee b/app/assets/javascripts/app/controllers/_channel/form.coffee index d9697b132..6955b3b60 100644 --- a/app/assets/javascripts/app/controllers/_channel/form.coffee +++ b/app/assets/javascripts/app/controllers/_channel/form.coffee @@ -3,12 +3,14 @@ class App.ChannelForm extends App.ControllerSubContent requiredPermission: 'admin.channel_formular' header: 'Form' events: - 'change form.js-params': 'updateParams' - 'keyup form.js-params': 'updateParams' + 'change form.js-paramsDesigner': 'updateParamsDesigner' + 'keyup form.js-paramsDesigner': 'updateParamsDesigner' 'change .js-formSetting input': 'toggleFormSetting' + 'change .js-paramsSetting select': 'updateGroup' elements: '.js-paramsBlock': 'paramsBlock' + '.js-paramsSetting': 'paramsSetting' '.js-formSetting input': 'formSetting' constructor: -> @@ -20,22 +22,38 @@ class App.ChannelForm extends App.ControllerSubContent render: => setting = App.Setting.get('form_ticket_create') - @html App.view('channel/form')( + + element = $(App.view('channel/form')( baseurl: window.location.origin formSetting: setting + )) + + group_id = App.Setting.get('form_ticket_create_group_id') + selection = App.UiElement.select.render( + name: 'group_id' + multiple: false + null: false + relation: 'Group' + nulloption: false + value: group_id + #class: 'form-control--small' ) + console.log('s', element.find('.js-groupSelector'), selection) + element.find('.js-groupSelector').html(selection) + + @html element @paramsBlock.each (i, block) -> hljs.highlightBlock block - @updateParams() + @updateParamsDesigner() - updateParams: -> + updateParamsDesigner: -> quote = (string) -> string = string.replace('\'', '\\\'') .replace(/\/g, '>') - params = @formParam(@$('.js-params')) + params = @formParam(@$('.js-paramsDesigner')) paramString = '' for key, value of params if value != '' @@ -63,4 +81,8 @@ class App.ChannelForm extends App.ControllerSubContent value = @formSetting.prop('checked') App.Setting.set('form_ticket_create', value) + updateGroup: => + value = @paramsSetting.find('[name=group_id]').val() + App.Setting.set('form_ticket_create_group_id', value) + App.Config.set('Form', { prio: 2000, name: 'Form', parent: '#channels', target: '#channels/form', controller: App.ChannelForm, permission: ['admin.formular'] }, 'NavBarAdmin') diff --git a/app/assets/javascripts/app/views/channel/form.jst.eco b/app/assets/javascripts/app/views/channel/form.jst.eco index 6f6e891f7..f0e412a8f 100644 --- a/app/assets/javascripts/app/views/channel/form.jst.eco +++ b/app/assets/javascripts/app/views/channel/form.jst.eco @@ -10,8 +10,20 @@

<%- @T('With form you can add a form to your web page which directly generates a ticket for you.') %>

+

<%- @T('Settings') %>

+
+
+
+
+ +
+
+
+
+
+

<%- @T('Designer') %>

-
+
diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 91e63c155..cb3b68a9d 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -99,9 +99,12 @@ class FormController < ApplicationController # set current user UserInfo.current_user_id = customer.id - group = Group.where(active: true).first + group = Group.find_by(id: Setting.get('form_ticket_create_group_id')) if !group - group = Group.first + group = Group.where(active: true).first + if !group + group = Group.first + end end ticket = Ticket.create!( group_id: group.id, diff --git a/db/migrate/20170628000001_form_group_selection.rb b/db/migrate/20170628000001_form_group_selection.rb new file mode 100644 index 000000000..a7a1b6c60 --- /dev/null +++ b/db/migrate/20170628000001_form_group_selection.rb @@ -0,0 +1,103 @@ +class FormGroupSelection < ActiveRecord::Migration + def up + + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + + group = Group.where(active: true).first + if !group + group = Group.first + end + group_id = 1 + if group + group_id = group.id + end + Setting.create_if_not_exists( + title: 'Group selection for Ticket creation', + name: 'form_ticket_create_group_id', + area: 'Form::Base', + description: 'Defines if group of created tickets via web form.', + options: { + form: [ + { + display: '', + null: true, + name: 'form_ticket_create_group_id', + tag: 'select', + relation: 'Group', + }, + ], + }, + state: group_id, + preferences: { + permission: ['admin.channel_formular'], + }, + frontend: false, + ) + + Setting.create_if_not_exists( + title: 'Limit tickets by ip per hour', + name: 'form_ticket_create_by_ip_per_hour', + area: 'Form::Base', + description: 'Defines limit of tickets by ip per hour via web form.', + options: { + form: [ + { + display: '', + null: true, + name: 'form_ticket_create_by_ip_per_hour', + tag: 'input', + }, + ], + }, + state: 20, + preferences: { + permission: ['admin.channel_formular'], + }, + frontend: false, + ) + Setting.create_if_not_exists( + title: 'Limit tickets by ip per day', + name: 'form_ticket_create_by_ip_per_day', + area: 'Form::Base', + description: 'Defines limit of tickets by ip per day via web form.', + options: { + form: [ + { + display: '', + null: true, + name: 'form_ticket_create_by_ip_per_day', + tag: 'input', + }, + ], + }, + state: 240, + preferences: { + permission: ['admin.channel_formular'], + }, + frontend: false, + ) + Setting.create_if_not_exists( + title: 'Limit tickets per day', + name: 'form_ticket_create_per_day', + area: 'Form::Base', + description: 'Defines limit of tickets per day via web form.', + options: { + form: [ + { + display: '', + null: true, + name: 'form_ticket_create_per_day', + tag: 'input', + }, + ], + }, + state: 5000, + preferences: { + permission: ['admin.channel_formular'], + }, + frontend: false, + ) + + end +end diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 777dc1aa1..9734aa262 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -1489,6 +1489,101 @@ Setting.create_if_not_exists( frontend: false, ) +group = Group.where(active: true).first +if !group + group = Group.first +end +group_id = 1 +if group + group_id = group.id +end +Setting.create_if_not_exists( + title: 'Group selection for Ticket creation', + name: 'form_ticket_create_group_id', + area: 'Form::Base', + description: 'Defines if group of created tickets via web form.', + options: { + form: [ + { + display: '', + null: true, + name: 'form_ticket_create_group_id', + tag: 'select', + relation: 'Group', + }, + ], + }, + state: group_id, + preferences: { + permission: ['admin.channel_formular'], + }, + frontend: false, +) + +Setting.create_if_not_exists( + title: 'Limit tickets by ip per hour', + name: 'form_ticket_create_by_ip_per_hour', + area: 'Form::Base', + description: 'Defines limit of tickets by ip per hour via web form.', + options: { + form: [ + { + display: '', + null: true, + name: 'form_ticket_create_by_ip_per_hour', + tag: 'input', + }, + ], + }, + state: 20, + preferences: { + permission: ['admin.channel_formular'], + }, + frontend: false, +) +Setting.create_if_not_exists( + title: 'Limit tickets by ip per day', + name: 'form_ticket_create_by_ip_per_day', + area: 'Form::Base', + description: 'Defines limit of tickets by ip per day via web form.', + options: { + form: [ + { + display: '', + null: true, + name: 'form_ticket_create_by_ip_per_day', + tag: 'input', + }, + ], + }, + state: 240, + preferences: { + permission: ['admin.channel_formular'], + }, + frontend: false, +) +Setting.create_if_not_exists( + title: 'Limit tickets per day', + name: 'form_ticket_create_per_day', + area: 'Form::Base', + description: 'Defines limit of tickets per day via web form.', + options: { + form: [ + { + display: '', + null: true, + name: 'form_ticket_create_per_day', + tag: 'input', + }, + ], + }, + state: 5000, + preferences: { + permission: ['admin.channel_formular'], + }, + frontend: false, +) + Setting.create_if_not_exists( title: 'Ticket Subject Size', name: 'ticket_subject_size',