Cannot access roaming settings when UI dialog open - outlook-addin

I can access the roaming settings from the side panel in the outlook Add-in.But when I am trying to access roaming settings if the UI dialog ( DialogAsync) is open. It getting as undefined.
var _settings = Office.context.roamingSettings;
var numberDetails = _settings.get('PHONENUMBERSLIST');

There are only two Office.js APIs that can be called in the dialog:
messageParent
isSetSupported
See the note about 1/3 of the way down in the is article: Use the Dialog API in your Office Add-ins

RoamingSettings will be only available in the frame that created it. If you need to share some values between your dialog and side panel, you can pass these values as parameters in url:
var url = new URI('Dialog/myDialog.html').absoluteTo(window.location).toString();
url += '?myvalue=' + Office.context.roamingSettings.get('myvalue')
+ '&othervalue=' + Office.context.roamingSettings.get('othervalue');
var dialogOptions = { width: 20, height: 35, displayInIframe: true };
Office.context.ui.displayDialogAsync(url, dialogOptions, function (result) {
settingsDialog = result.value;
settingsDialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived, receiveSettingsMessage);
settingsDialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogEventReceived, settingsDialogClosed);
});
Then, in your dialog, you can use them or set them again inside $(document).ready() using getUrlParameter('myvalue').
You can also send needed values back to the side panel using:
function sendMessage(param) {
Office.context.ui.messageParent(JSON.stringify(param));
}

Related

How to change the database if printed?

I have a button that prints
<input type = "button" onclick = "printDiv ('printableArea')" class = "button1" value = "Print" />
<script>
function printDiv (divName) {
var printContents = document.getElementById (divName) .innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print ();
document.body.innerHTML = originalContents;
}
</script>
And it sends to print operation.
The customer currently has the option to print or cancel.
Is there a way to access code behind in case the customer presses a print button?
(I want to change in my database that the client has already printed ...)
Regards
Is there a way to access code behind in case the customer presses a print button?
Please note that we can not directly detect if user clicked the 'Print' or 'Cancel' button in printing dialog via JS code from a html page.
Similar issue discussed in this SO thread: How to capture the click event on the default print menu called by Javascript window.print()?
As a workaround, you can try to show a prompt dialog to confirm if the printing is complete and then make request to backend to update database once the afterprint event is raised, like below.
window.onafterprint = function () {
var message = "Have you printed the page(s)?";
var result = window.prompt(message,"yes");
if (result=="yes") {
//...
//make ajax request to backend
//...
}
};
You can add a GET request to an MVC Action like (in jQuery):
...
document.body.innerHTML = printContents;
var clientId = $("#clientId").val();
$.get("#Url.Action("SavePrinted", "Client")", { clientId: clientId });
window.print();
...

Change ICN contentViewer's tab title in split pane mode?

