Office-JS Outlook Add-in - outlook

I am having trouble with using Office.EventType.RecipientsChanged for Outlook.
I've tested this on Windows and Outlook.com. Mac apparently does not support 1.7 yet.
This is the error I get when I use the following code block:
Function addHandlerAsync has invalid parameters.
$(document).ready(function () {
try {
if(Office.context.requirements.isSetSupported('MailBox', '1.7')) {
console.log('MailBox 1.7 supported');
Office.context.mailbox.addHandlerAsync(Office.EventType.RecipientsChanged, function(result){
if (result.status === Office.AsyncResultStatus.Failed) {
console.log("Error with event handler.");
}
else {
processRecipientsChanged();
}
});
}
}catch(e){
console.log(e);
}

Since RecipientsChanged events occur in the item scoped, the call is Office.context.mailbox.item.addHandlerAsync. See https://learn.microsoft.com/en-us/office/dev/add-ins/reference/objectmodel/requirement-set-1.8/office.context.mailbox.item#addhandlerasynceventtype-handler-options-callback

Related

how to get the text of bootstrap alert message for testing with protractor

this is my spec
it('should save edited majorObject', function () {
var description = element(by.id('objectDescription'));
description.clear();
description.sendKeys('edited');
var add = element(by.id('saveObject'));
add.click().then(function () {
expect(element(by.css('.alert-success')).isDisplayed()).toBe(true);
expect(element(by.css('.alert-success')).toText()).toBe("Saved Successfully");
})
});
i used
expect(element(by.css('.alert-success')).toText()).toBe("Saved Successfully");
But it is showing undefined and is their any alternative way to do this?
You meant to use getText() instead of toText():
expect(element(by.css('.alert-success')).getText()).toBe("Saved Successfully");

Using Kango API from iFrame

Using Kango, I have added an iFrame to a page. This iFrame points to an internal resource. I want this iFrame to be able to communicate with the background script. I would love to actually get the Kango API accessable from the iFrame, but if this is not possible I wonder how I might target this iFrame with a content script.
From your application that is inside the iFrame you can do:
top.window.postMessage({ type: 'EVENT', data: {} }, "*");
Then inside your Kango extension HTML link a JS file that has:
KangoAPI.onReady(function () {
window.addEventListener('message', function (event) {
console.log('host.js -> message', event);
kango.dispatchMessage('MessageToWindow', event);
});
document.body.onload = function () {
try {
document.getElementById('iFrameID').src = 'URL';
} catch (ex) {
throw ex;
}
}
});
Then inside the background.js
kango.addMessageListener('MessageToWindow', function (event) {
console.log('background.js -> MessageToWindow', event);
kango.browser.tabs.getCurrent(function (tab) {
console.log('background.js -> TAB', tab || 'NONE');
console.log('background.js -> TYPE', event.data.data.type || 'NONE');
console.log('background.js -> DATA', event.data.data.data || 'NONE');
tab.dispatchMessage(event.data.data.type, event.data.data.data);
});
});
Lastly, inside the content.js
kango.addMessageListener('EVENT', function(event) {
kango.console.log('got event');
});
Seems like a lot, but this was the only way that I could get it to work. Hope that helps!

How to handle server side validation in Ember-Data 1.0.0

I'm using Ember 1.2.0 and the latest Ember Data Beta and wonder, how to handle server side errors (from API calls).
This question is quite similar, but it doesn't work.
At first, the becameInvalid method doesn't triggered. I'm using ember-validations (do I have to?)
My API sends an 422 status code and responses like that:
{"errors":{"name":["has already been taken"],"initial":["has already been taken"]}}
model.js
Docket.Customer = DS.Model.extend( Ember.Validations, {
name: DS.attr('string'),
initial: DS.attr('string'),
description: DS.attr('string'),
validations: {
name: {
presence: true
}
},
becameError: function() {
alert('there was an error!');
},
becameInvalid: function(errors) {
alert("Record was invalid because: " + errors);
}
});
controller.js
Docket.OrganizationCustomersController = Ember.ArrayController.extend({
actions: {
save: function () {
var customer = this.store.createRecord('customer');
customer.set('name', this.get('name'));
customer.set('initial', this.get('initial'));
customer.set('description', this.get('description'));
customer.save().then(function() {
console.log('jeah')
}, function() {
console.log('nooo')
});
}
}
});
The becameError method gets fired, but the becameInvalid method doesn't.
The second problem: even if the error is triggered, Ember.js adds the new record to the DOM. How can I prevent this behaviour?
Your errors json is ok, I think you are using the DS.RESTAdapter, and it doesn't implement the becameInvalid based in json with errors.
Just DS.ActiveModelAdapter have implemented in the moment, so I recommend you to change your adapter configuration to:
Docket.ApplicationAdapter = DS.ActiveModelAdapter;
In order to keep DS.RestAdapter, you can override its ajaxError method with the one from ActiveModelAdapter.
As for today the code, slightly adapted because some dependencies are needed, would be :
App.ApplicationAdapter = DS.RESTAdapter.extend({
// ... your own customizations,
ajaxError: function(jqXHR) {
var error = this._super(jqXHR);
if (jqXHR && jqXHR.status === 422) {
var response = Ember.$.parseJSON(jqXHR.responseText),
errors = {};
if (response.errors !== undefined) {
var jsonErrors = response.errors;
Ember.EnumerableUtils.forEach(Ember.keys(jsonErrors), function(key) {
errors[Ember.String.camelize(key)] = jsonErrors[key];
});
}
return new DS.InvalidError(errors);
} else {
return error;
}
}
});
Obviously you have a chance here to adapt to your backend specifics: HTTP code (422 is not a standard one) and format.
Source :
http://discuss.emberjs.com/t/how-to-handle-failure-to-save-on-server/3789

TFS 2012 Web Access Work Item Custom Control

I´m developing a TFS 2012 web access custom control and I need to change some workitem field values when the save workitem button is clicked.
I’ve just developed the same custom control for Visual Studio and I’ve performed these changes in the IWorkItemControl.FlushToDatasource method but I don't know how to achieve the same at web access control.
I’ve tried to change the workitem field values in the invalidate function when the workitem is being saved,
invalidate: function (flushing) {
if (this._workItem.isSaving()) {
this._workItem.getField("FieldName").setValue("newValue");
}
},
But it does not work, although the changes made while saving the workitem are included in the list of updated fields, they are not saved.
Any idea how can it be implemented by using the Javascript API?
Thanks.
Oscar
Can you try this:
_control: null,
_init: function() {
alert("_init() called!");
debugger;
if (this._workItem) {
var originalEstimate = this._workItem.getField("Microsoft.VSTS.Scheduling.OriginalEstimate").getValue();
alert('OriginalEstimate value is ' + originalEstimate);
console.log('this in _init');
console.log(this);
} else {
alert('_workItem is null or undefined!');
console.log('this in _init');
console.log(this);
}
this._base();
this._control = $("<div style='width:100%;height:100%;background-color:lightblue;'><button type='submit'>CLICK ME!</button></div>").appendTo(this._container).bind("click", delegate(this, this._onClick));
},
invalidate: function(flushing) {
alert("invalidate(flushing) called!");
var value = this._getField().getValue();
debugger;
if (this._workItem) {
var originalEstimate = this._workItem.getField("Microsoft.VSTS.Scheduling.OriginalEstimate").getValue();
alert('OriginalEstimate value is ' + originalEstimate);
console.log('this in _init');
console.log(this);
} else {
alert('_workItem is null or undefined!');
console.log('this in _init');
console.log(this);
}
alert(value);
},
clear: function() {
alert("clear() called!");
},
_onClick: function() {
alert("Butona tıklandı!");
}

Sencha touch listening to phonegap events

I'm trying to get Sencha Touch to listen to the events phonegap gives off, any help I can find online only points to sencha events. I've also tried setting up listeners and " .on " but it doesn't seem to work on outside events.
I'm not talking about any specific event, just any event like 'resume', or 'batterystatus'.
Please don't reply with a reference to Ext.device because Sencha support for Ext.device is limited and outdated as it always has been when one company tries to provide a wrapper around a different company, I'd like to take full advantage of all the features the most up-to-date phonegap version offers.
You should be able to add PhoneGap-specific listeners like this:
document.addEventListener("deviceready", function() {
document.addEventListener("backbutton", MyApp.backButtonListener, false);
document.addEventListener("menubutton", MyApp.menuButtonListener, false);
}, false);
MyApp.backButtonListener = function(e) {
e.preventDefault();
//do other stuff here...
}
MyApp.menuButtonListener = function(e) {
e.preventDefault();
//do other stuff here...
}
You can do something like this, I have tested it and it's working!
Ext.application({
name: 'TestApp',
...
launch: function() {
// Hook up events of PhoneGap here
document.addEventListener("pause", this.onPause, false);
document.addEventListener("resume", this.onResume, false);
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
Ext.Viewport.add(Ext.create('TestApp.view.Main'));
},
onPause: function() {
// this code is fine but using 'this' here is not safe
console.log("onPause");
},
onResume: function() {
console.log("onResume");
}
...
});
Edited:
Turn out it's not a very good idea to put the handler in the app.js file (although it will still work anw). Because if you upgrade sencha, it expects this file not to be modified much.
So you should instead put it in your launch function of a main controller. Controllers' launch function are executed after Application's launch function.
Ext.define('TestApp.controller.Main', {
extend: 'Ext.app.Controller',
...
launch: function() {
// Hook up events of PhoneGap here
document.addEventListener("pause", this.onPause, false);
document.addEventListener("resume", this.onResume, false);
},
onPause: function() {
// this code is fine but using 'this' here is not safe
console.log("onPause");
},
onResume: function() {
console.log("onResume");
}
...
});

Resources