- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / options / media_galleries_manager_overlay.js
1 // Copyright (c) 2012 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 cr.define('options', function() {
6   /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
7   /** @const */ var OptionsPage = options.OptionsPage;
8
9   /**
10    * This class is an overlay which allows the user to add or remove media
11    * galleries, and displays known media galleries.
12    * @constructor
13    * @extends {OptionsPage}
14    */
15   function MediaGalleriesManager() {
16     OptionsPage.call(this, 'manageGalleries',
17                      loadTimeData.getString('manageMediaGalleriesTabTitle'),
18                      'manage-media-galleries-overlay');
19   }
20
21   cr.addSingletonGetter(MediaGalleriesManager);
22
23   MediaGalleriesManager.prototype = {
24     __proto__: OptionsPage.prototype,
25
26     /**
27      * Decorate the overlay and set up event handlers.
28      */
29     initializePage: function() {
30       OptionsPage.prototype.initializePage.call(this);
31
32       this.availableGalleriesList_ = $('available-galleries-list');
33       options.MediaGalleriesList.decorate(this.availableGalleriesList_);
34
35       $('new-media-gallery').addEventListener('click', function() {
36         chrome.send('addNewGallery');
37       });
38
39       $('manage-media-confirm').addEventListener(
40           'click', OptionsPage.closeOverlay.bind(OptionsPage));
41
42       this.addEventListener('visibleChange', this.handleVisibleChange_);
43     },
44
45     /** @private */
46     handleVisibleChange_: function() {
47       if (!this.visible)
48         return;
49
50       chrome.send('initializeMediaGalleries');
51
52       if (this.availableGalleriesList_)
53         this.availableGalleriesList_.redraw();
54     },
55
56     /**
57      * @param {Array} galleries List of structs describibing galleries.
58      * @private
59      */
60     setAvailableMediaGalleries_: function(galleries) {
61       $('available-galleries-list').dataModel = new ArrayDataModel(galleries);
62       $('new-media-gallery').disabled = false;
63       $('media-galleries-section').hidden = false;
64     },
65   },
66
67   // Forward public APIs to private implementations.
68   [
69     'setAvailableMediaGalleries',
70   ].forEach(function(name) {
71     MediaGalleriesManager[name] = function() {
72       var instance = MediaGalleriesManager.getInstance();
73       return instance[name + '_'].apply(instance, arguments);
74     };
75   });
76
77   // Export
78   return {
79     MediaGalleriesManager: MediaGalleriesManager
80   };
81 });