Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/c/feature/#81' into c/feature/#84
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Dec 10, 2014
2 parents f56057e + a22d0f8 commit be18548
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
13 changes: 10 additions & 3 deletions app/assets/javascripts/event_suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ EVENT_URL = '/events/'
SUGGEST_URL = '/new_event_suggestion'

$(document).ready(function() {
$('#sugguest-form input').change(checkVacancy);
$('#sugguest-form #selectpicker').change(checkVacancy);
var typingTimer;
var doneTypingInterval = 1000;
$('#sugguest-form input').change(function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(checkVacancy, doneTypingInterval);
});

$('#sugguest-form #selectpicker').change(function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(checkVacancy, doneTypingInterval);
});
// $(document).ajaxComplete(function(event, request) {
// var flash = $.parseJSON(request.getResponseHeader('X-Flash-Messages'));
// if(!flash) return;
Expand All @@ -17,7 +25,6 @@ $(document).ready(function() {
});

function checkVacancy(e) {
e.preventDefault();
rooms = []
$("#selectpicker option:selected").each(function(){ rooms.push($(this).val());});

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/event_suggestions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create
@event_suggestion = EventSuggestion.new(event_suggestion_params)
respond_to do |format|
if @event_suggestion.save
format.html { redirect_to @event_suggestion, notice: t('notices.successful_create', :model => Event.model_name.human) }
format.html { redirect_to @event_suggestion, notice: t('notices.successful_create', :model => EventSuggestion.model_name.human) }
format.json { render :show, status: :created, location: @event_suggestion }
else
format.html { render :new }
Expand Down
14 changes: 7 additions & 7 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class Event < ActiveRecord::Base
validate :dates_cannot_be_in_the_past,:start_before_end_date


def dates_cannot_be_in_the_past
errors.add(:starts_at, "can't be in the past") if starts_at < Date.today
errors.add(:ends_at, "can't be in the past") if ends_at < Date.today
end
def start_before_end_date
errors.add(:starts_at, "start has to be before the end") if starts_at && starts_at && ends_at < starts_at
end
def dates_cannot_be_in_the_past
errors.add(I18n.t('time.starts_at'), I18n.t('errors.messages.date_in_the_past')) if starts_at < Date.today
errors.add(I18n.t('time.ends_at'), I18n.t('errors.messages.date_in_the_past')) if ends_at < Date.today
end
def start_before_end_date
errors.add(I18n.t('time.starts_at'), I18n.t('errors.messages.start_date_not_before_end_date')) if starts_at && starts_at && ends_at < starts_at
end

# Scope definitions. We implement all Filterrific filters through ActiveRecord
# scopes. In this example we omit the implementation of the scopes for brevity.
Expand Down
16 changes: 16 additions & 0 deletions app/models/event_suggestion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,20 @@ class EventSuggestion < ActiveRecord::Base

date_time_attribute :starts_at
date_time_attribute :ends_at

validate :dates_cannot_be_in_the_past,:start_before_end_date


validates :starts_at, presence: true
validates :ends_at, presence: true


def dates_cannot_be_in_the_past
errors.add(I18n.t('time.starts_at'), I18n.t('errors.messages.date_in_the_past')) if starts_at < Date.today
errors.add(I18n.t('time.ends_at'), I18n.t('errors.messages.date_in_the_past')) if ends_at < Date.today
end
def start_before_end_date
errors.add(I18n.t('time.starts_at'), I18n.t('errors.messages.start_date_not_before_end_date')) if starts_at && starts_at && ends_at < starts_at
end

end
5 changes: 0 additions & 5 deletions app/views/events/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => 'btn btn-xs btn-danger' %>
<% end %>
<% if can? :sugguest, event%>
<%= link_to t('.sugguest', :default => t("helpers.links.sugguest")),
new_event_suggestion_from_event_path(event),
:class => 'btn btn-xs btn-warning' %>
<% end %>
</td>
</tr>
<% end %>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ de:
too_long: ist zu lang (mehr als %{count} Zeichen)
too_short: ist zu kurz (weniger als %{count} Zeichen)
wrong_length: hat die falsche Länge (muss genau %{count} Zeichen haben)
date_in_the_past: kann nicht in der Vergangenheit liegen
start_date_not_before_end_date: muss vor dem Endzeitpunkt liegen
template:
body: ! 'Bitte überprüfen Sie die folgenden Felder:'
header:
Expand Down Expand Up @@ -203,6 +205,8 @@ de:
long: ! '%A, %d. %B %Y, %H:%M Uhr'
short: ! '%d. %B, %H:%M Uhr'
pm: nachmittags
starts_at: Startzeitpunkt
ends_at: Endzeitpunkt
notices:
successful_create: ! '%{model} wurde erfolgreich erstellt.'
successful_update: ! '%{model} wurde erfolgreich aktualisiert.'
Expand Down

0 comments on commit be18548

Please sign in to comment.