I need to change the "title" for each document shown in ICN Viewer, dynamically, at runtime. I'll read the new viewer tab title from the document properties
ENVIRONMENT: ICN 2.0.3 CM8.5 WAS 8.5.5
CODE SO FAR:
I found a PARTIAL solution by hooking "ecm.model.desktop, onChange":
aspect.after(ecm.model.desktop, 'onChange', function() {
var contentViewer = dijit.byId('contentViewer');
if (contentViewer) {
var viewerTabTitleDef = new ViewerTabTitleDef ();
contentViewer.mainTabContainer.getChildren().forEach(function(child) {
viewerTabTitleDef.changeTitle(viewerTabTitleDef.self,
child.controlButton, child.contentViewerPane.viewerItem.item);
});
...
I was able to extend this for subsequent documents opened in the same viewer, and optimized by "removing()" the handler after this initial call. Here is the complete code:
var kill = aspect.after(ecm.model.desktop, 'onChange', function() {
var contentViewer = dijit.byId('contentViewer');
// "contentViewer" will be "unknown" unless viewer invoked
console.log('onChange: contentViewer', contentViewer);
if (contentViewer) {
console.log("new ViewerTabTitleDef()...");
kill.remove();
var viewerTabTitleDef = new ViewerTabTitleDef ();
contentViewer.mainTabContainer.getChildren().forEach(function(child) {
// For initially opened tabs
console.log('initially opened: child', child);
viewerTabTitleDef.changeTitle(viewerTabTitleDef.self, child.controlButton, child.contentViewerPane.viewerItem.item);
});
aspect.after(contentViewer.mainTabContainer, 'addChild', function(child) {
// For tabs added after the viewer was opened
console.log('subsequently opened: child', child);
viewerTabTitleDef.changeTitle(viewerTabTitleDef, child.controlButton, child.contentViewerPane.viewerItem.item);
}, true);
} // end if contentViewer
}); // end aspect.after(onChange desktop)
CURRENT PROBLEM:
Q: How can I change the label for a split tab (either vertical or horizontal)?
So far, I have NOT been able to find any event for any ICN/ECM widget or object variable that I can trigger on.
Thank you in advance!
===============================================
ADDENDUM:
Many thanks to Ivo Jonker, for his suggestion to modify the widget prototype's
"getHtmlName()" method. It worked!
Specifically:
I'm invoking this code from an ICN plugin. I set event handlers in my plugin's base .js file, but it actually gets invoked in the new, separate viewer window.
The original prototype looked like this:
getHtmlName: function() {
var methodName = "getHtmlName";
this.logEntry(methodName);
var displayName = this.item.getDisplayValue("{NAME}");
if (displayName == "") {
displayName = this.item.name;
}
var htmlName = entities.encode(displayName);
this.logExit(methodName);
return htmlName;
},
Per Ivo's suggestion, I overrode the prototype method like this:
myPluginDojo.viewerTabTitleDef = viewerTabTitleDef;
...
ecm.widget.viewer.model.ViewerItem.prototype.getHtmlName = function () {
console.log("NEW getHtmlName()...");
var displayName = myPluginDojo.viewerTabTitleDef.getTitle(this.item);
return displayName;
};
If i understand you correctly, you want to show a different tab-title (instead of the document title) in the navigator viewer whenever a doc is opened?
How about this:
Every document you open in the viewer is wrapped in a ecm.widget.viewer.model.ViewerItem which exposes the getHtmlName that returns the name used in the tab.
Your solution would be to implement your own getHtmlName.
Unfortunately though, the ViewerItem is constructed in the ecm.widget.viewer.ContentViewer#_open and then passed to the ecm.widget.viewer.ContentViewer#_openTab. So you'll either violate best practice by mingling with IBM private method's, or you'll go for a generic approach and just replace the ecm.widget.viewer.model.ViewerItem.prototype.getHtmlName

Node-Webkit MenuItem click function issue

I have an issue with my Node-Webkit MenuItem click function which I believe I have narrowed down to changing the URL from within the Javascript on my loading page. I have a 5 second timer which changes the page when complete. If I set the document location to a web page on a web server (could be anything even www.google.com) from within the javascript in my loading.html page, my MenuItem Click functions do not work
$(document).ready(function() {
window.setTimeout(function() {
document.location = "http://localhost:8080/myapp/index.htm";
}, 5000);
});
If I change the document location to a html page which is contained within my app.nw package, my MenuItem click functions work and the page will change to any of my
http://localhost:8080/myapp pages
$(document).ready(function() {
window.setTimeout(function() {
document.location = "test.html";
}, 5000);
});
Here is my Node-Webkit javascript file contained within the app.nw package which places a menu bar on the application window.
var gui = require('nw.gui');
var win = gui.Window.get();
var rootMenu = new gui.Menu({ type: 'menubar'});
var sysMenu = new gui.Menu();
sysMenu.append(new gui.MenuItem({
type: 'normal',
label: 'Google',
click: function (){
Window.window.location.assign("http://localhost:8080/myapp/customers.htm");
}
}));
gui.Window.get().menu = rootMenu;
Has anyone else come across this or am I doing something the wrong way?
Thanks

Clicking 'back' on a form unloads web resource

Say I have a form with a web resource on it, when viewing the form and clicking the web browser's 'back' button the web resource seems to unload, if I click the back button again then it behaves as I'd expect.
Has anyone else experienced this? Is there a way to prevent the web resource from unloading when a user clicks 'back'?
Note: This seems to happen in both IE (10,11) and Chrome, but not Firefox.
Had the same issue, looks like a bug.
Until Microsoft fixes it, use the following in your webresource to trap the back event and redirect it properly.
$(document).ready(function () {
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
var hashLocation = location.hash;
var hashSplit = hashLocation.split("#!/");
var hashName = hashSplit[1];
if (hashName !== '') {
var hash = window.location.hash;
window.parent.history.back();
window.parent.history.back();
}
});
window.history.pushState('forward', null, './#forward');
}
}

jqGrid: different navigator buttons depending on login status

I want to use different navigator buttons in jqGrid depending on login status.
for example: if the user is logged in then add/delete/edit button appeared.
Any ideas?
Thanks in advance.
It is possible to add buttons programmatically using the navButtonAdd method (for the navigation bar) and the toolbarButtonAdd method for the toolbar. For example:
jQuery("#grid").toolbarButtonAdd('#t_meters',{caption:"MyButton",
id: "t_my_button",
title: "Do my button action",
buttonicon: 'ui-icon-edit',
onClickButton:function(){
// Button handle code goes here...
}
});
And:
jQuery("#grid")..navButtonAdd('#pager',{
id: "t_my_button",
title: "Do my button action",
buttonicon: 'ui-icon-edit',
onClickButton:function(){
// Button handle code goes here...
}
});
For more information see the Custom Buttons on the Wiki.
Anyway, once this code is in place, you can detect login status server-side. Then use this knowledge to generate client code that only adds the buttons to your grid if the user is supposed to have access to them.
You can also use for example userdata (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#user_data) to send information about buttons which you need to have in the navigator. userdata should be set by server. Then with respect of:
var navGridParams = jQuery("grid_id").getGridParam('userData');
// var navGridParams = { edit: false, add: false, search: true }
you can get the data set by the server.
Now the typical call like:
jQuery("grid_id").navGrid('#pager', { edit: false, add: false, search: true });
You should place not after creating of jqGrid, but inside of than inside of loadComplete. So the code could looks like following:
var isNavCreated = false;
jQuery('#list').jqGrid({
// ...
loadComplete: function () {
var grid = jQuery("grid_id");
if (isNavCreated === false) {
isNavCreated = true;
var navGridParams = grid.getGridParam('userData');
grid.navGrid('#pager', navGridParams);
}
},
// ...
});
Another option that I see, is to use cookie instead of userdata to send information about navGridParams back to the client.