/usr/share/transmission/web/javascript/prefs-dialog.js is in transmission-common 2.84-3ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | /**
* Copyright © Jordan Lee, Dave Perrett, Malcolm Jarvis and Bruno Bierbaumer
*
* This file is licensed under the GPLv2.
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
function PrefsDialog(remote) {
var data = {
dialog: null,
remote: null,
elements: { },
// all the RPC session keys that we have gui controls for
keys: [
'alt-speed-down',
'alt-speed-time-begin',
'alt-speed-time-day',
'alt-speed-time-enabled',
'alt-speed-time-end',
'alt-speed-up',
'blocklist-enabled',
'blocklist-size',
'blocklist-url',
'dht-enabled',
'download-dir',
'encryption',
'idle-seeding-limit',
'idle-seeding-limit-enabled',
'lpd-enabled',
'peer-limit-global',
'peer-limit-per-torrent',
'peer-port',
'peer-port-random-on-start',
'pex-enabled',
'port-forwarding-enabled',
'rename-partial-files',
'seedRatioLimit',
'seedRatioLimited',
'speed-limit-down',
'speed-limit-down-enabled',
'speed-limit-up',
'speed-limit-up-enabled',
'start-added-torrents',
'utp-enabled'
],
// map of keys that are enabled only if a 'parent' key is enabled
groups: {
'alt-speed-time-enabled': ['alt-speed-time-begin',
'alt-speed-time-day',
'alt-speed-time-end' ],
'blocklist-enabled': ['blocklist-url',
'blocklist-update-button' ],
'idle-seeding-limit-enabled': [ 'idle-seeding-limit' ],
'seedRatioLimited': [ 'seedRatioLimit' ],
'speed-limit-down-enabled': [ 'speed-limit-down' ],
'speed-limit-up-enabled': [ 'speed-limit-up' ]
}
},
initTimeDropDown = function(e)
{
var i, hour, mins, value, content;
for (i=0; i<24*4; ++i) {
hour = parseInt(i/4, 10);
mins = ((i%4) * 15);
value = i * 15;
content = hour + ':' + (mins || '00');
e.options[i] = new Option(content, value);
}
},
onPortChecked = function(response)
{
var is_open = response['arguments']['port-is-open'],
text = 'Port is <b>' + (is_open ? 'Open' : 'Closed') + '</b>',
e = data.elements.root.find('#port-label');
setInnerHTML(e[0],text);
},
setGroupEnabled = function(parent_key, enabled)
{
var i, key, keys, root;
if (parent_key in data.groups)
{
root = data.elements.root,
keys = data.groups[parent_key];
for (i=0; key=keys[i]; ++i)
root.find('#'+key).attr('disabled',!enabled);
}
},
onBlocklistUpdateClicked = function ()
{
data.remote.updateBlocklist();
setBlocklistButtonEnabled(false);
},
setBlocklistButtonEnabled = function(b)
{
var e = data.elements.blocklist_button;
e.attr('disabled',!b);
e.val(b ? 'Update' : 'Updating...');
},
getValue = function(e)
{
var str;
switch (e[0].type)
{
case 'checkbox':
case 'radio':
return e.prop('checked');
case 'text':
case 'url':
case 'email':
case 'number':
case 'search':
case 'select-one':
str = e.val();
if( parseInt(str,10).toString() === str)
return parseInt(str,10);
if( parseFloat(str).toString() === str)
return parseFloat(str);
return str;
default:
return null;
}
},
/* this callback is for controls whose changes can be applied
immediately, like checkboxs, radioboxes, and selects */
onControlChanged = function(ev)
{
var o = {};
o[ev.target.id] = getValue($(ev.target));
data.remote.savePrefs(o);
},
/* these two callbacks are for controls whose changes can't be applied
immediately -- like a text entry field -- because it takes many
change events for the user to get to the desired result */
onControlFocused = function(ev)
{
data.oldValue = getValue($(ev.target));
},
onControlBlurred = function(ev)
{
var newValue = getValue($(ev.target));
if (newValue !== data.oldValue)
{
var o = {};
o[ev.target.id] = newValue;
data.remote.savePrefs(o);
delete data.oldValue;
}
},
getDefaultMobileOptions = function()
{
return {
width: $(window).width(),
height: $(window).height(),
position: [ 'left', 'top' ]
};
},
initialize = function (remote)
{
var i, key, e, o;
data.remote = remote;
e = $('#prefs-dialog');
data.elements.root = e;
initTimeDropDown(e.find('#alt-speed-time-begin')[0]);
initTimeDropDown(e.find('#alt-speed-time-end')[0]);
o = isMobileDevice
? getDefaultMobileOptions()
: { width: 350, height: 400 };
o.autoOpen = false;
o.show = o.hide = 'fade';
o.close = onDialogClosed;
e.tabbedDialog(o);
e = e.find('#blocklist-update-button');
data.elements.blocklist_button = e;
e.click(onBlocklistUpdateClicked);
// listen for user input
for (i=0; key=data.keys[i]; ++i)
{
e = data.elements.root.find('#'+key);
switch (e[0].type)
{
case 'checkbox':
case 'radio':
case 'select-one':
e.change(onControlChanged);
break;
case 'text':
case 'url':
case 'email':
case 'number':
case 'search':
e.focus(onControlFocused);
e.blur(onControlBlurred);
default:
break;
}
}
},
getValues = function()
{
var i, key, val, o={},
keys = data.keys,
root = data.elements.root;
for (i=0; key=keys[i]; ++i) {
val = getValue(root.find('#'+key));
if (val !== null)
o[key] = val;
}
return o;
},
onDialogClosed = function()
{
transmission.hideMobileAddressbar();
$(data.dialog).trigger('closed', getValues());
};
/****
***** PUBLIC FUNCTIONS
****/
// update the dialog's controls
this.set = function (o)
{
var e, i, key, val, option,
keys = data.keys,
root = data.elements.root;
setBlocklistButtonEnabled(true);
for (i=0; key=keys[i]; ++i)
{
val = o[key];
e = root.find('#'+key);
if (key === 'blocklist-size')
{
// special case -- regular text area
e.text('' + val.toStringWithCommas());
}
else switch (e[0].type)
{
case 'checkbox':
case 'radio':
e.prop('checked', val);
setGroupEnabled(key, val);
break;
case 'text':
case 'url':
case 'email':
case 'number':
case 'search':
// don't change the text if the user's editing it.
// it's very annoying when that happens!
if (e[0] !== document.activeElement)
e.val(val);
break;
case 'select-one':
e.val(val);
break;
default:
break;
}
}
};
this.show = function ()
{
transmission.hideMobileAddressbar();
setBlocklistButtonEnabled(true);
data.remote.checkPort(onPortChecked,this);
data.elements.root.dialog('open');
};
this.close = function ()
{
transmission.hideMobileAddressbar();
data.elements.root.dialog('close');
},
this.shouldAddedTorrentsStart = function()
{
return data.elements.root.find('#start-added-torrents')[0].checked;
};
data.dialog = this;
initialize (remote);
};
|