Rev 642 | 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 | }, |
||
43 | error:function(jqXHR, textStatus, errorThrown) { |
||
44 | if (errorThrown == "abort") return; |
||
833 | daniel-mar | 45 | alertError(_L("Error: %1",errorThrown)); |
635 | daniel-mar | 46 | }, |
47 | success:function(data) { |
||
48 | if ("error" in data) { |
||
833 | daniel-mar | 49 | alertError(_L("Error: %1",data.error)); |
635 | daniel-mar | 50 | } else if (data.status >= 0) { |
51 | console.log(_L("Imported OID %1",oid)); |
||
52 | OIDplusPageAdminOIDInfoExport.removeMissingOid(oid); |
||
53 | } else { |
||
833 | daniel-mar | 54 | alertError(_L("Error: %1",data)); |
635 | daniel-mar | 55 | } |
56 | } |
||
57 | }); |
||
58 | }, |
||
59 | |||
60 | uploadXmlFile: function(file) { |
||
61 | var file_data = $('#userfile').prop('files')[0]; |
||
62 | |||
63 | var form_data = new FormData(); |
||
64 | form_data.append('userfile', file_data); |
||
65 | form_data.append('plugin', OIDplusPageAdminOIDInfoExport.oid), |
||
66 | form_data.append('action', "import_xml_file"); |
||
67 | form_data.append('csrf_token', csrf_token); |
||
68 | |||
69 | $.ajax({ |
||
70 | url:"ajax.php", |
||
71 | method:"POST", |
||
72 | processData:false, |
||
73 | contentType:false, |
||
74 | beforeSend: function(jqXHR, settings) { |
||
75 | $.xhrPool.abortAll(); |
||
76 | $.xhrPool.add(jqXHR); |
||
77 | }, |
||
78 | complete: function(jqXHR, text) { |
||
79 | $.xhrPool.remove(jqXHR); |
||
80 | }, |
||
81 | data: form_data, |
||
82 | error:function(jqXHR, textStatus, errorThrown) { |
||
83 | if (errorThrown == "abort") return; |
||
833 | daniel-mar | 84 | alertError(_L("Error: %1",errorThrown)); |
635 | daniel-mar | 85 | }, |
86 | success:function(data) { |
||
87 | // 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" |
||
88 | if ("error" in data) { |
||
89 | if ("count_imported_oids" in data) { |
||
833 | daniel-mar | 90 | // TODO: Device if alertSuccess, alertWarning oder alertError is shown |
91 | alertSuccess(_L("Successfully imported OIDs: %1",data.count_imported_oids)+"\n"+ |
||
635 | daniel-mar | 92 | _L("Ignored OIDs because they are already existing: %1",data.count_already_existing)+"\n"+ |
93 | _L("Not imported because of errors: %1",data.count_errors)+"\n"+ |
||
94 | _L("Warnings: %1",data.count_warnings)+"\n"+ |
||
95 | "\n"+ |
||
96 | _L("Warnings / Error messages:")+"\n"+ |
||
97 | "\n"+ |
||
98 | data.error); |
||
99 | } else { |
||
833 | daniel-mar | 100 | alertError(_L("Error: %1",data.error)); |
635 | daniel-mar | 101 | } |
102 | } else if (data.status >= 0) { |
||
833 | daniel-mar | 103 | // TODO: Device if alertSuccess, alertWarning oder alertError is shown |
104 | alertSuccess(_L("Successfully imported OIDs: %1",data.count_imported_oids)+"\n"+ |
||
635 | daniel-mar | 105 | _L("Ignored OIDs because they are already existing: %1",data.count_already_existing)+"\n"+ |
106 | _L("Not imported because of errors: %1",data.count_errors)+"\n"+ |
||
107 | _L("Warnings: %1",data.count_warnings)); |
||
108 | $('#userfile').val(''); |
||
109 | } else { |
||
110 | if ("count_imported_oids" in data) { |
||
833 | daniel-mar | 111 | // TODO: Device if alertSuccess, alertWarning oder alertError is shown |
112 | alertSuccess(_L("Successfully imported OIDs: %1",data.count_imported_oids)+"\n"+ |
||
635 | daniel-mar | 113 | _L("Ignored OIDs because they are already existing: %1",data.count_already_existing)+"\n"+ |
114 | _L("Not imported because of errors: %1",data.count_errors)+"\n"+ |
||
115 | _L("Warnings: %1",data.count_warnings)+"\n"+ |
||
116 | "\n"+ |
||
117 | _L("Warnings / Error messages:")+"\n"+ |
||
118 | "\n"+ |
||
119 | data/*sic*/); |
||
120 | } else { |
||
833 | daniel-mar | 121 | alertError(_L("Error: %1",data)); |
635 | daniel-mar | 122 | } |
123 | } |
||
124 | } |
||
125 | }); |
||
126 | }, |
||
127 | |||
128 | uploadXmlFileOnSubmit: function() { |
||
129 | try { |
||
130 | OIDplusPageAdminOIDInfoExport.uploadXmlFile($("#userfile")[0].value); |
||
131 | } finally { |
||
132 | return false; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | }; |