support pinnable task pane with angular 1.x - angularjs

I am right now trying to implement pinnable task pane in Outlook Windows version, which is the only supported platform. After I added Office.context.mailbox.addHandlerAsync() into Office.initialize. I found a problem with the angular bootstrapping. Should I bootstrap my app again in the itemChanged handler function? Is there any elegant way to do this?
Here i my code now.
Office.initialize = function(reason) {
$(document).ready(function() {
Office.context.mailbox.addHandlerAsync(
Office.EventType.ItemChanged,
function(eventArgs) {
// angular.bootstrap(document.body, ["my-addin"]);
location.reload();
},
function(asyncResult) {
// This is callback for addHandlerAsync. This will be called ONCE when the event is registered.
}
);
angular.bootstrap(document.body, ["my-addin"]);
});
if (OfficeHelpers.Authenticator.isAuthDialog()) return;
};
I am right now using location.reload() for every itemChanged event.

Can you try this?
I could not set up the pinnable feature in my Outlook because I do not have the required Windows/Office update yet to see the pinnable feature but on an assumption, this is what you may be looking for:
Office.initialize = function(reason) {
$(document).ready(function() {
Office.context.mailbox.addHandlerAsync(
Office.EventType.ItemChanged,
function(eventArgs) {
// angular.bootstrap(document.body, ["my-addin"]);
//location.reload();
//inject the '$window' provider in your service/controller
$window.location.reload();
},
function(asyncResult) {
// This is callback for addHandlerAsync. This will be called ONCE when the event is registered.
}
);
angular.bootstrap(document.body, ["my-addin"]);
});
if (OfficeHelpers.Authenticator.isAuthDialog()) return;
};
NOTE:
Office.context.mailbox.addHandlerAsync requires API requirement set v1.5 whereas Outlook 2016 MSI install only supports till v1.4 at the time of posting this answer.

Related

when I resume app by Custom URL scheme first time,the window.handleOpenURL doesn't execute

When I start app by custom scheme url,event 'deviceready' trigger,and window.handleOpenURL in the getBillFromLink() execute;
then I open a webpage and resume the app from it,but window.handleOpenURL didn't execute;function onResume and getBillFromLink will execute;
but no matter how many times I resume the app from webpage after the first time,
window.handleOpenURL will execute normally;
Here are code:
$ionicPlatform.on("deviceready", function () {
document.addEventListener("resume", onResume, false);
getBillFromLink().then(function (data) {
//todo
});
});
function onResume() {
getBillFromLink().then(function (data) {
//todo
});
}
function getBillFromLink() {
var deferred = $q.defer();
$timeout(function() {
window.handleOpenURL = function(url){
if(!!url){
deferred.resolve(url);
}else{
deferred.reject(url);
}
};
}, 0);
return deferred.promise;
}
how could I deal with the trouble?
thanks for your advice and sorry for my poor English:-)
Your issue is not linked to custom-scheme-url plugin as your apps properly starts when you call your specific URL.
I assume that, once the app is already started; custom-scheme-url does not trigger again your function.
You have to use a backgroundmode plugin.
I suggest to use : https://github.com/katzer/cordova-plugin-background-mode
This plugin let s you define events when apps goes from background to active app. and more.

How to add a custom error page in Cordova InAppBrowser or hide the error url?

