Repository: syncthing/syncthing
File: gui/default/syncthing/core/syncthingController.js (JavaScript)

Code before:
                // omitted on purpose, as old Chrome versions reported "false"
                // despite supporting the feature.
                var textarea = document.createElement("textarea");
                event.currentTarget.appendChild(textarea);
                textarea.style.position = "fixed";
                textarea.style.opacity = "0";
                textarea.textContent = text;
                textarea.select();
                try {
                    document.execCommand("copy");
                    return alert(success);
                }
                catch (ex) {
                    return alert(failure);
                }
                finally {
                    event.currentTarget.removeChild(textarea);
                }
            }
            return alert(failure);
        };

        $scope.shareDeviceId = function(method) {
            // Title and footer can be reused between email, SMS, and possibly
            // other methods, hence we define them separately in the beginning.
            var title = $translate.instant("{%name%} has shared their Syncthing device ID!", {name: $scope.currentDevice.name});
            var footer = $translate.instant("Learn more at {%address%}.", {address: "https://syncthing.net"});

            switch (method) {
                case 'email':
                    var subject = title;
                    var body = $translate.instant("You have been invited to connect with {%name%} using Syncthing!\r\n\r\nTo accept the invitation, add a new device using the ID below.", {name: $scope.currentDevice.name});
                    body += '\r\n\r\n';
                    body += $scope.currentDevice.deviceID;
                    body += '\r\n\r\n';
                    body += $translate.instant("Syncthing is a continuous file synchronization program. It synchronizes files between two or more computers in real time, safely protected from prying eyes. Your data is your data alone and you deserve to choose where it is stored, whether it is shared with some third party, and how it's transmitted over the internet.");
                    body += '\r\n\r\n';
                    body += footer;
                    try {
                        location.href = 'mailto:?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body);
                        success = true;
                    }
                    catch (ex) {
                        var error = $translate.instant("No email client found. Do you want to copy the email text to clipboard instead?");
                        if (confirm(error)) {
                              $scope.copyToClipboard(onclick, body);
                        }
                    }
                    break;
                case 'sms':
                    // SMS is limited to 160 characters (non-Unicode), so we keep

Review comment (suggestion):
You could use `$scope.deviceName()` here or at least provide a fallback yourself for when the device name is empty.

Code after:
            if (value === null) {
                return 'null';
            }
            if (typeof value === 'number') {
                return 'number';
            }
            if (typeof value === 'boolean') {
                return 'checkbox';
            }
            if (value instanceof Array) {
                return 'list';
            }
            if (typeof value === 'object') {
                return 'skip';
            }
            return 'text';
        };

        $scope.themeName = function (theme) {
            var translation = $translate.instant("theme-name-" + theme);
            if (translation.indexOf("theme-name-") == 0) {
                // Fall back to simple Title Casing on missing translation
                translation = theme.toLowerCase().replace(/(?:^|\s)\S/g, function (a) {
                    return a.toUpperCase();
                });
            }
            return translation;
        };

        $scope.modalLoaded = function () {
            // once all modal elements have been processed
            if ($('modal').length === 0) {
                // pseudo main. called on all definitions assigned
                initController();
            }
        };

        $scope.toggleUnits = function () {
            $scope.metricRates = !$scope.metricRates;
            try {
                window.localStorage["metricRates"] = $scope.metricRates;
            } catch (exception) { }
        };

        $scope.sizeOf = function (dict) {
            if (dict === undefined) {
                return 0;
            }
            return Object.keys(dict).length;
        };