Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9129b021

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

  • ID 9129b021dfac0fa3df3c446b23deb71299171f03
  • Vorgänger 90aba193
  • Nachfolger 57f15027

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) {
57
    $("#upload_modal").modal("open");
58

  
48 59
    kivi.FileDB.retrieve_all((myfiles) => {
49 60
      let filesize  = 0;
50 61
      myfiles.forEach(file => {
......
55 66
        }
56 67

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

  
65 76
        $("#upload_result").html(kivi.t8("start upload"));
66 77

  
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
        });
78
        let xhr = new XMLHttpRequest;
79
        xhr.open('POST', 'controller.pl', true);
80
        xhr.success = ns.attSuccess;
81
        xhr.progress = ns.attProgress;
82
        xhr.error = ns.attFailed;
83
        xhr.abort = ns.attCanceled;
84
        xhr.send(data);
75 85
      });
76 86
    });
77 87
  };
......
98 108
    $("#upload_result").html(kivi.t8("Files have been uploaded successfully."));
99 109
  };
100 110

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

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

  
101 139
  ns.init = function() {
102 140
    ns.reload_images();
103 141
  };

Auch abrufbar als: Unified diff