pleas check this attached image I'm building an Ionic Android app with the InAppBrowser plugin. When the internet connection is not available, the plugin shows web page not available and requesting url.
Please help me customise the InAppBrowser error page (404 page). Or help me hide the requesting url.
Thank you.
I think I misunderstood your problem, first time, sorry about that. I'm reading again your problem and I'm figuring out what's happening. You need to add a custom configuration at config.xml to redirect to an error page when Cordova detect it. I hope this solve your problem.
<preference name="ErrorUrl" value="myErrorPage.html"/>
The original response works when you want to open a link through Cordova inAppBrowser plugin. If this doesn't sort out your problem, please reformulate your question.
Original response
You could be listening inAppBrowser events to figure what's happening.
Here, you can see how listen browser events, such as loaderror and manage the 404 error as you want. You must save a reference to inAppBrowser when open method is called, and then you could listen for error event.
function loadErrorCallBack(params) {
// Do stuff
}
inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);
inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);
I am using Ionic 4 and I couldn’t manage to make the solution based on config.xml editing to work :
preference name="ErrorUrl" value="myErrorPage.html"/
Placing an addEventListener on loaderror didn’t work neither. It looks like it is not triggered by http errors and the plugin need a fix.
But we found a hack that is much simpler.
On loadstop we wait 500 milliseconds and then we get the loaded url by triggering executeScript with and window.location.href
If the loaded url is of the custom error page, in Cordova (not in IAB) we display a custom message with a back button.
It's a hack but that cover the requirement for now
I just came across the same problem and here's what I did. The code is for Android and works on IOS as well. But you would want to remove navigator.app.exitApp(); for IOS as Apple does not allow apps to take exit without pressing the home button.
Let me know if this works for you. It will hide default error page and open your custom error page. Write your own error code in myerrorpage.html
document.getElementById("openBrowser").addEventListener("click", openBrowser);
document.addEventListener("offline", onOffline, false);
function onOffline(e) {
e.preventDefault();
var src = 'myErrorPage.html';
var target = '_blank';
var option = "loaction=no, toolbar=no, zoom=no, hidden=yes, hardwareback=no";
var ref = cordova.InAppBrowser.open(src, target, option);
alert('Your device is Offline. Please check your connection and try again.');
navigator.app.exitApp();
}
function openBrowser() {
var url = 'https://www.yourlink.com';
var target = '_self';
var options = "location=no,toolbar=no,zoom=no, hardwareback=no, hidden=yes" ;
var ref = cordova.InAppBrowser.open(url, target, options);
}
When the components do not work, I perform the following procedure
ionic state reset
ionic platform remove android
ionic platform remove ios
ionic platform add android
ionic platform add ios
and try with ionicPlatform ready
<button class="button button-balanced" ng-click="OpenBrowser()">Test</button>
In controller
$scope.OpenBrowser = undefined;
$ionicPlatform.ready(function () {
$scope.OpenBrowser = function () {
$cordovaInAppBrowser.open('http://ngcordova.com', '_blank', options)
.then(function (event) {
})
.catch(function (event) {
$scope.Error = event;
});
};
});
I couldn't manage solution with setting ErrorUrl in Ionic 4 on Android to work.
Finally I came up with another solution - hide default error page and redirect user to any page (I use last page from event.url).
constructor(private iab: InAppBrowser) {
}
private openUrl(url: string)
{
this.platform.ready().then(() => {
if (this.platform.is('cordova')) {
this.openBrowser(url);
}
});
}
private openBrowser(url: string): InAppBrowserObject
{
const options: InAppBrowserOptions = {
location: 'no',
zoom: 'no',
hidden: 'no'
};
const browser = this.iab.create(url, '_blank', options);
browser.on('loaderror').subscribe(
event => this.onLoadError(event, browser)
);
return browser;
}
private onLoadError(event: InAppBrowserEvent, browser: InAppBrowserObject): void
{
browser.executeScript({
code: `
window.addEventListener('DOMContentLoaded', function () {
document.querySelector('body').style.background = 'black';
document.querySelector('body').innerHTML = '';
}, true);
window.addEventListener('load', function () {
window.location.replace('${event.url}');
}, true);
`,
}
).then();
}
Changing background and redirecting is tricky - from my experiments using injectCss won't work, because body is generated in the meantime. Using DOMContentLoader makes it black and clears text on screen.
But redirecting won't work in DOMContentLoader (don't ask me why), so you need to use load event.
It works great when user is using hardware back and returns to POST request - this way he will be redirected to GET of the same url (but you can use any url you want).

Detect internet working or not in Cordova Ionic Framework

