Subversion Repositories oidplus

Rev

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