all files / scripts/ app.js

78.95% Statements 15/19
100% Branches 2/2
66.67% Functions 6/9
77.78% Lines 14/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54    14×                                                                            
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
  };
}