I want show message when internet not working in cordova Ionic Application, Can anybody done this in Ionic Cordova Application.
There is a network-information plugin to get network information from the device. Add the
cordova plugin add org.apache.cordova.network-information
include it and in app.js and register an offline event handler from within the onDeviceReadyevent handler,
onDeviceReady: function() {
document.addEventListener("offline", onOffline, false);
},
onOffline: function () {
//handle offline
}
Its quite simple actually.
Add the plugin:
cordova plugin add org.apache.cordova.network-information
You don't need to include anything in index.html. Just add $cordovaNetwork on the controller you are using. And, the following snippet will go well with it.
document.addEventListener("deviceready", function () {
// Check for network connection
if(window.Connection) {
//you can log your connection as well, whether it is internet, wifi and so on.In this case you are checking for no connection
alert(navigator.connection.type);
if(navigator.connection.type == Connection.NONE) {
$ionicPopup.confirm({
title: 'Network Problem',
content: 'Sorry, Please Check Your Network Connection.'
})
//or you can simply navigate it to a page with the no internet connection html.
}
}
})
//This is one of the way. The next way is having the following snippet in the controller you want to use. Don't forget to add the $cordovaNetwork, $ionicPlatform in this case.
var type = $cordovaNetwork.getNetwork();
var isOnline = $cordovaNetwork.isOnline();
var isOffline = $cordovaNetwork.isOffline();
$rootScope.$on('$cordovaNetwork:online', function(event, networkState){
var onlineState = networkState;
alert(onlineState);
})
$rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
var offlineState = networkState;
alert(offlineState);
})
document.addEventListener("deviceready", function () {
$rootScope.$on('$cordovaNetwork:online',function(event,networkState){
$location.path('/japp/login');
})
$rootScope.$on('$cordovaNetwork:offline',function(event,networkState){
$ionicPopup.confirm({
title: "Internet Disconnected",
content: "The internet is disconnected on your device."
}).then(function(){
ionic.Platform.exitApp();
})
})
If you are still having problem feel free to ask any small detail.
here is some discussion on the ionic forum: http://forum.ionicframework.com/t/how-to-check-network-coneection/15806/14
you can find a lot like this one. I would suggest to use ngCordova and do something like this:
$rootScope.$on('$cordovaNetwork:online', function() {});
$rootScope.$on('$cordovaNetwork:offline', function() {});
After installing plugin (cordova plugin add org.apache.cordova.network-information), you can use following code inside app.js to show alert message
if(window.Connection) {
console.log("checking connection");
if(navigator.connection.type == Connection.NONE) {
$ionicPopup.alert({
title: "No Internet Connection",
content: "Internet Connection is not available. In offline you can see previously fetched data.",
okType:"balanced",
})
.then(function(result) {
if(!result) {
console.log('ok clicked');
}
});
}
}
Hi there is another issue here. Network information only tells you wether there is a connection. But that doesn't mean you have connection to a website and/or a running database. In most cases an app depends on the website and/or the database are available. So you have to check those too.

How to check internet connection in AngularJs

This is how I would check internet connection in vanilla javascript:
setInterval(function(){
if(navigator.onLine){
$("body").html("Connected.");
}else{
$("body").html("Not connected.");
}
},1000);
I have angular controllers and modules in my project. Where should I put the code above? It should be executed in global context and not be assigned to a certain controller. Are there some kind of global controllers maybe?
First of all, I advise you to listen to online/offline events.
You can do it this way in AnguarJS:
var app = module('yourApp', []);
app.run(function($window, $rootScope) {
$rootScope.online = navigator.onLine;
$window.addEventListener("offline", function() {
$rootScope.$apply(function() {
$rootScope.online = false;
});
}, false);
$window.addEventListener("online", function() {
$rootScope.$apply(function() {
$rootScope.online = true;
});
}, false);
});
NOTE: I am wrapping changing of root scope's variable in $apply method to notify Angular that something was changed.
After that you can:
In controlller:
$scope.$watch('online', function(newStatus) { ... });
In HTML markup:
<div ng-show="online">You're online</div>
<div ng-hide="online">You're offline</div>
Here is a working Plunker: http://plnkr.co/edit/Q3LkiI7Cj4RWBNRLEJUA?p=preview
Other solution could be to broadcast online/offline event. But in this case you need to initialize current status upon loading and then subscribe to event.
It's definitely not as nice, but you could just try an AJAX request to your web server; it'll either succeed or time out.
Also, the HubSpot/offline project looks really good.
Your options:
addEventListener on the window, document, or document.body.
setting the .ononline or .onoffline properties on document or
document.body to a JavaScript Function object.
specifying ononline="..." or onoffline="..." attributes on the tag in
the HTML markup
I will demonstrate the easiest.
In you controller
document.body.onoffline = function() {
alert('You are offline now');
$scope.connection = 'offline'
}
document.body.ononline = function() {
alert('You are online again');
$scope.connection = 'online'
}
Check $scope.connection variable before you try to send requests around.
For Angular 2+ you can use ng-speed-test:
Just install:
npm install ng-speed-test --save
Inject into your module:
import { SpeedTestModule } from 'ng-speed-test';
#NgModule({
...
imports: [
SpeedTestModule,
...
],
...
})
export class AppModule {}
Use service to get speed:
import {SpeedTestService} from 'ng-speed-test';
#Injectable()
export class TechCheckService {
constructor(
private speedTestService:SpeedTestService
) {
this.speedTestService.getMbps().subscribe(
(speed) => {
console.log('Your speed is ' + speed);
}
);
}
}

ExtJS 4.1: unload event

I am working with ext js 4.1. I am developing an application that have to support IE9, the latest Firefox, the latest Chrome and Safari.
I need to show an alert message when the user wants to leave the if there are some data that is pending to submit.
I did the following using raw Javascript:
window.onbeforeunload=function(){
if (Ext.getStore('LocalChangesStore')){
if (Ext.getStore('LocalChangesStore').getCount() > 0) {
return 'Your changes are be lost.';
}
}
};
I am wondering if that would be possible with ext js. I saw the following function:
app.js:
EventManager.onWindowUnload( function(){
if (Ext.getStore('LocalChangesStore')){
if (Ext.getStore('LocalChangesStore').getCount() > 0) {
return 'Your changes are be lost.';
}
}
}, this
);
but it did not work.
Can somebody let me know which would be the best approach to solve this issue?
The onWindowUnload method attachs a function to the unload event but what you need is attach a function to the beforeunload event. Try this please
Ext.EventManager.on(window, 'beforeunload', function() {
return 'Your changes are be lost.';
});
Good luck.

Resources