Sha256: 1e19ffbcaa9d4556ed00f7e94d61ff59e8fca919cf076d3c0e425284fb64f4bb

Contents?: true

Size: 1.64 KB

Versions: 19

Compression:

Stored size: 1.64 KB

Contents

module Locomotive
  module API
    module Forms

      class PageForm < BaseForm

        attrs :title, :slug, :handle, :response_type, :published, :cache_enabled

        # Tree
        attrs :parent_id, :position, :listed

        # Template
        attrs :is_layout, :allow_layout, :raw_template

        # Redirection
        attrs  :redirect, :redirect_url, :redirect_type

        # Templatized
        attrs :templatized, :target_klass_slug

        # SEO
        attrs :seo_title, :meta_keywords, :meta_description

        # Editable elements
        attrs :editable_elements_attributes

        def initialize(site, attributes = {}, existing_page = nil)
          @site = site
          @existing_page = existing_page
          super(attributes)
        end

        ## Custom setters ##

        def parent=(id_or_path)
          self.parent_id = @site.pages.by_id_or_fullpath(id_or_path).pluck(:_id).first
        end

        def template=(template)
          self.raw_template = template
        end

        def editable_elements=(elements)
          self.editable_elements_attributes = elements.map do |attrs|
            if element = @existing_page.try(:find_editable_element, attrs[:block], attrs[:slug])
              attrs[:_id] = element._id
            end

            EditableElementForm.new(attrs).serializable_hash
          end
        end

        def content_type=(value)
          self.templatized = true if value.present?

          self.target_klass_slug = value
        end

        def redirect_url=(value)
          self.redirect = true if value.present?

          set_attribute :redirect_url, value
        end

      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
locomotivecms-3.1.2 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.2.1 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.2.0 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.2.0.rc2 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.2.0.rc1 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.1.1 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.1.0 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.1.0.rc3 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.1.0.rc2 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.1.0.rc1 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.0.1 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.0.0 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.0.0.rc7 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.0.0.rc6 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.0.0.rc5 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.0.0.rc4 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.0.0.rc3 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.0.0.rc2 app/api/locomotive/api/forms/page_form.rb
locomotivecms-3.0.0.rc1 app/api/locomotive/api/forms/page_form.rb