Add method to manage cache
Benjamin Renard

Benjamin Renard commited on 2014-11-22 17:23:37
Showing 3 changed files, with 41 additions and 5 deletions.

... ...
@@ -1,7 +1,5 @@
1 1
 CACHE MANIFEST
2
-
3
-NETWORK:
4
-*
2
+# Date : 2014/11/22 - Version : 11
5 3
 
6 4
 CACHE:
7 5
 index.html
... ...
@@ -45,3 +43,5 @@ inc/lib/uuid.js
45 43
 inc/lib/typeahead.bundle.js
46 44
 inc/lib/moment.min.js
47 45
 
46
+NETWORK:
47
+*
... ...
@@ -950,6 +950,35 @@ pleaseWaitHide=function() {
950 950
   $('#please_wait_modal').modal('hide');
951 951
 }
952 952
 
953
+/**************************
954
+ * Cache / Update
955
+ *************************/
956
+
957
+onUpdateReady=function() {
958
+  myconfirm(
959
+    "Une nouvelle version de l'application est disponible. Voulez-vous lancer la mise à jour ?",
960
+    onConfirmUpdate,null,{} 
961
+  );
962
+}
963
+
964
+onConfirmUpdate=function() {
965
+  window.applicationCache.swapCache();
966
+  location.reload();  
967
+}
968
+
969
+_checkForUpgrade=false;
970
+updateApp = function() {
971
+  _checkForUpgrade=true;
972
+  window.applicationCache.update();
973
+}
974
+
975
+onNoUpdate = function() {
976
+  if (_checkForUpgrade) {
977
+    _checkForUpgrade=false;
978
+    alert('Aucune mise à jour disponible');
979
+  }
980
+}
981
+
953 982
 /*********************
954 983
  * Activate
955 984
  *********************/
... ...
@@ -1030,4 +1059,11 @@ $( document ).ready( function() {
1030 1059
   
1031 1060
   view_home();
1032 1061
   pleaseWaitHide();
1062
+
1063
+  $('#update_app').bind('click',updateApp);
1064
+  window.applicationCache.addEventListener('updateready', onUpdateReady);
1065
+  window.applicationCache.addEventListener('noupdate', onNoUpdate);
1066
+  if(window.applicationCache.status === window.applicationCache.UPDATEREADY) {
1067
+    onUpdateReady();
1068
+  }
1033 1069
 } );
... ...
@@ -1,6 +1,5 @@
1 1
 <!DOCTYPE html>
2
-<!--<html manifest="cache.manifest">-->
3
-<html>
2
+<html manifest="cache.manifest">
4 3
   <head>
5 4
     <title>MyCo</title>
6 5
     <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
... ...
@@ -186,6 +185,7 @@ span.cat-color {
186 185
               <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class='glyphicon glyphicon-user'></span> <span id='user-name'>Connexion</span> <b class="caret"></b></a>
187 186
               <ul id="user-menu" class="dropdown-menu"></ul>
188 187
             </li>
188
+            <li><a id='update_app'><span class='glyphicon glyphicon-refresh'></span> Mise à jour de l'application</a></li>
189 189
           </ul>
190 190
 
191 191
         </div><!--/.nav-collapse -->
192 192