Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatted date #1638

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ module.exports = function(grunt) {
var done = this.async();
grunt.util.spawn({
cmd: 'npm',
args: ['install', '--save-dev', 'git+https://github.com/balanced/balanced-admin.git']
args: ['install', '--save-dev', 'balanced/balanced-admin']
}, function(err) {
if (err) {
grunt.log.error(err);
Expand Down
7 changes: 7 additions & 0 deletions app/models/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ var Customer = Model.extend(Ember.Validations, {
return addressParts.join(seperator);
}.property('address.line1', 'address.line2', 'address.city', 'address.state', 'address.postal_code', 'address.country_code'),

formattedDateOfBirth: Ember.computed("dob_month", "dob_year", function() {
var month = this.get('dob_month') || "";
var year = this.get('dob_year') || "";
var pattern = month < 10 ? "0%@ / %@" : "%@ / %@";
return pattern.fmt(month, year);
}),

dob: function() {
var month = this.get('dob_month');
var year = this.get('dob_year');
Expand Down
6 changes: 6 additions & 0 deletions app/templates/form-fields/month-year-input-form-field.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{formatted-month-year-input
viewName="inputElement"
name=view.inputName
value=view.value
class=view.inputClassNames
}}
5 changes: 3 additions & 2 deletions app/templates/modals/customer-info-modal.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{#view "form-fields/form-section" model=view.model sectionTitle="Customer information"}}
{{view.model.name}}
{{view "form-fields/text-form-field"
model=view.model
labelText="Name"
Expand Down Expand Up @@ -65,13 +64,15 @@
labelText="Phone number"
field="phone"
}}
{{view "form-fields/month-year-select-form-field"

{{view "form-fields/month-year-input-form-field"
model=view.model
monthValue=view.model.dob_month
yearValue=view.model.dob_year
labelText="Date of birth"
name="dob"
}}

{{view "form-fields/text-form-field"
model=view.model
labelText="Last 4 of SSN"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var CustomerTitledKeyValuesSectionView = TitledKeyValuesSectionView.extend({
.add("Postal code", "address.postal_code")
.add("Country", "country_name")
.add("Phone number", "phone")
.add("Date of birth", "dob")
.add("Date of birth", "formattedDateOfBirth")
.add("SSN", "ssn_last4")
.add("Country", "country_name")
.add("Facebook ID", "facebook_id", "facebook_url")
Expand Down
6 changes: 5 additions & 1 deletion app/views/form-fields/base-form-field.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ BaseFormFieldView = Ember.View.extend
templateName: "form-fields/base-form-field"
classNameBindings: [":form-group", "isError:has-error"]
inputName: Ember.computed "field", ->
@get("field").replace(/\./, "_")
value = @get("field")
if Ember.isBlank(value)
return undefined
else
return value.replace(/\./, "_")

value: Ember.computed "model", "field", (a, value) ->
model = @get("model")
Expand Down
2 changes: 1 addition & 1 deletion app/views/form-fields/country-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var CountrySelectView = SelectFormFieldView.extend({
content: Ember.computed(function() {
var result = [{
name: "",
code: ""
code: null
}];
return result.concat(CountryCodes);
}),
Expand Down
37 changes: 37 additions & 0 deletions app/views/form-fields/month-year-input-form-field.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
`import BaseFormField from "./base-form-field";`

DATE_FORMAT = /^(\d\d) [\/-] (\d\d\d\d)$/

FormFieldView = BaseFormField.extend(
templateName: "form-fields/month-year-input-form-field"

value: Ember.computed "monthValue", "yearValue", (attrName, val) ->
if arguments.length > 1
@setValue(val)
@getValue @get("monthValue"), @get("yearValue")

getValue: (month, year) ->
if month && year
if month < 10
return "0#{month} / #{year}"
else
return "#{month} / #{year}"
else
return ""

setValue: (val) ->
month = null
year = null
if !Ember.isBlank(val)
match = val.match(DATE_FORMAT)
if match
month = match[1]
year = match[2]

@setProperties(
monthValue: month
yearValue: year
)
)

`export default FormFieldView;`