Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
310 | 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 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) { |
||
27 | if(!window.confirm("Are you sure that you want to delete "+file+"?")) return false; |
||
28 | |||
29 | $.ajax({ |
||
30 | url:"ajax.php", |
||
31 | method:"POST", |
||
32 | data: { |
||
33 | action:"deleteAttachment", |
||
34 | id:id, |
||
35 | filename:file, |
||
36 | }, |
||
37 | error:function(jqXHR, textStatus, errorThrown) { |
||
38 | alert("Error: " + errorThrown); |
||
39 | }, |
||
40 | success:function(data) { |
||
41 | if ("error" in data) { |
||
42 | alert("Error: " + data.error); |
||
43 | } else if (data.status == 0) { |
||
44 | alert("OK"); |
||
45 | reloadContent(); |
||
46 | } else { |
||
47 | alert("Error: " + data); |
||
48 | } |
||
49 | } |
||
50 | }); |
||
51 | } |
||
52 | |||
53 | function uploadAttachment(id, file) { |
||
54 | var file_data = $('#fileAttachment').prop('files')[0]; |
||
55 | |||
56 | var form_data = new FormData(); |
||
57 | form_data.append('userfile', file_data); |
||
58 | form_data.append('action', "uploadAttachment"); |
||
59 | form_data.append('id', id); |
||
60 | |||
61 | $.ajax({ |
||
62 | url:"ajax.php", |
||
63 | method:"POST", |
||
64 | processData:false, |
||
65 | contentType:false, |
||
66 | data: form_data, |
||
67 | error:function(jqXHR, textStatus, errorThrown) { |
||
68 | alert("Error: " + errorThrown); |
||
69 | }, |
||
70 | success:function(data) { |
||
71 | if ("error" in data) { |
||
72 | alert("Error: " + data.error); |
||
73 | } else if (data.status == 0) { |
||
74 | alert("OK"); |
||
75 | $('#fileAttachment').val(''); |
||
76 | reloadContent(); |
||
77 | } else { |
||
78 | alert("Error: " + data); |
||
79 | } |
||
80 | } |
||
81 | }); |
||
82 | } |
||
83 | |||
84 | function uploadAttachmentOnSubmit() { |
||
85 | try { |
||
86 | uploadAttachment(current_node, document.getElementById("fileAttachment").value); |
||
87 | } finally { |
||
88 | return false; |
||
89 | } |
||
90 | } |