Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d04d57fd

Von Bernd Bleßmann vor fast 4 Jahren hinzugefügt

  • ID d04d57fdb3e955daa37cf650d887d2e06f06e90c
  • Vorgänger a9107c90
  • Nachfolger 86dcebf0

Dateimanagement: Upload per Drag/Drop

Unterschiede anzeigen:

css/common.css
213 213
div.cke_textarea_inline:focus {
214 214
  outline: 0;
215 215
}
216

  
217
span.upload_drop_zone {
218
  padding: 4px;
219
  border: 2px;
220
  border-color: darkgray lightgray lightgray;
221
  border-style: solid;
222
  background-color: whitesmoke;
223
}
js/kivi.File.js
1 1
namespace('kivi.File', function(ns) {
2
  ns.list_div_id = undefined;
2 3

  
3 4
  ns.rename = function(id,type,file_type,checkbox_class,is_global) {
4 5
    var $dlg       = $('#rename_dialog_'+file_type);
......
77 78
  }
78 79

  
79 80
  ns.upload = function(id,type,filetype,upload_title,gl) {
81
    $('#upload_status_dialog').remove();
82

  
80 83
    kivi.popup_dialog({ url:     'controller.pl',
81 84
                        data:    { action: 'File/ajax_upload',
82 85
                                   file_type:   filetype,
......
99 102
      $('#upload_selected_button').prop('disabled',$('#upload_files').val() === '');
100 103
  }
101 104

  
105
  ns.upload_status_dialog = function() {
106
    $('#files_upload').remove();
107
    $('#upload_status_dialog').remove();
108

  
109
    var html  = '<div id="upload_status_dialog"><p><div id="upload_result"></div></p>';
110
    html      = html + '<p><input type="button" value="' + kivi.t8('close') + '" size="30" onclick="$(\'#upload_status_dialog\').dialog(\'close\');">';
111
    html      = html + '</p></div>';
112
    $(html).hide().appendTo('#' + ns.list_div_id);
113

  
114
    kivi.popup_dialog({id: 'upload_status_dialog',
115
                       dialog: {title:  kivi.t8('Upload Status'),
116
                                height: 200,
117
                                width:  650 }});
118
  };
119

  
102 120
  ns.upload_selected_files = function(id,type,filetype,maxsize,is_global) {
103 121
      var myform = document.getElementById("upload_form");
104
      var filesize  = 0;
105 122
      var myfiles = document.getElementById("upload_files").files;
123

  
124
      ns.upload_files(id, type, filetype, maxsize,is_global, myfiles, myform);
125
  }
126

  
127
  ns.upload_files = function(id, type, filetype, maxsize, is_global, myfiles, myform) {
128
      var filesize  = 0;
106 129
      for ( i=0; i < myfiles.length; i++ ) {
107 130
          var fname ='';
108 131
          try {
......
125 148
          return;
126 149
      }
127 150

  
128
      myform.action ="controller.pl?action=File/ajax_files_uploaded&json=1&object_type="+
129
          type+'&object_id='+id+'&file_type='+filetype+'&is_global='+is_global;
151
      var fd = new FormData(myform);
152
      if (!myform) {
153
        $(myfiles).each(function(idx, elt) {
154
          fd.append('uploadfiles[+]', elt);
155
        });
156
      }
157
      fd.append('action',      'File/ajax_files_uploaded');
158
      fd.append('json',        1);
159
      fd.append('object_type', type);
160
      fd.append('object_id',   id);
161
      fd.append('file_type',   filetype);
162
      fd.append('is_global',   is_global);
163

  
130 164
      var oReq = new XMLHttpRequest();
131 165
      oReq.onload            = ns.attSuccess;
132 166
      oReq.upload.onprogress = ns.attProgress;
133 167
      oReq.upload.onerror    = ns.attFailed;
134 168
      oReq.upload.onabort    = ns.attCanceled;
135
      oReq.open("post",myform.action, true);
169
      oReq.open("post", 'controller.pl', true);
136 170
      $("#upload_result").html(kivi.t8("start upload"));
137
      oReq.send(new FormData(myform));
171
      oReq.send(fd);
138 172
  }
139 173

  
140 174
  ns.attProgress = function(oEvent) {
......
155 189
  }
156 190

  
157 191
  ns.attSuccess = function() {
192
      $('#upload_status_dialog').dialog('close');
158 193
      $('#files_upload').dialog('close');
159 194
      kivi.eval_json_result(jQuery.parseJSON(this.response));
160 195
  }
......
265 300
    $.download("controller.pl", data);
266 301
    return false;
267 302
  }
303

  
304
  ns.init = function() {
305
    // Preventing page from redirecting
306
    $("#" + ns.list_div_id).on("dragover", function(e) {
307
      e.preventDefault();
308
      e.stopPropagation();
309
    });
310

  
311
    $("#" + ns.list_div_id).on("drop", function(e) {
312
      e.preventDefault();
313
      e.stopPropagation();
314
    });
315

  
316
    // Drag enter
317
    $('.upload_drop_zone').on('dragenter', function (e) {
318
      e.stopPropagation();
319
      e.preventDefault();
320
    });
321

  
322
    // Drag over
323
    $('.upload_drop_zone').on('dragover', function (e) {
324
      e.stopPropagation();
325
      e.preventDefault();
326
    });
327

  
328
    // Drop
329
    $('.upload_drop_zone').on('drop', function (e) {
330
      e.stopPropagation();
331
      e.preventDefault();
332

  
333
      ns.upload_status_dialog();
334

  
335
      var object_type = $(e.target).data('object-type');
336
      var object_id   = $(e.target).data('object-id');
337
      var file_type   = $(e.target).data('file-type');
338
      var is_global   = $(e.target).data('is-global');
339
      var maxsize     = $(e.target).data('maxsize');
340
      var files       = e.originalEvent.dataTransfer.files;
341
      ns.upload_files(object_id, object_type, file_type, maxsize, is_global, files);
342
    });
343

  
344
  };
345

  
268 346
});
js/locale/de.js
137 137
"Transaction description":"Vorgangsbezeichnung",
138 138
"Update":"Erneuern",
139 139
"Update quotation/order":"Auftrag/Angebot aktualisieren",
140
"Upload Status":"Upload-Status",
140 141
"Vendor details":"Lieferantendetails",
141 142
"Vendor missing!":"Lieferant fehlt!",
142 143
"Version actions":"Aktionen für Versionen",
......
146 147
"Yes":"Ja",
147 148
"You have changed the currency or exchange rate. Please check prices.":"Die Währung oder der Wechselkurs hat sich geändert. Bitte überprüfen Sie die Preise.",
148 149
"You have entered or selected the following shipping address for this customer:":"Sie haben die folgende Lieferadresse eingegeben oder ausgewählt:",
150
"close":"schließen",
149 151
"filename has not uploadable characters ":"Bitte Dateinamen ändern. Er hat für den Upload nicht verwendbare Sonderzeichen ",
150 152
"filesize too big: ":"Datei zu groß: ",
151 153
"flat-rate position":"Pauschalposition",
js/locale/en.js
137 137
"Transaction description":"",
138 138
"Update":"",
139 139
"Update quotation/order":"",
140
"Upload Status":"",
140 141
"Vendor details":"",
141 142
"Vendor missing!":"",
142 143
"Version actions":"",
......
146 147
"Yes":"",
147 148
"You have changed the currency or exchange rate. Please check prices.":"",
148 149
"You have entered or selected the following shipping address for this customer:":"",
150
"close":"",
149 151
"filename has not uploadable characters ":"",
150 152
"filesize too big: ":"",
151 153
"flat-rate position":"",
locale/de/all
1121 1121
  'Draft for this Letter saved!' => 'Briefentwurf gespeichert!',
1122 1122
  'Draft saved.'                => 'Entwurf gespeichert.',
1123 1123
  'Drafts'                      => 'Entwürfe',
1124
  'Drag and drop files here'    => 'Dateien hierher ziehen und fallen lassen',
1124 1125
  'Drawing'                     => 'Zeichnung',
1125 1126
  'Due'                         => 'Fällig',
1126 1127
  'Due Date'                    => 'Fälligkeitsdatum',
......
3880 3881
  'Upload Attachments'          => 'Anhänge hochladen',
3881 3882
  'Upload Documents'            => 'Dokumente hochladen',
3882 3883
  'Upload Images'               => 'Bilder hochladen',
3884
  'Upload Status'               => 'Upload-Status',
3883 3885
  'Upload all marked'           => 'Markierte aktualisieren',
3884 3886
  'Upload file'                 => 'Datei hochladen',
3885 3887
  'Uploaded at'                 => 'Hochgeladen um',
locale/en/all
1121 1121
  'Draft for this Letter saved!' => '',
1122 1122
  'Draft saved.'                => '',
1123 1123
  'Drafts'                      => '',
1124
  'Drag and drop files here'    => '',
1124 1125
  'Drawing'                     => '',
1125 1126
  'Due'                         => '',
1126 1127
  'Due Date'                    => '',
......
3879 3880
  'Upload Attachments'          => '',
3880 3881
  'Upload Documents'            => '',
3881 3882
  'Upload Images'               => '',
3883
  'Upload Status'               => '',
3882 3884
  'Upload all marked'           => '',
3883 3885
  'Upload file'                 => '',
3884 3886
  'Uploaded at'                 => '',
templates/webpages/file/list.html
1 1
[%- USE LxERP -%][% USE L %]
2
[% USE T8 %]
2 3
[%- IF ! json %]
3 4
 <div id="[% file_type %]_list_[% object_type %]">
4 5
[%- END %]
......
81 82
    [%- can_rename = 1 %]
82 83
    [% L.button_tag("kivi.File.rename(" _ object_id _ ",'" _ object_type _ "','" _ file_type _ "','" _ checkname _ "'," _ is_global _ ");",  source.rename_title ) %]
83 84
   [%- END %]
84
   [%- IF source.can_upload %]
85
    [% L.button_tag("kivi.File.upload(" _ object_id _ ",'" _ object_type _ "','" _ file_type _ "','" _ source.upload_title _ "'," _ is_global _ ");", source.upload_title ) %]
86
   [%- END %]
87 85
   [%- IF source.can_import %]
88 86
    [% L.button_tag("kivi.File.import("   _ object_id _ ",'" _ object_type _ "','" _ file_type _ "','" _ source.name _ "','" _ source.path _"');",  source.import_title ) %]
89 87
   [%- END %]
88
   [%- IF source.can_upload %]
89
    [% L.button_tag("kivi.File.upload(" _ object_id _ ",'" _ object_type _ "','" _ file_type _ "','" _ source.upload_title _ "'," _ is_global _ ");", source.upload_title ) %]
90
    <span class="upload_drop_zone"
91
          data-object-type="[% object_type %]"
92
          data-object-id="[% object_id %]"
93
          data-file-type="[% file_type %]"
94
          data-is-global="[% is_global %]"
95
          data-maxsize="[% INSTANCE_CONF.get_doc_max_filesize %]">
96
      [% 'Drag and drop files here' | $T8 %]
97
    </span>
98
   [%- END %]
90 99
  </div>
91 100
 [%- END # FOREACH source %]
92 101
 <div></div>
......
103 112
  [%- END %]
104 113
 [%- END %]
105 114
[%- END %]
115

  
116
<script>
117
  $(function() {
118
    kivi.File.list_div_id = "[% file_type %]_list_[% object_type %]";
119
    kivi.File.init();
120
  });
121
</script>

Auch abrufbar als: Unified diff