Class: Alchemy::Admin::ElementsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- BaseController
- Alchemy::Admin::ElementsController
- Defined in:
- app/controllers/alchemy/admin/elements_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Creates a element as discribed in config/alchemy/elements.yml on page via AJAX.
- #destroy ⇒ Object
-
#fold ⇒ Object
Toggle fodls the element and persists the state in the db.
- #index ⇒ Object
- #new ⇒ Object
- #order ⇒ Object
- #publish ⇒ Object
-
#update ⇒ Object
Updates the element.
Methods inherited from BaseController
Methods included from Modules
included, #module_definition_for, register_module
Methods included from Alchemy::AbilityHelper
Methods included from ConfigurationMethods
#configuration, #multi_language?, #multi_site?, #prefix_locale?
Instance Method Details
#create ⇒ Object
Creates a element as discribed in config/alchemy/elements.yml on page via AJAX.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/alchemy/admin/elements_controller.rb', line 28 def create @page_version = PageVersion.find(params[:element][:page_version_id]) @page = @page_version.page Element.transaction do if @paste_from_clipboard = params[:paste_from_clipboard].present? @element = paste_element_from_clipboard else @element = Element.new(create_element_params) end if @page.definition["insert_elements_at"] == "top" @insert_at_top = true @element.position = 1 end end if @element.save render :create else @element.page_version = @page_version @elements = @page.available_element_definitions load_clipboard_items render :new end end |
#destroy ⇒ Object
66 67 68 69 70 |
# File 'app/controllers/alchemy/admin/elements_controller.rb', line 66 def destroy @richtext_ids = @element.richtext_contents_ids + @element.richtext_ingredients_ids @element.destroy @notice = Alchemy.t("Successfully deleted element") % { element: @element.display_name } end |
#fold ⇒ Object
Toggle fodls the element and persists the state in the db
Ingredient validations might make the element invalid. In this case we are just toggling a UI state and do not care about the validations.
97 98 99 100 101 |
# File 'app/controllers/alchemy/admin/elements_controller.rb', line 97 def fold @page = @element.page @element.folded = !@element.folded @element.save(validate: false) end |
#index ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'app/controllers/alchemy/admin/elements_controller.rb', line 9 def index @page_version = PageVersion.find(params[:page_version_id]) @page = @page_version.page elements = @page_version.elements.order(:position).includes(*element_includes) @elements = elements.not_nested.unfixed @fixed_elements = elements.not_nested.fixed load_clipboard_items end |
#new ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'app/controllers/alchemy/admin/elements_controller.rb', line 18 def new @page_version = PageVersion.find(params[:page_version_id]) @page = @page_version.page @parent_element = Element.find_by(id: params[:parent_element_id]) @elements = @page.available_elements_within_current_scope(@parent_element) @element = @page_version.elements.build load_clipboard_items end |
#order ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/alchemy/admin/elements_controller.rb', line 76 def order @parent_element = Element.find_by(id: params[:parent_element_id]) Element.transaction do params.fetch(:element_ids, []).each.with_index(1) do |element_id, position| # We need to set the parent_element_id, because we might have dragged the # element over from another nestable element Element.find_by(id: element_id).update_columns( parent_element_id: params[:parent_element_id], position: position, ) end # Need to manually touch the parent because Rails does not do it # with the update_columns above @parent_element&.touch end end |
#publish ⇒ Object
72 73 74 |
# File 'app/controllers/alchemy/admin/elements_controller.rb', line 72 def publish @element.update(public: !@element.public?) end |
#update ⇒ Object
Updates the element.
And update all contents in the elements by calling update_contents.
56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/alchemy/admin/elements_controller.rb', line 56 def update @page = @element.page if element_params.key?(:ingredients_attributes) update_element_with_ingredients else update_element_with_contents end end |