Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / pdf / html_office / elements / viewer-password-screen / viewer-password-screen.js
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 Polymer('viewer-password-screen', {
6   text: 'This document is password protected. Please enter a password.',
7   active: false,
8   timerId: undefined,
9   ready: function () {
10     this.activeChanged();
11   },
12   accept: function() {
13     this.successMessage = '✔'  // Tick.
14     this.$.successMessage.style.color = 'rgb(0,125,0)';
15     this.active = false;
16   },
17   deny: function() {
18     this.successMessage = '✘';  // Cross.
19     this.$.successMessage.style.color = 'rgb(255,0,0)';
20     this.$.password.disabled = false;
21     this.$.submit.disabled = false;
22     this.$.password.focus();
23     this.$.password.select();
24   },
25   submit: function(e) {
26     // Prevent the default form submission behavior.
27     e.preventDefault();
28     if (this.$.password.value.length == 0)
29       return;
30     this.successMessage = '...';
31     this.$.successMessage.style.color = 'rgb(0,0,0)';
32     this.$.password.disabled = true;
33     this.$.submit.disabled = true;
34     this.fire('password-submitted', {password: this.$.password.value});
35   },
36   activeChanged: function() {
37     clearTimeout(this.timerId);
38     this.timerId = undefined;
39     if (this.active) {
40       this.style.visibility = 'visible';
41       this.style.opacity = 1;
42       this.successMessage = '';
43       this.$.password.focus();
44     } else {
45       this.style.opacity = 0;
46       this.timerId = setTimeout(function() {
47         this.style.visibility = 'hidden'
48       }.bind(this), 400);
49     }
50   }
51 });