Toggle navigation
Run LIVE DEMO
Show CODE
LIVE DEMO PAGE
Updated: 19.06.18 11:05
Basic example
<!DOCTYPE html> <html> <head> <title>Retry dialog smartapp2.js example</title> <!-- jQuery --> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <!-- Bootstrap --> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <!-- Smartapp --> <script src="https://smartapp.ikx.no/downloads/jquery.smartapp2.js"></script> </head> <body> <div id="AppContainer"></div> <!-- View1 added through markup --> <div id="View1" class="text-center"> <h1>The main view</h1> <p>This is the only view in this demo. It runs a failed HTTP GET the button below. A retry dialog will be shown.</p> <a class="btn btn-default" id="CallBtn">Call to server (will fail)</a> </div> <!-- Modal1 added through markup --> <div id="Retry" class="modal"> <div class="modal-dialog"> <div class="modal-content"> <header class="modal-header"> <h1 data-control="HeaderLbl">Feil med tilkobling</h1> </header> <section class="modal-body"> <p id="MessageLbl"> Beklager, det har oppstått en feil med forbindelsen til internett. Vennligst kontroller at tilgang til internett er aktivert på enheten. </p> <p id="Message2Lbl"> OBS! Klikk på prøv igjen knappen under for å fortsette og evt. unngå å miste data. </p> </section> <footer class="modal-footer"> <button type="button" class="btn btn-danger btn-lg btn-block" id="RetryBtn"> <span class="glyphicon glyphicon-repeat"></span> <span data-control="RetryLbl">Prøv igjen</span> </button> <button type="button" class="btn btn-default btn-lg btn-block" id="CancelBtn"> <span class="glyphicon glyphicon-remove"></span> <span data-control="CancelLbl">Avbryt</span> </button> </footer> </div> </div> </div> <script> $(function() { var options = { disableJsonp:true }; // Initialize app on a DOM container element var $app = $("#AppContainer").smartapp2("http://invalidserviceurl", null, options); // Register a view on route #View1 (will be default view, as it is registered first) $app.createView("View1", $("#View1"), function($me) { $me.on("viewinit", function() { $me.CallBtn.on("click", function() { $app.APIGet("Test", "Test", {}).done(function(result){ // This will always fail and show the retry }); }); }); }); // Register the "Retry" dialog $app.createDialog("Retry", $("#Retry"), function($me) { $me.on("dialoginit", function () { $me.RetryBtn.click(function () { $me.ExecCalls($app.FailedRetryCalls); $app.FailedRetryCalls = null; $app.FailedCancelCalls = null; return false; }); $me.CancelBtn.click(function () { $me.ExecCalls($app.FailedCancelCalls); $app.FailedRetryCalls = null; $app.FailedCancelCalls = null; return false; }); }); $me.ExecCalls = function(callList) { $app.RetryView = null; $me.closeDialog(); for (var i = 0; i < callList.length; i++) callList[i](); return false; }; }); $app.RetryDialogName = "Retry"; // Run the application $app.run(); }); </script> </body> </html>