Fix link in structure
This commit is contained in:
parent
a885313e75
commit
00010867a4
|
@ -1,4 +1,5 @@
|
||||||
class Admin::ItemsController < OrbitBackendController
|
class Admin::ItemsController < OrbitBackendController
|
||||||
|
include ActionView::Helpers::TagHelper
|
||||||
include ActionView::Helpers::DynamicForm
|
include ActionView::Helpers::DynamicForm
|
||||||
|
|
||||||
layout "structure"
|
layout "structure"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Admin::LinksController < Admin::ItemsController
|
class Admin::LinksController < Admin::ItemsController
|
||||||
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@item = Link.new
|
@item = Link.new
|
||||||
@item.parent = Page.find(params[:parent_id]) rescue nil
|
@item.parent = Page.find(params[:parent_id]) rescue nil
|
||||||
|
@ -13,27 +14,21 @@ class Admin::LinksController < Admin::ItemsController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@item = Link.new(params[:link])
|
@item = Link.new(params[:link])
|
||||||
|
if @item.save
|
||||||
if @item.save(params[:link])
|
render 'admin/items/reload_items'
|
||||||
success = true
|
|
||||||
else
|
else
|
||||||
success = check_valid_url
|
@error = error_messages_for(@item)
|
||||||
end
|
render 'admin/items/form_error'
|
||||||
if success
|
|
||||||
flash.now[:notice] = t('create.success.link')
|
|
||||||
respond_to do |format|
|
|
||||||
format.js { render 'admin/items/reload_items' }
|
|
||||||
end
|
|
||||||
else
|
|
||||||
flash.now[:error] = t('create.error.link')
|
|
||||||
render :action => "new"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@item = Link.find(params[:id])
|
@item = Link.find(params[:id])
|
||||||
unless @item.update_attributes(params[:link])
|
if @item.update_attributes(params[:link])
|
||||||
|
render 'admin/items/reload_items'
|
||||||
|
else
|
||||||
@error = error_messages_for(@item)
|
@error = error_messages_for(@item)
|
||||||
|
render 'admin/items/form_error'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ class Link < Item
|
||||||
|
|
||||||
field :url, localize: true
|
field :url, localize: true
|
||||||
|
|
||||||
|
validates :url, at_least_one: true
|
||||||
|
|
||||||
# validates :url, :presence => true, :format => /^(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|localhost(:[0-9]{1,5})?(\/.*)?/i
|
# validates :url, :presence => true, :format => /^(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|localhost(:[0-9]{1,5})?(\/.*)?/i
|
||||||
|
|
||||||
before_validation :add_http
|
before_validation :add_http
|
||||||
|
@ -11,20 +13,27 @@ class Link < Item
|
||||||
end
|
end
|
||||||
|
|
||||||
def urls
|
def urls
|
||||||
|
if self.url_translations.present?
|
||||||
self.url_translations.inject({}) do |result, (key, value)|
|
self.url_translations.inject({}) do |result, (key, value)|
|
||||||
result["url-#{key}"] = value
|
result["url-#{key}"] = value
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def add_http
|
def add_http
|
||||||
if self.url_translations.present?
|
if self.url_translations.present?
|
||||||
self.url_translations.each_value do |u|
|
self.url_translations = self.url_translations.inject({}) do |translations, (key, value)|
|
||||||
unless u[/^(http|https):\/\//] || u.blank?
|
if value.blank? || value[/^(http|https):\/\//]
|
||||||
u = 'http://' + u
|
translations[key] = value
|
||||||
|
else
|
||||||
|
translations[key] = 'http://' + value
|
||||||
end
|
end
|
||||||
|
translations
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,15 +7,16 @@
|
||||||
<%= f.text_field :name, class: 'input-xlarge', placeholder: t(:name), id: 'name' %>
|
<%= f.text_field :name, class: 'input-xlarge', placeholder: t(:name), id: 'name' %>
|
||||||
<span class="help-block"><%= t("front_page.name_field_helper") %></span>
|
<span class="help-block"><%= t("front_page.name_field_helper") %></span>
|
||||||
|
|
||||||
<%= f.fields_for :title_translations do |f| %>
|
|
||||||
<% @site_valid_locales.each do |locale| %>
|
<% @site_valid_locales.each do |locale| %>
|
||||||
|
<%= f.fields_for :title_translations do |f| %>
|
||||||
<%= f.label :locale, "#{t(:title)} #{I18nVariable.from_locale(locale)}" %>
|
<%= f.label :locale, "#{t(:title)} #{I18nVariable.from_locale(locale)}" %>
|
||||||
<%= f.text_field locale, class: 'input-xlarge', placeholder: "#{t(:title)} #{I18nVariable.from_locale(locale)}", id: locale %>
|
<%= f.text_field locale, class: 'input-xlarge', placeholder: "#{t(:title)} #{I18nVariable.from_locale(locale)}", id: locale %>
|
||||||
<%= f.label :url, "#{t(:url)} #{I18nVariable.from_locale(locale)}" %>
|
<% end %>
|
||||||
<%= f.text_field :url, :class => 'input-xlarge', placeholder: "#{t(:url)} #{I18nVariable.from_locale(locale)}", id: "url-#{locale}" %>
|
<%= f.fields_for :url_translations do |f| %>
|
||||||
|
<%= f.label :locale, "#{t(:url)} #{I18nVariable.from_locale(locale)}" %>
|
||||||
|
<%= f.text_field locale, :class => 'input-xlarge', placeholder: "#{t(:url)} #{I18nVariable.from_locale(locale)}", id: "url-#{locale}" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="checkbox-groups" id="link-is-published">
|
<div class="checkbox-groups" id="link-is-published">
|
||||||
<%= f.label :is_published, t(:is_published) %>
|
<%= f.label :is_published, t(:is_published) %>
|
||||||
<p>
|
<p>
|
||||||
|
|
Loading…
Reference in New Issue