implemented client-side error handling + translation
authordurandn
Thu, 19 May 2016 12:58:05 +0200
changeset 70 97e57904f11d
parent 69 0abec1f6a66f
child 71 1b93c07510e4
implemented client-side error handling + translation
.settings/org.eclipse.core.resources.prefs
server/src/metaeducation/locale/fr/LC_MESSAGES/django.po
server/src/metaeducation/settings/__init__.py
server/src/metaeducation/static/metaeducation/css/style.css
server/src/metaeducation/static/metaeducation/js/mtdc-save.js
server/src/metaeducation/templates/base.html
server/src/metaeducation/templates/renkan_edit.html
server/src/metaeducation/templates/renkan_view.html
--- a/.settings/org.eclipse.core.resources.prefs	Fri May 13 13:12:14 2016 +0200
+++ b/.settings/org.eclipse.core.resources.prefs	Thu May 19 12:58:05 2016 +0200
@@ -3,4 +3,5 @@
 encoding//server/src/metaeducation/migrations/0001_initial.py=utf-8
 encoding//server/src/metaeducation/migrations/0002_user_uai.py=utf-8
 encoding//server/src/metaeducation/migrations/0003_renkan_permissions.py=utf-8
+encoding//server/src/metaeducation/migrations/0004_auto_20160414_1057.py=utf-8
 encoding//server/src/metaeducation/settings/dev.py=utf-8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/src/metaeducation/locale/fr/LC_MESSAGES/django.po	Thu May 19 12:58:05 2016 +0200
@@ -0,0 +1,78 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2016-05-19 11:35+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+#: metaeducation/admin.py:61
+msgid "Personal info"
+msgstr "Informations personnelles"
+
+#: metaeducation/admin.py:62
+msgid "Permissions"
+msgstr "Permissions"
+
+#: metaeducation/admin.py:64
+msgid "Important dates"
+msgstr "Dates"
+
+#: metaeducation/models.py:35
+msgid "first name"
+msgstr "Prénom"
+
+#: metaeducation/models.py:36
+msgid "last name"
+msgstr "Nom"
+
+#: metaeducation/templates/renkan_edit.html:67
+msgid "The Renkan server has reported an error"
+msgstr "Le serveur Renkan a rencontré une erreur."
+
+#: metaeducation/templates/renkan_edit.html:71
+msgid ""
+"The Renkan graph you are trying to edit is currently being edited by another "
+"user. We advise you to reload the page."
+msgstr "Le graphe Renkan que vous tentez d'éditer est actuellement en cours d'édition par un autre "
+"utilisateur. Nous vous conseillons de recharger la page."
+
+#: metaeducation/templates/renkan_edit.html:73
+msgid ""
+"There was an error with the graph data sent to the Renkan server. If the "
+"problem persists after a page reload, please contact an administrator. Error "
+"message was : "
+msgstr "Une erreur s'est produite lors de l'envoi des données d'éditions du graphe Renkan. Si le "
+"problème persiste après rechargement de la page, merci de contacter un administrateur. Message "
+"d'erreur: "
+
+#: metaeducation/templates/renkan_edit.html:75
+msgid "You don't have the permission to edit this Renkan graph."
+msgstr "Vous n'avez pas le droit d'éditer ce graphe Renkan."
+
+#: metaeducation/templates/renkan_edit.html:77
+msgid "The Renkan graph you are trying to edit or view doesn't exist"
+msgstr "Le graphe Renkan que vous cherchez à visualiser ou éditer n'existe pas."
+
+#: metaeducation/templates/renkan_edit.html:79
+msgid ""
+"There was an error with the Renkan server. If the problem persists after a "
+"page reload, please contact an administrator. The error message was : "
+msgstr "Une erreur s'est produite au niveau du serveur Renkan. Si le problème persiste après "
+"rechargement de la page, merci de contacter un administrateur. Message d'erreur: "
+
+#: metaeducation/templates/renkan_edit.html:83
+msgid "Reload the page"
+msgstr "Recharger la page"
--- a/server/src/metaeducation/settings/__init__.py	Fri May 13 13:12:14 2016 +0200
+++ b/server/src/metaeducation/settings/__init__.py	Thu May 19 12:58:05 2016 +0200
@@ -55,7 +55,7 @@
     ),
     'DEFAULT_PERMISSION_CLASSES': (
         'rest_framework.permissions.IsAuthenticatedOrReadOnly',
-        'metaeducation.permissions.MtdcObjectPermissions',
+        #'rest_framework.permissions.DjangoObjectPermissions',
     ),
     'DEFAULT_PARSER_CLASSES': (
         'rest_framework.parsers.JSONParser',
--- a/server/src/metaeducation/static/metaeducation/css/style.css	Fri May 13 13:12:14 2016 +0200
+++ b/server/src/metaeducation/static/metaeducation/css/style.css	Thu May 19 12:58:05 2016 +0200
@@ -61,4 +61,8 @@
 
 #renkanErrorReload {
 	cursor: pointer;
+}
+
+.errorMsg{
+	display: none;
 }
