diff --git a/web_warning_sound/AUTHORS b/web_warning_sound/AUTHORS new file mode 100644 index 00000000..f3111174 --- /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 00000000..fa66544d --- /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/__init__.py b/web_warning_sound/__init__.py new file mode 100644 index 00000000..19ddd656 --- /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 00000000..fdc78219 --- /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/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/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 00000000..7030f98a --- /dev/null +++ b/web_warning_sound/static/src/js/sound_extend.js @@ -0,0 +1,34 @@ +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(); + } + } catch(e) { + console.error(e); + } + return this._super.apply(this, arguments); + }, + }); + + 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, ''); + } + return this._super.apply(this, arguments); + }, + }); +}