diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index cde82533..fec00457 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -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 \ No newline at end of file diff --git a/tracks/app/controllers/context_controller.rb b/tracks/app/controllers/context_controller.rb index 97289d30..56e6cc0d 100644 --- a/tracks/app/controllers/context_controller.rb +++ b/tracks/app/controllers/context_controller.rb @@ -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 diff --git a/tracks/app/controllers/project_controller.rb b/tracks/app/controllers/project_controller.rb index 5e058157..b38911e3 100644 --- a/tracks/app/controllers/project_controller.rb +++ b/tracks/app/controllers/project_controller.rb @@ -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 diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index c9854c2e..7a9b98b2 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -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" ) diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index 689810bd..b350c528 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -1,15 +1,14 @@ # The methods added to this helper will be available to all templates in the application. module ApplicationHelper + # Convert a date object to the format specified + # in config/settings.yml + # def format_date(date) - # Convert a date object to the format specified - # in config/settings.yml - # 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 diff --git a/tracks/app/views/context/show.rhtml b/tracks/app/views/context/show.rhtml index 1a8512eb..d3d5f6cc 100644 --- a/tracks/app/views/context/show.rhtml +++ b/tracks/app/views/context/show.rhtml @@ -24,7 +24,7 @@ <%= options_from_collection_for_select(@projects, "id", "name" ) %>

- <%= text_field( "new_item", "due", {"size" => 10, "maxlength" => 10} ) %> + <%= date_select( "new_item", "due", :include_blank => true ) %>
diff --git a/tracks/app/views/project/show.rhtml b/tracks/app/views/project/show.rhtml index 3dd1c70b..146c58be 100644 --- a/tracks/app/views/project/show.rhtml +++ b/tracks/app/views/project/show.rhtml @@ -31,7 +31,7 @@

- <%= text_field( "new_item", "due", {"size" => 10, "maxlength" => 10} ) %> + <%= date_select( "new_item", "due", :include_blank => true ) %>
diff --git a/tracks/app/views/todo/_item.rhtml b/tracks/app/views/todo/_item.rhtml index 2450abfa..bd12a8b9 100644 --- a/tracks/app/views/todo/_item.rhtml +++ b/tracks/app/views/todo/_item.rhtml @@ -36,5 +36,5 @@

-<%= text_field( "item", "due", {"size" => 10, "maxlength" => 10} ) %> +<%= date_select( "item", "due", :include_blank => true ) %>