| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright 2016 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 /** | 
|  | 6  * @fileoverview 'settings-channel-switcher-dialog' is a component allowing the | 
|  | 7  * user to switch between release channels (dev, beta, stable). A | 
|  | 8  * |target-channel-changed| event is fired if the user does select a different | 
|  | 9  * release channel to notify parents of this dialog. | 
|  | 10  */ | 
|  | 11 Polymer({ | 
|  | 12   is: 'settings-channel-switcher-dialog', | 
|  | 13 | 
|  | 14   behaviors: [I18nBehavior], | 
|  | 15 | 
|  | 16   properties: { | 
|  | 17     /** @private */ | 
|  | 18     browserChannelEnum_: { | 
|  | 19       type: Object, | 
|  | 20       value: BrowserChannel, | 
|  | 21     }, | 
|  | 22 | 
|  | 23     /** @private {!BrowserChannel} */ | 
|  | 24     currentChannel_: String, | 
|  | 25 | 
|  | 26     /** | 
|  | 27      * Controls which of the two action buttons is visible. | 
|  | 28      * @private {?{changeChannel: boolean, changeChannelAndPowerwash: boolean}} | 
|  | 29      */ | 
|  | 30     shouldShowButtons_: { | 
|  | 31       type: Object, | 
|  | 32       value: null, | 
|  | 33     }, | 
|  | 34 | 
|  | 35     /** @private {?{title: string, description: string}} */ | 
|  | 36     warning_: { | 
|  | 37       type: Object, | 
|  | 38       value: null, | 
|  | 39     }, | 
|  | 40   }, | 
|  | 41 | 
|  | 42   /** @private {?settings.AboutPageBrowserProxy} */ | 
|  | 43   browserProxy_: null, | 
|  | 44 | 
|  | 45   /** @override */ | 
|  | 46   ready: function() { | 
|  | 47     this.browserProxy_ = settings.AboutPageBrowserProxyImpl.getInstance(); | 
|  | 48 | 
|  | 49     this.browserProxy_.getCurrentChannel().then(function(channel) { | 
|  | 50       this.currentChannel_ = channel; | 
|  | 51       // Pre-populate radio group with current channel. | 
|  | 52       this.$$('paper-radio-group').select(channel); | 
|  | 53     }.bind(this)); | 
|  | 54   }, | 
|  | 55 | 
|  | 56   /** @override */ | 
|  | 57   attached: function() { | 
|  | 58     this.$.dialog.open(); | 
|  | 59   }, | 
|  | 60 | 
|  | 61   /** @private */ | 
|  | 62   onCancelTap_: function() { | 
|  | 63     this.$.dialog.close(); | 
|  | 64   }, | 
|  | 65 | 
|  | 66   /** @private */ | 
|  | 67   onChangeChannelTap_: function() { | 
|  | 68     var selectedChannel = this.$$('paper-radio-group').selected; | 
|  | 69     this.browserProxy_.setChannel(selectedChannel, false); | 
|  | 70     this.$.dialog.close(); | 
|  | 71     this.fire('target-channel-changed', selectedChannel); | 
|  | 72   }, | 
|  | 73 | 
|  | 74   /** @private */ | 
|  | 75   onChangeChannelAndPowerwashTap_: function() { | 
|  | 76     var selectedChannel = this.$$('paper-radio-group').selected; | 
|  | 77     this.browserProxy_.setChannel(selectedChannel, true); | 
|  | 78     this.$.dialog.close(); | 
|  | 79     this.fire('target-channel-changed', selectedChannel); | 
|  | 80   }, | 
|  | 81 | 
|  | 82   /** | 
|  | 83    * @param {string} titleId Localized string ID for the title. | 
|  | 84    * @param {string} descriptionId Localized string ID for the description. | 
|  | 85    * @param {string=} opt_productNameId Localized string ID for the product | 
|  | 86    *     name. | 
|  | 87    * @private | 
|  | 88    */ | 
|  | 89   updateWarning_: function(titleId, descriptionId, opt_productNameId) { | 
|  | 90     this.warning_ = { | 
|  | 91       title: this.i18n(titleId), | 
|  | 92       description: opt_productNameId ? | 
|  | 93           this.i18n(descriptionId, this.i18n(opt_productNameId)) : | 
|  | 94           this.i18n(descriptionId), | 
|  | 95     }; | 
|  | 96   }, | 
|  | 97 | 
|  | 98   /** | 
|  | 99    * @param {boolean} changeChannel Whether the changeChannel button sholud be | 
|  | 100    *     visible. | 
|  | 101    * @param {boolean} changeChannelAndPowerwash Whether the | 
|  | 102    *     changeChannelAndPowerwash button should be visible. | 
|  | 103    * @private | 
|  | 104    */ | 
|  | 105   updateButtons_: function(changeChannel, changeChannelAndPowerwash) { | 
|  | 106     if (changeChannel || changeChannelAndPowerwash) { | 
|  | 107       // Ensure that at most one button is visible at any given time. | 
|  | 108       assert(changeChannel != changeChannelAndPowerwash); | 
|  | 109     } | 
|  | 110 | 
|  | 111     this.shouldShowButtons_ = { | 
|  | 112       changeChannel: changeChannel, | 
|  | 113       changeChannelAndPowerwash: changeChannelAndPowerwash, | 
|  | 114     }; | 
|  | 115   }, | 
|  | 116 | 
|  | 117   /** @private */ | 
|  | 118   onChannelSelectionChanged_: function() { | 
|  | 119     var selectedChannel = this.$$('paper-radio-group').selected; | 
|  | 120 | 
|  | 121     if (selectedChannel == this.currentChannel_) { | 
|  | 122       this.shouldShowButtons_ = null; | 
|  | 123       this.warning_ = null; | 
|  | 124       this.$.dialog.notifyResize(); | 
|  | 125       return; | 
|  | 126     } | 
|  | 127 | 
|  | 128     if (settings.isTargetChannelMoreStable( | 
|  | 129         this.currentChannel_, selectedChannel)) { | 
|  | 130       if (loadTimeData.getBoolean('aboutEnterpriseManaged')) { | 
|  | 131         this.updateWarning_( | 
|  | 132             'aboutDelayedWarningTitle', | 
|  | 133             'aboutDelayedWarningMessage', | 
|  | 134             'aboutProductTitle'); | 
|  | 135         this.updateButtons_(true, false); | 
|  | 136       } else { | 
|  | 137         this.updateWarning_( | 
|  | 138           'aboutPowerwashWarningTitle', 'aboutPowerwashWarningMessage'); | 
|  | 139         this.updateButtons_(false, true); | 
|  | 140       } | 
|  | 141     } else { | 
|  | 142       this.updateWarning_( | 
|  | 143         'aboutUnstableWarningTitle', | 
|  | 144         'aboutUnstableWarningMessage', | 
|  | 145         'aboutProductTitle'); | 
|  | 146       this.updateButtons_(true, false); | 
|  | 147     } | 
|  | 148     this.$.dialog.notifyResize(); | 
|  | 149   }, | 
|  | 150 | 
|  | 151   /** | 
|  | 152    * @return {boolean} | 
|  | 153    * @private | 
|  | 154    */ | 
|  | 155   shouldShowWarning_: function() { | 
|  | 156     return this.warning_ !== null; | 
|  | 157   }, | 
|  | 158 }); | 
| OLD | NEW | 
|---|