Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
327 daniel-mar 1
/*
2
 * OIDplus 2.0
511 daniel-mar 3
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
327 daniel-mar 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
function removeMissingOid(oid) {
19
        $('#missing_oid_'+oid.replace(/\./g,'_')).remove();
20
}
21
 
22
function importMissingOid(oid) {
23
        $.ajax({
24
                url:"ajax.php",
25
                method:"POST",
26
                data: {
424 daniel-mar 27
                        csrf_token:csrf_token,
327 daniel-mar 28
                        plugin:"1.3.6.1.4.1.37476.2.5.2.4.3.400",
29
                        action:"import_oidinfo_oid",
30
                        oid:oid
31
                },
32
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 33
                        alert(_L("Error: %1",errorThrown));
327 daniel-mar 34
                },
35
                success:function(data) {
36
                        if ("error" in data) {
360 daniel-mar 37
                                alert(_L("Error: %1",data.error));
381 daniel-mar 38
                        } else if (data.status >= 0) {
360 daniel-mar 39
                                console.log(_L("Imported OID %1",oid));
327 daniel-mar 40
                                removeMissingOid(oid);
41
                        } else {
360 daniel-mar 42
                                alert(_L("Error: %1",data));
327 daniel-mar 43
                        }
44
                }
45
        });
46
}
47
 
48
function uploadXmlFile(file) {
49
        var file_data = $('#userfile').prop('files')[0];
50
 
51
        var form_data = new FormData();
52
        form_data.append('userfile', file_data);
53
        form_data.append('plugin', "1.3.6.1.4.1.37476.2.5.2.4.3.400");
54
        form_data.append('action', "import_xml_file");
424 daniel-mar 55
        form_data.append('csrf_token', csrf_token);
327 daniel-mar 56
 
57
        $.ajax({
58
                url:"ajax.php",
59
                method:"POST",
60
                processData:false,
61
                contentType:false,
62
                data: form_data,
63
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 64
                        alert(_L("Error: %1",errorThrown));
327 daniel-mar 65
                },
66
                success:function(data) {
67
                        // 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"
68
                        if ("error" in data) {
69
                                if ("count_imported_oids" in data) {
360 daniel-mar 70
                                        alert(_L("Successfully imported OIDs: %1",data.count_imported_oids)+"\n"+
71
                                              _L("Ignored OIDs because they are already existing: %1",data.count_already_existing)+"\n"+
72
                                              _L("Not imported because of errors: %1",data.count_errors)+"\n"+
73
                                              _L("Warnings: %1",data.count_warnings)+"\n"+
74
                                              "\n"+
75
                                              _L("Warnings / Error messages:")+"\n"+
76
                                              "\n"+
77
                                              data.error);
327 daniel-mar 78
                                } else {
360 daniel-mar 79
                                        alert(_L("Error: %1",data.error));
327 daniel-mar 80
                                }
381 daniel-mar 81
                        } else if (data.status >= 0) {
360 daniel-mar 82
                                alert(_L("Successfully imported OIDs: %1",data.count_imported_oids)+"\n"+
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));
327 daniel-mar 86
                                $('#userfile').val('');
87
                        } else {
88
                                if ("count_imported_oids" in data) {
360 daniel-mar 89
                                        alert(_L("Successfully imported OIDs: %1",data.count_imported_oids)+"\n"+
90
                                              _L("Ignored OIDs because they are already existing: %1",data.count_already_existing)+"\n"+
91
                                              _L("Not imported because of errors: %1",data.count_errors)+"\n"+
92
                                              _L("Warnings: %1",data.count_warnings)+"\n"+
93
                                              "\n"+
94
                                              _L("Warnings / Error messages:")+"\n"+
95
                                              "\n"+
96
                                              data/*sic*/);
327 daniel-mar 97
                                } else {
360 daniel-mar 98
                                        alert(_L("Error: %1",data));
327 daniel-mar 99
                                }
100
                        }
101
                }
102
        });
103
}
104
 
105
function uploadXmlFileOnSubmit() {
106
        try {
107
                uploadXmlFile(document.getElementById("userfile").value);
108
        } finally {
109
                return false;
110
        }
360 daniel-mar 111
}