Browse Source

Merge pull request #36 from kirca/web_warning_sound

[IMP] Web Warning Sounds
pull/53/head
Markus Schneider 10 years ago
parent
commit
71a6816f3f
  1. 2
      web_warning_sound/AUTHORS
  2. 22
      web_warning_sound/COPYRIGHT
  3. 3
      web_warning_sound/__init__.py
  4. 51
      web_warning_sound/__openerp__.py
  5. 34
      web_warning_sound/static/src/js/sound_extend.js

2
web_warning_sound/AUTHORS

@ -0,0 +1,2 @@
Domantas Jackūnas <domantas@hbee.eu>
Kiril Vangelovski <kiril@hbee.eu>

22
web_warning_sound/COPYRIGHT

@ -0,0 +1,22 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013 by UAB HacBee (Ltd.) <http://www.hbee.eu>
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################

3
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.

51
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,
}

34
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);
},
});
}
Loading…
Cancel
Save