Subversion Repositories oidplus

Rev

Rev 320 | 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
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) {
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: {
320 daniel-mar 33
                        plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.95",
310 daniel-mar 34
                        action:"deleteAttachment",
35
                        id:id,
36
                        filename:file,
37
                },
38
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 39
                        alert(_L("Error: %1",errorThrown));
310 daniel-mar 40
                },
41
                success:function(data) {
42
                        if ("error" in data) {
360 daniel-mar 43
                                alert(_L("Error: %1",data.error));
310 daniel-mar 44
                        } else if (data.status == 0) {
360 daniel-mar 45
                                alert(_L("OK"));
310 daniel-mar 46
                                reloadContent();
47
                        } else {
360 daniel-mar 48
                                alert(_L("Error: %1",data));
310 daniel-mar 49
                        }
50
                }
51
        });
52
}
53
 
54
function uploadAttachment(id, file) {
55
        var file_data = $('#fileAttachment').prop('files')[0];
56
 
57
        var form_data = new FormData();
58
        form_data.append('userfile', file_data);
320 daniel-mar 59
        form_data.append('plugin', "1.3.6.1.4.1.37476.2.5.2.4.1.95");
310 daniel-mar 60
        form_data.append('action', "uploadAttachment");
61
        form_data.append('id', id);
62
 
63
        $.ajax({
64
                url:"ajax.php",
65
                method:"POST",
66
                processData:false,
67
                contentType:false,
68
                data: form_data,
69
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 70
                        alert(_L("Error: %1",errorThrown));
310 daniel-mar 71
                },
72
                success:function(data) {
73
                        if ("error" in data) {
360 daniel-mar 74
                                alert(_L("Error: %1",data.error));
310 daniel-mar 75
                        } else if (data.status == 0) {
360 daniel-mar 76
                                alert(_L("OK"));
310 daniel-mar 77
                                $('#fileAttachment').val('');
78
                                reloadContent();
79
                        } else {
360 daniel-mar 80
                                alert(_L("Error: %1",data));
310 daniel-mar 81
                        }
82
                }
83
        });
84
}
85
 
86
function uploadAttachmentOnSubmit() {
87
        try {
88
                uploadAttachment(current_node, document.getElementById("fileAttachment").value);
89
        } finally {
90
                return false;
91
        }
360 daniel-mar 92
}