Javascript event callback to PowerBuilder with data - javascript

I am using PowerBuilder 2017 and have created an OLE control (Microsoft Web Browser) with a local html file using Leaflet JS.
When a user clicks on a marker on the leaflet map I would like a reference value (coordinates) sent back to PowerBuilder where the code there can react to the user event.
My question is how can I get a javascript event to also trigger an event in the main PowerBuilder application?

After a lot of investigating I have managed to solve my problem, I added the following code into PowerBuilder, inside the OLE Control's click event:
oleobject lole_data
string ls_innertext, ls_classname
lole_data = This.Object.Document.ActiveElement
if not IsNull(lole_data) then
ls_classname = Lower( string(This.Object.Document.ActiveElement.classname))
if ls_classname = "leaflet-popup-content" then
ls_innertext = string(lole_data.parentNode.InnerText)
end if
end if
ActiveElement is the method to use. I obtain the Leaflet class and can identify it is in fact a Marker PopUp that was clicked.

Related

Dynamics CRM 2016 Online - Refresh record after using dialog

I have a custom button on my ribbon which fires a dialog up. It's part of a workaround Qualification solution I'm putting together.
The creation of an Account/Contact/Opportunity and the choices given work fine, as well as changing the status of the Lead to qualified. The problem is that when the user is done with the Dialog and closes it, they're still looking at the Lead in its original state.
How do I force the form to refresh so that it shows its new state?
I've seen a Javascript solution online (codeplex), Process.js - callDialog() which seems popular but it doesn't want to work as described by the creator on my version of CRM - always get a invalid URL error message & it fires on load of the form as well as when using the custom button.
Has anyone come across a requirement like this and how have you resolved it?
Thanks
Edit: Here is the JS I use on my ribbon button currently. Where do I put my refresh call and what/how do I call the event being used when closing the Dialog.
I tried adding a refresh call at the bottom of the this code but its called whilst opening the Dialog at the start, which isn't much use as the changes I want to see are applied throughout the Dialog itself.
Thanks
Develop1_RibbonCommands_runDialogForm = function(objectTypeCode, dialogId) {
var primaryEntityId = Xrm.Page.data.entity.getId();
var rundialog = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
rundialog.get_query()['DialogId'] = dialogId;
rundialog.get_query()['ObjectId'] = primaryEntityId;
rundialog.get_query()['EntityName'] = objectTypeCode;
var hostWindow = window;
if (typeof(openStdWin) == 'undefined') {
hostWindow = window.parent; // Support for Turbo-forms in CRM2015 Update 1
}
if (typeof(hostWindow.openStdWin) != 'undefined') {
hostWindow.openStdDlgWithCallback(rundialog, hostWindow.buildWinName(null), 615, 480, Xrm.Page.data.refresh(false));
}
}
})();
Check out the Xrm.Page.data (client-side reference), you'll want to call Xrm.Page.data.refresh().
Depending on how you're launching your dialog, and assuming your dialog is a webresource hosted in CRM, the dialog can reach back out to the form it launched from and call refresh, or a callback could potentially be used.
EDIT (based on your posted code): If the 5th parameter of the function openStdDlgWithCallback is the callback for when the dialog closes you'd want to pass the function like Xrm.Page.data.refresh or wrap your call in a function function(){Xrm.Page.data.refresh()}. Currently your code is executing the function right away which is why you're seeing the refresh right away.
Using openStdDlgWithCallback you can subscribe a callback function which runs after the dialog is closed. You can then use Xrm.Page.data.refresh() inside the callback function.

How can I get two onClick calls to fire?

Firstly I am not a web developer, I'm an Analytics professional, so I apologise if this question seems basic and not using the correct terminology!...
I am trying to get _trackEvent code to fire 'onClick' for some Social buttons - however as the social buttons open in a new window they already run an onClick as follows....
I need to add in the following _trackEvent code:
onClick=_gaq.push(['_trackEvent', 'EN', 'Tower of London', 'Facebook']);
So what I am trying to do is fire an event to Google Analytics on click whilst not disturbing the button functionality. Any help is much appreciated
Just put the tracking command before the window open command in the onClick
like this:
A quick JavaScript/HTML lesson : what the contents of the inline "onclick"-attribute describe is the body of a "callback" function (a method that, in this case, is executed when the element is clicked). In this case it opens the Facebook share URL in a new window/tab when the anchor is clicked.
What you want to do is execute TWO different callbacks for the single click-event. This would lead us to using JavaScript to assign the event callbacks using "addEventListener/attachEvent" as the inline "onclick"-attribute only allows for a single callback handler, while adding listeners gives you the benefit of being able to add multiple callbacks for a single event type. As others have mentioned, if you have jQuery or another library available this can be a doddle to attach.
However, if you want a quick and dirty fix without getting too much JavaScript code going on outside of your HTML document, you can add the _gaq-tracking code inside the "onclick"-attribute by appending after the existing onclick-code like so:
Which will result in tracking the click in Analytics AND the window openeing. Semantically, this is quite fugly as it describes multiple handlers in a single of code, but for the sake of argument we assume you don't mind as the HTML had inline JS handling to begin with and we haven't even touched the subject of window opens being blocked when they are delegated through multiple functions instead of on a direct-click handler! ;)
Instead of using onclick, attach the events using jquery if you have it:
<script type="text/javascript">
$('.facebook').on('click', function () {
window.open('http://www.facebook.com/share.php?u=http://www.londonpass.com/infographic/hampton-court.html&title=Hampton Court - History and Stories Infographic from the London Pass/','newWin','width=400,height=200')
_gaq.push(['_trackEvent', 'EN', 'Tower of London', 'Facebook']);
//other code you like
});
</script>
For attaching the event using pure javascript:
var socials = document.getElementByClass("facebook");
socials.addEventListener('click', myFunction, false);
And define your function:
<script type="text/javascript">
function myFunction () {
window.open('http://www.facebook.com/share.php?u=http://www.londonpass.com/infographic/hampton-court.html&title=Hampton Court - History and Stories Infographic from the London Pass/','newWin','width=400,height=200')
_gaq.push(['_trackEvent', 'EN', 'Tower of London', 'Facebook']);
//other code you like
}
</script>

