BOM: change datetimepickers to datepickers

This commit is contained in:
Rob H
2014-04-10 10:51:55 +10:00
parent c5d5f5a9e6
commit 645b6d5a8f
5 changed files with 32 additions and 12 deletions

View File

@@ -341,10 +341,13 @@ formatDate = (date) ->
year = date.getFullYear()
month = twoDigitNumber date.getMonth() + 1
day = twoDigitNumber date.getDate()
return year + "-" + month + "-" + day
formatTime = (date) ->
hours = twoDigitNumber date.getHours()
mins = twoDigitNumber date.getMinutes()
secs = twoDigitNumber date.getSeconds()
return year + "-" + month + "-" + day + " " + hours + ":" + mins + ":" + secs
return hours + ":" + mins + ":" + secs
twoDigitNumber = (number) ->
twoDigits = "" + number

View File

@@ -12,6 +12,16 @@ sharedDirectivesModule.directive "datetimepicker", ->
# Fires ngModel.$parsers
ngModel.$setViewValue dateText
sharedDirectivesModule.directive "datepicker", ->
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
element.datepicker
dateFormat: "yy-mm-dd"
onSelect: (dateText, inst) ->
scope.$apply (scope) ->
# Fires ngModel.$parsers
ngModel.$setViewValue dateText
sharedDirectivesModule.directive "ofnSelect2MinSearch", [
->
return (

View File

@@ -7,14 +7,14 @@
%div{ 'ng-show' => '!spree_api_key_ok' }
{{ api_error_msg }}
.filters{ :class => "sixteen columns alpha" }
.date_filter{ :class => "three columns alpha" }
.date_filter{ :class => "two columns alpha" }
%label{ :for => 'start_date_filter' }Start Date
%br
%input{ :class => "three columns alpha", :type => "text", :id => 'start_date_filter', 'ng-model' => 'startDate', 'datetimepicker' => "startDate", 'ofn-confirm-change' => "startDate" }
.date_filter{ :class => "three columns omega" }
%input{ :class => "two columns alpha", :type => "text", :id => 'start_date_filter', 'ng-model' => 'startDate', 'datepicker' => "startDate", 'ofn-confirm-change' => "startDate" }
.date_filter{ :class => "two columns omega" }
%label{ :for => 'end_date_filter' }End Date
%br
%input{ :class => "three columns alpha", :type => "text", :id => 'end_date_filter', 'ng-model' => 'endDate', 'datetimepicker' => "endDate", 'ofn-confirm-change' => "endDate" }
%input{ :class => "two columns alpha", :type => "text", :id => 'end_date_filter', 'ng-model' => 'endDate', 'datepicker' => "endDate", 'ofn-confirm-change' => "endDate" }
.one.column.omega  
.filter_select{ :class => "three columns omega" }
%label{ :for => 'supplier_filter' }Producer

View File

@@ -326,8 +326,8 @@ feature %q{
end
it "displays date fields for filtering orders, with default values set" do
one_week_ago = Date.today.prev_day(7).strftime("%F %T")
tonight = Date.tomorrow.strftime("%F %T")
one_week_ago = Date.today.prev_day(7).strftime("%F")
tonight = Date.tomorrow.strftime("%F")
page.should have_field "start_date_filter", with: one_week_ago
page.should have_field "end_date_filter", with: tonight
end
@@ -339,12 +339,12 @@ feature %q{
end
it "displays only line items whose orders meet the date restriction criteria, when changed" do
fill_in "start_date_filter", :with => (Date.today - 9).strftime("%F %T")
fill_in "start_date_filter", :with => (Date.today - 9).strftime("%F")
page.should have_selector "tr#li_#{li1.id}", visible: true
page.should have_selector "tr#li_#{li2.id}", visible: true
page.should_not have_selector "tr#li_#{li3.id}", visible: true
fill_in "end_date_filter", :with => (Date.today + 3).strftime("%F %T")
fill_in "end_date_filter", :with => (Date.today + 3).strftime("%F")
page.should have_selector "tr#li_#{li1.id}", visible: true
page.should have_selector "tr#li_#{li2.id}", visible: true
page.should have_selector "tr#li_#{li3.id}", visible: true

View File

@@ -609,8 +609,10 @@ describe "Auxiliary functions", ->
expect(twoDigitNumber(1)).toEqual "01"
expect(twoDigitNumber(9)).toEqual "09"
describe "formatting a date", ->
it "returns a date formatted as yyyy-mm-dd hh-MM:ss", ->
describe "formatting dates and times", ->
date = null
beforeEach ->
date = new Date
date.setYear(2010)
date.setMonth(5) # Zero indexed, so 5 is June
@@ -618,4 +620,9 @@ describe "Auxiliary functions", ->
date.setHours(5)
date.setMinutes(10)
date.setSeconds(30)
expect(formatDate(date)).toEqual "2010-06-15 05:10:30"
it "returns a date formatted as yyyy-mm-dd", ->
expect(formatDate(date)).toEqual "2010-06-15"
it "returns a time formatted as hh-MM:ss", ->
expect(formatTime(date)).toEqual "05:10:30"