Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / options / autofill_edit_creditcard_overlay.js
index 4458ecc..d3e82cb 100644 (file)
@@ -110,15 +110,10 @@ cr.define('options', function() {
       var expirationMonth = $('expiration-month');
       expirationMonth.options.length = 0;
       for (var i = 1; i <= 12; ++i) {
-        var text;
-        if (i < 10)
-          text = '0' + i;
-        else
-          text = i;
+        var text = (i < 10 ? '0' : '') + i;
 
         var option = document.createElement('option');
-        option.text = text;
-        option.value = text;
+        option.text = option.value = text;
         expirationMonth.add(option, null);
       }
 
@@ -127,11 +122,11 @@ cr.define('options', function() {
       expirationYear.options.length = 0;
 
       var date = new Date();
-      var year = parseInt(date.getFullYear());
+      var year = parseInt(date.getFullYear(), 10);
       for (var i = 0; i < 10; ++i) {
         var text = year + i;
         var option = document.createElement('option');
-        option.text = text;
+        option.text = String(text);
         option.value = text;
         expirationYear.add(option, null);
       }
@@ -153,6 +148,7 @@ cr.define('options', function() {
 
     /**
      * Sets the value of each input field according to |creditCard|
+     * @param {CreditCardData} creditCard
      * @private
      */
     setInputFields_: function(creditCard) {
@@ -168,9 +164,9 @@ cr.define('options', function() {
       var idx = parseInt(creditCard.expirationMonth, 10);
       $('expiration-month').selectedIndex = idx - 1;
 
-      expYear = creditCard.expirationYear;
+      var expYear = creditCard.expirationYear;
       var date = new Date();
-      var year = parseInt(date.getFullYear());
+      var year = parseInt(date.getFullYear(), 10);
       for (var i = 0; i < 10; ++i) {
         var text = year + i;
         if (expYear == String(text))
@@ -179,8 +175,18 @@ cr.define('options', function() {
     },
 
     /**
+     * Called to prepare the overlay when a new card is being added.
+     * @private
+     */
+    prepForNewCard_: function() {
+      // Focus the first element.
+      this.pageDiv.querySelector('input').focus();
+    },
+
+    /**
      * Loads the credit card data from |creditCard|, sets the input fields based
      * on this data and stores the GUID of the credit card.
+     * @param {CreditCardData} creditCard
      * @private
      */
     loadCreditCard_: function(creditCard) {
@@ -190,6 +196,10 @@ cr.define('options', function() {
     },
   };
 
+  AutofillEditCreditCardOverlay.prepForNewCard = function() {
+    AutofillEditCreditCardOverlay.getInstance().prepForNewCard_();
+  };
+
   AutofillEditCreditCardOverlay.loadCreditCard = function(creditCard) {
     AutofillEditCreditCardOverlay.getInstance().loadCreditCard_(creditCard);
   };