Welcome to mirror list, hosted at ThFree Co, Russian Federation.

EditUriBackendConfig.js « services « scripts « ngax « webroot « Server « Duplicati - github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8a2d27cc5028c10395cb97d7741efde612029c16 (plain)
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
backupApp.service('EditUriBackendConfig', function(AppService, AppUtils, SystemInfo, DialogService, gettextCatalog) {

    var self = this;

    // All backends with a custom UI must register here
    this.templates = { };

    // Loaders are a way for backends to request extra data from the server
    this.loaders = { };

    // Parsers take a decomposed uri input and sets up the scope variables
    this.parsers = { };

    // Builders take the scope and produce the uri output
    this.builders = { };

    // Validaters check the input and show the user an error or warning
    this.validaters = { };

    // Testers perform additional checks when pressing the Test button
    this.testers = { };

    this.defaultbackend = 'file';
    this.defaulttemplate = 'templates/backends/generic.html';
    this.defaultbuilder = function(scope) {
        var opts = {};
        self.merge_in_advanced_options(scope, opts);

        var url = AppUtils.format('{0}{1}://{2}{3}/{4}{5}',
            scope.Backend.Key,
            (scope.SupportsSSL && scope.UseSSL) ? 's' : '',
            scope.Server || '',
            (scope.Port || '') == '' ? '' : ':' + scope.Port,
            scope.Path || '',
            AppUtils.encodeDictAsUrl(opts)
        );

        return url;
    };

    this.merge_in_advanced_options = function(scope, dict) {
        if (scope.Username != null && scope.Username != '')
            dict['auth-username'] = scope.Username;
        if (scope.Password != null && scope.Password != '')
            dict['auth-password'] = scope.Password;

        if (!AppUtils.parse_extra_options(scope.AdvancedOptions, dict))
            return false;

        for(var k in dict)
            if (k.indexOf('--') == 0) {
                dict[k.substr(2)] = dict[k];
                delete dict[k];
            }

        return true;

    };

    this.show_error_dialog = function(msg) {
        DialogService.dialog('Error', msg);
        return false;
    }

    this.show_warning_dialog = function(msg, continuation) {
        DialogService.dialog(gettextCatalog.getString('Confirmation required'), msg, [gettextCatalog.getString('No'), gettextCatalog.getString('Yes')], function(ix) {
            if (ix == 1)
                continuation();
        });
    }

    this.defaultvalidater = function(scope, continuation) {
        continuation();
    };

    this.require_field = function(scope, field, label) {
        if ((scope[field] || '').trim().length == 0)
            return self.show_error_dialog(gettextCatalog.getString('You must fill in {{field}}', { field: label || field }));

        return true;
    };

    this.require_server = function(scope) {
        if ((scope.Server || '').trim().length == 0)
            return self.show_error_dialog(gettextCatalog.getString('You must fill in the server name or address'));

        return true;
    };

    this.require_path = function(scope) {
        if ((scope.Path || '').trim().length == 0)
            return self.show_error_dialog(gettextCatalog.getString('You must fill in the path'));

        return true;
    };

    this.recommend_path = function(scope, continuation) {
        if ((scope.Path || '').trim().length == 0)
            return self.show_warning_dialog(gettextCatalog.getString('If you do not enter a path, all files will be stored in the login folder.\nAre you sure this is what you want?'), continuation);
        else
            continuation();
    };

    this.require_username_and_password = function(scope) {
        if ((scope.Username || '').trim().length == 0)
            return self.show_error_dialog(gettextCatalog.getString('You must fill in the username'));
        if ((scope.Password || '').trim().length == 0)
            return self.show_error_dialog(gettextCatalog.getString('You must fill in the password'));

        return true;
    };

});