I know this question may seem weird but I'd like to get a list of currently dispatched events.
The thing is that I am a lazy man and I would like to check if the 'checkout_cart_add_product_complete' has been fired without creating an observer for it.
So the idea is to get an array of all dispatched events and do an in_array on it :)
I thought that Mage::getEvents()->getAllEvents() would throw some info but it just returns an empty array.
I also digged a bit in lib/Varien/Event files and folders but didn't manage to be successful at creating an observer programmatically. Yep, I know, why being simple while one can be complicated ? :)
So this main question (getting a list of dispatched events) hides another (for the pure knowledge) wich would be "how to create an observer programmatically".
What do you think?
Thanks a lot!
Take a look at dispatchEvent and you'll see that events are only loaded from the assorted config.xml files, via SimpleXML. I cannot see any way to intercept this except to override Mage_Core_Model_App.
Of course there cannot be an event-dispatched-event, that would create an infinite loop, so there is no way to observe all events.
If you need to see events for development my advice would be to set a breakpoint in dispatchEvent with your debugger, that way you get to see not only the event names but also the objects passed as parameters too. I've tried other ways before but this was most convenient for me.
I need to do the same and I think it's possible to trick magento by the function getEventConfig in Mage_Core_Model_Config. You could force him to add automatically a default observer.
Related
So, we all know that you can add events post-render by calling Template.templateName.events() and passing in new events. My question is: How do I remove them? I've found that I'm adding them how I like, but I end up with several of the same event, that all fire, and it's causing all sorts of problems. Is there a specific place that meteor stores the actual events? Where I could clear them out?
Template events should not be called several times but used once for static event definitions for this template that every instance of the template will listen to.
The documentation is not very helpful here. However, if you need dynamic template events you are still in good hands using the classic addEventListener or jQuery on and use bind to bind them to the template instance.
Don't forget to remove them when required but at least in Template#onDestroyed
I found that Template.templateName.__eventMaps = [] did the trick. I run this before creating a new instance of my template, and therefore only get one set of event handlers. woo!
I have faced an issue while using .set(#{value}) to fill the text field in registering form, e.g: the phone number i wanna put in is 506307 then it ended up with 063075.
The work-around i have been made is executing Javascript block like
execute_script("document.querySelector('#{selector}').value = '#{value}'")
However, using the same scripts applying for Webmobile based on React.JS, the scripts above just send the text but didn't send the onChange event, which cause another element cannot be selected/clicked -> made the test failed.
I came up with another approach is to use the send_keys #{value} to trigger the key-pressed event that would make browser think there was a key-pressed event happen for that form, but it ended up with race-condition like set(#{value}) as i mentioned.
The another work-around is using What is the best way to trigger onchange event in react js , but i tend to use the native Capybara actions before making that tricky Javascript.
So, is there any other way to interact / fill the form field which won't cause that Race condition issue ?
Thanks everybody in advance.
Note: Any "solution" suggested that is purely the use of execute_script to run some JS is a terrible idea since it completely bypasses the concept of testing what a user can do and can basically make your test worthless.
The root cause of the issue here is the JS behavior attached to the input not being able to handle the key events fast enough. The proper fix would be to fix the JS, however if that's not possible there's a few things you can try
First you can try changing the clear method being used by set
element.set('506307', clear: :backspace)
or
element.set('506307', clear: :none)
If that doesn't change anything then try clicking on the input, followed by a short sleep before setting the content
element.click
sleep 0.25
element.set('506307')
If none of those work around the issue we need to know exactly what JS behavior you have attached to the input and/or what events that JS behavior is listening to.
I am banging my head looking at the code for ... quite some time.
I have a lightning event, created from ics (including an alarm).
I want to delete the alarm after something has occurred. I found calItemBase has mAlarms. But how to delete a single alarm? (there should be only one). What is the proper value of mAlarms if there is no alarm?
What to do with mAlarmLastAck and other properties?
My workaround is to recreate from ical without the alarm, but then the user looses categories and other things he set for the event in the UI.
Many thanks,
Klaus
A summary of the methods intended to be public for an item can be seen here: http://mxr.mozilla.org/comm-central/source/calendar/base/public/calIItemBase.idl
Specifically, there is a deleteAlarm method. Example:
var alarms = item.getAlarms({});
item.deleteAlarm(alarms[0]);
If you are sure you want to delete all alarms, you can also use the clearAlarms method.
item.clearAlarms();
I am using paper_trail for audit trail. Along with create, update and delete events I want to track few custom events like view(record), sent(email) etc. How can we introduce such custom events while auditing a model?
I have found a tweak to add custom events in paper_trail managed Versions:
Version.create(item_type: "Campaign", item_id: campaign.id, event: "Sent")
Maybe this is not right solution, but it helped me to achieve the goal. I would like to explore paper_trail more to find a better solution.
Following the paper trail flow, and having paper trail hooked to your touch events:
record.paper_trail_event = 'notified'
record.touch
If you don't want to have that hook in place you can:
record.versions.create!(event: 'notified')
The main problem with the second approach is that it won't apply any of the PaperTrail scoped params, nor any other dynamic field you may have defined for that model PaperTrail config.
You will need to set those manually. For the request.whodunnit it would be like:
record.versions.create!(event: 'notified', whodunnit: current_user.id)
See simple hit counter for page views in rails as an answer to the first part of your question. As for tracking sent mails, you may want to use Observer pattern.
In any case all these events are outside of paper_trail domain. While paper_trail simply creates versions of your model during data changing, what you need is to observe custom event and write to DB all necessary information about that event.
Hey, i've been looking around for a ajax dropdown sorter for my Views in Drupal.
Unfortunatly, i haven't found alot of usefull information about this subject.
Can anyone tell me if theres a solution already available or can help me started on a custom module by telling me which hooks i should use?
I had a similar issue. Unfortunately I wasn't able to sort the data from the database which is by far the best way. I was however able to take the data and sort it with PHP using a preprocessor function. Depending on the name of your view, setup a function similar to the following:
function templatename_preprocess_name_of__view(&$vars)
{
//Super sweet sorting code goes here
}
The name of your view needs to follow the name of the template file that it is driven by, if there isn't on you should create one. Make sure to change dashes to underscores in your function name. Hope this is helpful. If you find a way to do it from the DB I'm all ears because that would be super awesome.