\ No newline at end of file
--- a/server/src/metaeducation/static/metaeducation/js/mtdc-save.js	Fri May 13 13:12:14 2016 +0200
+++ b/server/src/metaeducation/static/metaeducation/js/mtdc-save.js	Thu May 19 12:58:05 2016 +0200
@@ -17,7 +17,6 @@
               _proj.set({
                   saveStatus : 0
               });
-              console.log(_proj.get("updated"))
               _proj.on("add:nodes add:edges add:users add:views", function(_model) {
                   _model.on("change remove", function(_model) {
                       _thrSave();
@@ -30,9 +29,8 @@
                       _thrSave();
                   }
               });
-          }).fail(function( jqXHR, textStatus ) {
-              _showErrorModal(jqXHR.responseText);
-              console.log(textStatus)
+          }).fail(function(jqXHR, textStatus) {
+              _showErrorModal(jqXHR);
           });
       };
       var _save = function() {
@@ -51,12 +49,9 @@
                           saveStatus : 0,
                           updated : data.updated
                       });
-                      //_showErrorModal("updated")
                   },
                   error: function (jqXHR, textStatus, errorThrown) {
-                      _showErrorModal(jqXHR.responseText);
-                      console.log(textStatus)
-                      console.log(errorThrown)
+                      _showErrorModal(jqXHR);
                   }
               });
           }
@@ -72,9 +67,30 @@
       });
       
       var errorModal = document.getElementById('renkanErrorModal');
