backend.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. class CoreWorkflow::Result::Backend
  3. def initialize(result_object:, field:, perform_config:, skip_rerun: false)
  4. @result_object = result_object
  5. @field = field
  6. @perform_config = perform_config
  7. @skip_rerun = skip_rerun
  8. end
  9. def field
  10. @field.sub(%r{.*\.}, '')
  11. end
  12. def set_rerun
  13. return if @skip_rerun
  14. @result_object.rerun = true
  15. end
  16. def result(backend, field, value = nil)
  17. @result_object.run_backend_value(backend, field, value)
  18. end
  19. def saved_value
  20. # make sure we have a saved object
  21. return if @result_object.attributes.saved_only.blank?
  22. # we only want to have the saved value in the restrictions
  23. # if no changes happend to the form. If the users does changes
  24. # to the form then also the saved value should get removed
  25. return if @result_object.attributes.selected.changed?
  26. # attribute can be blank e.g. in custom development
  27. # or if attribute is only available in the frontend but not
  28. # in the backend
  29. return if attribute.blank?
  30. @result_object.attributes.saved_attribute_value(attribute).to_s
  31. end
  32. def attribute
  33. @attribute ||= @result_object.attributes.object_elements_hash[field]
  34. end
  35. end