changeset 6bbf7d85b46e in sao:default
details: https://hg.tryton.org/sao?cmd=changeset&node=6bbf7d85b46e
description:
        Check server version

        issue11421
        review425561003
diffstat:

 CHANGELOG      |   2 ++
 src/sao.js     |  55 ++++++++++++++++++++++++++++++++++++++++---------------
 src/sao.less   |   6 ++++++
 src/session.js |  24 +++++++++++++++++++++++-
 4 files changed, 71 insertions(+), 16 deletions(-)

diffs (155 lines):

diff -r 8114a38ae71d -r 6bbf7d85b46e CHANGELOG
--- a/CHANGELOG Sun Sep 18 12:10:45 2022 +0200
+++ b/CHANGELOG Sun Sep 18 12:24:04 2022 +0200
@@ -1,3 +1,5 @@
+* Check server version
+
 Version 6.4.0 - 2022-05-02
 * Bug fixes (see mercurial logs for details)
 * Support notification message
diff -r 8114a38ae71d -r 6bbf7d85b46e src/sao.js
--- a/src/sao.js        Sun Sep 18 12:10:45 2022 +0200
+++ b/src/sao.js        Sun Sep 18 12:24:04 2022 +0200
@@ -615,15 +615,34 @@
     Sao.login = function() {
         Sao.set_title();
         Sao.i18n.setlang().always(function() {
-            Sao.Session.get_credentials()
-                .then(function(session) {
-                    Sao.Session.current_session = session;
-                    return session.reload_context();
-                }).then(Sao.get_preferences).then(function(preferences) {
-                    Sao.menu(preferences);
-                    Sao.user_menu(preferences);
-                    Sao.open_url();
-                    Sao.Bus.listen();
+            Sao.Session.server_version()
+                .then(function(version) {
+                    if (JSON.stringify(version.split('.').slice(0, 2)) !==
+                        JSON.stringify(Sao.__version__.split('.').slice(0, 2)))
+                    {
+                        Sao.common.warning.run(
+                            Sao.i18n.gettext(
+                                "Incompatible version of the server."),
+                            Sao.i18n.gettext("Version mismatch"));
+                    } else {
+                        Sao.Session.get_credentials()
+                            .then(function(session) {
+                                Sao.Session.current_session = session;
+                                return session.reload_context();
+                            })
+                            .then(Sao.get_preferences)
+                            .then(function(preferences) {
+                                Sao.menu(preferences);
+                                Sao.user_menu(preferences);
+                                Sao.open_url();
+                                Sao.Bus.listen();
+                            });
+                    }
+                }, function() {
+                    Sao.common.warning.run(
+                        Sao.i18n.gettext(
+                            "Could not connect to the server."),
+                        Sao.i18n.gettext("Connection error"));
                 });
         });
     };
@@ -887,7 +906,8 @@
     });
 
     Sao.Dialog = Sao.class_(Object, {
-        init: function(title, class_, size='sm', keyboard=true) {
+        init: function(
+            title, class_, size='sm', keyboard=true, small=null) {
             this.modal = jQuery('<div/>', {
                 'class': class_ + ' modal fade',
                 'role': 'dialog',
@@ -903,7 +923,7 @@
                 'class': 'modal-header'
             }).appendTo(this.content);
             if (title) {
-                this.add_title(title);
+                this.add_title(title, small);
             }
             this.body = jQuery('<div/>', {
                 'class': 'modal-body'
@@ -922,11 +942,15 @@
                 }
             });
         },
-        add_title: function(title) {
-            this.header.append(jQuery('<h4/>', {
+        add_title: function(title, small=null) {
+            var titleElement = jQuery('<h4/>', {
                 'class': 'modal-title',
                 'title': title,
-            }).text(Sao.common.ellipsize(title, 120)));
+            }).text(Sao.common.ellipsize(title, 120)  + (small? ' ' : ''));
+            if (small) {
+                titleElement.append(jQuery('<small/>').text(small));
+            }
+            this.header.append(titleElement);
         }
     });
 
@@ -1161,7 +1185,8 @@
 
     function help_dialog() {
         var dialog = new Sao.Dialog(
-            Sao.i18n.gettext("Help"), 'help-dialog', 'm');
+            Sao.i18n.gettext("Help"), 'help-dialog', 'md', true,
+            Sao.__version__);
         jQuery('<button>', {
             'class': 'close',
             'data-dismiss': 'modal',
diff -r 8114a38ae71d -r 6bbf7d85b46e src/sao.less
--- a/src/sao.less      Sun Sep 18 12:10:45 2022 +0200
+++ b/src/sao.less      Sun Sep 18 12:24:04 2022 +0200
@@ -99,6 +99,12 @@
 .modal-header {
     background-color: @brand-primary;
     color: #fff;
+
+    .modal-title {
+        small {
+            color: @gray-lighter;
+        }
+    }
 }
 
 #tablist {
diff -r 8114a38ae71d -r 6bbf7d85b46e src/session.js
--- a/src/session.js    Sun Sep 18 12:10:45 2022 +0200
+++ b/src/session.js    Sun Sep 18 12:24:04 2022 +0200
@@ -175,8 +175,30 @@
         }
     });
 
+    Sao.Session.server_version = function() {
+        var timeoutID = Sao.common.processing.show();
+        return jQuery.ajax({
+            'contentType': 'application/json',
+            'data': JSON.stringify({
+                'id': 0,
+                'method': 'common.server.version',
+                'params': []
+            }),
+            'dataType': 'json',
+            'url': '/',
+            'type': 'post',
+            'complete': [function() {
+                Sao.common.processing.hide(timeoutID);
+            }]
+        }).then(function(data) {
+            return data.result;
+        });
+    };
+
     Sao.Session.login_dialog = function() {
-        var dialog = new Sao.Dialog(Sao.i18n.gettext('Login'), 'lg');
+        var dialog = new Sao.Dialog(
+            Sao.i18n.gettext("Login"), 'login-dialog', 'md', true,
+            Sao.__version__);
         dialog.database_select = jQuery('<select/>', {
             'class': 'form-control',
             'id': 'database',

Reply via email to