Skip to content

Commit

Permalink
awesomefoundation#269 adding fields to chapter form
Browse files Browse the repository at this point in the history
  • Loading branch information
divideby0 committed Jul 7, 2017
1 parent 1201042 commit 47d92de
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/assets/stylesheets/_chapters-new.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
margin-bottom: 25px;
}
}
}

.input .error {
float: left;
width: 100%;
font-weight: bold;
font-size: 120%;
color: $pink;
margin: 1em 0;
}
}
11 changes: 10 additions & 1 deletion app/models/chapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ class Chapter < ActiveRecord::Base

validates_format_of :slug, :with => /\A[a-z0-9-]+\Z/

validate :project_review_end_after_start

attr_accessible :name, :twitter_url, :facebook_url, :blog_url, :rss_feed_url, :description,
:country, :extra_question_1, :extra_question_2, :extra_question_3, :slug,
:email_address, :time_zone, :inactive, :locale
:email_address, :time_zone, :inactive, :locale, :project_review_start,
:project_review_end

def should_generate_new_friendly_id?
slug.blank?
Expand Down Expand Up @@ -114,4 +117,10 @@ def inactive=(bool)
self.inactive_at = nil
end
end

def project_review_end_after_start
if project_review_start.present? && project_review_end.present? && project_review_end < project_review_start
errors.add(:project_review_end, "#{I18n.t('activerecord.errors.models.chapter.attributes.project_review_end.before_start')}")
end
end
end
23 changes: 23 additions & 0 deletions app/views/chapters/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,32 @@
<%= form.input :country, :priority => COUNTRY_PRIORITY %>
<%= form.input :time_zone %>
<%= form.input :locale, :collection => I18n.available_locales, :include_blank => false, :label => t('simple_form.labels.chapter.locale', :slug => chapter.slug) %>
<%= form.input :project_review_start, :as => 'string', :include_blank => true %>
<%= form.input :project_review_end, :as => 'string', :include_blank => true %>
<%= form.input :extra_question_1 %>
<%= form.input :extra_question_2 %>
<%= form.input :extra_question_3 %>
<%= form.button :submit %>
<% end -%>
<% content_for :javascript do %>
<% javascript_tag do %>
$(window).load(function(){
$('#chapter_project_review_start').datepicker({
dateFormat: 'yy-mm-dd',
onClose: function(selectedDate) {
$('#chapter_project_review_start').blur();
$('#chapter_project_review_end').datepicker("option", "minDate", selectedDate);
}
});

$('#chapter_project_review_end').datepicker({
dateFormat: 'yy-mm-dd',
onClose: function() { $('#chapter_project_review_end').blur() }
});
});
<% end %>
<% end %>

0 comments on commit 47d92de

Please sign in to comment.