Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /*
2 * Copyright 2012, Mozilla Foundation and contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
17 'use strict';
19 var l10n = require('../util/l10n');
20 var settings = require('../settings');
22 /**
23 * Format a list of settings for display
24 */
25 var prefsData = {
26 item: 'converter',
27 from: 'prefsData',
28 to: 'view',
29 exec: function(prefsData, conversionContext) {
30 var prefList = new PrefList(prefsData, conversionContext);
31 return {
32 html:
33 '<div ignore="${onLoad(__element)}">\n' +
34 ' <!-- This is broken, and unimportant. Comment out for now\n' +
35 ' <div class="gcli-pref-list-filter">\n' +
36 ' ${l10n.prefOutputFilter}:\n' +
37 ' <input onKeyUp="${onFilterChange}" value="${search}"/>\n' +
38 ' </div>\n' +
39 ' -->\n' +
40 ' <table class="gcli-pref-list-table">\n' +
41 ' <colgroup>\n' +
42 ' <col class="gcli-pref-list-name"/>\n' +
43 ' <col class="gcli-pref-list-value"/>\n' +
44 ' </colgroup>\n' +
45 ' <tr>\n' +
46 ' <th>${l10n.prefOutputName}</th>\n' +
47 ' <th>${l10n.prefOutputValue}</th>\n' +
48 ' </tr>\n' +
49 ' </table>\n' +
50 ' <div class="gcli-pref-list-scroller">\n' +
51 ' <table class="gcli-pref-list-table" save="${table}">\n' +
52 ' </table>\n' +
53 ' </div>\n' +
54 '</div>\n',
55 data: prefList,
56 options: {
57 blankNullUndefined: true,
58 allowEval: true,
59 stack: 'prefsData->view'
60 },
61 css:
62 '.gcli-pref-list-scroller {\n' +
63 ' max-height: 200px;\n' +
64 ' overflow-y: auto;\n' +
65 ' overflow-x: hidden;\n' +
66 ' display: inline-block;\n' +
67 '}\n' +
68 '\n' +
69 '.gcli-pref-list-table {\n' +
70 ' width: 500px;\n' +
71 ' table-layout: fixed;\n' +
72 '}\n' +
73 '\n' +
74 '.gcli-pref-list-table tr > th {\n' +
75 ' text-align: left;\n' +
76 '}\n' +
77 '\n' +
78 '.gcli-pref-list-table tr > td {\n' +
79 ' text-overflow: elipsis;\n' +
80 ' word-wrap: break-word;\n' +
81 '}\n' +
82 '\n' +
83 '.gcli-pref-list-name {\n' +
84 ' width: 70%;\n' +
85 '}\n' +
86 '\n' +
87 '.gcli-pref-list-command {\n' +
88 ' display: none;\n' +
89 '}\n' +
90 '\n' +
91 '.gcli-pref-list-row:hover .gcli-pref-list-command {\n' +
92 ' /* \'pref list\' is a bit broken and unimportant. Band-aid follows */\n' +
93 ' /* display: inline-block; */\n' +
94 '}\n',
95 cssId: 'gcli-pref-list'
96 };
97 }
98 };
100 /**
101 * 'pref list' command
102 */
103 var prefList = {
104 item: 'command',
105 name: 'pref list',
106 description: l10n.lookup('prefListDesc'),
107 manual: l10n.lookup('prefListManual'),
108 params: [
109 {
110 name: 'search',
111 type: 'string',
112 defaultValue: null,
113 description: l10n.lookup('prefListSearchDesc'),
114 manual: l10n.lookup('prefListSearchManual')
115 }
116 ],
117 returnType: 'prefsData',
118 exec: function(args, context) {
119 var deferred = context.defer();
121 // This can be slow, get out of the way of the main thread
122 setTimeout(function() {
123 var prefsData = {
124 settings: settings.getAll(args.search),
125 search: args.search
126 };
127 deferred.resolve(prefsData);
128 }.bind(this), 10);
130 return deferred.promise;
131 }
132 };
134 /**
135 * A manager for our version of about:config
136 */
137 function PrefList(prefsData, conversionContext) {
138 this.search = prefsData.search;
139 this.settings = prefsData.settings;
140 this.conversionContext = conversionContext;
141 }
143 /**
144 * A load event handler registered by the template engine so we can load the
145 * inner document
146 */
147 PrefList.prototype.onLoad = function(element) {
148 var table = element.querySelector('.gcli-pref-list-table');
149 this.updateTable(table);
150 return '';
151 };
153 /**
154 * Forward localization lookups
155 */
156 PrefList.prototype.l10n = l10n.propertyLookup;
158 /**
159 * Called from the template onkeyup for the filter element
160 */
161 PrefList.prototype.updateTable = function(table) {
162 var view = this.conversionContext.createView({
163 html:
164 '<table>\n' +
165 ' <colgroup>\n' +
166 ' <col class="gcli-pref-list-name"/>\n' +
167 ' <col class="gcli-pref-list-value"/>\n' +
168 ' </colgroup>\n' +
169 ' <tr class="gcli-pref-list-row" foreach="setting in ${settings}">\n' +
170 ' <td>${setting.name}</td>\n' +
171 ' <td onclick="${onSetClick}" data-command="pref set ${setting.name} ">\n' +
172 ' ${setting.value}\n' +
173 ' [Edit]\n' +
174 ' </td>\n' +
175 ' </tr>\n' +
176 '</table>\n',
177 options: { blankNullUndefined: true, stack: 'prefsData#inner' },
178 data: this
179 });
181 view.appendTo(table, true);
182 };
184 PrefList.prototype.onFilterChange = function(ev) {
185 if (ev.target.value !== this.search) {
186 this.search = ev.target.value;
188 var root = ev.target.parentNode.parentNode;
189 var table = root.querySelector('.gcli-pref-list-table');
190 this.updateTable(table);
191 }
192 };
194 PrefList.prototype.onSetClick = function(ev) {
195 var typed = ev.currentTarget.getAttribute('data-command');
196 this.conversionContext.update(typed);
197 };
199 exports.items = [ prefsData, prefList ];