applies_taskbar_state.rb 850 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module FormUpdater::Concerns::AppliesTaskbarState
  3. extend ActiveSupport::Concern
  4. def resolve
  5. if current_taskbar.present? && should_apply?
  6. apply_taskbar_state
  7. end
  8. super
  9. end
  10. private
  11. def apply_taskbar_state
  12. apply_value = FormUpdater::ApplyValue.new(context:, data:, meta:, result:)
  13. current_taskbar.state.each_pair do |field, value|
  14. apply_value.perform(field: field, config: { 'value' => value }, include_blank: true)
  15. end
  16. end
  17. def current_taskbar
  18. id = meta.dig(:additional_data, 'taskbarId')
  19. Gql::ZammadSchema.authorized_object_from_id(id, type: Taskbar, user: context[:current_user]) if id.present?
  20. end
  21. def should_apply?
  22. meta.dig(:additional_data, 'applyTaskbarState') == true || meta[:initial]
  23. end
  24. end