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/README.rst b/web_warning_sound/README.rst new file mode 100644 index 00000000..a0a71f11 --- /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 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..4cc3ef53 --- /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 00000000..5a681b9f --- /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"); }} + ] + }); + }, + }); +}