Subversion Repositories oidplus

Rev

Rev 1036 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
635 daniel-mar 1
/*
2
 * OIDplus 2.0
3
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
 
18
var OIDplusPageAdminOIDInfoExport = {
19
 
20
        oid: "1.3.6.1.4.1.37476.2.5.2.4.3.400",
21
 
22
        removeMissingOid: function(oid) {
23
                $('#missing_oid_'+oid.replace(/\./g,'_')).remove();
24
        },
25
 
26
        importMissingOid: function(oid) {
27
                $.ajax({
28
                        url:"ajax.php",
29
                        method:"POST",
30
                        beforeSend: function(jqXHR, settings) {
31
                                $.xhrPool.abortAll();
32
                                $.xhrPool.add(jqXHR);
33
                        },
34
                        complete: function(jqXHR, text) {
35
                                $.xhrPool.remove(jqXHR);
36
                        },
37
                        data: {
38
                                csrf_token: csrf_token,
39
                                plugin: OIDplusPageAdminOIDInfoExport.oid,
40
                                action: "import_oidinfo_oid",
41
                                oid: oid
42
                        },
1036 daniel-mar 43
                        error: oidplus_ajax_error,
44
                        success: function (data) {
45
                                oidplus_ajax_success(data, function (data) {
46
                                        console.log(_L("Imported OID %1", oid));
635 daniel-mar 47
                                        OIDplusPageAdminOIDInfoExport.removeMissingOid(oid);
1036 daniel-mar 48
                                });
635 daniel-mar 49
                        }
50
                });
51
        },
52
 
53
        uploadXmlFile: function(file) {
54
                var file_data = $('#userfile').prop('files')[0];
55
 
56
                var form_data = new FormData();
57
                form_data.append('userfile', file_data);
58
                form_data.append('plugin', OIDplusPageAdminOIDInfoExport.oid),
59
                form_data.append('action', "import_xml_file");
60
                form_data.append('csrf_token', csrf_token);
61
 
62
                $.ajax({
63
                        url:"ajax.php",
64
                        method:"POST",
65
                        processData:false,
66
                        contentType:false,
67
                        beforeSend: function(jqXHR, settings) {
68
                                $.xhrPool.abortAll();
69
                                $.xhrPool.add(jqXHR);
70
                        },
71
                        complete: function(jqXHR, text) {
72
                                $.xhrPool.remove(jqXHR);
73
                        },
74
                        data: form_data,
1036 daniel-mar 75
                        error: oidplus_ajax_error,
635 daniel-mar 76
                        success:function(data) {
77
                                // TODO XXX: (Future feature) If the user decides that existing OIDs shall be overwritten, then we may not print "Ignored OIDs because they are already existing"
1292 daniel-mar 78
                                // TODO: Use oidplus_ajax_success(), since this checks the existance of "error" in data, and checks if status>=0
1036 daniel-mar 79
                                if (typeof data === "object" && "error" in data) {
80
                                        if (typeof data === "object" && "count_imported_oids" in data) {
833 daniel-mar 81
                                                // TODO: Device if alertSuccess, alertWarning oder alertError is shown
82
                                                alertSuccess(_L("Successfully imported OIDs: %1",data.count_imported_oids)+"\n"+
635 daniel-mar 83
                                                          _L("Ignored OIDs because they are already existing: %1",data.count_already_existing)+"\n"+
84
                                                          _L("Not imported because of errors: %1",data.count_errors)+"\n"+
85
                                                          _L("Warnings: %1",data.count_warnings)+"\n"+
86
                                                          "\n"+
87
                                                          _L("Warnings / Error messages:")+"\n"+
88
                                                          "\n"+
89
                                                          data.error);
90
                                        } else {
833 daniel-mar 91
                                                alertError(_L("Error: %1",data.error));
635 daniel-mar 92
                                        }
1036 daniel-mar 93
                                } else if (typeof data === "object" && data.status >= 0) {
833 daniel-mar 94
                                        // TODO: Device if alertSuccess, alertWarning oder alertError is shown
95
                                        alertSuccess(_L("Successfully imported OIDs: %1",data.count_imported_oids)+"\n"+
635 daniel-mar 96
                                                  _L("Ignored OIDs because they are already existing: %1",data.count_already_existing)+"\n"+
97
                                                  _L("Not imported because of errors: %1",data.count_errors)+"\n"+
98
                                                  _L("Warnings: %1",data.count_warnings));
99
                                        $('#userfile').val('');
100
                                } else {
1036 daniel-mar 101
                                        if (typeof data === "object" && "count_imported_oids" in data) {
833 daniel-mar 102
                                                // TODO: Device if alertSuccess, alertWarning oder alertError is shown
103
                                                alertSuccess(_L("Successfully imported OIDs: %1",data.count_imported_oids)+"\n"+
635 daniel-mar 104
                                                          _L("Ignored OIDs because they are already existing: %1",data.count_already_existing)+"\n"+
105
                                                          _L("Not imported because of errors: %1",data.count_errors)+"\n"+
106
                                                          _L("Warnings: %1",data.count_warnings)+"\n"+
107
                                                          "\n"+
108
                                                          _L("Warnings / Error messages:")+"\n"+
109
                                                          "\n"+
110
                                                          data/*sic*/);
111
                                        } else {
833 daniel-mar 112
                                                alertError(_L("Error: %1",data));
635 daniel-mar 113
                                        }
114
                                }
115
                        }
116
                });
117
        },
118
 
119
        uploadXmlFileOnSubmit: function() {
120
                try {
121
                        OIDplusPageAdminOIDInfoExport.uploadXmlFile($("#userfile")[0].value);
122
                } finally {
123
                        return false;
124
                }
125
        }
126
 
127
};