import Ember from 'ember';

export default Ember.TextField.extend({
  classNames: 'ui-dollar-input',
  cents: null,

  value: function(key, value) {
    var cents;
    var dollars;

    if (arguments.length === 1) {
      cents = this.get('cents');

      if (cents) {
        return (cents / 100).toFixed(2);
      } else {
        return '0.00';
      }
    } else {
      dollars = parseFloat(value, 10);

      if (isNaN(dollars) || Ember.isNone(dollars)) {
        cents = 0;
        dollars = 0;
      } else {
        cents = (dollars * 100).toFixed(0);
      }

      this.set('cents', cents);

      return dollars.toFixed(2);
    }
  }.property('cents')
});

@@ -116,36 +116,31 @@
 %0A%0A  
-value: function(key, value) 
+blurHandler: function()
 %7B%0A  
@@ -173,198 +173,40 @@
 rs;%0A
-%0A
     
-if (arguments.length === 1) %7B%0A      cents = this.get('cents');%0A%0A      if (cents) %7B%0A        return (cents / 100).toFixed(2);%0A      %7D else %7B%0A        return '0.00';%0A      %7D%0A    %7D else %7B%0A  
+var value = this.$().val();%0A
     
@@ -235,26 +235,24 @@
 alue, 10);%0A%0A
-  
     if (isNa
@@ -288,34 +288,32 @@
 llars)) %7B%0A      
-  
 cents = 0;%0A     
@@ -303,26 +303,24 @@
  cents = 0;%0A
-  
       dollar
@@ -322,26 +322,24 @@
 ollars = 0;%0A
-  
     %7D else %7B
@@ -341,26 +341,24 @@
 lse %7B%0A      
-  
 cents = (dol
@@ -389,15 +389,11 @@
     
-  
 %7D%0A%0A
-  
     
@@ -422,21 +422,29 @@
 s);%0A
-%0A  
     
-return
+this.set('value',
  dol
@@ -458,16 +458,198 @@
 Fixed(2)
+);%0A  %7D.on('focusOut'),%0A%0A  value: function() %7B%0A    var cents;%0A%0A    cents = this.get('cents');%0A%0A    if (cents) %7B%0A      return (cents / 100).toFixed(2);%0A    %7D else %7B%0A      return '0.00'
 ;%0A    %7D%0A

fix ui dollar input component