Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
- var AppUrl = 'http://m.geaagronet.com';
- //var AppUrl = 'http://bd9b775b.ngrok.io/'; //localhost test
- var notificationData = '';
- var app = {
- // Application Constructor
- initialize: function() {
- document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
- document.addEventListener('resume', this.onResume.bind(this), false);
- },
- // deviceready Event Handler
- //
- // Bind any cordova events here. Common events are:
- // 'pause', 'resume', etc.
- onDeviceReady: function() {
- initApp();
- },
- onResume : function(){
- initNotifications();
- },
- // Update DOM on a Received Event
- receivedEvent: function(id) {
- var parentElement = document.getElementById(id);
- var listeningElement = parentElement.querySelector('.listening');
- var receivedElement = parentElement.querySelector('.received');
- listeningElement.setAttribute('style', 'display:none;');
- receivedElement.setAttribute('style', 'display:block;');
- console.log('Received Event: ' + id);
- }
- };
- app.initialize();
- function bindEvent(element, eventName, eventHandler) {
- if (element.addEventListener) {
- element.addEventListener(eventName, eventHandler, false);
- } else if (element.attachEvent) {
- element.attachEvent('on' + eventName, eventHandler);
- }
- }
- var firstTime = true;
- function initApp(){
- //probaj da uzmez info sa SIM kartice i salji aplikaciji
- if(firstTime){
- if (device.platform == "Android")
- window.plugins.sim.requestReadPermission(successReadPermission, errorReadPermission);
- firstTime = false;
- }
- // ako telefon nema pristup internetu
- if (navigator) {
- if (navigator.onLine == false) {
- alert("Trenutno nemate pristup internetu. Proverite vašu internet konekciju i pokušajte ponovo.");
- navigator.app.exitApp();
- }
- }
- // ako je stari telefon koji ne podrzava IFrame:
- if (device.platform == "Android") {
- if (parseFloat(device.version)) {
- if (parseFloat(device.version) < 4.3)
- window.location = AppUrl;
- }
- }
- //postavi IFrame url
- document.getElementById('contentFrame').src = AppUrl;
- //uzmi token za notifikacije i posalji ga aplikaciji (ovde salje i uuid)
- initNotifications();
- // Listen to message from child window
- bindEvent(window, 'message', function (e) {
- var msg = JSON.parse(e.data);
- if (msg && msg.type && msg.type == "open-link") {
- var url = msg.data;
- window.open(url, "_system");
- if (device.platform == "iOS") {
- document.getElementById('contentFrame').contentWindow.history.go(-1);
- return;
- }
- }
- });
- this.receivedEvent('deviceready');
- }
- function simInfoSuccess(result) {
- if(result && result.cards && result.cards.length > 0 && result.cards[0].simSerialNumber){
- $.get(AppUrl + "/Auth/AddToSession?key=simSerial&value=" + result.cards[0].simSerialNumber, function(data, status){});
- }
- if(result && result.cards && result.cards.length > 0 && result.cards[0].phoneNumber)
- $.get(AppUrl + "/Auth/AddToSession?key=phoneNumber&value=" + result.cards[0].simSerialNumber, function(data, status){});
- }
- function simInfoError(error) {
- console.log("simInfoError");
- }
- function successReadPermission(param) {
- window.plugins.sim.getSimInfo(simInfoSuccess, simInfoError);
- }
- function errorReadPermission(){
- console.log("errorReadPermission");
- }
- function initNotifications(){
- $.get(AppUrl + "/Auth/AddToSession?key=uuid&value=" + device.uuid, function(data, status){});
- const push = PushNotification.init({
- android: {},
- browser: {},
- ios: {},
- windows: {}
- });
- push.on('registration', data => {
- $.get(AppUrl + "/Auth/AddToSession?key=notificationToken&value=" + data.registrationId, function(data, status){});
- });
- push.on('notification', (data) => {
- if(data && data.additionalData && data.additionalData.onOpenUrl){
- document.getElementById('contentFrame').src = AppUrl + data.additionalData.onOpenUrl;
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement