Joomla: make a component act like a content plugin - joomla

I've created an admin component and now need to insert text on each page of the installing client. So I thought of using the function onContentPrepare but it's a method of a JPlugin class (a content plugin class to be exact).
Is there a way to invoke the component from the view in the same way like a plugin?

Short answer: No, you have to write a plugin. But that's not a big thing.
Long answer: On each request, exactly one component is called. Plugins are triggered at certain events within the control flow. The onContentPrepare event is triggered by the components (not from the Joomla! framework), so some components might not support it. Nevertheless, you can get access to the content of any component through plugins anyway - just use the onAfterRender event of the system plugins.

Related

Oxid eShop event handlers

I am trying to create some tracking events on OXID eShop Framework on a custom module but I can't find any event handlers or something to put the code on some custom pages, without editing the core files. What I want is to make some custom API calls if I am on product page, category page, basket, etc.
Is there any way I can handle this in a custom module?
OXID has no such events or hooks you might know from magento or shopware. You have two options:
1) For running server side php code you need to extend OXID's functions, e.g. render() function for the pages you want to track.
For the product page it would be "details" -> applications/controllers/details.php
category page is "alist.php" and basket is basket.php
2) Make client side api calls with simple JS. You could appent all your js code to a tempalte block (e.g. in header oder footer) and create some if-else logic for different controller classes.
Like here: https://github.com/OXID-eSales/oxideshop_ce/blob/b-5.3-ce/source/application/views/azure/tpl/layout/base.tpl#L32
You could also have a look at any tracking module for google analytics or piwik, they are pretty similar to what you want to do.
I can give you more examples if you want.

How do you know when Durandal has finished swapping views?

I need to perform an action after switching to a view.
The first time you switch to a view 'activate' and then 'compositionComplete' is called.
After that only 'activate' is called.
It would appear that 'activate' is called before the view has finished being displayed and this is causing issues with a JavaScript control I'm using (Bing Maps V7).
I've been using Hooking Lifecycle Callbacks as a reference but there doesn't appear to be a suitable callback to hook in to.
Is there another event or approach I can use to tell when the DOM has finished changing to the view?
It sounds as though your module is a singleton instead of an instance. Is that true? If you create an instance-based module, the module will be created anew each time it's activated. That will cause the compositionComplete to re-execute.
The activate handler is good for preparing data that will ultimately be displayed in the view. compositionComplete is best for handling matters that depend on a fully-constructed DOM.
We use Bing Maps AJAX v7 as well, and I've always placed it in an instance-based module.
To create an instance-based module, if you're not familiar, make sure your viewmodel returns a constructor function instead of an object literal.
Have you tried placing the Bing initialization in attached? Or creating a custom binding for it? Any third party libraries i use will always be initialized in attached, and if its something i want to use more than once, ill either create a custom binding for it or create a widget.

How to make parent component to listen, events fired by child components using eventbus in gwt

I have a custom panel with a couple of components, eg. a button and a text box.
Once the button is clicked I would like custom panel that is also the parent panel receives the event and decides what to do, like call setText on the textbox.
Is it possible to achieve this using an eventbus ?
This means that the child components need not handle their event and then relay it.
I don't know the exact classes and how they work together. But sure you could use the GWT EventBus to achieve this. Fire an event in your button class and handle this event in your custom panel. You can google or find related answers here on stackoverflow.
I think this answer will help you: How to use the GWT EventBus
It's pretty simple to fire events and handle this events in other classes in your application.

Alternatives to Struts2-jquery plugin for uploading files in Struts2 using Ajax

I want to upload a file using the < s:file > tag, but Struts2 doesn't support Ajax for this functionality, as far as I know. I tried to do it using the Struts2 jquery plugin but it overwrites some jquery functions that i need an can't change right now (like .dialog()).
Is there an alternative way to do it?
There are many jquery based plugins for this purpose.
I am using this library. Its the most simple and elegant plugin, minimal requirements and lots of options.
Here are some other plugins which I considered(my preference was a plugin which doesnt use flash)
This one shows thumbnail before uploading and also overall progress
This one shows remaining time, uploading speed and remaining size
This is how I do it (I'm not using JQuery):
I hide an iframe inside my page. I give it an id (iframe for example) and a name (the same than the id).
I set the attribute "target" on my form to the id of the hidden iframe (then, the response from the server is loaded inside the iframe.
I register an event handler on the iframe to react on the onload event. The handler analyse the response from the server. Alternatively, I sometime just return javascript code from the server in a <script> tag. This code performs action on the client upon success or failure of the intended action.
If you like the idea, you may want to read this article or this one:

Can I trigger a webcontrol panel's OnInit event without a page?

I am working with someone else's code. The code was originally designed so that data would dynamically create controls (and sub-controls of those controls...) on the OnInit event on numerous web control panels. And then later validation methods would check those dynamically created controls for valid data. This continues to work just fine for my web site. However, I need to be able to validate that data without my website (as in this will just be server side). The simpilist solution appeared to be to just have the panels initialize and then run the validation methods. That'd be great...if I could figure out how to initialize those panels server side without a web page.
Can this be done? Is there any way to get a panel to initialize without having a page to display that panel?
That way lies madness - you could use reflection to call the control's InitRecursive method, but it needs a Page (among other things) to run correctly.
You should extract the validation code into a new class that you can call from your server code an change your WebControl to use that class as well.
Try RenderControl.

Resources