From f3deeb346383ce0d0031030cff56f5c1e743ce65 Mon Sep 17 00:00:00 2001 From: Kiril Vangelovski Date: Wed, 3 Sep 2014 12:56:55 +0200 Subject: [PATCH 1/5] [IMP] Web Warning Sounds --- web_warning_sound/AUTHORS | 2 + web_warning_sound/COPYRIGHT | 22 +++++++ web_warning_sound/README.rst | 28 +++++++++ web_warning_sound/__init__.py | 3 + web_warning_sound/__openerp__.py | 51 ++++++++++++++++ .../static/src/js/sound_extend.js | 61 +++++++++++++++++++ 6 files changed, 167 insertions(+) create mode 100644 web_warning_sound/AUTHORS create mode 100644 web_warning_sound/COPYRIGHT create mode 100644 web_warning_sound/README.rst create mode 100644 web_warning_sound/__init__.py create mode 100644 web_warning_sound/__openerp__.py create mode 100644 web_warning_sound/static/src/js/sound_extend.js diff --git a/web_warning_sound/AUTHORS b/web_warning_sound/AUTHORS new file mode 100644 index 000000000..f3111174c --- /dev/null +++ b/web_warning_sound/AUTHORS @@ -0,0 +1,2 @@ +Domantas Jackūnas +Kiril Vangelovski diff --git a/web_warning_sound/COPYRIGHT b/web_warning_sound/COPYRIGHT new file mode 100644 index 000000000..fa66544d1 --- /dev/null +++ b/web_warning_sound/COPYRIGHT @@ -0,0 +1,22 @@ +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 by UAB HacBee (Ltd.) +# and contributors. See AUTHORS for more details. +# +# All Rights Reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## diff --git a/web_warning_sound/README.rst b/web_warning_sound/README.rst new file mode 100644 index 000000000..a0a71f11c --- /dev/null +++ b/web_warning_sound/README.rst @@ -0,0 +1,28 @@ +This plugin allows to create modules that can play sound files. +It can be used in on_change methods or when raising an orm_except. + +The sound files need to be located in the module's static directory:: + +module_name/static/path/to/audio/file/mysound.wav + +Then the web client can access these files using the url path:: + +/module_name/static/path/to/audio/file/mysound.wav + + +To use it in on_change methods just add the the url path of the +audio file in the result dictionary under the key 'sound'. Example:: + + res['sound'] = '/module_name/static/path/to/audio/file/mysound.wav' + res['warning'] = { + 'title': _('Cannot do something'), + 'message': _('The reason why...'), + } + return res + +On orm_except put the url path of the file inside '{{}}' as in this example:: + + raise orm_except( + 'Cannot do something', + 'The reason why... {{ sound: /module_name/static/path/to/audio/file/mysound.wav }}' + ) diff --git a/web_warning_sound/__init__.py b/web_warning_sound/__init__.py new file mode 100644 index 000000000..19ddd6567 --- /dev/null +++ b/web_warning_sound/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# This file is part of OpenERP. The COPYRIGHT file at the top level of +# this module contains the full copyright notices and license terms. diff --git a/web_warning_sound/__openerp__.py b/web_warning_sound/__openerp__.py new file mode 100644 index 000000000..4cc3ef536 --- /dev/null +++ b/web_warning_sound/__openerp__.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# This file is part of OpenERP. The COPYRIGHT file at the top level of +# this module contains the full copyright notices and license terms. +{ + 'name': 'Web Warning Sounds', + 'version': '0.1', + 'author': 'HacBee UAB', + 'category': 'Custom', + 'website': 'http://www.hbee.eu', + 'summary': '', + 'description': """ +This plugin allows to create modules that can play sound files. +It can be used in on_change methods or when raising an orm_except. + +The sound files need to be located in the module's static directory: + +module_name/static/path/to/audio/file/mysound.wav + +Then the web client can access these files using the url path: + +/module_name/static/path/to/audio/file/mysound.wav + + +To use it in on_change methods just add the the url path of the +audio file in the result dictionary under the key 'sound'. Example:: + + res['sound'] = '/module_name/static/path/to/audio/file/mysound.wav' + res['warning'] = { + 'title': _('Cannot do something'), + 'message': _('The reason why...'), + } + return res + +On orm_except put the url path of the file inside '{{}}' as in this example:: + + raise orm_except( + 'Cannot do something', + 'The reason why... {{ sound: /module_name/static/path/to/audio/file/mysound.wav }}' + ) +""", + 'depends': [ + ], + 'data': [ + ], + 'js': [ + 'static/src/js/sound_extend.js' + ], + 'installable': True, + 'application': True, + 'auto_install': False, +} diff --git a/web_warning_sound/static/src/js/sound_extend.js b/web_warning_sound/static/src/js/sound_extend.js new file mode 100644 index 000000000..5a681b9f5 --- /dev/null +++ b/web_warning_sound/static/src/js/sound_extend.js @@ -0,0 +1,61 @@ +openerp.web_warning_sound = function(instance) { + var QWeb = instance.web.qweb; + var _t = instance.web._t; + + instance.web.FormView = instance.web.FormView.extend({ + on_processed_onchange: function(result, processed) { + try { + if (!_.isEmpty(result.sound)) { + var audio = new Audio(result.sound); + audio.play(); + } + if (result.value) { + this._internal_set_values(result.value, processed); + } + if (!_.isEmpty(result.warning)) { + instance.web.dialog($(QWeb.render("CrashManager.warning", result.warning)), { + title:result.warning.title, + modal: true, + buttons: [ + {text: _t("Ok"), click: function() { $(this).dialog("close"); }} + ] + }); + } + + var fields = this.fields; + _(result.domain).each(function (domain, fieldname) { + var field = fields[fieldname]; + if (!field) { return; } + field.node.attrs.domain = domain; + }); + + return $.Deferred().resolve(); + } catch(e) { + console.error(e); + instance.webclient.crashmanager.show_message(e); + return $.Deferred().reject(); + } + }, + }); + + instance.web.CrashManager = instance.web.CrashManager.extend({ + show_warning: function(error) { + if (!this.active) { + return; + } + var re = /{{\s*sound\s*:\s*(\S*)+\s*}}/; + var matches = error.data.fault_code.match(re); + if (matches && matches.length == 2) { + var audio = new Audio(matches[1]); + audio.play(); + error.data.fault_code = error.data.fault_code.replace(re, ''); + } + instance.web.dialog($('
' + QWeb.render('CrashManager.warning', {error: error}) + '
'), { + title: "OpenERP " + _.str.capitalize(error.type), + buttons: [ + {text: _t("Ok"), click: function() { $(this).dialog("close"); }} + ] + }); + }, + }); +} From 2747f30e1028811c799e2cda710dfd088b850893 Mon Sep 17 00:00:00 2001 From: Kiril Vangelovski Date: Wed, 3 Sep 2014 13:13:48 +0200 Subject: [PATCH 2/5] pep8 --- web_warning_sound/__openerp__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_warning_sound/__openerp__.py b/web_warning_sound/__openerp__.py index 4cc3ef536..fdc78219d 100644 --- a/web_warning_sound/__openerp__.py +++ b/web_warning_sound/__openerp__.py @@ -24,7 +24,7 @@ Then the web client can access these files using the url path: To use it in on_change methods just add the the url path of the audio file in the result dictionary under the key 'sound'. Example:: - res['sound'] = '/module_name/static/path/to/audio/file/mysound.wav' + res['sound'] = '/module_name/static/mysound.wav' res['warning'] = { 'title': _('Cannot do something'), 'message': _('The reason why...'), @@ -35,7 +35,7 @@ On orm_except put the url path of the file inside '{{}}' as in this example:: raise orm_except( 'Cannot do something', - 'The reason why... {{ sound: /module_name/static/path/to/audio/file/mysound.wav }}' + 'The reason why... {{ sound: /module_name/static/mysound.wav }}' ) """, 'depends': [ From ebc79393982e922dd3a3d0b66ffd4bae601bf5f9 Mon Sep 17 00:00:00 2001 From: Kiril Vangelovski Date: Wed, 8 Oct 2014 14:21:49 +0200 Subject: [PATCH 3/5] web_warning_sound change on_processed_onchange method so that it doesn't break inheritance chain --- .../static/src/js/sound_extend.js | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/web_warning_sound/static/src/js/sound_extend.js b/web_warning_sound/static/src/js/sound_extend.js index 5a681b9f5..bd3740ab9 100644 --- a/web_warning_sound/static/src/js/sound_extend.js +++ b/web_warning_sound/static/src/js/sound_extend.js @@ -9,32 +9,10 @@ openerp.web_warning_sound = function(instance) { var audio = new Audio(result.sound); audio.play(); } - if (result.value) { - this._internal_set_values(result.value, processed); - } - if (!_.isEmpty(result.warning)) { - instance.web.dialog($(QWeb.render("CrashManager.warning", result.warning)), { - title:result.warning.title, - modal: true, - buttons: [ - {text: _t("Ok"), click: function() { $(this).dialog("close"); }} - ] - }); - } - - var fields = this.fields; - _(result.domain).each(function (domain, fieldname) { - var field = fields[fieldname]; - if (!field) { return; } - field.node.attrs.domain = domain; - }); - - return $.Deferred().resolve(); } catch(e) { console.error(e); - instance.webclient.crashmanager.show_message(e); - return $.Deferred().reject(); } + return this._super.apply(this, arguments); }, }); From 645fa8c768d12315feecf808ac57d489e3802e7a Mon Sep 17 00:00:00 2001 From: Kiril Vangelovski Date: Wed, 8 Oct 2014 16:56:28 +0200 Subject: [PATCH 4/5] refactor js show_warning method so that it doesn't break inheritance chain --- web_warning_sound/static/src/js/sound_extend.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/web_warning_sound/static/src/js/sound_extend.js b/web_warning_sound/static/src/js/sound_extend.js index bd3740ab9..7030f98ac 100644 --- a/web_warning_sound/static/src/js/sound_extend.js +++ b/web_warning_sound/static/src/js/sound_extend.js @@ -28,12 +28,7 @@ openerp.web_warning_sound = function(instance) { audio.play(); error.data.fault_code = error.data.fault_code.replace(re, ''); } - instance.web.dialog($('
' + QWeb.render('CrashManager.warning', {error: error}) + '
'), { - title: "OpenERP " + _.str.capitalize(error.type), - buttons: [ - {text: _t("Ok"), click: function() { $(this).dialog("close"); }} - ] - }); + return this._super.apply(this, arguments); }, }); } From a947f8a0abc8694bd018e8683e514bc308a53cf8 Mon Sep 17 00:00:00 2001 From: Kiril Vangelovski Date: Wed, 15 Oct 2014 10:14:37 +0200 Subject: [PATCH 5/5] remove README.rst since the information is already in __openerp__.py --- web_warning_sound/README.rst | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 web_warning_sound/README.rst diff --git a/web_warning_sound/README.rst b/web_warning_sound/README.rst deleted file mode 100644 index a0a71f11c..000000000 --- a/web_warning_sound/README.rst +++ /dev/null @@ -1,28 +0,0 @@ -This plugin allows to create modules that can play sound files. -It can be used in on_change methods or when raising an orm_except. - -The sound files need to be located in the module's static directory:: - -module_name/static/path/to/audio/file/mysound.wav - -Then the web client can access these files using the url path:: - -/module_name/static/path/to/audio/file/mysound.wav - - -To use it in on_change methods just add the the url path of the -audio file in the result dictionary under the key 'sound'. Example:: - - res['sound'] = '/module_name/static/path/to/audio/file/mysound.wav' - res['warning'] = { - 'title': _('Cannot do something'), - 'message': _('The reason why...'), - } - return res - -On orm_except put the url path of the file inside '{{}}' as in this example:: - - raise orm_except( - 'Cannot do something', - 'The reason why... {{ sound: /module_name/static/path/to/audio/file/mysound.wav }}' - )