OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 ///////////////////////////////////////////////////////////////////////////// | 6 ///////////////////////////////////////////////////////////////////////////// |
7 // OptionsPage class: | 7 // OptionsPage class: |
8 | 8 |
9 /** | 9 /** |
10 * Base class for options page. | 10 * Base class for options page. |
11 * @constructor | 11 * @constructor |
12 * @param {string} name Options page name, also defines id of the div element | 12 * @param {string} name Options page name, also defines id of the div element |
13 * containing the options view and the name of options page navigation bar | 13 * containing the options view and the name of options page navigation bar |
14 * item as name+'PageNav'. | 14 * item as name+'PageNav'. |
15 * @param {string} title Options page title, used for navigation bar | 15 * @param {string} title Options page title, used for navigation bar |
16 * @extends {EventTarget} | 16 * @extends {EventTarget} |
17 */ | 17 */ |
18 function OptionsPage(name, title, pageDivName) { | 18 function OptionsPage(name, title, pageDivName) { |
19 this.name = name; | 19 this.name = name; |
20 this.title = title; | 20 this.title = title; |
21 this.pageDivName = pageDivName; | 21 this.pageDivName = pageDivName; |
22 this.pageDiv = $(this.pageDivName); | 22 this.pageDiv = $(this.pageDivName); |
23 this.tab = null; | 23 this.tab = null; |
24 this.managed = false; | |
25 } | 24 } |
26 | 25 |
27 const SUBPAGE_SHEET_COUNT = 2; | 26 const SUBPAGE_SHEET_COUNT = 2; |
28 | 27 |
29 /** | 28 /** |
30 * Main level option pages. Maps lower-case page names to the respective page | 29 * Main level option pages. Maps lower-case page names to the respective page |
31 * object. | 30 * object. |
32 * @protected | 31 * @protected |
33 */ | 32 */ |
34 OptionsPage.registeredPages = {}; | 33 OptionsPage.registeredPages = {}; |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 * @type {OptionsPage} | 800 * @type {OptionsPage} |
802 */ | 801 */ |
803 associatedControls: null, | 802 associatedControls: null, |
804 | 803 |
805 /** | 804 /** |
806 * Initializes page content. | 805 * Initializes page content. |
807 */ | 806 */ |
808 initializePage: function() {}, | 807 initializePage: function() {}, |
809 | 808 |
810 /** | 809 /** |
811 * Sets managed banner visibility state. | |
812 */ | |
813 setManagedBannerVisibility: function(visible) { | |
814 this.managed = visible; | |
815 if (this.visible) { | |
816 this.updateManagedBannerVisibility(); | |
817 } | |
818 }, | |
819 | |
820 /** | |
821 * Updates managed banner visibility state. This function iterates over | 810 * Updates managed banner visibility state. This function iterates over |
822 * all input fields of a window and if any of these is marked as managed | 811 * all input fields of a window and if any of these is marked as managed |
823 * it triggers the managed banner to be visible. The banner can be enforced | 812 * it triggers the managed banner to be visible. The banner can be enforced |
824 * being on through the managed flag of this class but it can not be forced | 813 * being on through the managed flag of this class but it can not be forced |
825 * being off if managed items exist. | 814 * being off if managed items exist. |
826 */ | 815 */ |
827 updateManagedBannerVisibility: function() { | 816 updateManagedBannerVisibility: function() { |
828 var bannerDiv = $('managed-prefs-banner'); | 817 var bannerDiv = $('managed-prefs-banner'); |
829 | 818 |
830 var hasManaged = this.managed; | 819 var controlledByPolicy = false; |
831 if (!hasManaged) { | 820 var controlledByExtension = false; |
832 var inputElements = this.pageDiv.querySelectorAll('input'); | 821 var inputElements = this.pageDiv.querySelectorAll('input[controlledBy]'); |
833 for (var i = 0, len = inputElements.length; i < len; i++) { | 822 for (var i = 0, len = inputElements.length; i < len; i++) { |
834 if (inputElements[i].managed) { | 823 if (inputElements[i].controlledBy == 'policy') |
835 hasManaged = true; | 824 controlledByPolicy = true; |
836 break; | 825 else if (inputElements[i].controlledBy == 'extension') |
837 } | 826 controlledByExtension = true; |
838 } | |
839 } | 827 } |
840 if (hasManaged) { | 828 if (controlledByPolicy || controlledByExtension) { |
841 bannerDiv.hidden = false; | 829 bannerDiv.hidden = false; |
842 var height = window.getComputedStyle($('managed-prefs-banner')).height; | 830 var height = window.getComputedStyle(bannerDiv).height; |
843 $('subpage-backdrop').style.top = height; | 831 $('subpage-backdrop').style.top = height; |
| 832 $('policy-and-extension-managed-prefs-text').hidden = |
| 833 !controlledByPolicy || !controlledByExtension; |
| 834 $('policy-managed-prefs-text').hidden = |
| 835 !controlledByPolicy || controlledByExtension; |
| 836 $('extension-managed-prefs-text').hidden = |
| 837 controlledByPolicy || !controlledByExtension; |
844 } else { | 838 } else { |
845 bannerDiv.hidden = true; | 839 bannerDiv.hidden = true; |
846 $('subpage-backdrop').style.top = '0'; | 840 $('subpage-backdrop').style.top = '0'; |
847 } | 841 } |
848 }, | 842 }, |
849 | 843 |
850 /** | 844 /** |
851 * Gets page visibility state. | 845 * Gets page visibility state. |
852 */ | 846 */ |
853 get visible() { | 847 get visible() { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 canShowPage: function() { | 1014 canShowPage: function() { |
1021 return true; | 1015 return true; |
1022 }, | 1016 }, |
1023 }; | 1017 }; |
1024 | 1018 |
1025 // Export | 1019 // Export |
1026 return { | 1020 return { |
1027 OptionsPage: OptionsPage | 1021 OptionsPage: OptionsPage |
1028 }; | 1022 }; |
1029 }); | 1023 }); |
OLD | NEW |