Calendar Klasse überarbeitet Views,gefixt, Pictures hinzugefügt

This commit is contained in:
Andreas Stephanides
2013-08-11 01:17:37 +02:00
parent 116446ff63
commit a5a02e065a
17 changed files with 238 additions and 67 deletions

View File

@@ -10,7 +10,7 @@
*
*= require_self
*= require_tree .
* require 'bootstrap'
*= require 'bootstrap'
*/
$linkColor: #03006E;
@import 'bootstrap';

View File

@@ -3,7 +3,6 @@ class CalendarsController < ApplicationController
# GET /calendars.json
def index
@calendars = Calendar.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @calendars }
@@ -18,6 +17,7 @@ class CalendarsController < ApplicationController
respond_to do |format|
format.html # show.html.erb
format.json { render json: @calendar }
format.ics { render 'show.ics.erb'}
end
end

View File

@@ -1,6 +1,7 @@
class DateStringInput < FormtasticBootstrap::Inputs::StringInput
def input_html_options
super.merge(:class => "datetext", :onclick =>"beep", :value=>I18n.l(@object.send(method.to_sym)))
value = (@object.send(method.to_sym))
super.merge(:class => "datetext", :onclick =>"beep", :value=>I18n.l((value.is_a?(Time)||value.is_a?(Date)||value.is_a?(DateTime)) ? value : Time.now))
end
end

View File

@@ -1,4 +1,5 @@
class Calendar < ActiveRecord::Base
attr_accessible :name, :public
attr_accessible :name, :public, :picture
has_and_belongs_to_many :calentries
mount_uploader :picture, PictureUploader
end

View File

@@ -1,6 +1,13 @@
class Calentry < ActiveRecord::Base
attr_accessible :ende, :start, :summary, :typ,:calendar_ids
has_and_belongs_to_many :calendar
has_and_belongs_to_many :calendars
validates :start, :presence => true
validates :typ, :presence => true
validate do |entry|
if entry.ende.nil?
errors.add(:ende, "Es muss ein Endzeitpunkt vorhanden sein")
end
end
def start_time
start
end

View File

@@ -0,0 +1,51 @@
# encoding: utf-8
class PictureUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fill => [64, 64]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end

View File

@@ -2,6 +2,7 @@
<%= f.inputs do %>
<%= f.input :name %>
<%= f.input :public %>
<%= f.input :picture, :as => :file %>
<% end %>
<%= f.actions do %>

View File

@@ -1,25 +1,14 @@
<h1>Listing calendars</h1>
<table>
<tr>
<th>Name</th>
<th>Public</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @calendars.each do |calendar| %>
<tr>
<td><%= calendar.name %></td>
<td><%= calendar.public %></td>
<td><%= link_to 'Show', calendar %></td>
<td><%= link_to 'Edit', edit_calendar_path(calendar) %></td>
<td><%= link_to 'Destroy', calendar, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<div class="media">
<a class="pull-left" href="#">
<img class="media-object img-circle" src="<%= calendar.picture.thumb.url %>"/>
</a>
<div class="media-body">
<h4><%= link_to calendar.name, calendar %></h4>
</div>
</div>
<% end %>
</table>
<br />
<%= link_to 'New Calendar', new_calendar_path %>

View File

@@ -1,24 +1,30 @@
<div class="container-fluid">
<div class="row-fluid">
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @calendar.name %>
</p>
<p>
<b>Public:</b>
<%= @calendar.public %>
</p>
<p>
<ul>
<h1>
<%= '<i class="icon-globe"></i>'.html_safe unless !@calendar.public%>
<%= @calendar.name %>
</h1>
<div class="row-fluid">
<ul class="list-group">
<% @calendar.calentries.each do |entry| %>
<%= entry.summary+ "- " + entry.start.to_s %>
<li class="list-group-item">
<%= link_to entry.summary+ " - " + I18n.l(entry.start), entry %>
</li>
<% end %>
</ul>
</div>
<div class="row-fluid">
<%= calendar @calendar.calentries do |entry| %>
<div><%= link_to entry.name, entry %></div>
<% end %>
<%= link_to 'New Entry', new_calentry_path %>
<%= link_to 'Edit', edit_calendar_path(@calendar) %> |
<%= link_to 'Back', calendars_path %>
</div>
<div class="row-fluid">
<div class="btn-group">
<%= link_to 'New Entry', new_calentry_path, {:class=>"btn"} %>
<%= link_to 'Edit', edit_calendar_path(@calendar), {:class=>"btn"} %>
<%= link_to 'Back', calendars_path, {:class=>"btn"} %>
</div>
</div>
</div>

View File

@@ -0,0 +1,3 @@
<% @calendar.calentries.each do |entry| %>
<%= render entry %>
<% end %>

View File

@@ -0,0 +1,5 @@
<%= calentry.start %>
<%= calentry.ende %>
<%= calentry.summary %>
<%= calentry.typ %>

View File

@@ -1,13 +1,34 @@
<div class="container-fluid">
<%= semantic_form_for @calentry do |f| %>
<%= f.inputs do %>
<div class="row-fluid">
<div class="span6">
<%= f.input :start , :as => :date_string %>
<%= f.input :ende %>
</div>
<div class="span6">
<%= f.input :ende , :as => :date_string %>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<%= f.input :summary %>
<%= f.input :calendar, :as=> :radio %>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<%= f.input :calendars, :as=> :radio %>
</div>
<div class="span6">
<%= f.input :typ %>
</div>
</div>
<% end %>
<div class="row-fluid">
<div class="span12">
<%= f.actions do %>
<%= f.action :submit, :as => :input %>
<% end %>
</div>
</div>
<% end %>
</div>

View File

@@ -1,25 +1,25 @@
<p id="notice"><%= notice %></p>
<p>
<b>Start:</b>
<%= @calentry.start %>
</p>
<p>
<b>Ende:</b>
<%= @calentry.ende %>
</p>
<p>
<b>Summary:</b>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<b>
<%= @calentry.summary %>
</p>
</b>
<p>
<b>Typ:</b>
</div>
</div>
<div class="row-fluid">
<div class="span9">
<%= I18n.l @calentry.start %>
<%= " bis " unless @calentry.ende.nil? %>
<%= I18n.l @calentry.ende %>
</div>
<div class="span3">
<%= @calentry.typ %>
</p>
</div></div>
<div class="row-fluid">
<div class="span12">
<%= link_to 'Edit', edit_calentry_path(@calentry) %> |
<%= link_to 'Back', calentries_path %>
</div></div></div>