Skip to content
This repository
Browse code

Extract an input field for DateTime

  • Loading branch information...
commit b191bad2b4a14e00eda135b642282d0f2b6df5d3 1 parent 8c2b097
Stefan Kanev authored November 08, 2012
17  app/inputs/date_time_input.rb
... ...
@@ -0,0 +1,17 @@
  1
+# encoding: utf-8
  2
+class DateTimeInput < SimpleForm::Inputs::Base
  3
+  FORMAT = '%Y-%m-%d %H:%M:%S'
  4
+
  5
+  def input
  6
+    timestamp = @builder.object.send(attribute_name)
  7
+    formatted = timestamp.try(:strftime, FORMAT)
  8
+
  9
+    options[:hint] = 1.week.from_now.strftime "Формат: #{FORMAT}"
  10
+
  11
+    input_html_classes.unshift 'string'
  12
+    input_html_options[:type] = :string
  13
+    input_html_options[:value] = formatted
  14
+
  15
+    @builder.text_field attribute_name, input_html_options
  16
+  end
  17
+end
2  app/views/challenges/_form.html.haml
... ...
@@ -1,3 +1,3 @@
1 1
 = form.input :name
2 2
 = form.input :description
3  
-= form.input :closes_at, as: :string, input_html: {value: @challenge.closes_at.try(:strftime, '%Y-%m-%d %H:%M:%S')}
  3
+= form.input :closes_at, as: :date_time
6  app/views/challenges/index.html.haml
... ...
@@ -1,5 +1,9 @@
1 1
 %h1 Предизвиксателства
  2
+= admin_only do
  3
+  = link_to 'Ново', new_challenge_path, class: :action
2 4
 
3 5
 %ul
4 6
   - @challenges.each do |challenge|
5  
-    %li= link_to challenge.name, challenge
  7
+    %li
  8
+      = link_to challenge.name, challenge
  9
+      (краен срок: #{l(challenge.closes_at)})
1  app/views/layouts/application.html.haml
@@ -31,6 +31,7 @@
31 31
         %li= link_to 'Новини', announcements_path
32 32
         %li= link_to 'Материали', lectures_path
33 33
         %li= link_to 'Задачи', tasks_path
  34
+        %li= link_to 'Предизвикателства', challenges_path
34 35
         %li= link_to 'Форуми', topics_path
35 36
         %li= link_to 'Потребители', users_path
36 37
         - if admin?
2  app/views/tasks/_form.html.haml
... ...
@@ -1,6 +1,6 @@
1 1
 = simple_form_for task do |form|
2 2
   = form.input :name
3  
-  = form.input :closes_at, as: :string, input_html: {value: task.closes_at.try(:strftime, '%Y-%m-%d %H:%M:%S')}
  3
+  = form.input :closes_at, as: :date_time
4 4
   = form.input :checked
5 5
   = form.input :description
6 6
   = form.input :test_case
2  config/locales/bg.yml
@@ -21,8 +21,6 @@ bg:
21 21
         phone: Не е публичен; ползваме го само в краен случай
22 22
         site: Ако имате такъв; не забравяйте да укажете протокол (например http://)
23 23
         about: Ако искате
24  
-      task:
25  
-        closes_at: 'Формат: 2011-03-31 13:20:45'
26 24
   helpers:
27 25
     submit:
28 26
       reply:

0 notes on commit b191bad

Please sign in to comment.
Something went wrong with that request. Please try again.