[IMP] web, point_of_sale: basic implementation of the cordova integration.

This time without a new js file
This commit is contained in:
Frédéric van der Essen 2015-05-26 17:35:29 +02:00
parent 46eb9e2639
commit 19eda68547
2 changed files with 80 additions and 0 deletions

View File

@ -972,6 +972,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
$('.oe_web_client').off();
$('.openerp_webclient_container').off();
self.renderElement();
self.$('.neworder-button').click(function(){
@ -1017,6 +1018,8 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
instance.webclient.set_content_full_screen(true);
self.$('.loader').animate({opacity:0},1500,'swing',function(){self.$('.loader').addClass('oe_hidden');});
instance.web.cordova.send('posready');
self.pos.push_order();
@ -1231,6 +1234,7 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
function close(){
self.pos.push_order().then(function(){
instance.web.cordova.send('poslogout');
return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_client_pos_menu']], ['res_id']).pipe(function(res) {
window.location = '/web#action=' + res[0]['res_id'];
},function(err,event) {

View File

@ -1202,6 +1202,7 @@ instance.web.WebClient = instance.web.Client.extend({
this.on("change:title_part", this, this._title_changed);
this._title_changed();
return $.when(this._super()).then(function() {
if (jQuery.deparam !== undefined && jQuery.deparam(jQuery.param.querystring()).kitten !== undefined) {
self.to_kitten();
@ -1213,6 +1214,10 @@ instance.web.WebClient = instance.web.Client.extend({
self.action_manager.do_action(self.client_options.action);
delete(self.client_options.action);
}
instance.web.cordova.ready();
instance.web.cordova.on('back', self, function() {
self.do_action('history_back');
});
});
},
to_kitten: function() {
@ -1368,6 +1373,7 @@ instance.web.WebClient = instance.web.Client.extend({
on_logout: function() {
var self = this;
if (!this.has_uncommitted_changes()) {
instance.web.cordova.logout();
self.action_manager.do_action('logout');
}
},
@ -1529,6 +1535,76 @@ instance.web.embed = function (origin, dbname, login, key, action, options) {
client.insertAfter(currentScript);
};
/*
* The Android/iPhone App is a JS/HTML app that launches the
* Odoo webclient in an iframe, using the Cordova framework.
*
* This class acts as a link between the webclient and the
* Odoo Android/iPhone App implemented with cordova.
*/
instance.web.Cordova = instance.web.Class.extend({}, instance.web.PropertiesMixin, {
init: function(parent) {
var self = this;
instance.web.PropertiesMixin.init.call(this, parent);
window.addEventListener('message', function(event) {
self.receive(event);
}, false);
},
// odoo.send('foobar') in cordova will call messages.foobar()
messages: {
// launch the POS !
pos: function() {
if (window.location.href.indexOf('/pos/web') < 0) {
window.location.href = "/pos/web";
}
},
},
// what happens when we receive an event from cordova
// -> call messages[event.data]()
// -> selfs trigger(event.data)
receive: function(event) {
if (event.origin !== 'file://') {
return;
}
if (typeof event.data === 'string') {
this.trigger(event.data);
if (this.messages[event.data]) {
this.messages[event.data].call(this);
}
}
},
// send a message to cordova
send: function(message) {
function inIframe(){
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
if (inIframe()) {
window.parent.postMessage(message,'file://');
}
},
// notifies cordova that the webclient is ready.
ready: function() { this.send('ready'); },
// notifies cordova that we want to exit the app.
logout: function() { this.send('logout'); },
// asks cordova to emit a beep.
beep: function() { this.send('beep'); },
// ask cordova to vibrate the phone.
vibrate: function() { this.send('vibrate'); },
});
instance.web.cordova = new instance.web.Cordova();
})();
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: