toolkit/devtools/gcli/source/lib/gcli/commands/preflist.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial