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