diff --git a/Gruntfile.js b/Gruntfile.js index 820b59c0d..d55061249 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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); diff --git a/app/models/customer.js b/app/models/customer.js index 23e66b615..f5abbf40b 100644 --- a/app/models/customer.js +++ b/app/models/customer.js @@ -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'); diff --git a/app/templates/form-fields/month-year-input-form-field.hbs b/app/templates/form-fields/month-year-input-form-field.hbs new file mode 100644 index 000000000..9977c92c9 --- /dev/null +++ b/app/templates/form-fields/month-year-input-form-field.hbs @@ -0,0 +1,6 @@ +{{formatted-month-year-input + viewName="inputElement" + name=view.inputName + value=view.value + class=view.inputClassNames +}} diff --git a/app/templates/modals/customer-info-modal.hbs b/app/templates/modals/customer-info-modal.hbs index 413474404..31661a7e2 100644 --- a/app/templates/modals/customer-info-modal.hbs +++ b/app/templates/modals/customer-info-modal.hbs @@ -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" @@ -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" diff --git a/app/views/detail-views/description-lists/customer-titled-key-values-section.js b/app/views/detail-views/description-lists/customer-titled-key-values-section.js index ab9210b5d..0ce263f0d 100644 --- a/app/views/detail-views/description-lists/customer-titled-key-values-section.js +++ b/app/views/detail-views/description-lists/customer-titled-key-values-section.js @@ -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") diff --git a/app/views/form-fields/base-form-field.coffee b/app/views/form-fields/base-form-field.coffee index dabc05125..bd92b762f 100644 --- a/app/views/form-fields/base-form-field.coffee +++ b/app/views/form-fields/base-form-field.coffee @@ -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") diff --git a/app/views/form-fields/country-select.js b/app/views/form-fields/country-select.js index 107ed53d2..9b3152a6a 100644 --- a/app/views/form-fields/country-select.js +++ b/app/views/form-fields/country-select.js @@ -6,7 +6,7 @@ var CountrySelectView = SelectFormFieldView.extend({ content: Ember.computed(function() { var result = [{ name: "", - code: "" + code: null }]; return result.concat(CountryCodes); }), diff --git a/app/views/form-fields/month-year-input-form-field.coffee b/app/views/form-fields/month-year-input-form-field.coffee new file mode 100644 index 000000000..61e6c76e4 --- /dev/null +++ b/app/views/form-fields/month-year-input-form-field.coffee @@ -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;`