| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 Copyright 2015 The Chromium Authors. All rights reserved. | 2 Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style license that can be | 3 Use of this source code is governed by a BSD-style license that can be |
| 4 found in the LICENSE file. | 4 found in the LICENSE file. |
| 5 --> | 5 --><html><head><link href="../bower_components/polymer/polymer.html" rel="import
"> |
| 6 <link rel="import" href="../appengine_module/components/net.html"> |
| 7 <dom-module id="ct-user-prefs"> |
| 8 <script> |
| 9 (function () { |
| 10 // Folloing the "MonoState" pattern suggested in |
| 11 // https://www.polymer-project.org/0.5/docs/polymer/polymer.html#global |
| 12 // Instantiate as many ct-user-prefs elements as you'd like, they'll alway
s |
| 13 // bind to the same shared set of values. |
| 14 var values = {}; |
| 15 Polymer({ |
| 16 is: 'ct-user-prefs', |
| 17 properties: { |
| 18 linkTarget: { notify: true }, |
| 19 user: { notify: true }, |
| 20 values: { notify: true } |
| 21 }, |
| 22 ready: function () { |
| 23 this.values = values; |
| 24 }, |
| 25 attached: function () { |
| 26 if (!this.values.loaded && !this.values.loading) { |
| 27 this.values.loading = true; |
| 28 this.load(); |
| 29 } |
| 30 }, |
| 31 load: function () { |
| 32 net.json('/api/v1/prefs').then(function (data) { |
| 33 this.values.user = data.user; |
| 34 this.values.xsrfToken = data.xsrf_token; |
| 35 this.values.loginUrl = data.login_url; |
| 36 this.values.logoutUrl = data.logout_url; |
| 37 if (data.prefs) { |
| 38 this.values.useUberchromegw = data.prefs.use_uberchromegw; |
| 39 this.values.useNewWindows = data.prefs.use_new_windows; |
| 40 this.values.linkTarget = data.prefs.use_new_windows ? '_blank' : '
_self'; |
| 41 } |
| 42 this.values.loaded = true; |
| 43 this.values.loading = false; |
| 44 }.bind(this), function (err) { |
| 45 window.console.log('could not load user prefs: ' + err); |
| 46 this.values.loading = false; |
| 47 }.bind(this)); |
| 48 }, |
| 49 rewriteUrl: function (url) { |
| 50 if (this.values.useUberchromegw) { |
| 51 url = url.replace('//build.chromium.org/p/', '//uberchromegw.corp.go
ogle.com/i/'); |
| 52 } |
| 53 return url; |
| 54 } |
| 55 }); |
| 56 }()); |
| 57 </script> |
| 58 </dom-module> |
| 6 | 59 |
| 7 <link href="../bower_components/polymer/polymer.html" rel="import"> | |
| 8 <link rel="import" href="../appengine_module/components/net.html"> | |
| 9 <polymer-element name="ct-user-prefs" attributes="user linkTarget values"> | |
| 10 <script> | |
| 11 (function() { | |
| 12 // Folloing the "MonoState" pattern suggested in | |
| 13 // https://www.polymer-project.org/0.5/docs/polymer/polymer.html#global | |
| 14 // Instantiate as many ct-user-prefs elements as you'd like, they'll always | |
| 15 // bind to the same shared set of values. | |
| 16 var values = {}; | |
| 17 | |
| 18 Polymer({ | |
| 19 ready: function() { | |
| 20 this.values = values; | |
| 21 }, | |
| 22 | |
| 23 attached: function() { | |
| 24 if (!this.values.loaded && !this.values.loading) { | |
| 25 this.values.loading = true; | |
| 26 this.load(); | |
| 27 } | |
| 28 }, | |
| 29 | |
| 30 load: function() { | |
| 31 net.json('/api/v1/prefs').then(function(data) { | |
| 32 this.values.user = data.user; | |
| 33 this.values.xsrfToken = data.xsrf_token; | |
| 34 this.values.loginUrl = data.login_url; | |
| 35 this.values.logoutUrl = data.logout_url; | |
| 36 | |
| 37 if (data.prefs) { | |
| 38 this.values.useUberchromegw = data.prefs.use_uberchromegw; | |
| 39 this.values.useNewWindows = data.prefs.use_new_windows; | |
| 40 this.values.linkTarget = data.prefs.use_new_windows ? '_blank' : '_sel
f'; | |
| 41 } | |
| 42 this.values.loaded = true; | |
| 43 this.values.loading = false; | |
| 44 }.bind(this), function(err) { | |
| 45 window.console.log('could not load user prefs: ' + err); | |
| 46 this.values.loading = false; | |
| 47 }.bind(this)); | |
| 48 }, | |
| 49 | |
| 50 rewriteUrl: function(url) { | |
| 51 if (this.values.useUberchromegw) { | |
| 52 url = url.replace( | |
| 53 '//build.chromium.org/p/', | |
| 54 '//uberchromegw.corp.google.com/i/'); | |
| 55 } | |
| 56 return url; | |
| 57 }, | |
| 58 }); | |
| 59 })(); | |
| 60 </script> | |
| 61 </polymer-element> | |
| 62 | |
| OLD | NEW |