Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8fcabb09

Von Sven Schöling vor mehr als 3 Jahren hinzugefügt

  • ID 8fcabb092e4a9c36e21f2e28e53146d91481b45f
  • Vorgänger 5b47f7d4
  • Nachfolger 72151f75

ImageUpload: client side Scripte

Unterschiede anzeigen:

js/kivi.FileDB.js
15 15
    ns.create_image_store(event.target.result);
16 16
  };
17 17
  request.onerror = ns.onerror;
18
  request.aftersuccess = [];
18 19
  request.onsuccess = () => {
19 20
    db = request.result;
20 21

  
......
32 33
        };
33 34
      }
34 35
    }
36

  
37
    request.aftersuccess.forEach(f => f());
35 38
  };
36 39

  
37 40
  ns.create_image_store = function (db) {
......
84 87
    console.error("Error creating/accessing IndexedDB database");
85 88
    console.error(event.errorState);
86 89
  };
90

  
91
  ns.with_db = function(success) {
92
    if (db && db_version == db.version) {
93
      success();
94
    } else {
95
      // assume the page load db init isn't done yet and push it onto the success
96
      request.aftersuccess.push(success);
97
    }
98
  };
87 99
});
js/kivi.ImageUpload.js
1 1
namespace("kivi.ImageUpload", function(ns) {
2 2
  "use strict";
3 3

  
4
  const MAXSIZE = 5*1024*1024; // 5MB size limit
5

  
4 6
  ns.add_files = function(target) {
5 7
    let files = [];
6 8
    for (var i = 0; i < target.files.length; i++) {
......
44 46
    });
45 47
  };
46 48

  
47
  ns.upload_selected_files = function(id,type,filetype,maxsize) {
49
  ns.upload_files = function() {
50
    let id = $('#object_id').val();
51
    let type = $('#object_type').val();
52

  
53
    ns.upload_selected_files(id, type, MAXSIZE);
54
  };
55

  
56
  ns.upload_selected_files = function(id, type, maxsize) {
48 57
    kivi.FileDB.retrieve_all((myfiles) => {
49 58
      let filesize  = 0;
50 59
      myfiles.forEach(file => {
......
55 64
        }
56 65

  
57 66
        let data = new FormData();
58
        data.append(file);
67
        data.append("file", file);
59 68
        data.append("action", "File/ajax_files_uploaded");
60 69
        data.append("json", "1");
61 70
        data.append("object_type", type);
62 71
        data.append("object_id", id);
63
        data.append("file_type", filetype);
72
        data.append("file_type", "attachment");
64 73

  
65 74
        $("#upload_result").html(kivi.t8("start upload"));
66 75

  
67
        $.ajax({
68
          url: "controller.pl",
69
          data: data,
70
          success: ns.attSuccess,
71
          progress: ns.attProgress,
72
          error: ns.attFailes,
73
          abort: ns.attCanceled
74
        });
76
        let xhr = new XMLHttpRequest;
77
        xhr.open('POST', 'controller.pl', true);
78
        xhr.success = ns.attSuccess;
79
        xhr.progress = ns.attProgress;
80
        xhr.error = ns.attFailed;
81
        xhr.abort = ns.attCanceled;
82
        xhr.send(data);
75 83
      });
76 84
    });
77 85
  };
......
98 106
    $("#upload_result").html(kivi.t8("Files have been uploaded successfully."));
99 107
  };
100 108

  
109
  ns.resolve_object = function(event) {
110
    let obj_type = $('#object_type').val();
111
    let number   = event.target.value;
112

  
113
    $.ajax({
114
      url: "controller.pl",
115
      data: {
116
        action: "ImageUpload/resolve_object_by_number",
117
        object_type: obj_type,
118
        object_number: number
119
      },
120
      type: "json",
121
      success: (json) => {
122
        if (json.error) {
123
          $("#object_description").html("");
124
          $("#object_id").val("");
125
        } else {
126
          $("#object_description").html(json.description);
127
          $("#object_id").val(json.id);
128
        }
129
      },
130
      error: () => {
131
        $("#object_description").html("");
132
        $("#object_id").val("");
133
      }
134
    });
135
  };
136

  
101 137
  ns.init = function() {
102 138
    ns.reload_images();
103 139
  };

Auch abrufbar als: Unified diff