backend.rb 1.2 KB

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