Subversion Repositories oidplus

Rev

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 OIDplusPagePublicAttachments = {
19
 
20
        oid: "1.3.6.1.4.1.37476.2.5.2.4.1.95",
21
 
22
        downloadAttachment: function(webpath, id, file) {
23
 
24
                //OIDplus::webpath(__DIR__).'download.php?id='.urlencode($id).'&filename='.urlencode(basename($file)).'
25
 
26
                window.open(webpath + 'download.php?id='+encodeURI(id)+'&filename='+encodeURI(file), '_blank');
27
 
28
        },
29
 
30
        deleteAttachment: function(id, file) {
31
                if(!window.confirm(_L("Are you sure that you want to delete %1?",file))) return false;
32
 
33
                $.ajax({
34
                        url:"ajax.php",
35
                        method:"POST",
36
                        beforeSend: function(jqXHR, settings) {
37
                                $.xhrPool.abortAll();
38
                                $.xhrPool.add(jqXHR);
39
                        },
40
                        complete: function(jqXHR, text) {
41
                                $.xhrPool.remove(jqXHR);
42
                        },
43
                        data: {
44
                                csrf_token:csrf_token,
45
                                plugin:OIDplusPagePublicAttachments.oid,
46
                                action:"deleteAttachment",
47
                                id:id,
48
                                filename:file,
49
                        },
50
                        error:function(jqXHR, textStatus, errorThrown) {
51
                                if (errorThrown == "abort") return;
833 daniel-mar 52
                                alertError(_L("Error: %1",errorThrown));
635 daniel-mar 53
                        },
54
                        success:function(data) {
55
                                if ("error" in data) {
833 daniel-mar 56
                                        alertError(_L("Error: %1",data.error));
635 daniel-mar 57
                                } else if (data.status >= 0) {
833 daniel-mar 58
                                        alertSuccess(_L("OK"));
635 daniel-mar 59
                                        reloadContent();
60
                                } else {
833 daniel-mar 61
                                        alertError(_L("Error: %1",data));
635 daniel-mar 62
                                }
63
                        }
64
                });
65
        },
66
 
67
        uploadAttachment: function(id, file) {
68
                var file_data = $('#fileAttachment').prop('files')[0];
69
 
70
                var form_data = new FormData();
71
                form_data.append('csrf_token', csrf_token);
72
                form_data.append('userfile', file_data);
73
                form_data.append('plugin', OIDplusPagePublicAttachments.oid);
74
                form_data.append('action', "uploadAttachment");
75
                form_data.append('id', id);
76
 
77
                $.ajax({
78
                        url:"ajax.php",
79
                        method:"POST",
80
                        processData:false,
81
                        contentType:false,
82
                        beforeSend: function(jqXHR, settings) {
83
                                $.xhrPool.abortAll();
84
                                $.xhrPool.add(jqXHR);
85
                        },
86
                        complete: function(jqXHR, text) {
87
                                $.xhrPool.remove(jqXHR);
88
                        },
89
                        data: form_data,
90
                        error:function(jqXHR, textStatus, errorThrown) {
91
                                if (errorThrown == "abort") return;
833 daniel-mar 92
                                alertError(_L("Error: %1",errorThrown));
635 daniel-mar 93
                        },
94
                        success:function(data) {
95
                                if ("error" in data) {
833 daniel-mar 96
                                        alertError(_L("Error: %1",data.error));
635 daniel-mar 97
                                } else if (data.status >= 0) {
833 daniel-mar 98
                                        alertSuccess(_L("OK"));
635 daniel-mar 99
                                        $('#fileAttachment').val('');
100
                                        reloadContent();
101
                                } else {
833 daniel-mar 102
                                        alertError(_L("Error: %1",data));
635 daniel-mar 103
                                }
104
                        }
105
                });
106
        },
107
 
108
        uploadAttachmentOnSubmit: function() {
109
                try {
110
                        OIDplusPagePublicAttachments.uploadAttachment(current_node, $("#fileAttachment")[0].value);
111
                } finally {
112
                        return false;
113
                }
114
        }
115
 
116
};