Implemented issue #1206 - Feedback Form Channel - Ability to set a target group for incoming tickets.

This commit is contained in:
Martin Edenhofer 2017-06-28 19:19:19 +02:00
parent 1d4ce42c67
commit c734a52240
5 changed files with 244 additions and 9 deletions

View file

@ -3,12 +3,14 @@ class App.ChannelForm extends App.ControllerSubContent
requiredPermission: 'admin.channel_formular' requiredPermission: 'admin.channel_formular'
header: 'Form' header: 'Form'
events: events:
'change form.js-params': 'updateParams' 'change form.js-paramsDesigner': 'updateParamsDesigner'
'keyup form.js-params': 'updateParams' 'keyup form.js-paramsDesigner': 'updateParamsDesigner'
'change .js-formSetting input': 'toggleFormSetting' 'change .js-formSetting input': 'toggleFormSetting'
'change .js-paramsSetting select': 'updateGroup'
elements: elements:
'.js-paramsBlock': 'paramsBlock' '.js-paramsBlock': 'paramsBlock'
'.js-paramsSetting': 'paramsSetting'
'.js-formSetting input': 'formSetting' '.js-formSetting input': 'formSetting'
constructor: -> constructor: ->
@ -20,22 +22,38 @@ class App.ChannelForm extends App.ControllerSubContent
render: => render: =>
setting = App.Setting.get('form_ticket_create') setting = App.Setting.get('form_ticket_create')
@html App.view('channel/form')(
element = $(App.view('channel/form')(
baseurl: window.location.origin baseurl: window.location.origin
formSetting: setting 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) -> @paramsBlock.each (i, block) ->
hljs.highlightBlock block hljs.highlightBlock block
@updateParams() @updateParamsDesigner()
updateParams: -> updateParamsDesigner: ->
quote = (string) -> quote = (string) ->
string = string.replace('\'', '\\\'') string = string.replace('\'', '\\\'')
.replace(/\</g, '&lt;') .replace(/\</g, '&lt;')
.replace(/\>/g, '&gt;') .replace(/\>/g, '&gt;')
params = @formParam(@$('.js-params')) params = @formParam(@$('.js-paramsDesigner'))
paramString = '' paramString = ''
for key, value of params for key, value of params
if value != '' if value != ''
@ -63,4 +81,8 @@ class App.ChannelForm extends App.ControllerSubContent
value = @formSetting.prop('checked') value = @formSetting.prop('checked')
App.Setting.set('form_ticket_create', value) 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') App.Config.set('Form', { prio: 2000, name: 'Form', parent: '#channels', target: '#channels/form', controller: App.ChannelForm, permission: ['admin.formular'] }, 'NavBarAdmin')

View file

@ -10,8 +10,20 @@
<div class="page-content"> <div class="page-content">
<p><%- @T('With form you can add a form to your web page which directly generates a ticket for you.') %></p> <p><%- @T('With form you can add a form to your web page which directly generates a ticket for you.') %></p>
<h2><%- @T('Settings') %></h2>
<form class="js-paramsSetting">
<fieldset>
<div class="input form-group formGroup--halfSize">
<div class="formGroup-label">
<label for="form-group"><%- @T('Group selection for Ticket creation') %></label>
</div>
<div class="controls js-groupSelector" id="from-group"></div>
</div>
</fieldset>
</form>
<h2><%- @T('Designer') %></h2> <h2><%- @T('Designer') %></h2>
<form class="js-params"> <form class="js-paramsDesigner">
<fieldset> <fieldset>
<div class="input form-group formGroup--halfSize"> <div class="input form-group formGroup--halfSize">

View file

@ -99,10 +99,13 @@ class FormController < ApplicationController
# set current user # set current user
UserInfo.current_user_id = customer.id UserInfo.current_user_id = customer.id
group = Group.find_by(id: Setting.get('form_ticket_create_group_id'))
if !group
group = Group.where(active: true).first group = Group.where(active: true).first
if !group if !group
group = Group.first group = Group.first
end end
end
ticket = Ticket.create!( ticket = Ticket.create!(
group_id: group.id, group_id: group.id,
customer_id: customer.id, customer_id: customer.id,

View file

@ -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

View file

@ -1489,6 +1489,101 @@ Setting.create_if_not_exists(
frontend: false, 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( Setting.create_if_not_exists(
title: 'Ticket Subject Size', title: 'Ticket Subject Size',
name: 'ticket_subject_size', name: 'ticket_subject_size',