mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Add cache_response option to completable form fields
When `cache_response` is set to `false` for completable fields the returned options will not be cached on the client side. The default is `true`. Clearing the cache is needed when the completable response depends on a different option of the Agent. Usage Example: ``` form_configurable :models, roles: :completable, cache_response: false ``` * Disable the completion callback when `select2` is opened programmatically to avoid an infinite loop * Moved the completion ajax call from `select2-open` to `select2-opening` to clear the cached results before `completableDefaultOptions` is called (shows the "Loading ..." message instead of the previous results)
This commit is contained in:
parent
e114202f5f
commit
3e76fa0e41
3 changed files with 10 additions and 5 deletions
|
@ -53,10 +53,13 @@ $ ->
|
|||
updateDropdownData = (form_data, element, data) ->
|
||||
returnedResults[form_data.attribute] = {text: 'Options', children: data}
|
||||
$(element).trigger('change')
|
||||
$("input[role~=completable]").off 'select2-opening', select2OpeningCallback
|
||||
$(element).select2('open')
|
||||
$("input[role~=completable]").on 'select2-opening', select2OpeningCallback
|
||||
|
||||
$("input[role~=completable]").on 'select2-open', (e) ->
|
||||
select2OpeningCallback = (e) ->
|
||||
form_data = getFormData(e.currentTarget)
|
||||
delete returnedResults[form_data.attribute] if returnedResults[form_data.attribute] && !$(e.currentTarget).data('cacheResponse')
|
||||
return if returnedResults[form_data.attribute]
|
||||
|
||||
$.ajax '/agents/complete',
|
||||
|
@ -67,10 +70,12 @@ $ ->
|
|||
error: (data) ->
|
||||
updateDropdownData(form_data, e.currentTarget, [{id: undefined, text: 'Error loading data.'}])
|
||||
|
||||
$("input[role~=completable]").on 'select2-opening', select2OpeningCallback
|
||||
|
||||
$("input[type=radio][role~=form-configurable]").change (e) ->
|
||||
input = $(e.currentTarget).parents().siblings("input[data-attribute=#{$(e.currentTarget).data('attribute')}]")
|
||||
if $(e.currentTarget).val() == 'manual'
|
||||
input.removeClass('hidden')
|
||||
else
|
||||
input.val($(e.currentTarget).val())
|
||||
input.addClass('hidden')
|
||||
input.addClass('hidden')
|
||||
|
|
|
@ -32,7 +32,7 @@ module FormConfigurable
|
|||
options = args.extract_options!.reverse_merge(roles: [], type: :string)
|
||||
|
||||
if args.all? { |arg| arg.is_a?(Symbol) }
|
||||
options.assert_valid_keys([:type, :roles, :values, :ace])
|
||||
options.assert_valid_keys([:type, :roles, :values, :ace, :cache_response])
|
||||
end
|
||||
|
||||
if options[:type] == :array && (options[:values].blank? || !options[:values].is_a?(Array))
|
||||
|
|
|
@ -43,7 +43,7 @@ class FormConfigurableAgentPresenter < Decorator
|
|||
@view.concat(@view.text_field_tag "agent[options][#{attribute}]", value, html_options.merge(:class => "form-control #{@agent.send(:boolify, value) != nil ? 'hidden' : ''}"))
|
||||
end
|
||||
when :array, :string
|
||||
@view.text_field_tag "agent[options][#{attribute}]", value, html_options.merge(:class => 'form-control')
|
||||
@view.text_field_tag "agent[options][#{attribute}]", value, html_options.deep_merge(:class => 'form-control', data: {cache_response: data[:cache_response] != false})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue