Explorar el Código

[ADD] update socket config

Gogs hace 6 años
padre
commit
3ce4518c4e
Se han modificado 1 ficheros con 26 adiciones y 3 borrados
  1. 26 3
      static/src/js/main.js

+ 26 - 3
static/src/js/main.js

@@ -13,8 +13,7 @@ openerp.print_engine = function (instance, local) {
         },
         open_socket: function () {
             var self = this;
-
-            var setup_socket = function (config) {
+            var setup = self.setup_socket = function (config) {
                 self.config = config;
                 self.config.is_mobile = self.is_mobile_browser()
 
@@ -31,7 +30,19 @@ openerp.print_engine = function (instance, local) {
                 }
             }
 
-            this.get_socket_config().then(setup_socket);
+            this.get_socket_config().then(setup);
+        },
+        update_config: function () {
+            instance.web.blockUI();
+            var self = this;
+
+            this.get_socket_config().then(function (config) {
+                instance.web.unblockUI();
+                self.config = _.extend(self.config, config);
+
+                self.socket.destroy();
+                self.setup_socket(config);
+            });
         },
         handle_connect: function () {
             $('#printer-status').removeClass();
@@ -450,6 +461,18 @@ openerp.print_engine = function (instance, local) {
             });
         }
 
+        if (instance.web.FormView) {
+            instance.web.FormView.include({
+                record_saved: function (r) {
+                    if (this.model === 'res.users') {
+                        local.socket_manager.update_config();
+                    }
+
+                    return this._super.apply(this, arguments);
+                }
+            });
+        }
+
         if (instance.web.ActionManager) {
             instance.web.ActionManager.include({
                 trigger_preview_pdf: function (action) {