@karpeleslab/klbfw 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/rest.js +10 -1
  3. package/upload.js +60 -56
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karpeleslab/klbfw",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Frontend Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/rest.js CHANGED
@@ -9,7 +9,16 @@ module.exports.rest = (name, verb, params, context) => {
9
9
  context = context || {};
10
10
  var ctx_final = fwWrapper.getContext();
11
11
  for (var i in context) ctx_final[i] = context[i];
12
- return __platformAsyncRest(name, verb, params, ctx_final);
12
+ var p1 = new Promise(function(resolve, reject) {
13
+ __platformAsyncRest(name, verb, params, ctx_final).then(function(result) {
14
+ if (result.result != "success") {
15
+ reject(result);
16
+ } else {
17
+ resolve(result);
18
+ }
19
+ }, reject);
20
+ });
21
+ return p1;
13
22
  }
14
23
  if (typeof __platformRest !== "undefined") {
15
24
  // direct SSR-mode call to rest api
package/upload.js CHANGED
@@ -186,15 +186,17 @@ module.exports.upload = (function () {
186
186
  delete upload_running[up.up_id];
187
187
  upload.run();
188
188
  sendprogress();
189
- setTimeout(function () {
190
- var evt = new CustomEvent("upload:failed", {
191
- detail: {
192
- item: up,
193
- res: data
194
- }
195
- });
196
- document.dispatchEvent(evt);
197
- }, 10);
189
+ if (typeof document !== "undefined") {
190
+ setTimeout(function () {
191
+ var evt = new CustomEvent("upload:failed", {
192
+ detail: {
193
+ item: up,
194
+ res: data
195
+ }
196
+ });
197
+ document.dispatchEvent(evt);
198
+ }, 10);
199
+ }
198
200
  }
199
201
 
200
202
  function do_upload_part(up, partno) {
@@ -341,49 +343,51 @@ module.exports.upload = (function () {
341
343
  upload.run();
342
344
  };
343
345
 
344
- upload.init = function (path, params, notify) {
345
- // perform upload to a given API, for example Drive/Item/<id>:upload
346
- // will allow multiple files to be uploaded
347
- params = params || {};
346
+ if (typeof document !== "undefined") {
347
+ upload.init = function (path, params, notify) {
348
+ // perform upload to a given API, for example Drive/Item/<id>:upload
349
+ // will allow multiple files to be uploaded
350
+ params = params || {};
348
351
 
349
- if (last_input != null) {
350
- last_input.parentNode.removeChild(last_input);
351
- last_input = null;
352
- }
352
+ if (last_input != null) {
353
+ last_input.parentNode.removeChild(last_input);
354
+ last_input = null;
355
+ }
353
356
 
354
- var input = document.createElement("input");
355
- input.type = "file";
356
- input.style.display = "none";
357
- if (!params["single"]) {
358
- input.multiple = "multiple";
359
- }
357
+ var input = document.createElement("input");
358
+ input.type = "file";
359
+ input.style.display = "none";
360
+ if (!params["single"]) {
361
+ input.multiple = "multiple";
362
+ }
360
363
 
361
- document.getElementsByTagName('body')[0].appendChild(input);
362
- last_input = input;
364
+ document.getElementsByTagName('body')[0].appendChild(input);
365
+ last_input = input;
363
366
 
364
- var promise = new Promise(function (resolve, reject) {
365
- input.onchange = function () {
366
- if (this.files.length == 0) {
367
- resolve();
368
- }
367
+ var promise = new Promise(function (resolve, reject) {
368
+ input.onchange = function () {
369
+ if (this.files.length == 0) {
370
+ resolve();
371
+ }
369
372
 
370
- var count = this.files.length;
371
- if (notify !== undefined) notify({status: 'init', count: count});
372
- for (var i = 0; i < this.files.length; i++) {
373
- upload.append(path, this.files[i], params, fwWrapper.getContext()).then(function (obj) {
374
- count -= 1;
375
- // Todo notify process
376
- if (notify !== undefined) notify(obj);
377
- if (count == 0) resolve();
378
- });
379
- }
380
- upload.run();
381
- };
382
- });
373
+ var count = this.files.length;
374
+ if (notify !== undefined) notify({status: 'init', count: count});
375
+ for (var i = 0; i < this.files.length; i++) {
376
+ upload.append(path, this.files[i], params, fwWrapper.getContext()).then(function (obj) {
377
+ count -= 1;
378
+ // Todo notify process
379
+ if (notify !== undefined) notify(obj);
380
+ if (count == 0) resolve();
381
+ });
382
+ }
383
+ upload.run();
384
+ };
385
+ });
383
386
 
384
- input.click();
385
- return promise;
386
- };
387
+ input.click();
388
+ return promise;
389
+ };
390
+ }
387
391
 
388
392
 
389
393
  upload.append = function (path, file, params, context) {
@@ -525,16 +529,16 @@ module.exports.upload = (function () {
525
529
  upload_queue.push(up);
526
530
 
527
531
  upload.run();
528
- setTimeout(function () {
529
- var evt = new CustomEvent("upload:retry", {
530
- detail: {
531
- item: up,
532
- }
533
- });
534
- document.dispatchEvent(evt);
535
- }, 10);
536
-
537
-
532
+ if (typeof document !== "undefined") {
533
+ setTimeout(function () {
534
+ var evt = new CustomEvent("upload:retry", {
535
+ detail: {
536
+ item: up,
537
+ }
538
+ });
539
+ document.dispatchEvent(evt);
540
+ }, 10);
541
+ }
538
542
  }
539
543
  sendprogress();
540
544
  };