1// Copyright (c) 2011 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 5cr.define('options', function() { 6 7 var OptionsPage = options.OptionsPage; 8 9 ///////////////////////////////////////////////////////////////////////////// 10 // ChangePictureOptions class: 11 12 /** 13 * Encapsulated handling of ChromeOS change picture options page. 14 * @constructor 15 */ 16 function ChangePictureOptions() { 17 OptionsPage.call( 18 this, 19 'changePicture', 20 localStrings.getString('changePicturePage'), 21 'change-picture-page'); 22 } 23 24 cr.addSingletonGetter(ChangePictureOptions); 25 26 ChangePictureOptions.prototype = { 27 // Inherit ChangePictureOptions from OptionsPage. 28 __proto__: options.OptionsPage.prototype, 29 30 /** 31 * Initializes ChangePictureOptions page. 32 */ 33 initializePage: function() { 34 // Call base class implementation to starts preference initialization. 35 OptionsPage.prototype.initializePage.call(this); 36 37 $('take-photo-button').addEventListener('click', 38 this.handleTakePhoto_, 39 false); 40 $('choose-file-button').addEventListener('click', 41 this.handleChooseFile_, 42 false); 43 chrome.send('getAvailableImages'); 44 }, 45 46 /** 47 * Handler for when the user clicks on "Take photo" button. 48 * @private 49 * @param {Event} e Click Event. 50 */ 51 handleTakePhoto_: function(e) { 52 chrome.send('takePhoto'); 53 OptionsPage.navigateToPage('personal'); 54 }, 55 56 /** 57 * Handler for when the user clicks on "Choose a file" button. 58 * @private 59 * @param {Event} e Click Event. 60 */ 61 handleChooseFile_: function(e) { 62 chrome.send('chooseFile'); 63 OptionsPage.navigateToPage('personal'); 64 }, 65 66 /** 67 * Handler for when the user clicks on any available user image. 68 * @private 69 * @param {Event} e Click Event. 70 */ 71 handleImageClick_: function(e) { 72 chrome.send('selectImage', [e.target.src]); 73 OptionsPage.navigateToPage('personal'); 74 }, 75 76 /** 77 * Appends new image to the end of the image list. 78 * @param {string} src A url for the user image. 79 * @private 80 */ 81 addUserImage_: function(src) { 82 var imageElement = document.createElement('img'); 83 imageElement.src = src; 84 imageElement.addEventListener('click', 85 this.handleImageClick_, 86 false); 87 var divElement = document.createElement('div'); 88 divElement.classList.add('list-element'); 89 divElement.appendChild(imageElement); 90 $('images-list').appendChild(divElement); 91 }, 92 93 /** 94 * Inserts received images before "Choose file" button. 95 * @param {List} images A list of urls to user images. 96 * @private 97 */ 98 addUserImages_: function(images) { 99 for (var i = 0; i < images.length; i++) { 100 var imageUrl = images[i]; 101 this.addUserImage_(imageUrl); 102 } 103 }, 104 }; 105 106 // Forward public APIs to private implementations. 107 [ 108 'addUserImages', 109 ].forEach(function(name) { 110 ChangePictureOptions[name] = function(value) { 111 ChangePictureOptions.getInstance()[name + '_'](value); 112 }; 113 }); 114 115 // Export 116 return { 117 ChangePictureOptions: ChangePictureOptions 118 }; 119 120}); 121 122