Subversion Repositories oidplus

Rev

Rev 424 | Go to most recent revision | View as "text/javascript" | Blame | Last modification | View Log | RSS feed

  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. 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(_L("Are you sure that you want to delete %1?",file))) return false;
  28.  
  29.         $.ajax({
  30.                 url:"ajax.php",
  31.                 method:"POST",
  32.                 data: {
  33.                         csrf_token:csrf_token,
  34.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.95",
  35.                         action:"deleteAttachment",
  36.                         id:id,
  37.                         filename:file,
  38.                 },
  39.                 error:function(jqXHR, textStatus, errorThrown) {
  40.                         alert(_L("Error: %1",errorThrown));
  41.                 },
  42.                 success:function(data) {
  43.                         if ("error" in data) {
  44.                                 alert(_L("Error: %1",data.error));
  45.                         } else if (data.status >= 0) {
  46.                                 alert(_L("OK"));
  47.                                 reloadContent();
  48.                         } else {
  49.                                 alert(_L("Error: %1",data));
  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();
  59.         form_data.append('csrf_token', csrf_token);
  60.         form_data.append('userfile', file_data);
  61.         form_data.append('plugin', "1.3.6.1.4.1.37476.2.5.2.4.1.95");
  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) {
  72.                         alert(_L("Error: %1",errorThrown));
  73.                 },
  74.                 success:function(data) {
  75.                         if ("error" in data) {
  76.                                 alert(_L("Error: %1",data.error));
  77.                         } else if (data.status >= 0) {
  78.                                 alert(_L("OK"));
  79.                                 $('#fileAttachment').val('');
  80.                                 reloadContent();
  81.                         } else {
  82.                                 alert(_L("Error: %1",data));
  83.                         }
  84.                 }
  85.         });
  86. }
  87.  
  88. function uploadAttachmentOnSubmit() {
  89.         try {
  90.                 uploadAttachment(current_node, document.getElementById("fileAttachment").value);
  91.         } finally {
  92.                 return false;
  93.         }
  94. }