Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 /** @suppress {duplicate} */ | |
| 6 var remoting = remoting || {}; | |
| 7 | |
| 8 (function() { | |
| 9 | |
| 10 'use strict'; | |
| 11 | |
| 12 /** | |
| 13 * A helper class for implementing dialogs with an input field using | |
| 14 * remoting.setMode(). | |
| 15 * | |
| 16 * @param {remoting.AppMode} mode | |
| 17 * @param {HTMLElement} formElement | |
| 18 * @param {HTMLElement} inputField | |
| 19 * @param {HTMLElement} cancelButton | |
| 20 * | |
| 21 * @constructor | |
| 22 */ | |
| 23 remoting.InputDialog = function(mode, formElement, inputField, cancelButton) { | |
| 24 /** @private */ | |
| 25 this.appMode_ = mode; | |
| 26 /** @private */ | |
| 27 this.formElement_ = formElement; | |
| 28 /** @private */ | |
| 29 this.cancelButton_ = cancelButton; | |
| 30 /** @private */ | |
| 31 this.inputField_ = inputField; | |
| 32 /** @private {base.Deferred} */ | |
| 33 this.deferred_ = null; | |
| 34 /** @private {base.Disposables} */ | |
| 35 this.eventHooks_ = null; | |
| 36 }; | |
| 37 | |
| 38 /** | |
| 39 * @return {Promise<string>} Promise that resolves with the value of the | |
| 40 * inputField or rejects with |remoting.Error.CANCELLED| if the user clicks | |
| 41 * on the cancel button. | |
| 42 */ | |
| 43 remoting.InputDialog.prototype.show = function() { | |
| 44 var onCancel = this.createFormEventHandler_(this.onCancel_.bind(this)); | |
| 45 var onOk = this.createFormEventHandler_(this.onSubmit_.bind(this)); | |
| 46 | |
| 47 this.eventHooks_ = new base.Disposables( | |
| 48 new base.DomEventHook(this.formElement_, 'submit', onOk, false), | |
| 49 new base.DomEventHook(this.cancelButton_, 'click', onCancel, false)); | |
| 50 base.debug.assert(this.deferred_ === null); | |
| 51 this.deferred_ = new base.Deferred(); | |
| 52 remoting.setMode(this.appMode_); | |
| 53 return this.deferred_.promise(); | |
| 54 }; | |
| 55 | |
| 56 /** @return {HTMLElement} */ | |
| 57 remoting.InputDialog.prototype.inputField = function() { | |
| 58 return this.inputField_; | |
| 59 } | |
| 60 | |
| 61 /** @private */ | |
| 62 remoting.InputDialog.prototype.onSubmit_ = function() { | |
| 63 this.deferred_.resolve(this.inputField_.value); | |
| 64 } | |
| 65 | |
| 66 /** @private */ | |
| 67 remoting.InputDialog.prototype.onCancel_ = function() { | |
| 68 this.deferred_.reject(new remoting.Error(remoting.Error.Tag.CANCELLED)); | |
| 69 } | |
| 70 | |
| 71 /** | |
| 72 * @param {function():void} handler | |
| 73 * @return {Function} | |
| 74 * @private | |
| 75 */ | |
| 76 remoting.InputDialog.prototype.createFormEventHandler_ = function(handler) { | |
| 77 var that = this; | |
| 78 return function (/** Event */ e) { | |
| 79 // Prevents form submission from reloading the v1 app. | |
| 80 e.preventDefault(); | |
| 81 | |
| 82 // Set the focus away from the password field. This has to be done | |
| 83 // before the password field gets hidden, to work around a Blink | |
| 84 // clipboard-handling bug - http://crbug.com/281523. | |
| 85 that.cancelButton_.focus(); | |
| 86 handler(); | |
| 87 base.dispose(that.eventHooks_); | |
| 88 that.eventHooks_ = null; | |
| 89 that.deferred_ = null; | |
| 90 }; | |
| 91 }; | |
| 92 | |
| 93 })(); | |
|
Jamie
2015/04/08 20:07:29
Did you intend to remove this? I don't see any cha
kelvinp
2015/04/08 20:10:20
This is renamed to modal_dialog.js as it now also
| |
| OLD | NEW |