= semantic_form_for [:admin, @page], url: (@page.new_record? ? admin_pages_path : admin_page_path(@page.id)), html: { multipart: true } do |form| %input{name: "_change_layout", type: "hidden"} - @page.initialize_missing_translations - current_locale = ActiveadminSelleoCms::Locale.find_by_code(I18n.locale) - @page.initialize_missing_sections - @section_forms = [] = form.inputs "Layout" do = form.input :layout, collection: ActiveadminSelleoCms::Layout.all, include_blank: false, hint: "The form will reload on change" = form.inputs "General options" do = form.input :parent_id, as: :select, collection: nested_set_options(ActiveadminSelleoCms::Page, @page) {|i| "#{'-' * i.level} #{i.title}" } = form.input :is_published, as: :boolean, input_html: { checked: @page.published_at.present? } = form.input :is_link_url, as: :boolean, input_html: { checked: @page.link_url.present? } = form.input :link_url, hint: "Enter remote URL including the http part at the beginning" = form.inputs "Page icon", for: [:icon, form.object.icon || ActiveadminSelleoCms::Icon.new] do |icon_form| = icon_form.input :data, label: "Icon", hint: (form.object.icon ? icon_form.template.image_tag(form.object.icon_url) : "No icon uploaded yet" ) = form.inputs "Header image", for: [:header_image, form.object.header_image || ActiveadminSelleoCms::HeaderImage.new] do |header_image_form| = header_image_form.input :data, label: "Header image", hint: (form.object.header_image ? header_image_form.template.image_tag(form.object.header_image_url) : "No header image uploaded yet" ) = form.inputs "Attachments", for: [:attachments, ActiveadminSelleoCms::Attachment.new] do |attachment_form| = attachment_form.input :data, label: "Attachment", input_html: { multiple: true, name: "page[attachments_attributes][][data]" } - form.object.attachments.each do |attachment| %li{"data-attachment-id" => attachment.id} %label File = attachment.data_file_name = link_to_function "Delete", "delete_asset(#{@page.id}, #{attachment.id})" = form.semantic_fields_for :sections do |section_form| - if @page.section_names.include? section_form.object.name - @section_forms << section_form = section_form.input :name, as: :hidden, label: false - else = "" .language-tabs %ul.language-selection %li= link_to current_locale.name, "#lang-#{current_locale.code}" - @page.translations.each do |translation| - unless translation.locale == current_locale.code - additional_locale = ActiveadminSelleoCms::Locale.find_by_code(translation.locale) %li= link_to additional_locale.name, "#lang-#{additional_locale.code}" = form.semantic_fields_for :translations do |translated_form| - additional_locale = ActiveadminSelleoCms::Locale.find_by_code(translated_form.object.locale) %div{id: "lang-#{additional_locale.code}", style: "#{'display:none;' if additional_locale.code == current_locale.code}"} = render partial: 'translated_fields', locals: { locale: additional_locale, form: translated_form } = form.actions do = form.action :submit %li.cancel = link_to I18n.t('active_admin.cancel'), admin_pages_path :javascript function is_link_url(){ if($('input#page_is_link_url').is(':checked')){ $('div.language-tabs').hide(); $('li#page_link_url_input').show(); }else{ $('li#page_link_url_input').hide(); $('div.language-tabs').show(); } } $(function() { $(".language-tabs").tabs(); is_link_url(); $("input[id$='_title']").blur(function(){ slugId = '#' + $(this).attr('id').replace('_title', '_slug'); if ($(slugId).attr('value') == '') { $(slugId).attr('value', slug($(this).attr('value')) ) } browserTitleId = '#' + $(this).attr('id').replace('_title', '_browser_title'); if ($(browserTitleId).attr('value') == '') { $(browserTitleId).attr('value', $(this).attr('value') ) } }); $('input#page_is_link_url').change(function(){ is_link_url(); }); $('select#page_layout').change(function(){ $(this).closest('form').find('input[name="_change_layout"]').attr('value','1'); $(this).closest('form').submit(); }); });