jshint and format app.js

This commit is contained in:
Jakob Borg 2014-09-18 20:05:05 +02:00
parent 9c68be4d5e
commit bf909db3f9
2 changed files with 78 additions and 61 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
/*jslint browser: true, continue: true, plusplus: true */ /*jslint browser: true, continue: true, plusplus: true */
/*global $: false, angular: false */ /*global $: false, angular: false, console: false, validLangs: false */
'use strict'; 'use strict';
@ -42,7 +42,7 @@ syncthing.controller('EventCtrl', function ($scope, $http) {
console.log("event", event.id, event.type, event.data); console.log("event", event.id, event.type, event.data);
$scope.$emit(event.type, event); $scope.$emit(event.type, event);
}); });
}; }
$scope.lastEvent = data[data.length - 1]; $scope.lastEvent = data[data.length - 1];
lastID = $scope.lastEvent.id; lastID = $scope.lastEvent.id;
@ -108,11 +108,11 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
// The langs returned by the /rest/langs call will be in lower // The langs returned by the /rest/langs call will be in lower
// case. We compare to the lowercase version of the language // case. We compare to the lowercase version of the language
// code we have as well. // code we have as well.
possibleLang = possibleLang.toLowerCase() possibleLang = possibleLang.toLowerCase();
if (possibleLang.length > lang.length) { if (possibleLang.length > lang.length) {
return possibleLang.indexOf(lang) == 0; return possibleLang.indexOf(lang) === 0;
} else { } else {
return lang.indexOf(possibleLang) == 0; return lang.indexOf(possibleLang) === 0;
} }
}); });
if (matching.length >= 1) { if (matching.length >= 1) {
@ -122,7 +122,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
} }
// Fallback if nothing matched // Fallback if nothing matched
$translate.use("en"); $translate.use("en");
}) });
$(window).bind('beforeunload', function () { $(window).bind('beforeunload', function () {
navigatingAway = true; navigatingAway = true;
@ -140,13 +140,13 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
'rmdir': 'Del (dir)', 'rmdir': 'Del (dir)',
'sync': 'Sync', 'sync': 'Sync',
'touch': 'Update', 'touch': 'Update',
} };
$scope.needIcons = { $scope.needIcons = {
'rm': 'remove', 'rm': 'remove',
'rmdir': 'remove', 'rmdir': 'remove',
'sync': 'download', 'sync': 'download',
'touch': 'asterisk', 'touch': 'asterisk',
} };
$scope.$on('UIOnline', function (event, arg) { $scope.$on('UIOnline', function (event, arg) {
if (online && !restarting) { if (online && !restarting) {
@ -222,7 +222,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
}); });
$scope.$on('ConfigLoaded', function (event) { $scope.$on('ConfigLoaded', function (event) {
if ($scope.config.Options.URAccepted == 0) { if ($scope.config.Options.URAccepted === 0) {
// If usage reporting has been neither accepted nor declined, // If usage reporting has been neither accepted nor declined,
// we want to ask the user to make a choice. But we don't want // we want to ask the user to make a choice. But we don't want
// to bug them during initial setup, so we set a cookie with // to bug them during initial setup, so we set a cookie with
@ -239,7 +239,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
} }
} }
} }
}) });
$scope.$on('ConfigSaved', function (event, arg) { $scope.$on('ConfigSaved', function (event, arg) {
updateLocalConfig(arg.data); updateLocalConfig(arg.data);
@ -301,7 +301,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
function refreshCompletion(node, repo) { function refreshCompletion(node, repo) {
if (node === $scope.myID) { if (node === $scope.myID) {
return return;
} }
var key = "refreshCompletion" + node + repo; var key = "refreshCompletion" + node + repo;
@ -313,7 +313,8 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
} }
$scope.completion[node][repo] = data.completion; $scope.completion[node][repo] = data.completion;
var tot = 0, cnt = 0; var tot = 0,
cnt = 0;
for (var cmp in $scope.completion[node]) { for (var cmp in $scope.completion[node]) {
if (cmp === "_total") { if (cmp === "_total") {
continue; continue;
@ -497,7 +498,9 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
}; };
$scope.findNode = function (nodeID) { $scope.findNode = function (nodeID) {
var matches = $scope.nodes.filter(function (n) { return n.NodeID == nodeID; }); var matches = $scope.nodes.filter(function (n) {
return n.NodeID == nodeID;
});
if (matches.length != 1) { if (matches.length != 1) {
return undefined; return undefined;
} }
@ -536,7 +539,11 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
$scope.saveConfig = function () { $scope.saveConfig = function () {
var cfg = JSON.stringify($scope.config); var cfg = JSON.stringify($scope.config);
var opts = {headers: {'Content-Type': 'application/json'}}; var opts = {
headers: {
'Content-Type': 'application/json'
}
};
$http.post(urlbase + '/config', cfg, opts).success(function () { $http.post(urlbase + '/config', cfg, opts).success(function () {
$http.get(urlbase + '/config/sync').success(function (data) { $http.get(urlbase + '/config/sync').success(function (data) {
$scope.configInSync = data.configInSync; $scope.configInSync = data.configInSync;
@ -565,7 +572,9 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
$scope.thisNode().Name = $scope.tmpOptions.NodeName; $scope.thisNode().Name = $scope.tmpOptions.NodeName;
$scope.config.Options = angular.copy($scope.tmpOptions); $scope.config.Options = angular.copy($scope.tmpOptions);
$scope.config.GUI = angular.copy($scope.tmpGUI); $scope.config.GUI = angular.copy($scope.tmpGUI);
$scope.config.Options.ListenAddress = $scope.config.Options.ListenStr.split(',').map(function (x) { return x.trim(); }); $scope.config.Options.ListenAddress = $scope.config.Options.ListenStr.split(',').map(function (x) {
return x.trim();
});
$scope.saveConfig(); $scope.saveConfig();
} }
@ -628,7 +637,10 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
}; };
$scope.addNode = function () { $scope.addNode = function () {
$scope.currentNode = {AddressesStr: 'dynamic', Compression: true}; $scope.currentNode = {
AddressesStr: 'dynamic',
Compression: true
};
$scope.editingExisting = false; $scope.editingExisting = false;
$scope.editingSelf = false; $scope.editingSelf = false;
$scope.nodeEditor.$setPristine(); $scope.nodeEditor.$setPristine();
@ -660,7 +672,9 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
$('#editNode').modal('hide'); $('#editNode').modal('hide');
nodeCfg = $scope.currentNode; nodeCfg = $scope.currentNode;
nodeCfg.Addresses = nodeCfg.AddressesStr.split(',').map(function (x) { return x.trim(); }); nodeCfg.Addresses = nodeCfg.AddressesStr.split(',').map(function (x) {
return x.trim();
});
done = false; done = false;
for (i = 0; i < $scope.nodes.length; i++) { for (i = 0; i < $scope.nodes.length; i++) {
@ -763,7 +777,9 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
}; };
$scope.addRepo = function () { $scope.addRepo = function () {
$scope.currentRepo = {selectedNodes: {}}; $scope.currentRepo = {
selectedNodes: {}
};
$scope.currentRepo.RescanIntervalS = 60; $scope.currentRepo.RescanIntervalS = 60;
$scope.currentRepo.FileVersioningSelector = "none"; $scope.currentRepo.FileVersioningSelector = "none";
$scope.currentRepo.simpleKeep = 5; $scope.currentRepo.simpleKeep = 5;
@ -784,7 +800,9 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
repoCfg.selectedNodes[$scope.myID] = true; repoCfg.selectedNodes[$scope.myID] = true;
for (var nodeID in repoCfg.selectedNodes) { for (var nodeID in repoCfg.selectedNodes) {
if (repoCfg.selectedNodes[nodeID] === true) { if (repoCfg.selectedNodes[nodeID] === true) {
repoCfg.Nodes.push({NodeID: nodeID}); repoCfg.Nodes.push({
NodeID: nodeID
});
} }
} }
delete repoCfg.selectedNodes; delete repoCfg.selectedNodes;
@ -852,7 +870,7 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
$('#urPreview').modal().on('hidden.bs.modal', function () { $('#urPreview').modal().on('hidden.bs.modal', function () {
$('#settings').modal(); $('#settings').modal();
}); });
} };
$scope.acceptUR = function () { $scope.acceptUR = function () {
$scope.config.Options.URAccepted = 1000; // Larger than the largest existing report version $scope.config.Options.URAccepted = 1000; // Larger than the largest existing report version
@ -958,12 +976,11 @@ function decimals(val, num) {
return decs; return decs;
} }
function randomString(len, bits) function randomString(len, bits) {
{
bits = bits || 36; bits = bits || 36;
var outStr = "", newStr; var outStr = "",
while (outStr.length < len) newStr;
{ while (outStr.length < len) {
newStr = Math.random().toString(bits).slice(2); newStr = Math.random().toString(bits).slice(2);
outStr += newStr.slice(0, Math.min(newStr.length, (len - outStr.length))); outStr += newStr.slice(0, Math.min(newStr.length, (len - outStr.length)));
} }
@ -1138,5 +1155,5 @@ syncthing.directive('modal', function () {
close: '@', close: '@',
large: '@', large: '@',
}, },
} };
}); });