Rev 424 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
310 | daniel-mar | 1 | /* |
2 | * OIDplus 2.0 |
||
511 | daniel-mar | 3 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
310 | 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 downloadAttachment(webpath, id, file) { |
||
19 | |||
20 | //OIDplus::webpath(__DIR__).'download.php?id='.urlencode($id).'&filename='.urlencode(basename($file)).' |
||
21 | |||
22 | window.open(webpath + 'download.php?id='+encodeURI(id)+'&filename='+encodeURI(file), '_blank'); |
||
23 | |||
24 | } |
||
25 | |||
26 | function deleteAttachment(id, file) { |
||
360 | daniel-mar | 27 | if(!window.confirm(_L("Are you sure that you want to delete %1?",file))) return false; |
310 | daniel-mar | 28 | |
29 | $.ajax({ |
||
30 | url:"ajax.php", |
||
31 | method:"POST", |
||
32 | data: { |
||
424 | daniel-mar | 33 | csrf_token:csrf_token, |
320 | daniel-mar | 34 | plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.95", |
310 | daniel-mar | 35 | action:"deleteAttachment", |
36 | id:id, |
||
37 | filename:file, |
||
38 | }, |
||
39 | error:function(jqXHR, textStatus, errorThrown) { |
||
360 | daniel-mar | 40 | alert(_L("Error: %1",errorThrown)); |
310 | daniel-mar | 41 | }, |
42 | success:function(data) { |
||
43 | if ("error" in data) { |
||
360 | daniel-mar | 44 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 45 | } else if (data.status >= 0) { |
360 | daniel-mar | 46 | alert(_L("OK")); |
310 | daniel-mar | 47 | reloadContent(); |
48 | } else { |
||
360 | daniel-mar | 49 | alert(_L("Error: %1",data)); |
310 | daniel-mar | 50 | } |
51 | } |
||
52 | }); |
||
53 | } |
||
54 | |||
55 | function uploadAttachment(id, file) { |
||
56 | var file_data = $('#fileAttachment').prop('files')[0]; |
||
57 | |||
58 | var form_data = new FormData(); |
||
424 | daniel-mar | 59 | form_data.append('csrf_token', csrf_token); |
310 | daniel-mar | 60 | form_data.append('userfile', file_data); |
320 | daniel-mar | 61 | form_data.append('plugin', "1.3.6.1.4.1.37476.2.5.2.4.1.95"); |
310 | daniel-mar | 62 | form_data.append('action', "uploadAttachment"); |
63 | form_data.append('id', id); |
||
64 | |||
65 | $.ajax({ |
||
66 | url:"ajax.php", |
||
67 | method:"POST", |
||
68 | processData:false, |
||
69 | contentType:false, |
||
70 | data: form_data, |
||
71 | error:function(jqXHR, textStatus, errorThrown) { |
||
360 | daniel-mar | 72 | alert(_L("Error: %1",errorThrown)); |
310 | daniel-mar | 73 | }, |
74 | success:function(data) { |
||
75 | if ("error" in data) { |
||
360 | daniel-mar | 76 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 77 | } else if (data.status >= 0) { |
360 | daniel-mar | 78 | alert(_L("OK")); |
310 | daniel-mar | 79 | $('#fileAttachment').val(''); |
80 | reloadContent(); |
||
81 | } else { |
||
360 | daniel-mar | 82 | alert(_L("Error: %1",data)); |
310 | daniel-mar | 83 | } |
84 | } |
||
85 | }); |
||
86 | } |
||
87 | |||
88 | function uploadAttachmentOnSubmit() { |
||
89 | try { |
||
90 | uploadAttachment(current_node, document.getElementById("fileAttachment").value); |
||
91 | } finally { |
||
92 | return false; |
||
93 | } |
||
360 | daniel-mar | 94 | } |