From 2bb70595ebc98acf29625770906848b7dfcbef6a Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Wed, 9 Jan 2019 00:25:37 +0000 Subject: [PATCH] publish muk_web_utils - 12.0 --- muk_web_utils/__manifest__.py | 2 +- muk_web_utils/static/src/js/core/async.js | 82 +++++++++++++++++++++++ muk_web_utils/template/assets.xml | 1 + 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 muk_web_utils/static/src/js/core/async.js diff --git a/muk_web_utils/__manifest__.py b/muk_web_utils/__manifest__.py index 3d1d1d2..64e25d7 100644 --- a/muk_web_utils/__manifest__.py +++ b/muk_web_utils/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Web Utils", "summary": """Utility Features""", - "version": "12.0.2.8.5", + "version": "12.0.2.8.6", "category": "Extra Tools", "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_web_utils/static/src/js/core/async.js b/muk_web_utils/static/src/js/core/async.js new file mode 100644 index 0000000..0c72a18 --- /dev/null +++ b/muk_web_utils/static/src/js/core/async.js @@ -0,0 +1,82 @@ +/********************************************************************************** +* +* Copyright (C) 2017 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 . +* +**********************************************************************************/ + +odoo.define('muk_web_utils.async', function (require) { +"use strict"; + +var core = require('web.core'); + +var _t = core._t; +var QWeb = core.qweb; + +var syncLoop = function(items, func, callback) { + items.reduce(function(promise, item) { + return promise.then(func); + }, $.Deferred().resolve()).then(callback); +}; + +var syncProgress = function(items, func, callback, update) { + var progress = 0; + items.reduce(function(promise, item) { + return promise.then(function() { + update(++progress / items.length); + return func(item); + }); + }, $.Deferred().resolve()).then(callback); +}; + +var createNotification = function(widget, title) { + return widget.call('notification', 'notify', { + title: title || _t('Upload'), + message: _t('Uploading...'), + icon: 'fa-upload', + sticky: true, + progress: { + text: "0%", + state: 0.0, + }, + }); +}; + +var updateNotification = function(widget, notification, progress) { + widget.call('notification', 'progress', notification, { + text: (progress * 100).toFixed(2) + "%", + state: (progress * 100).toFixed(2), + }); +}; + +var closeNotification = function(widget, notification) { + widget.call('notification', 'close', notification); +}; + +var syncNotification = function(widget, title, items, func, callback) { + var notification = createNotification(widget, title); + var update = _.partial(updateNotification, widget, notification); + syncProgress(items, func, function() { + $.when(closeNotification(widget, notification)).then(callback); + }, update); +}; + +return { + syncLoop: syncLoop, + syncProgress: syncProgress, + syncNotification: syncNotification, +}; + +}); \ No newline at end of file diff --git a/muk_web_utils/template/assets.xml b/muk_web_utils/template/assets.xml index 1a159a2..9915b3e 100644 --- a/muk_web_utils/template/assets.xml +++ b/muk_web_utils/template/assets.xml @@ -34,6 +34,7 @@