Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: ui/login/account_picker/user_pod_row.js

Issue 426063005: Allow recommended locales to be set for public sessions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview User pod row implementation. 6 * @fileoverview User pod row implementation.
7 */ 7 */
8 8
9 cr.define('login', function() { 9 cr.define('login', function() {
10 /** 10 /**
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 return this.classList.contains('expanded'); 990 return this.classList.contains('expanded');
991 }, 991 },
992 992
993 set expanded(expanded) { 993 set expanded(expanded) {
994 if (this.expanded == expanded) 994 if (this.expanded == expanded)
995 return; 995 return;
996 996
997 this.resetTabOrder(); 997 this.resetTabOrder();
998 this.classList.toggle('expanded', expanded); 998 this.classList.toggle('expanded', expanded);
999 if (expanded) { 999 if (expanded) {
1000 // Show the advanced expanded pod directly if there are at least two
1001 // recommended locales. This will be the case in multilingual
1002 // environments where users are likely to want to choose among locales.
1003 if (this.querySelector('.language-select').multipleRecommendedLocales)
1004 this.classList.add('advanced');
1000 this.usualLeft = this.left; 1005 this.usualLeft = this.left;
1001 this.makeSpaceForExpandedPod_(); 1006 this.makeSpaceForExpandedPod_();
1002 } else if (typeof(this.usualLeft) != 'undefined') { 1007 } else if (typeof(this.usualLeft) != 'undefined') {
1003 this.left = this.usualLeft; 1008 this.left = this.usualLeft;
1004 } 1009 }
1005 1010
1006 var self = this; 1011 var self = this;
1007 this.classList.add('animating'); 1012 this.classList.add('animating');
1008 this.addEventListener('webkitTransitionEnd', function f(e) { 1013 this.addEventListener('webkitTransitionEnd', function f(e) {
1009 self.removeEventListener('webkitTransitionEnd', f); 1014 self.removeEventListener('webkitTransitionEnd', f);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 learnMore.addEventListener('mousedown', stopEventPropagation); 1057 learnMore.addEventListener('mousedown', stopEventPropagation);
1053 learnMore.addEventListener('click', this.handleLearnMoreEvent); 1058 learnMore.addEventListener('click', this.handleLearnMoreEvent);
1054 learnMore.addEventListener('keydown', this.handleLearnMoreEvent); 1059 learnMore.addEventListener('keydown', this.handleLearnMoreEvent);
1055 1060
1056 learnMore = this.querySelector('.expanded-pane-learn-more'); 1061 learnMore = this.querySelector('.expanded-pane-learn-more');
1057 learnMore.addEventListener('click', this.handleLearnMoreEvent); 1062 learnMore.addEventListener('click', this.handleLearnMoreEvent);
1058 learnMore.addEventListener('keydown', this.handleLearnMoreEvent); 1063 learnMore.addEventListener('keydown', this.handleLearnMoreEvent);
1059 1064
1060 var languageSelect = this.querySelector('.language-select'); 1065 var languageSelect = this.querySelector('.language-select');
1061 languageSelect.tabIndex = UserPodTabOrder.POD_INPUT; 1066 languageSelect.tabIndex = UserPodTabOrder.POD_INPUT;
1067 languageSelect.manuallyChanged = false;
1062 languageSelect.addEventListener( 1068 languageSelect.addEventListener(
1063 'change', 1069 'change',
1064 this.getPublicSessionKeyboardLayouts_.bind(this)); 1070 function() {
1065 this.querySelector('.keyboard-select').tabIndex = 1071 languageSelect.manuallyChanged = true;
1066 UserPodTabOrder.POD_INPUT; 1072 this.getPublicSessionKeyboardLayouts_();
1073 }.bind(this));
1074
1075 var keyboardSelect = this.querySelector('.keyboard-select');
1076 keyboardSelect.tabIndex = UserPodTabOrder.POD_INPUT;
1077 keyboardSelect.loadedLocale = null;
1067 1078
1068 var languageAndInput = this.querySelector('.language-and-input'); 1079 var languageAndInput = this.querySelector('.language-and-input');
1069 languageAndInput.tabIndex = UserPodTabOrder.POD_INPUT; 1080 languageAndInput.tabIndex = UserPodTabOrder.POD_INPUT;
1070 languageAndInput.addEventListener('click', 1081 languageAndInput.addEventListener('click',
1071 this.transitionToAdvanced_.bind(this)); 1082 this.transitionToAdvanced_.bind(this));
1072 1083
1073 this.enterButtonElement.addEventListener('click', (function(e) { 1084 this.enterButtonElement.addEventListener('click', (function(e) {
1074 this.enterButtonElement.disabled = true; 1085 this.enterButtonElement.disabled = true;
1075 var locale = ""; 1086 var locale = this.querySelector('.language-select').value;
1076 var keyboardLayout = ""; 1087 var keyboardSelect = this.querySelector('.keyboard-select');
1077 if (this.advanced) { 1088 // The contents of |keyboardSelect| is updated asynchronously. If its
1078 // If the advanced pod is being shown, honor the selected UI language 1089 // locale does not match |locale|, it has not updated yet and the
1079 // and keyboard layout. 1090 // currently selected keyboard layout may not be applicable to |locale|.
1080 locale = this.querySelector('.language-select').value; 1091 // Do not return any keyboard layout in this case and let the backend
1081 keyboardLayout = this.querySelector('.keyboard-select').value; 1092 // choose a suitable layout.
1082 } 1093 var keyboardLayout =
1094 keyboardSelect.loadedLocale == locale ? keyboardSelect.value : "";
Nikita (slow) 2014/07/30 11:22:59 nit: ''
bartfab (slow) 2014/08/05 17:16:24 Done.
1083 chrome.send('launchPublicSession', 1095 chrome.send('launchPublicSession',
1084 [this.user.username, locale, keyboardLayout]); 1096 [this.user.username, locale, keyboardLayout]);
1085 }).bind(this)); 1097 }).bind(this));
1086 }, 1098 },
1087 1099
1088 /** @override **/ 1100 /** @override **/
1089 initialize: function() { 1101 initialize: function() {
1090 UserPod.prototype.initialize.call(this); 1102 UserPod.prototype.initialize.call(this);
1091 1103
1104 id = this.user.username + '-keyboard';
1105 this.querySelector('.keyboard-select-label').htmlFor = id;
1106 this.querySelector('.keyboard-select').setAttribute('id', id);
1107
1092 var id = this.user.username + '-language'; 1108 var id = this.user.username + '-language';
1093 this.querySelector('.language-select-label').htmlFor = id; 1109 this.querySelector('.language-select-label').htmlFor = id;
1094 var languageSelect = this.querySelector('.language-select'); 1110 var languageSelect = this.querySelector('.language-select');
1095 languageSelect.setAttribute('id', id); 1111 languageSelect.setAttribute('id', id);
1096 var list = this.user.initialLocales; 1112 this.populateLanguageSelect(this.user.initialLocales,
1097 languageSelect.innerHTML = ''; 1113 this.user.initialLocale,
1098 var group = languageSelect; 1114 this.user.initialMultipleRecommendedLocales);
1099 for (var i = 0; i < list.length; ++i) {
1100 var item = list[i];
1101 if (item.optionGroupName) {
1102 group = document.createElement('optgroup');
1103 group.label = item.optionGroupName;
1104 languageSelect.appendChild(group);
1105 } else {
1106 group.appendChild(
1107 new Option(item.title, item.value, item.selected, item.selected));
1108 }
1109 }
1110
1111 id = this.user.username + '-keyboard';
1112 this.querySelector('.keyboard-select-label').htmlFor = id;
1113 this.querySelector('.keyboard-select').setAttribute('id', id);
1114 this.populateKeyboardSelect_([this.user.initialKeyboardLayout]);
1115 this.getPublicSessionKeyboardLayouts_();
1116 }, 1115 },
1117 1116
1118 /** @override **/ 1117 /** @override **/
1119 update: function() { 1118 update: function() {
1120 UserPod.prototype.update.call(this); 1119 UserPod.prototype.update.call(this);
1121 this.querySelector('.expanded-pane-name').textContent = 1120 this.querySelector('.expanded-pane-name').textContent =
1122 this.user_.displayName; 1121 this.user_.displayName;
1123 this.querySelector('.info').textContent = 1122 this.querySelector('.info').textContent =
1124 loadTimeData.getStringF('publicAccountInfoFormat', 1123 loadTimeData.getStringF('publicAccountInfoFormat',
1125 this.user_.enterpriseDomain); 1124 this.user_.enterpriseDomain);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 // Guard timer set to animation duration + 20ms. 1229 // Guard timer set to animation duration + 20ms.
1231 ensureTransitionEndEvent(languageAndInputSection, 380); 1230 ensureTransitionEndEvent(languageAndInputSection, 380);
1232 }, 0); 1231 }, 0);
1233 }, 1232 },
1234 1233
1235 /** 1234 /**
1236 * Retrieves the list of keyboard layouts available for the currently 1235 * Retrieves the list of keyboard layouts available for the currently
1237 * selected locale. 1236 * selected locale.
1238 */ 1237 */
1239 getPublicSessionKeyboardLayouts_: function() { 1238 getPublicSessionKeyboardLayouts_: function() {
1240 var languageSelect = this.querySelector('.language-select'); 1239 var selectedLocale = this.querySelector('.language-select').value;
1241 chrome.send('getPublicSessionKeyboardLayouts', [ 1240 if (selectedLocale ==
1242 this.user.username, 1241 this.querySelector('.keyboard-select').loadedLocale) {
1243 languageSelect.options[languageSelect.selectedIndex].value]); 1242 // If the list of keyboard layouts was loaded for the currently selected
1243 // locale, it is already up to date.
1244 return;
1245 }
1246 chrome.send('getPublicSessionKeyboardLayouts',
1247 [this.user.username, selectedLocale]);
1244 }, 1248 },
1245 1249
1246 /** 1250 /**
1247 * Populates the keyboard layout "select" element with a list of layouts. 1251 * Populates the keyboard layout "select" element with a list of layouts.
1252 * @param {string} locale The locale to which this list of keyboard layouts
1253 * applies
1248 * @param {!Object} list List of available keyboard layouts 1254 * @param {!Object} list List of available keyboard layouts
1249 */ 1255 */
1250 populateKeyboardSelect_: function(list) { 1256 populateKeyboardSelect: function(locale, list) {
1257 if (locale != this.querySelector('.language-select').value) {
1258 // The selected locale has changed and the list of keyboard layouts is
1259 // not applicable. This method will be called again when a list of
1260 // keyboard layouts applicable to the selected locale is retrieved.
1261 return;
1262 }
1263
1251 var keyboardSelect = this.querySelector('.keyboard-select'); 1264 var keyboardSelect = this.querySelector('.keyboard-select');
1265 keyboardSelect.loadedLocale = locale;
1252 keyboardSelect.innerHTML = ''; 1266 keyboardSelect.innerHTML = '';
1253 for (var i = 0; i < list.length; ++i) { 1267 for (var i = 0; i < list.length; ++i) {
1254 var item = list[i]; 1268 var item = list[i];
1255 keyboardSelect.appendChild( 1269 keyboardSelect.appendChild(
1256 new Option(item.title, item.value, item.selected, item.selected)); 1270 new Option(item.title, item.value, item.selected, item.selected));
1257 } 1271 }
1272 },
1273
1274 /**
1275 * Populates the language "select" element with a list of locales.
1276 * @param {!Object} locales The list of available locales
1277 * @param {string} defaultLocale The locale to select by default
1278 * @param {boolean} multipleRecommendedLocales Whether |locales| contains
1279 * two or more recommended locales
1280 */
1281 populateLanguageSelect: function(locales,
1282 defaultLocale,
1283 multipleRecommendedLocales) {
1284 var languageSelect = this.querySelector('.language-select');
1285 // If the user manually selected a locale, do not change the selection.
1286 // Otherwise, select the new |defaultLocale|.
1287 var selected =
1288 languageSelect.manuallyChanged ? languageSelect.value : defaultLocale;
1289 languageSelect.innerHTML = '';
1290 var group = languageSelect;
1291 for (var i = 0; i < locales.length; ++i) {
1292 var item = locales[i];
1293 if (item.optionGroupName) {
1294 group = document.createElement('optgroup');
1295 group.label = item.optionGroupName;
1296 languageSelect.appendChild(group);
1297 } else {
1298 group.appendChild(new Option(item.title,
1299 item.value,
1300 item.value == selected,
1301 item.value == selected));
1302 }
1303 }
1304 languageSelect.multipleRecommendedLocales = multipleRecommendedLocales;
1305
1306 // Retrieve a list of keyboard layouts applicable to the locale that is
1307 // now selected.
1308 this.getPublicSessionKeyboardLayouts_();
1258 } 1309 }
1259 }; 1310 };
1260 1311
1261 /** 1312 /**
1262 * Creates a user pod to be used only in desktop chrome. 1313 * Creates a user pod to be used only in desktop chrome.
1263 * @constructor 1314 * @constructor
1264 * @extends {UserPod} 1315 * @extends {UserPod}
1265 */ 1316 */
1266 var DesktopUserPod = cr.ui.define(function() { 1317 var DesktopUserPod = cr.ui.define(function() {
1267 // Don't just instantiate a UserPod(), as this will call decorate() on the 1318 // Don't just instantiate a UserPod(), as this will call decorate() on the
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 * @param {string} userID The user ID of the public session 1906 * @param {string} userID The user ID of the public session
1856 * @param {string} displayName The new display name 1907 * @param {string} displayName The new display name
1857 */ 1908 */
1858 setPublicSessionDisplayName: function(userID, displayName) { 1909 setPublicSessionDisplayName: function(userID, displayName) {
1859 var pod = this.getPodWithUsername_(userID); 1910 var pod = this.getPodWithUsername_(userID);
1860 if (pod != null) 1911 if (pod != null)
1861 pod.setDisplayName(displayName); 1912 pod.setDisplayName(displayName);
1862 }, 1913 },
1863 1914
1864 /** 1915 /**
1916 * Updates the list of locales available for a public session.
1917 * @param {string} userID The user ID of the public session
1918 * @param {!Object} locales The list of available locales
1919 * @param {string} defaultLocale The locale to select by default
1920 * @param {boolean} multipleRecommendedLocales Whether |locales| contains
1921 * two or more recommended locales
1922 */
1923 setPublicSessionLocales: function(userID,
1924 locales,
1925 defaultLocale,
1926 multipleRecommendedLocales) {
1927 var pod = this.getPodWithUsername_(userID);
1928 if (pod != null) {
1929 pod.populateLanguageSelect(locales,
1930 defaultLocale,
1931 multipleRecommendedLocales);
1932 }
1933 },
1934
1935 /**
1865 * Updates the list of available keyboard layouts for a public session pod. 1936 * Updates the list of available keyboard layouts for a public session pod.
1866 * @param {string} userID The user ID of the public session 1937 * @param {string} userID The user ID of the public session
1938 * @param {string} locale The locale to which this list of keyboard layouts
1939 * applies
1867 * @param {!Object} list List of available keyboard layouts 1940 * @param {!Object} list List of available keyboard layouts
1868 */ 1941 */
1869 setPublicSessionKeyboardLayouts: function(userID, list) { 1942 setPublicSessionKeyboardLayouts: function(userID, locale, list) {
1870 var pod = this.getPodWithUsername_(userID); 1943 var pod = this.getPodWithUsername_(userID);
1871 if (pod != null) 1944 if (pod != null)
1872 pod.populateKeyboardSelect_(list); 1945 pod.populateKeyboardSelect(locale, list);
1873 }, 1946 },
1874 1947
1875 /** 1948 /**
1876 * Called when window was resized. 1949 * Called when window was resized.
1877 */ 1950 */
1878 onWindowResize: function() { 1951 onWindowResize: function() {
1879 var layout = this.calculateLayout_(); 1952 var layout = this.calculateLayout_();
1880 if (layout.columns != this.columns || layout.rows != this.rows) 1953 if (layout.columns != this.columns || layout.rows != this.rows)
1881 this.placePods_(); 1954 this.placePods_();
1882 1955
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 if (this.podsWithPendingImages_.length == 0) { 2505 if (this.podsWithPendingImages_.length == 0) {
2433 this.classList.remove('images-loading'); 2506 this.classList.remove('images-loading');
2434 } 2507 }
2435 } 2508 }
2436 }; 2509 };
2437 2510
2438 return { 2511 return {
2439 PodRow: PodRow 2512 PodRow: PodRow
2440 }; 2513 };
2441 }); 2514 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698