Added reload support for autocompletion.

This commit is contained in:
Martin Edenhofer 2013-07-13 13:12:29 +02:00
parent a056363a42
commit bff4013c0c
8 changed files with 67 additions and 40 deletions

View file

@ -180,8 +180,9 @@ class App.Controller extends Spine.Controller
# start customer info controller # start customer info controller
new App.UserInfo( new App.UserInfo(
el: el el: el
user_id: data.user_id user_id: data.user_id
callback: data.callback
) )
authenticate: -> authenticate: ->

View file

@ -177,6 +177,10 @@ class App.ControllerForm extends App.Controller
if attribute.name of @params if attribute.name of @params
attribute.value = @params[attribute.name] 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 App.Log.debug 'ControllerForm', 'formGenItem-before', attribute
# build options list based on config # build options list based on config
@ -414,10 +418,14 @@ class App.ControllerForm extends App.Controller
@local_attribute_full = '#' + attribute.id + '_autocompletion' @local_attribute_full = '#' + attribute.id + '_autocompletion'
@callback = attribute.callback @callback = attribute.callback
b = (event, key) => # call calback on init
if @callback && attribute.value && @params
@callback( @params )
b = (event, item) =>
# set html form attribute # set html form attribute
$(@local_attribute).val(key) $(@local_attribute).val(item.id)
$(@local_attribute + '_autocompletion_value_shown').val(item.value)
# call calback # call calback
if @callback if @callback
@ -431,17 +439,17 @@ class App.ControllerForm extends App.Controller
auto: { auto: {
source: '/users/search', source: '/users/search',
minLength: 2, minLength: 2,
select: ( event, ui ) => select: ( event, ui ) ->
@log 'notice', 'selected', event, ui #@log 'notice', 'selected', event, ui
b(event, ui.item.id) b(event, ui.item)
} }
) )
### ###
$(@local_attribute_full).autocomplete( $(@local_attribute_full).autocomplete(
source: 'api/users/search', source: attribute.source,
minLength: 2, minLength: attribute.minLengt || 3,
select: ( event, ui ) => select: ( event, ui ) =>
b(event, ui.item.id) b(event, ui.item)
) )
@delay( a, 180 ) @delay( a, 180 )

View file

@ -71,6 +71,7 @@ class App.TicketCreate extends App.Controller
activate: => activate: =>
@navupdate '#' @navupdate '#'
@el.find('textarea').elastic()
changed: => changed: =>
formCurrent = @formParam( @el.find('.ticket-create') ) formCurrent = @formParam( @el.find('.ticket-create') )
@ -151,23 +152,13 @@ class App.TicketCreate extends App.Controller
render: (template = {}) -> render: (template = {}) ->
# set defaults # set defaults
defaults = template['options'] || App.TaskManager.get(@task_key).state || {} defaults =
if !( 'ticket_state_id' of defaults ) ticket_state_id: App.Collection.findByAttribute( 'TicketState', 'name', 'open' ).id
defaults['ticket_state_id'] = App.Collection.findByAttribute( 'TicketState', 'name', 'open' ).id ticket_priority_id: App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ).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'
# generate form # generate form
configure_attributes = [ 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">&raquo;</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">&raquo;</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: '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: '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', }, { 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') 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( new App.ControllerForm(
el: @el.find('.ticket_create') el: @el.find('.ticket_create')
form_id: @form_id form_id: @form_id
@ -191,6 +188,7 @@ class App.TicketCreate extends App.Controller
className: 'create_' + @type + '_' + @id className: 'create_' + @type + '_' + @id
autofocus: true autofocus: true
form_data: @edit_form form_data: @edit_form
params: params
) )
# update taskbar with new meta data # update taskbar with new meta data
@ -202,12 +200,6 @@ class App.TicketCreate extends App.Controller
# update textarea size # update textarea size
@el.find('textarea').trigger('change') @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 # show template UI
new App.TemplateUI( new App.TemplateUI(
el: @el.find('[data-id="ticket_template"]'), el: @el.find('[data-id="ticket_template"]'),
@ -217,14 +209,24 @@ class App.TicketCreate extends App.Controller
@formDefault = @formParam( @el.find('.ticket-create') ) @formDefault = @formParam( @el.find('.ticket-create') )
# show text module UI # show text module UI
new App.TextModuleUI( @textModule = new App.TextModuleUI(
el: $('.ticket-create') el: $('.ticket-create')
) )
localUserInfo: (params) => localUserInfo: (params) =>
# update text module UI
callback = (user) =>
@textModule.reload(
data:
ticket:
customer: user
)
@userInfo( @userInfo(
user_id: params.customer_id user_id: params.customer_id
el: @el.find('[data-id="customer_info"]') el: @el.find('[data-id="customer_info"]')
callback: callback
) )
userNew: (e) => userNew: (e) =>

View file

@ -5,8 +5,7 @@ class App.TicketCustomer extends App.ControllerModal
render: -> render: ->
configure_attributes = [ 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">&raquo;</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.', source: 'api/users/search', minLengt: 2 },
{ 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.', },
] ]
@html App.view('agent_ticket_customer')() @html App.view('agent_ticket_customer')()

View file

@ -5,7 +5,13 @@ class App.UserInfo extends App.Controller
constructor: -> constructor: ->
super 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) => render: (user) =>

View file

@ -1,2 +1,3 @@
<input id="<%= @attribute.id %>" type="hidden" name="<%= @attribute.name %>" value="<%= @attribute.value %>" <%= @attribute.required %> /> <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 %>"/>

View file

@ -2,7 +2,7 @@
require 'browser_test_helper' require 'browser_test_helper'
class AgentTicketActionLevel1Test < TestCase class AgentTicketActionLevel1Test < TestCase
def test_agent_ticket def test_agent_ticket_create
tests = [ tests = [
{ {
:name => 'agent ticket create 1', :name => 'agent ticket create 1',

View file

@ -2,7 +2,7 @@
require 'browser_test_helper' require 'browser_test_helper'
class AgentTicketActionsLevel2Test < TestCase class AgentTicketActionsLevel2Test < TestCase
def test_websocket def test_work_with_two_browser_on_same_ticket
message = 'message 1äöüß ' + rand(99999999999999999).to_s message = 'message 1äöüß ' + rand(99999999999999999).to_s
tests = [ tests = [
{ {
@ -167,6 +167,11 @@ class AgentTicketActionsLevel2Test < TestCase
:execute => 'wait', :execute => 'wait',
:value => 1, :value => 1,
}, },
{
:where => :instance2,
:execute => 'js',
:value => '$("#global-search").val("")',
},
{ {
:where => :instance2, :where => :instance2,
:execute => 'js', :execute => 'js',
@ -181,6 +186,11 @@ class AgentTicketActionsLevel2Test < TestCase
:execute => 'js', :execute => 'js',
:value => '$("#global-search").blur()', :value => '$("#global-search").blur()',
}, },
{
:where => :instance2,
:execute => 'js',
:value => '$("#global-search").parent().parent().removeClass("open")',
},
{ {
:execute => 'wait', :execute => 'wait',
:value => 3, :value => 3,