mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[IMP] Web Warning Sounds
This commit is contained in:
2
web_warning_sound/AUTHORS
Normal file
2
web_warning_sound/AUTHORS
Normal file
@@ -0,0 +1,2 @@
|
||||
Domantas Jackūnas <domantas@hbee.eu>
|
||||
Kiril Vangelovski <kiril@hbee.eu>
|
||||
22
web_warning_sound/COPYRIGHT
Normal file
22
web_warning_sound/COPYRIGHT
Normal file
@@ -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/>.
|
||||
#
|
||||
##############################################################################
|
||||
28
web_warning_sound/README.rst
Normal file
28
web_warning_sound/README.rst
Normal file
@@ -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 }}'
|
||||
)
|
||||
3
web_warning_sound/__init__.py
Normal file
3
web_warning_sound/__init__.py
Normal file
@@ -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
Normal file
51
web_warning_sound/__openerp__.py
Normal file
@@ -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,
|
||||
}
|
||||
61
web_warning_sound/static/src/js/sound_extend.js
Normal file
61
web_warning_sound/static/src/js/sound_extend.js
Normal file
@@ -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($('<div>' + QWeb.render('CrashManager.warning', {error: error}) + '</div>'), {
|
||||
title: "OpenERP " + _.str.capitalize(error.type),
|
||||
buttons: [
|
||||
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
|
||||
]
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user