Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Front validation #29

Merged
merged 2 commits into from
Feb 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/assets/javascripts/pages/places.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ ->
$('#place_form').validate()
1 change: 1 addition & 0 deletions app/assets/javascripts/pages/travels.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ $ ->
params: (params) ->
params._method = 'patch'
return params
$('#travel_form').validate()
2 changes: 2 additions & 0 deletions app/assets/javascripts/pages/users.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ ->
$('#user_form').validate()
4 changes: 4 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ def setup
def ssl_configured?
Rails.env.production?
end

def set_page_js
@need_pages_js = true
end
end
2 changes: 2 additions & 0 deletions app/controllers/places_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class PlacesController < ApplicationController
before_action :set_place, only: [:show, :edit, :update, :destroy]
before_action :set_page_js, only: [:new, :show, :edit, :update]

def index
@places = if params[:already]
Expand All @@ -15,6 +16,7 @@ def show
end

def new
@need_pages_js
@place = Place.new

@places = params[:query].present? ? Geocoder.search(params[:query]) : []
Expand Down
1 change: 1 addition & 0 deletions app/controllers/travels_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class TravelsController < ApplicationController
before_action :set_travel, only: [:edit, :update, :edit_photo]
before_action :set_travel_by_owner, only: [:destroy]
before_action :set_page_js, only: [:new, :show, :edit, :update]

def index
@travels = Travel.belong(current_user).order('start_date DESC').page(params[:page])
Expand Down
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class UsersController < ApplicationController
before_action :set_user, only: [:edit, :update, :destroy]
before_action :set_page_js, only: [:new, :show, :edit, :update]

def edit
@user.build_photo_service_user_info unless @user.photo_service_user_info
Expand Down
7 changes: 4 additions & 3 deletions app/views/places/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
= form_for(@place) do |f|
= form_for(@place, html: { id: 'place_form' }) do |f|
- if @place.errors.any?
= render partial: 'form_error_header', locals: { error_messages: @place.errors.full_messages }
.form-group
= f.label :name
span.text-primary.p-lg
| (必須)
br
= f.text_field :name, class: "form-control"
= f.text_field :name, class: "form-control", required: 'required'
.form-group
= f.label :address
span
span.text-primary.p-lg
| (必須)
br
= f.text_field :address, class: "form-control"
= f.text_field :address, class: "form-control", required: 'required'
.form-group
= f.label :urls
br
Expand All @@ -24,4 +24,5 @@
= f.text_area :memo, class: "form-control"
.col-md-12.col-sm-12
.text-center
= hidden_field_tag :display_form, :true
= f.submit class: "btn btn-md btn-primary", value: '登録', data: { disable_with: "Please wait..." }
2 changes: 1 addition & 1 deletion app/views/places/_search.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= form_for(new_place_path, method: :get, html: { class: 'sp-form' } ) do |f|
.col-sm-12.form-group
= text_field_tag :query, params[:query], class: "form-control input-lg", placeholder: 'Search', id: 'search'
= text_field_tag :query, params[:query], class: "form-control input-lg", placeholder: 'Search', id: 'search', required: 'required'
= f.submit class: "btn btn-md btn-center btn-primary", value: '検索'
br
br
Expand Down
2 changes: 1 addition & 1 deletion app/views/places/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ section.page-block.space-top.space-bottom
= place.address
br
- if place.urls.present?
- place.urls.each_with_index do |url, i|
- place.urls.reject(&:blank?).each_with_index do |url, i|
= link_to "参考URL#{i + 1}", url, target: '_blank'
br
= simple_format(place.memo)
Expand Down
8 changes: 4 additions & 4 deletions app/views/places/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ section.page-block.space-top.space-bottom
.row
.col-sm-8.col-sm-offset-2
ul.nav.nav-tabs
li.active
li class="#{"active" unless params[:display_form]}"
a[href="#search" data-toggle="tab" aria-expanded="false"]
| 名称を検索して登録する
li.
li class="#{"active" if params[:display_form]}"
a[href="#form" data-toggle="tab" aria-expanded="true"]
| 名称・住所を登録する
.tab-content
#search.tab-pane.active
div id="search" class="tab-pane #{"active" unless params[:display_form]}"
hr
= render 'search'
#form.tab-pane.fade
div id="form" class="tab-pane #{"active" if params[:display_form]}"
hr
= render 'form'
14 changes: 9 additions & 5 deletions app/views/travels/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
= form_for(@travel) do |f|
= form_for(@travel, html: { id: 'travel_form'}) do |f|
- if @travel.errors.any?
= render partial: 'form_error_header', locals: { error_messages: @travel.errors.full_messages }
.form-group
= f.label :name
span.text-primary.p-lg
| (必須)
br
= f.text_field :name, class: "form-control"
= f.text_field :name, class: "form-control", required: 'required'
.form-group
= label_tag(I18n.t :shcedule, scope: [:activerecord, :attributes, :travel])
span.text-primary.p-lg
| (必須)
br
= f.date_field :start_date, { class: "form-control-select" }
| 〜
= f.date_field :end_date, { class: "form-control-select" }
= f.date_field :start_date, { class: "form-control-select", required: 'required' }
| 〜
= f.date_field :end_date, { class: "form-control-select", required: 'required' }
.form-group
= f.label :memo
br
Expand Down
3 changes: 2 additions & 1 deletion app/views/travels/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ section.page-block.double-padding-top.double-space-bottom
= link_to schedule_route_path(schedule, route), method: :delete, data: { confirm: '削除します。宜しいですか?' }, title: '削除' do
i.fa.fa-trash-o
h5.timeline-title
= create_route_title_from_schedules(travel_date.schedules, i)
strong.text-primary
= create_route_title_from_schedules(travel_date.schedules, i)
.timeline-body
= simple_format(route.detail)
li
Expand Down
10 changes: 7 additions & 3 deletions app/views/users/_photo_service_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
h3.heading.center
| 写真サービス 連携設定
span
= form_for(@user) do |f|
= form_for(@user, html: { id: 'user_form' }) do |f|
- if @user.errors.any?
= render partial: 'form_error_header', locals: { error_messages: @user.errors.full_messages }
= f.fields_for(:photo_service_user_info) do |f_photo|
.form-group
= f_photo.label :service_type
span.text-primary.p-lg
| (必須)
br
= f_photo.select :service_type, PhotoServiceUserInfo.service_types.keys, {}, { class: "form-control-select", prompt: 'Please select' }
= f_photo.select :service_type, PhotoServiceUserInfo.service_types.keys, {}, { class: "form-control-select", prompt: 'Please select', required: 'required' }
.form-group
= f_photo.label :photo_service_user_id
span.text-primary.p-lg
| (必須)
br
= f_photo.text_field :photo_service_user_id, class: "form-control"
= f_photo.text_field :photo_service_user_id, class: "form-control", required: 'required'
.col-md-12.col-sm-12
.text-center
= f.submit class: "btn btn-md btn-primary", value: '更新', data: { disable_with: "Please wait..." }
2 changes: 2 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ ja:
urls: HP
travel:
name: 名前
start_date: 開始日
end_date: 終了日
memo: メモ
shcedule: スケジュール
user:
Expand Down