mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Changed the method of specifying a date to one using form options. By default, a blank date (which returns NULL) is selected. The due date is still _displayed_ in your chosen date format (from settings.yml).
This seems a more robust method, and is much simpler to use. The month is given as a name rather than a number, so it's obvious what should be entered. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@17 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
3fe9326322
commit
14298d1787
8 changed files with 15 additions and 37 deletions
|
|
@ -16,4 +16,13 @@ class ApplicationController < ActionController::Base
|
|||
helper :application
|
||||
include LoginSystem
|
||||
|
||||
|
||||
# Convert a date entered in the format in settings.yml
|
||||
# to database-compatible YYYY-MM-DD format
|
||||
def date_to_YMD(date)
|
||||
date_fmt = app_configurations["formats"]["date"]
|
||||
formatted_date = DateTime.strptime(date, "#{date_fmt}")
|
||||
formatted_date.strftime("%Y-%m-%d")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -55,16 +55,6 @@ class ContextController < ApplicationController
|
|||
item = Todo.new
|
||||
item.attributes = @params["new_item"]
|
||||
|
||||
# Convert the date format entered (as set in config/settings.yml)
|
||||
# to the mysql format YYYY-MM-DD
|
||||
if @params["new_item"]["due"] != ""
|
||||
date_fmt = app_configurations["formats"]["date"]
|
||||
formatted_date = DateTime.strptime(@params["new_item"]["due"], "#{date_fmt}")
|
||||
item.due = formatted_date.strftime("%Y-%m-%d")
|
||||
else
|
||||
item.due = "0000-00-00"
|
||||
end
|
||||
|
||||
back_to = item.context_id
|
||||
|
||||
if item.save
|
||||
|
|
|
|||
|
|
@ -54,16 +54,6 @@ class ProjectController < ApplicationController
|
|||
item = Todo.new
|
||||
item.attributes = @params["new_item"]
|
||||
|
||||
# Convert the date format entered (as set in config/settings.yml)
|
||||
# to the mysql format YYYY-MM-DD
|
||||
if @params["new_item"]["due"] != ""
|
||||
date_fmt = app_configurations["formats"]["date"]
|
||||
formatted_date = DateTime.strptime(@params["new_item"]["due"], "#{date_fmt}")
|
||||
item.due = formatted_date.strftime("%Y-%m-%d")
|
||||
else
|
||||
item.due = "0000-00-00"
|
||||
end
|
||||
|
||||
back_to = item.project_id
|
||||
|
||||
if item.save
|
||||
|
|
|
|||
|
|
@ -36,16 +36,6 @@ class TodoController < ApplicationController
|
|||
@item = Todo.new
|
||||
@item.attributes = @params["item"]
|
||||
|
||||
# Convert the date format entered (as set in config/settings.yml)
|
||||
# to the mysql format YYYY-MM-DD
|
||||
if @params["item"]["due"] != ""
|
||||
date_fmt = app_configurations["formats"]["date"]
|
||||
formatted_date = DateTime.strptime(@params["item"]["due"], "#{date_fmt}")
|
||||
@item.due = formatted_date.strftime("%Y-%m-%d")
|
||||
else
|
||||
@item.due = "0000-00-00"
|
||||
end
|
||||
|
||||
if @item.save
|
||||
flash["confirmation"] = "Next action was successfully added"
|
||||
redirect_to( :action => "list" )
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
# The methods added to this helper will be available to all templates in the application.
|
||||
module ApplicationHelper
|
||||
|
||||
def format_date(date)
|
||||
# Convert a date object to the format specified
|
||||
# in config/settings.yml
|
||||
#
|
||||
def format_date(date)
|
||||
date_fmt = app_configurations["formats"]["date"]
|
||||
formatted_date = date.strftime("#{date_fmt}")
|
||||
end
|
||||
|
||||
|
||||
# Uses RedCloth to transform text using either Textile or Markdown
|
||||
# Need to require redcloth above
|
||||
# RedCloth 3.0 or greater is needed to use Markdown, otherwise it only handles Textile
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
<%= options_from_collection_for_select(@projects, "id", "name" ) %>
|
||||
</select><br />
|
||||
<label for="new_item_due">Due</label><br />
|
||||
<%= text_field( "new_item", "due", {"size" => 10, "maxlength" => 10} ) %>
|
||||
<%= date_select( "new_item", "due", :include_blank => true ) %>
|
||||
<br />
|
||||
<input type="submit" value="Add item">
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
</select>
|
||||
<br />
|
||||
<label for="new_item_due">Due</label><br />
|
||||
<%= text_field( "new_item", "due", {"size" => 10, "maxlength" => 10} ) %>
|
||||
<%= date_select( "new_item", "due", :include_blank => true ) %>
|
||||
<br />
|
||||
<input type="submit" value="Add item">
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -36,5 +36,5 @@
|
|||
</select>
|
||||
<br />
|
||||
<label for="item_due">Due</label><br />
|
||||
<%= text_field( "item", "due", {"size" => 10, "maxlength" => 10} ) %>
|
||||
<%= date_select( "item", "due", :include_blank => true ) %>
|
||||
<br />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue