Browse Source

publish muk_web_utils - 12.0

pull/35/head
MuK IT GmbH 6 years ago
parent
commit
c75d187d9e
  1. 2
      muk_web_utils/__manifest__.py
  2. 11
      muk_web_utils/static/src/js/core/dropzone.js
  3. 174
      muk_web_utils/static/src/js/core/files.js
  4. 4
      muk_web_utils/static/src/js/core/utils.js
  5. 1
      muk_web_utils/template/assets.xml

2
muk_web_utils/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Web Utils", "name": "MuK Web Utils",
"summary": """Utility Features""", "summary": """Utility Features""",
"version": "12.0.2.4.2",
"version": "12.0.2.4.3",
"category": "Extra Tools", "category": "Extra Tools",
"license": "AGPL-3", "license": "AGPL-3",
"author": "MuK IT", "author": "MuK IT",

11
muk_web_utils/static/src/js/core/dropzone.js

@ -29,10 +29,10 @@ var DropzoneMixin = {
dropzoneData: {}, dropzoneData: {},
dropzoneClasses: 'mk_dropzone', dropzoneClasses: 'mk_dropzone',
dropzoneEvents: { dropzoneEvents: {
'dragenter .o_form_sheet': '_dragenterDropzone',
'dragover .o_form_sheet': '_dragoverDropzone',
'dragleave .o_form_sheet': '_dragleaveDropzone',
'drop .o_form_sheet': '_dropDropzone',
'dragenter .mk_dropzone': '_dragenterDropzone',
'dragover .mk_dropzone': '_dragoverDropzone',
'dragleave .mk_dropzone': '_dragleaveDropzone',
'drop .mk_dropzone': '_dropDropzone',
}, },
_checkDropzoneEvent: function(event) { _checkDropzoneEvent: function(event) {
return true; return true;
@ -97,8 +97,9 @@ var FileDropzoneMixin = _.extend({}, DropzoneMixin, {
'data-dropzone-text': _t("Drop files here to upload!"), 'data-dropzone-text': _t("Drop files here to upload!"),
}, },
dropzoneClasses: DropzoneMixin.dropzoneClasses + ' mk_dropzone_file', dropzoneClasses: DropzoneMixin.dropzoneClasses + ' mk_dropzone_file',
dropzoneCheck: window.File && window.FileReader && window.FileList && window.Blob,
_checkDropzoneEvent: function(event) { _checkDropzoneEvent: function(event) {
return window.File && window.FileReader && window.FileList && window.Blob;
return this.dropzoneCheck;
}, },
_handleDrag: function(event) { _handleDrag: function(event) {
if(event.originalEvent.dataTransfer) { if(event.originalEvent.dataTransfer) {

174
muk_web_utils/static/src/js/core/files.js

@ -0,0 +1,174 @@
/**********************************************************************************
*
* Copyright (C) 2018 MuK IT GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**********************************************************************************/
odoo.define('muk_web_utils.files', function (require) {
"use strict";
var core = require('web.core');
var utils = require('web.utils');
var QWeb = core.qweb;
var _t = core._t;
var traverseItems = function(items, tree) {
var def = $.Deferred();
var files = [];
var defs = [];
_.each(items, function(item, index) {
var entry = item.webkitGetAsEntry();
if(entry) {
var traverse = $.Deferred();
traverseEntry(entry, tree).then(function(result) {
if(tree) {
files = files.concat(result);
} else {
files = _.union(files, result);
}
traverse.resolve();
});
defs.push(traverse);
} else {
file = item.getAsFile();
if(file) {
if(file.size) {
files.push(_.extend({}, file, {isFileItem: true}));
}
} else {
console.warn("Your browser doesn't support Drag and Drop!");
}
}
});
$.when.apply($, defs).then(function () {
def.resolve(files);
});
return def;
};
var traverseEntries = function(entries, tree) {
var def = $.Deferred();
var files = [];
var defs = [];
_.each(entries, function(entry, index) {
var traverse = $.Deferred();
traverseEntry(entry, tree).then(function(result) {
if(tree) {
files = files.concat(result);
} else {
files = _.union(files, result);
}
traverse.resolve();
});
defs.push(traverse);
});
$.when.apply($, defs).then(function () {
def.resolve(files);
});
return def;
}
var traverseEntry = function(entry, tree) {
var def = $.Deferred();
if(entry.isFile) {
def.resolve([entry]);
} else if(entry.isDirectory) {
entry.createReader().readEntries(function (entries) {
traverseEntries(entries, tree).then(function (files) {
if(tree) {
def.resolve([{
name: entry.name,
files: files,
isFile: false,
isDirectory: true,
childCount: files.length,
fullPath: entry.fullPath,
fileCount: _.reduce(files, function(sum, item) {
return item.isFile ? sum + 1 : sum + item.fileCount || 0;
}, 0),
}]);
} else {
def.resolve(files);
}
});
});
} else {
def.resolve([]);
}
return def;
};
var getFileTree = function(items, count) {
var traverse = traverseItems(items, true);
if(count) {
var def = $.Deferred();
traverse.then(function(files) {
def.resolve({
files: files,
count: _.reduce(files, function(sum, item) {
return item.isFile ? sum + 1 : sum + item.fileCount || 0;
}, 0),
});
});
return def;
}
return traverse;
};
var getFileList = function(items, count) {
var traverse = traverseItems(items, false);
if(count) {
var def = $.Deferred();
traverse.then(function(files) {
def.resolve({
files: files,
count: files.length,
});
});
return def;
}
return traverse;
};
var loadFile = function(file, callback) {
var fileReader = new FileReader();
fileReader.readAsDataURL(file);
fileReader.onloadend = callback;
};
var readFile = function(file, callback) {
if(file.isFile) {
file.file(function(file) {
loadFile(file, callback);
});
} else {
loadFile(file, callback);
}
};
return {
traverseItems: traverseItems,
traverseEntries: traverseEntries,
traverseEntry: traverseEntry,
getFileTree: getFileTree,
getFileList: getFileList,
loadFile: loadFile,
readFile: readFile,
};
});

4
muk_web_utils/static/src/js/core/utils.js

@ -25,7 +25,7 @@ var core = require('web.core');
var _t = core._t; var _t = core._t;
var QWeb = core.qweb; var QWeb = core.qweb;
function isUrl(string) {
var isUrl = function(string) {
var protocol = string.match(/^(?:\w+:)?\/\/(\S+)$/); var protocol = string.match(/^(?:\w+:)?\/\/(\S+)$/);
if (protocol && protocol[1]) { if (protocol && protocol[1]) {
var localHost = (/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/).test(protocol[1]); var localHost = (/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/).test(protocol[1]);
@ -35,7 +35,7 @@ function isUrl(string) {
return false; return false;
} }
function parseText2Html(text) {
var parseText2Html= function(text) {
return text return text
.replace(/((?:https?|ftp):\/\/[\S]+)/g,'<a href="$1">$1</a> ') .replace(/((?:https?|ftp):\/\/[\S]+)/g,'<a href="$1">$1</a> ')
.replace(/[\n\r]/g,'<br/>'); .replace(/[\n\r]/g,'<br/>');

1
muk_web_utils/template/assets.xml

@ -41,6 +41,7 @@
<xpath expr="//script[last()]" position="after"> <xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/muk_web_utils/static/src/js/libs/jquery.js"></script> <script type="text/javascript" src="/muk_web_utils/static/src/js/libs/jquery.js"></script>
<script type="text/javascript" src="/muk_web_utils/static/src/js/core/utils.js"></script> <script type="text/javascript" src="/muk_web_utils/static/src/js/core/utils.js"></script>
<script type="text/javascript" src="/muk_web_utils/static/src/js/core/files.js"></script>
<script type="text/javascript" src="/muk_web_utils/static/src/js/core/dropzone.js"></script> <script type="text/javascript" src="/muk_web_utils/static/src/js/core/dropzone.js"></script>
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/module.js"></script> <script type="text/javascript" src="/muk_web_utils/static/src/js/fields/module.js"></script>
<script type="text/javascript" src="/muk_web_utils/static/src/js/fields/copy.js"></script> <script type="text/javascript" src="/muk_web_utils/static/src/js/fields/copy.js"></script>

Loading…
Cancel
Save