Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / chromeos / login / screen_locally_managed_user_creation.js
index d6f318a..5fd61df 100644 (file)
@@ -37,6 +37,7 @@ login.createScreen('LocallyManagedUserCreationScreen',
                             this.handleMouseDown_.bind(this));
       var screen = $('managed-user-creation');
       var managerPod = this;
+      var managerPodList = screen.managerList_;
       var hideManagerPasswordError = function(element) {
         managerPod.passwordElement.classList.remove('password-error');
         $('bubble').hide();
@@ -50,6 +51,19 @@ login.createScreen('LocallyManagedUserCreationScreen',
             screen.getScreenButton('next').focus();
           },
           hideManagerPasswordError);
+
+      this.passwordElement.addEventListener('keydown', function(e) {
+        switch (e.keyIdentifier) {
+          case 'Up':
+            managerPodList.selectNextPod(-1);
+            e.stopPropagation();
+            break;
+          case 'Down':
+            managerPodList.selectNextPod(+1);
+            e.stopPropagation();
+            break;
+        }
+      });
     },
 
     /**
@@ -196,6 +210,31 @@ login.createScreen('LocallyManagedUserCreationScreen',
       chrome.send('managerSelectedOnLocallyManagedUserCreationFlow',
           [podToSelect.user.username]);
     },
+
+    /**
+     * Select pod next to currently selected one in given |direction|.
+     * @param {integer} direction - +1 for selecting pod below current, -1 for
+     *     selecting pod above current.
+     * @type {boolean} returns if selected pod has changed.
+     */
+    selectNextPod: function(direction) {
+      if (!this.selectedPod_)
+        return false;
+      var index = -1;
+      for (var i = 0, pod; pod = this.pods[i]; ++i) {
+        if (pod == this.selectedPod_) {
+          index = i;
+          break;
+        }
+      }
+      if (-1 == index)
+        return false;
+      index = index + direction;
+      if (index < 0 || index >= this.pods.length)
+        return false;
+      this.selectPod(this.pods[index]);
+      return true;
+    }
   };
 
   var ImportPod = cr.ui.define(function() {
@@ -485,6 +524,7 @@ login.createScreen('LocallyManagedUserCreationScreen',
 
       imageGrid.previewElement = previewElement;
       imageGrid.selectionType = 'default';
+      imageGrid.flipPhotoElement = this.getScreenElement('flip-photo');
 
       imageGrid.addEventListener('activate',
                                  this.handleActivate_.bind(this));
@@ -951,11 +991,15 @@ login.createScreen('LocallyManagedUserCreationScreen',
         this.setButtonDisabledStatus('import', !passwordOk);
         return passwordOk;
       }
+      var imageGrid = this.getScreenElement('image-grid');
+      var imageChosen = !(imageGrid.selectionType == 'camera' &&
+                          imageGrid.cameraLive);
       var canProceed =
           passwordOk &&
           (userName.length > 0) &&
-           this.lastVerifiedName_ &&
-           (userName == this.lastVerifiedName_);
+          this.lastVerifiedName_ &&
+          (userName == this.lastVerifiedName_) &&
+          imageChosen;
 
       this.setButtonDisabledStatus('next', !canProceed);
       return canProceed;
@@ -1014,9 +1058,9 @@ login.createScreen('LocallyManagedUserCreationScreen',
 
       var pagesWithCancel = ['intro', 'manager', 'username', 'import-password',
           'error', 'import'];
-      var cancelButton = $('cancel-add-user-button');
-      cancelButton.hidden = pagesWithCancel.indexOf(visiblePage) < 0;
-      cancelButton.disabled = false;
+      $('login-header-bar').allowCancel =
+          pagesWithCancel.indexOf(visiblePage) > 0;
+      $('cancel-add-user-button').disabled = false;
 
       this.getScreenElement('import-link').hidden = true;
       this.getScreenElement('create-link').hidden = true;
@@ -1028,8 +1072,7 @@ login.createScreen('LocallyManagedUserCreationScreen',
 
       if (visiblePage == 'manager' || visiblePage == 'intro') {
         $('managed-user-creation-password').classList.remove('password-error');
-        this.managerList_.selectPod(null);
-        if (this.managerList_.pods.length == 1)
+        if (this.managerList_.pods.length > 0)
           this.managerList_.selectPod(this.managerList_.pods[0]);
       }
 
@@ -1222,7 +1265,7 @@ login.createScreen('LocallyManagedUserCreationScreen',
       this.managerList_.clearPods();
       for (var i = 0; i < userList.length; ++i)
         this.managerList_.addPod(userList[i]);
-      if (userList.length == 1)
+      if (userList.length > 0)
         this.managerList_.selectPod(this.managerList_.pods[0]);
     },
 
@@ -1367,7 +1410,16 @@ login.createScreen('LocallyManagedUserCreationScreen',
      */
     handleSelect_: function(e) {
       var imageGrid = this.getScreenElement('image-grid');
-      if (!(imageGrid.selectionType == 'camera' && imageGrid.cameraLive)) {
+      this.updateNextButtonForUser_();
+
+      $('managed-user-creation-flip-photo').tabIndex =
+          (imageGrid.selectionType == 'camera') ? 0 : -1;
+      if (imageGrid.cameraLive || imageGrid.selectionType != 'camera')
+        imageGrid.previewElement.classList.remove('phototaken');
+      else
+        imageGrid.previewElement.classList.add('phototaken');
+
+      if (!imageGrid.cameraLive || imageGrid.selectionType != 'camera') {
         this.context_.selectedImageUrl = imageGrid.selectedItemUrl;
         chrome.send('supervisedUserSelectImage',
                     [imageGrid.selectedItemUrl, imageGrid.selectionType]);
@@ -1381,9 +1433,13 @@ login.createScreen('LocallyManagedUserCreationScreen',
           imageGrid.startCamera(
               function() {
                 // Start capture if camera is still the selected item.
+                $('managed-user-creation-image-preview-img').classList.toggle(
+                    'animated-transform', true);
                 return imageGrid.selectedItem == imageGrid.cameraImage;
               });
         } else {
+          $('managed-user-creation-image-preview-img').classList.toggle(
+              'animated-transform', false);
           imageGrid.stopCamera();
         }
       }