-      var _showErrorModal = function(message) {
+      var _showErrorModal = function(jqXHR) {
           errorModal.style.display = "block";
-          Rkns.$(".errorMsg").text(message);
+          switch(jqXHR.status){
+              case 400:
+                  var jsonResp = JSONparse(jqXHR.responseText)
+                  if(jsonResp.hasOwnAttribute('validation_timestamp')){
+                      document.getElementById('400Error_timestamp').style.display = "block";
+                  }
+                  else {
+                      Rkns.$("#400Error_other").append(jqXHR.responseText)
+                      document.getElementById('400Error_other').style.display = "block";
+                  }
+                  break;
+              case 403:
+                  document.getElementById('403Error').style.display = "block";
+                  break;
+              case 404:
+                  document.getElementById('404Error').style.display = "block";
+                  break;
+              case 500:
+                  Rkns.$("#500Error").append(jqXHR.responseText)
+                  document.getElementById('500Error').style.display = "block";
+                  break;
+          }
       }
       
       _load();
--- a/server/src/metaeducation/templates/base.html	Fri May 13 13:12:14 2016 +0200
+++ b/server/src/metaeducation/templates/base.html	Thu May 19 12:58:05 2016 +0200
@@ -1,4 +1,5 @@
 {% load staticfiles %}
+{% load i18n %}
 <!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
--- a/server/src/metaeducation/templates/renkan_edit.html	Fri May 13 13:12:14 2016 +0200
+++ b/server/src/metaeducation/templates/renkan_edit.html	Thu May 19 12:58:05 2016 +0200
@@ -1,5 +1,6 @@
 {% extends "base.html" %}
 {% load staticfiles %}
+{% load i18n %}
 {% block js_import %}
   {{block.super}}
   <script src="{% static 'renkanmanager/lib/jquery-mousewheel/jquery.mousewheel.js' %}"></script>
@@ -62,15 +63,19 @@
   <div id="renkan"></div>
   <div id="renkanErrorModal" class="errorModal">
     <div class="errorModal-cnt">
-    <div class="errorModal-header">
-      <h2>Le serveur Renkan a renvoyé une erreur.</h2>
-    </div>
-    <div class="errorModal-body">
-      <p class="errorMsg"></p>
-    </div>
-    <div class="errorModal-footer">
-      <h4 id="renkanErrorReload">Recharger la page</h4>
+      <div class="errorModal-header">
+        <h2>{% trans "The Renkan server has reported an error" %}</h2>
+      </div>
+      <div class="errorModal-body">
+        <p id="400Error_timestamp" class="errorMsg">{% trans "The Renkan graph you are trying to edit is currently being edited by another user. We advise you to reload the page." %}</p>
+        <p id="400Error_other" class="errorMsg">{% trans "There was an error with the graph data sent to the Renkan server. If the problem persists after a page reload, please contact an administrator. Error message was : " %} </p>
+        <p id="403Error" class="errorMsg">{% trans "You don't have the permission to edit this Renkan graph." %}</p>
+        <p id="404Error" class="errorMsg">{% trans "The Renkan graph you are trying to edit or view doesn't exist" %}</p>
+        <p id="500Error" class="errorMsg">{% trans "There was an error with the Renkan server. If the problem persists after a page reload, please contact an administrator. The error message was : " %}</p>
+      </div>
+      <div class="errorModal-footer">
+        <h4 id="renkanErrorReload">{% trans "Reload the page" %}</h4>
+      </div>
     </div>
   </div>
-  </div>
 {% endblock main_content %}
\ No newline at end of file
--- a/server/src/metaeducation/templates/renkan_view.html	Fri May 13 13:12:14 2016 +0200
+++ b/server/src/metaeducation/templates/renkan_view.html	Thu May 19 12:58:05 2016 +0200
@@ -1,5 +1,6 @@
 {% extends "base.html" %}
 {% load staticfiles %}
+{% load i18n %}
 {% block js_import %}
   {{block.super}}
   <script src="{% static 'renkanmanager/lib/jquery-mousewheel/jquery.mousewheel.js' %}"></script>
@@ -62,13 +63,17 @@
   <div id="renkanErrorModal" class="errorModal">
     <div class="errorModal-cnt">
       <div class="errorModal-header">
-        <h2>Le serveur Renkan a renvoyé une erreur.</h2>
+        <h2>{% trans "The Renkan server has reported an error" %}</h2>
       </div>
       <div class="errorModal-body">
-        <p class="errorMsg"></p>
+        <p id="400Error_timestamp" class="errorMsg">{% trans "The Renkan graph you are trying to edit is currently being edited by another user. We advise you to reload the page." %}</p>
+        <p id="400Error_other" class="errorMsg">{% trans "There was an error with the graph data sent to the Renkan server. If the problem persists after a page reload, please contact an administrator. Error message was : " %} </p>
+        <p id="403Error" class="errorMsg">{% trans "You don't have the permission to edit this Renkan graph." %}</p>
+        <p id="404Error" class="errorMsg">{% trans "The Renkan graph you are trying to edit or view doesn't exist" %}</p>
+        <p id="500Error" class="errorMsg">{% trans "There was an error with the Renkan server. If the problem persists after a page reload, please contact an administrator. The error message was : " %}</p>
       </div>
       <div class="errorModal-footer">
-        <h4 id="renkanErrorReload">Recharger la page</h4>
+        <h4 id="renkanErrorReload">{% trans "Reload the page" %}</h4>
       </div>
     </div>
   </div>