|
1 | 1 | /* Copyright 2018 Dinar Gabbasov <https://it-projects.info/team/GabbasovDinar> |
2 | | -* License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). */ |
3 | | -odoo.define('pos_cashbox.open', function (require) { |
| 2 | + * License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). */ |
| 3 | +odoo.define("pos_cashbox.open", function(require) { |
4 | 4 | "use strict"; |
5 | 5 |
|
6 | | - var WidgetButton = require('web.form_widgets').WidgetButton; |
7 | | - var Session = require('web.Session'); |
8 | | - var Model = require('web.DataModel'); |
9 | | - var core = require('web.core'); |
10 | | - var CrashManager = require('web.CrashManager'); |
| 6 | + var WidgetButton = require("web.form_widgets").WidgetButton; |
| 7 | + var Session = require("web.Session"); |
| 8 | + var Model = require("web.DataModel"); |
| 9 | + var core = require("web.core"); |
| 10 | + var CrashManager = require("web.CrashManager"); |
11 | 11 |
|
12 | 12 | var _t = core._t; |
13 | 13 |
|
14 | | - |
15 | 14 | WidgetButton.include({ |
16 | | - on_click: function(){ |
| 15 | + on_click: function() { |
17 | 16 | var self = this; |
18 | | - if (this.node.attrs.special === 'open_backend_cashbox'){ |
| 17 | + if (this.node.attrs.special === "open_backend_cashbox") { |
19 | 18 | var proxy_ip = this.view.datarecord.proxy_ip; |
20 | 19 | if (!proxy_ip) { |
21 | | - return this.show_warning_message(_t('Connection Refused. Please check the IP address to PosBox')); |
| 20 | + return this.show_warning_message( |
| 21 | + _t("Connection Refused. Please check the IP address to PosBox") |
| 22 | + ); |
22 | 23 | } |
23 | 24 | var url = this.get_full_url(proxy_ip); |
24 | 25 | this.connect(url); |
25 | | - this.open_cashbox().done(function(){ |
26 | | - if (self.$el.hasClass('o_wow')) { |
27 | | - self.show_wow(); |
28 | | - } |
29 | | - }).fail(function(){ |
30 | | - return self.show_warning_message(_t("Connection Refused. Please check the connection to CashBox")); |
31 | | - }); |
| 26 | + this.open_cashbox() |
| 27 | + .done(function() { |
| 28 | + if (self.$el.hasClass("o_wow")) { |
| 29 | + self.show_wow(); |
| 30 | + } |
| 31 | + }) |
| 32 | + .fail(function() { |
| 33 | + return self.show_warning_message( |
| 34 | + _t( |
| 35 | + "Connection Refused. Please check the connection to CashBox" |
| 36 | + ) |
| 37 | + ); |
| 38 | + }); |
32 | 39 | } else { |
33 | 40 | this._super.apply(this, arguments); |
34 | 41 | } |
35 | 42 | }, |
36 | 43 | show_warning_message: function(message) { |
37 | | - new CrashManager().show_warning({data: { |
38 | | - exception_type: _t("Incorrect Operation"), |
39 | | - message: message |
40 | | - }}); |
| 44 | + new CrashManager().show_warning({ |
| 45 | + data: { |
| 46 | + exception_type: _t("Incorrect Operation"), |
| 47 | + message: message, |
| 48 | + }, |
| 49 | + }); |
41 | 50 | }, |
42 | 51 | get_full_url: function(current_url) { |
43 | | - var port = ':8069'; |
| 52 | + var port = ":8069"; |
44 | 53 | var url = current_url; |
45 | | - if(url.indexOf('//') < 0){ |
46 | | - url = 'http://' + url; |
| 54 | + if (url.indexOf("//") < 0) { |
| 55 | + url = "http://" + url; |
47 | 56 | } |
48 | | - if(url.indexOf(':',5) < 0){ |
| 57 | + if (url.indexOf(":", 5) < 0) { |
49 | 58 | url += port; |
50 | 59 | } |
51 | 60 | return url; |
52 | 61 | }, |
53 | 62 | connect: function(url) { |
54 | | - this.connection = new Session(void 0, url, { use_cors: true}); |
| 63 | + this.connection = new Session(void 0, url, {use_cors: true}); |
55 | 64 | }, |
56 | | - open_cashbox: function(){ |
| 65 | + open_cashbox: function() { |
57 | 66 | var self = this; |
58 | 67 | function send_opening_job(retries, done) { |
59 | 68 | done = done || new $.Deferred(); |
60 | | - self.connection.rpc('/hw_proxy/open_cashbox').done(function(){ |
61 | | - done.resolve(); |
62 | | - }).fail(function(){ |
63 | | - if(retries > 0){ |
64 | | - send_opening_job(retries-1,done); |
65 | | - }else{ |
66 | | - done.reject(); |
67 | | - } |
68 | | - }); |
| 69 | + self.connection |
| 70 | + .rpc("/hw_proxy/open_cashbox") |
| 71 | + .done(function() { |
| 72 | + done.resolve(); |
| 73 | + }) |
| 74 | + .fail(function() { |
| 75 | + if (retries > 0) { |
| 76 | + send_opening_job(retries - 1, done); |
| 77 | + } else { |
| 78 | + done.reject(); |
| 79 | + } |
| 80 | + }); |
69 | 81 | return done; |
70 | 82 | } |
71 | 83 | return send_opening_job(3); |
|
0 commit comments