Created
May 27, 2010 02:32
-
-
Save jsjohnst/415367 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callAPI(url, callback) { | |
var request = new URL(); | |
request.callback = callback; | |
request.location = url; | |
KONtx.utility.WaitIndicator.up(); | |
request.fetchAsync(function (u) { | |
KONtx.utility.WaitIndicator.down(); | |
if (u.response == 200){ | |
KONtx.application.setNetworkRequestFailed(false); | |
u.callback(u.result); | |
} else { | |
KONtx.application.setNetworkRequestFailed(true); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This example assumes you are following the code pattern | |
// set forth in our best practices guide. | |
// | |
// If you are not, then you need to just subscribe your method | |
// you created like you would for anything else in the framework | |
EventHandlers.onNetworkHideDialog.subscribeTo( | |
KONtx.application, | |
"onNetworkHideDialog", | |
EventHandlers | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (event.payload.type == 1) { | |
// Check if you have the base data you need to render your main view | |
// This would normally be config data which you would fetch at widget startup | |
// DO NOT fetch data inside this handler, the network is unstable | |
if (data_ready == false) { | |
event.preventDefault(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Replace myWidget with your widget's custom object | |
myWidget.network = (function () { | |
var setDownByUser = false; | |
return { | |
setNetworkRequestFailed: function (status) { | |
KONtx.application.setNetworkRequestFailed(status); | |
setDownByUser = status; | |
}, | |
isPhysicalNetworkDown: function () { | |
if (KONtx.application.getNetworkDownStatus) { | |
return !setDownByUser; | |
} | |
return false; | |
} | |
}; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof KONtx.application.isPhysicalNetworkDown === "undefined") { | |
KONtx.application.isPhysicalNetworkDown = function () { | |
// Replace myWidget with your widget's custom object | |
return myWidget.network.isPhysicalNetworkDown(); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callAPI(url, callback){ | |
var request = new URL(); | |
request.callback = callback; | |
request.location = url; | |
KONtx.utility.WaitIndicator.up(); | |
request.fetchAsync(function (u) { | |
KONtx.utility.WaitIndicator.down(); | |
if (u.response == 200) { | |
myWidget.network.setNetworkRequestFailed(false); | |
u.callback(u.result); | |
} else { | |
myWidget.network.setNetworkRequestFailed(true); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (KONtx.application.isPhysicalNetworkDown()) { | |
log("the network is down!"); | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callAPI(url, callback) { | |
if (KONtx.application.isPhysicalNetworkDown()) { | |
log("the network is down!"); | |
return; | |
} | |
var request = new URL(); | |
request.callback = callback; | |
request.location = url; | |
KONtx.utility.WaitIndicator.up(); | |
request.fetchAsync(function (u) { | |
KONtx.utility.WaitIndicator.down(); | |
if (u.response == 200){ | |
myWidget.application.setNetworkRequestFailed(false); | |
u.callback(u.result); | |
} else { | |
myWidget.application.setNetworkRequestFailed(true); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment