Added reload support for autocompletion.
This commit is contained in:
parent
a056363a42
commit
bff4013c0c
8 changed files with 67 additions and 40 deletions
|
@ -180,8 +180,9 @@ class App.Controller extends Spine.Controller
|
|||
|
||||
# start customer info controller
|
||||
new App.UserInfo(
|
||||
el: el
|
||||
user_id: data.user_id
|
||||
el: el
|
||||
user_id: data.user_id
|
||||
callback: data.callback
|
||||
)
|
||||
|
||||
authenticate: ->
|
||||
|
|
|
@ -177,6 +177,10 @@ class App.ControllerForm extends App.Controller
|
|||
if attribute.name of @params
|
||||
attribute.value = @params[attribute.name]
|
||||
|
||||
if attribute.tag is 'autocompletion'
|
||||
if @params[ attribute.name + '_autocompletion_value_shown' ]
|
||||
attribute.valueShown = @params[ attribute.name + '_autocompletion_value_shown' ]
|
||||
|
||||
App.Log.debug 'ControllerForm', 'formGenItem-before', attribute
|
||||
|
||||
# build options list based on config
|
||||
|
@ -414,10 +418,14 @@ class App.ControllerForm extends App.Controller
|
|||
@local_attribute_full = '#' + attribute.id + '_autocompletion'
|
||||
@callback = attribute.callback
|
||||
|
||||
b = (event, key) =>
|
||||
# call calback on init
|
||||
if @callback && attribute.value && @params
|
||||
@callback( @params )
|
||||
|
||||
b = (event, item) =>
|
||||
# set html form attribute
|
||||
$(@local_attribute).val(key)
|
||||
$(@local_attribute).val(item.id)
|
||||
$(@local_attribute + '_autocompletion_value_shown').val(item.value)
|
||||
|
||||
# call calback
|
||||
if @callback
|
||||
|
@ -431,17 +439,17 @@ class App.ControllerForm extends App.Controller
|
|||
auto: {
|
||||
source: '/users/search',
|
||||
minLength: 2,
|
||||
select: ( event, ui ) =>
|
||||
@log 'notice', 'selected', event, ui
|
||||
b(event, ui.item.id)
|
||||
select: ( event, ui ) ->
|
||||
#@log 'notice', 'selected', event, ui
|
||||
b(event, ui.item)
|
||||
}
|
||||
)
|
||||
###
|
||||
$(@local_attribute_full).autocomplete(
|
||||
source: 'api/users/search',
|
||||
minLength: 2,
|
||||
source: attribute.source,
|
||||
minLength: attribute.minLengt || 3,
|
||||
select: ( event, ui ) =>
|
||||
b(event, ui.item.id)
|
||||
b(event, ui.item)
|
||||
)
|
||||
@delay( a, 180 )
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ class App.TicketCreate extends App.Controller
|
|||
|
||||
activate: =>
|
||||
@navupdate '#'
|
||||
@el.find('textarea').elastic()
|
||||
|
||||
changed: =>
|
||||
formCurrent = @formParam( @el.find('.ticket-create') )
|
||||
|
@ -151,23 +152,13 @@ class App.TicketCreate extends App.Controller
|
|||
render: (template = {}) ->
|
||||
|
||||
# set defaults
|
||||
defaults = template['options'] || App.TaskManager.get(@task_key).state || {}
|
||||
if !( 'ticket_state_id' of defaults )
|
||||
defaults['ticket_state_id'] = App.Collection.findByAttribute( 'TicketState', 'name', 'open' ).id
|
||||
if !( 'ticket_priority_id' of defaults )
|
||||
defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ).id
|
||||
|
||||
# remember customers
|
||||
if $('#create_customer_id').val()
|
||||
defaults['customer_id'] = $('#create_customer_id').val()
|
||||
defaults['customer_id_autocompletion'] = $('#create_customer_id_autocompletion').val()
|
||||
else
|
||||
# defaults['customer_id'] = '2'
|
||||
# defaults['customer_id_autocompletion'] = '12312313'
|
||||
defaults =
|
||||
ticket_state_id: App.Collection.findByAttribute( 'TicketState', 'name', 'open' ).id
|
||||
ticket_priority_id: App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ).id
|
||||
|
||||
# generate form
|
||||
configure_attributes = [
|
||||
{ name: 'customer_id', display: 'Customer', tag: 'autocompletion', type: 'text', limit: 200, null: false, relation: 'User', class: 'span7', autocapitalize: false, help: 'Select the customer of the Ticket or create one.', link: '<a href="" class="customer_new">»</a>', callback: @localUserInfo },
|
||||
{ name: 'customer_id', display: 'Customer', tag: 'autocompletion', type: 'text', limit: 200, null: false, relation: 'User', class: 'span7', autocapitalize: false, help: 'Select the customer of the Ticket or create one.', link: '<a href="" class="customer_new">»</a>', callback: @localUserInfo, source: 'api/users/search', minLengt: 2 },
|
||||
{ name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, filter: @edit_form, nulloption: true, relation: 'Group', default: defaults['group_id'], class: 'span7', },
|
||||
{ name: 'owner_id', display: 'Owner', tag: 'select', multiple: false, null: true, filter: @edit_form, nulloption: true, relation: 'User', default: defaults['owner_id'], class: 'span7', },
|
||||
{ name: 'tags', display: 'Tags', tag: 'tag', type: 'text', null: true, default: defaults['tags'], class: 'span7', },
|
||||
|
@ -183,6 +174,12 @@ class App.TicketCreate extends App.Controller
|
|||
admin: @isRole('Admin')
|
||||
)
|
||||
|
||||
params = undefined
|
||||
if template && !_.isEmpty( template.options )
|
||||
params = template.options
|
||||
else if App.TaskManager.get(@task_key) && !_.isEmpty( App.TaskManager.get(@task_key).state )
|
||||
params = App.TaskManager.get(@task_key).state
|
||||
|
||||
new App.ControllerForm(
|
||||
el: @el.find('.ticket_create')
|
||||
form_id: @form_id
|
||||
|
@ -191,6 +188,7 @@ class App.TicketCreate extends App.Controller
|
|||
className: 'create_' + @type + '_' + @id
|
||||
autofocus: true
|
||||
form_data: @edit_form
|
||||
params: params
|
||||
)
|
||||
|
||||
# update taskbar with new meta data
|
||||
|
@ -202,12 +200,6 @@ class App.TicketCreate extends App.Controller
|
|||
# update textarea size
|
||||
@el.find('textarea').trigger('change')
|
||||
|
||||
# start customer info controller
|
||||
if defaults['customer_id']
|
||||
$('#create_customer_id').val( defaults['customer_id'] )
|
||||
$('#create_customer_id_autocompletion').val( defaults['customer_id_autocompletion'] )
|
||||
@userInfo( user_id: defaults['customer_id'] )
|
||||
|
||||
# show template UI
|
||||
new App.TemplateUI(
|
||||
el: @el.find('[data-id="ticket_template"]'),
|
||||
|
@ -217,14 +209,24 @@ class App.TicketCreate extends App.Controller
|
|||
@formDefault = @formParam( @el.find('.ticket-create') )
|
||||
|
||||
# show text module UI
|
||||
new App.TextModuleUI(
|
||||
@textModule = new App.TextModuleUI(
|
||||
el: $('.ticket-create')
|
||||
)
|
||||
|
||||
localUserInfo: (params) =>
|
||||
|
||||
# update text module UI
|
||||
callback = (user) =>
|
||||
@textModule.reload(
|
||||
data:
|
||||
ticket:
|
||||
customer: user
|
||||
)
|
||||
|
||||
@userInfo(
|
||||
user_id: params.customer_id
|
||||
el: @el.find('[data-id="customer_info"]')
|
||||
user_id: params.customer_id
|
||||
el: @el.find('[data-id="customer_info"]')
|
||||
callback: callback
|
||||
)
|
||||
|
||||
userNew: (e) =>
|
||||
|
|
|
@ -5,8 +5,7 @@ class App.TicketCustomer extends App.ControllerModal
|
|||
|
||||
render: ->
|
||||
configure_attributes = [
|
||||
# { name: 'customer_id', display: 'Customer', tag: 'autocompletion', type: 'text', limit: 100, null: false, relation: 'User', class: 'span7', autocapitalize: false, help: 'Select the customer of the Ticket or create one.', link: '<a href="" class="customer_new">»</a>', callback: @userInfo },
|
||||
{ name: 'customer_id', display: 'Customer', tag: 'autocompletion', type: 'text', limit: 100, null: false, relation: 'User', class: 'span5', autocapitalize: false, help: 'Select the new customer of the Ticket.', },
|
||||
{ name: 'customer_id', display: 'Customer', tag: 'autocompletion', type: 'text', limit: 100, null: false, relation: 'User', class: 'span5', autocapitalize: false, help: 'Select the new customer of the Ticket.', source: 'api/users/search', minLengt: 2 },
|
||||
]
|
||||
|
||||
@html App.view('agent_ticket_customer')()
|
||||
|
@ -36,7 +35,7 @@ class App.TicketCustomer extends App.ControllerModal
|
|||
|
||||
# close modal
|
||||
@modalHide()
|
||||
|
||||
|
||||
# reload zoom view
|
||||
@zoom.render()
|
||||
|
||||
|
|
|
@ -5,7 +5,13 @@ class App.UserInfo extends App.Controller
|
|||
|
||||
constructor: ->
|
||||
super
|
||||
App.Collection.find( 'User', @user_id, @render )
|
||||
|
||||
callback = (user) =>
|
||||
@render(user)
|
||||
if @callback
|
||||
@callback(user)
|
||||
|
||||
App.Collection.find( 'User', @user_id, callback )
|
||||
|
||||
render: (user) =>
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
<input id="<%= @attribute.id %>" type="hidden" name="<%= @attribute.name %>" value="<%= @attribute.value %>" <%= @attribute.required %> />
|
||||
<input id="<%= @attribute.id %>_autocompletion" type="text" name="<%= @attribute.name %>_autocompletion" value="" class="<%= @attribute.class %>" <%= @attribute.required %> <%= @attribute.autofocus %> <%- @attribute.autocapitalize %>/>
|
||||
<input id="<%= @attribute.id %>_autocompletion" type="text" name="<%= @attribute.name %>_autocompletion" value="<%= @attribute.valueShown %>" class="<%= @attribute.class %>" <%= @attribute.required %> <%= @attribute.autofocus %> <%- @attribute.autocapitalize %>/>
|
||||
<input id="<%= @attribute.id %>_autocompletion_value_shown" type="hidden" name="<%= @attribute.name %>_autocompletion_value_shown" value="<%= @attribute.valueShown %>"/>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
require 'browser_test_helper'
|
||||
|
||||
class AgentTicketActionLevel1Test < TestCase
|
||||
def test_agent_ticket
|
||||
def test_agent_ticket_create
|
||||
tests = [
|
||||
{
|
||||
:name => 'agent ticket create 1',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
require 'browser_test_helper'
|
||||
|
||||
class AgentTicketActionsLevel2Test < TestCase
|
||||
def test_websocket
|
||||
def test_work_with_two_browser_on_same_ticket
|
||||
message = 'message 1äöüß ' + rand(99999999999999999).to_s
|
||||
tests = [
|
||||
{
|
||||
|
@ -167,6 +167,11 @@ class AgentTicketActionsLevel2Test < TestCase
|
|||
:execute => 'wait',
|
||||
:value => 1,
|
||||
},
|
||||
{
|
||||
:where => :instance2,
|
||||
:execute => 'js',
|
||||
:value => '$("#global-search").val("")',
|
||||
},
|
||||
{
|
||||
:where => :instance2,
|
||||
:execute => 'js',
|
||||
|
@ -181,6 +186,11 @@ class AgentTicketActionsLevel2Test < TestCase
|
|||
:execute => 'js',
|
||||
:value => '$("#global-search").blur()',
|
||||
},
|
||||
{
|
||||
:where => :instance2,
|
||||
:execute => 'js',
|
||||
:value => '$("#global-search").parent().parent().removeClass("open")',
|
||||
},
|
||||
{
|
||||
:execute => 'wait',
|
||||
:value => 3,
|
||||
|
|
Loading…
Reference in a new issue