var client;
document.onreadystatechange = function() {
if (document.readyState === 'interactive') renderApp();
function renderApp() {
var onInit = app.initialized();
onInit.then(getClient).catch(handleErr);
function getClient(_client) {
client = _client;
client.events.on('app.activated', onAppActivate);
}
}
};
function onAppActivate() {
var btn = document.querySelector('.btn-open');
btn.addEventListener('click', openModal);
// Start writing your code...
getphone();
}
function openModal() {
client.interface.trigger(
'showModal',
useTemplate('Title of the Modal', './views/modal.html')
);
}
function getphone() {
var options = { "url": "https://api.github.com/users/sample" };
client.request.invoke("serverMethod", options).then(
function(data) {
// data is a json object with requestID and response.
// data.response gives the output sent as the second argument in renderData.
console.log("server method Request ID is: " + data.requestID);
console.log("server method response is: " + data.response);
},
function(err) {
// err is a json object with requestID, status and message.
console.log("Request ID: " + err.requestID);
console.log("error status: " + err.status);
console.log("error message: " + err.message);
});
}
function useTemplate(title, template) {
return {
title,
template
};
}
|