From 417cb283a4bc36c732bc3c4257bea9a4547f5109 Mon Sep 17 00:00:00 2001 From: gine Date: Sat, 18 Mar 2017 13:48:23 +0100 Subject: [PATCH] Miglior gestione dell'errore no connessione. Fix errore social network. --- www/index.html | 2 +- www/js/main.js | 63 ++++++++++++++++++++----------------------------- www/js/share.js | 37 +++++++++++++++-------------- 3 files changed, 46 insertions(+), 56 deletions(-) diff --git a/www/index.html b/www/index.html index 5bf17ef..105af6a 100644 --- a/www/index.html +++ b/www/index.html @@ -335,7 +335,7 @@ - + diff --git a/www/js/main.js b/www/js/main.js index aa8b01b..2e29f85 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -156,7 +156,10 @@ function overlayblock() { $(".overlaynero").toggleClass("hide"); } /*per network info*/ -function checkConnection() { +function checkConnection(code, msgConnect) { + var msgTitle = "Non sei connesso"; + msgConnect = msgConnect || "Occore essere connessi per poter ricevere i nuovi articoli"; + var networkState = navigator.connection.type; var states = {}; states[Connection.UNKNOWN] = 'Unknown connection'; @@ -168,7 +171,8 @@ function checkConnection() { states[Connection.CELL] = 'Cell generic connection'; states[Connection.NONE] = 'No network connection'; if (states[networkState] == 'Unknown connection' || states[networkState] == 'No network connection') { - //alert('Non sei connesso ad internet, connettiti ad una rete per procedere.'); + toastr.warning(msgConnect, msgTitle); + console.log(code); return false } else { return true @@ -227,8 +231,6 @@ function postInListTag(div) { }); }; - - function initTag(div) { $.mobile.loading('show'); FONTE.dbHandler.executeSql("SELECT * FROM xm24_tags ORDER BY date COLLATE NOCASE DESC;", [], function (resultSet) { @@ -792,55 +794,42 @@ function JSONErrorHandler(jqXHR, textStatus, errorThrown) { }; function cerca() { - if (checkConnection()) { + var ret = checkConnection('ERR_CERCA'); + + if (ret) { cercaMe(); - return true; - } else { - toastr.error('Err: ERR_CERCA'); - - return false; - } + } + + return ret; }; function segnalaBug() { - if (checkConnection()) - return true; - else { - toastr.error('Err: ERR_SEGNALA'); - - return false; - } + return checkConnection('ERR_SEGNALA'); }; function mostraEsperto() { - if (checkConnection()) { + var ret = checkConnection('ERR_ESPERTO'); + if (ret) { myJsonPage(2167, '#espertotitle', '#mostraesperto'); - return true; - } else { - toastr.error('Err: ERR_ESPERTO'); - - return false; } + + return ret; }; function checkAndUpdate() { - if (checkConnection()) { + var ret = checkConnection('ERR_ESPERTO'); + if (ret) { update(); - return true; - } else { - toastr.error('Err: ERR_UPDATE'); - - return false; } + + return ret; }; function checkAndReset() { - if (checkConnection()) { + var ret = checkConnection('ERR_ESPERTO'); + if (ret) { resetAndUpdate(); - return true; - } else { - toastr.error('Err: ERR_RESET'); - - return false; - } + } + + return ret; }; \ No newline at end of file diff --git a/www/js/share.js b/www/js/share.js index d3b99c1..51be674 100644 --- a/www/js/share.js +++ b/www/js/share.js @@ -1,19 +1,20 @@ -// this is the complete list of currently supported params you can pass to the plugin (all optional) -var options = { - message: 'share this', // not supported on some apps (Facebook, Instagram) - subject: 'the subject', // fi. for email - files: ['', ''], // an array of filenames either locally or remotely - url: 'https://www.website.com/foo/#bar?a=b', - chooserTitle: 'Pick an app' // Android only, you can override the default share sheet title +function shareMeNow(message, subject, url) { + // this is the complete list of currently supported params you can pass to the plugin (all optional) + var options = { + message: message || 'share this', // not supported on some apps (Facebook, Instagram) + subject: subject || 'the subject', // fi. for email + //files: ['', ''], // an array of filenames either locally or remotely + url: url || 'https://www.website.com/foo/#bar?a=b', + } + + var onSuccess = function(result) { + console.log("Share completed? " + result.completed); // On Android apps mostly return false even while it's true + console.log("Shared to app: " + result.app); // On Android result.app is currently empty. On iOS it's empty when sharing is cancelled (result.completed=false) + } + + var onError = function(msg) { + console.log("Sharing failed with message: " + msg); + } + + window.plugins.socialsharing.shareWithOptions(options, onSuccess, onError); } - -var onSuccess = function(result) { - console.log("Share completed? " + result.completed); // On Android apps mostly return false even while it's true - console.log("Shared to app: " + result.app); // On Android result.app is currently empty. On iOS it's empty when sharing is cancelled (result.completed=false) -} - -var onError = function(msg) { - console.log("Sharing failed with message: " + msg); -} - -window.plugins.socialsharing.shareWithOptions(options, onSuccess, onError); \ No newline at end of file