Setting a default popup from the URL in a modestmaps/mapbox wax map

An app I inherited at http://bei.bclcmaps.com shows popups when locations are clicked, which works fine.
However, I need to add the ability to auto-show a popup on page load based on something in the URL. Whether it's a latitude and longitude of some sort of ID or anything, it doesn't matter, anything will do.
The problem I'm having is that I can't figure out how to programmatically open a popup. I've tried figuring out some way to trigger a click on a location in JS using the wax API or the modestmaps API and I can't get it.
I've even tried manually clicking with jQuery, using:
function clickAt(x, y) {
var e = new jQuery.Event("click");
e.pageX = 10;
e.pageY = 10;
$(".zoombox").trigger(e);
}
And from there I've set debugger within a .click() callback on zoombox to get the coordinate of an example location, and tried those coordinates with the clickAt function, and nothing happens.
On IRC, someone told me to use map.gridLayer.fire('click', {latLng: L.latLng(0, 0)) to trigger a click, but this doesn't seem like a proper mapbox app since I don't have access to the full mapbox JS API, so I don't have mapbox.gridLayer.
Any tips? Or maybe programmatically triggering a click isn't the correct approach and there's an easier way to show a prepopulated popup on page load? I'm out of ideas.
You can do something like this
$(document.elementFromPoint(x, y)).click();
https://developer.mozilla.org/En/DOM:document.elementFromPoint
I ended up just converting it to use the regular mapbox API after all, making things like this easier.

Event change doesn't fire on dynamically populated Picker - Titanium SDK

I'm trying to create a custom Picker whose data is from a remote JSON. The problem is that it doesn't fire the 'change' event on the picker at the first time when I select a row from the picker, I have to close the picker and select a row from the picker again and then the event change works.
var clubs_data = [];
//custom object to handle the httpClient
new K().scoutmobile.Tools.getData(new K().scoutmobile.URL_BASE, {Accion:new K().scoutmobile.CLUBS}, function(_response){
if(response.status.codigo === "RESULT"){
clubs_data.push(Ti.UI.createPickerRow({title:'select a club'}));
for(_j in _response.data){
clubs_data.push(Ti.UI.createPickerRow({color:'#fff',title: _response.data[_j].Propiedades.club_nombre.Valor, id:_response.data[_j].Propiedades.club_id.Valor}));
inputClubs.add(clubs_data); //where inputClubs is created previously
}else{
new K().scoutmobile.Tools.createDialog('invalid_user_alert_dialog_title','invalid_user_alert_dialog_message');
}
});
//event listener
inputClubs.addEventListener('change', function(e){
Ti.API.info(e.row.id);
});
win.add(inputClubs);
In the Titanium Studio Console I get this:
[WARN][InputManagerService( 60)] Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#43f8dbb8
Any ideas what it is happening?
I have three solutions for this, none of them are good enough:
A very stupid solution would be having picker pointing at empty option at start, then user need to change it anyways
If you loading another element of UI using that picker value, you can preload that part with the default (or first) option
You can modify Titanium SDK source code, where they write this log "Window already focused' and fire change event instead. This is pretty simple, I have done that for TabGroup control, it may take 2 hours of your time (either for Android or iOS)

RadScheduler update interval

I'm using RadScheduler for my project. In the scheduler, I need a periodical update, so in my javascript, I set interval for a method that call rebind() on the RadScheduler for every 60 seconds. The problem is that, when my user open the advanced form, the rebind() method makes the form disappear. How can I detect AdvancedForm opening and closing event so that I can stop /restart the timer ?
Thank you in advance.
While there is an event for when the RadScheduler opens its Edit form, called OnClientFormCreated, there is not one for when the edit form closes. There are ways to do this though, but you have do add some additional code.
When you think about it there are several different items that can lead to the form closing - the user can click on the close icon at the top right (or left, depending on your orientation) of the window, they can click cancel, or they can hit save.
Keeping that in mind, we can take a look at this demo, which shows the Advanced Edit Form in action, and also has some JavaScript pre-written for us.
Within the schedulerFormCreated() function we can do the following:
function schedulerFormCreated(scheduler, eventArgs) {
// Create a client-side object only for the advanced templates
var mode = eventArgs.get_mode();
if (mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert ||
mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit) {
// Initialize the client-side object for the advanced form
var formElement = eventArgs.get_formElement();
var cancelButton = $("[id$='_CancelButton']");
cancelButton.on("click", formClosed);
var templateKey = scheduler.get_id() + "_" + mode;
....
And then we have the formClosed event:
function formClosed(eventArgs) {
}
in formClosed you can just create your logic for resuming the timer, while in schedulerFormCreated you can directly call the function that stops the timer right after that if-statement.
In case you're wondering what we're doing here we're simply grabbing an instance of the jQuery object representing the element with an id that ends with _CancelButton (we're not interested in the beginning part) and then just binding to the click event using the .on() jQuery function.
To get an instance of the save button you just have to use _UpdateButton, and for the close icon it is _AdvancedEditCloseButton. Keep in mind that any element that ends with these substrings will be selected, so if you want to be more specific I recommend inspecting the elements of your advanced form using FireBug or the Chrome Dev tools to get their ID and plug that into the selector above.
This should allow you to get the functionality you're looking for.

Categories