Yii widget: where to place an action? I need to access server from js - yii

I am going to write a widget such as user could select country and city.
The widget will use geo db from vk.com, but I want to request vk.com from the server-side, internally. Currently I am doing so by actionSuggestCities().
browser <-- widget: js routine <-- site: actionSuggestCities() <-- vk.com: api
How could I make a well-formed widget, such that someone could install it and do not add actionAutocomplete() in his controllers?

I think the best is to provide a an action with the widget as an extension, to be reused in every controller using the extension, an action class extends CAction can be configured can has it's own behavior etc, read the wiki and the api

Related

How to add additional query parameters in cms page content api call

we want to append the cms page content api used out of box by spartacus for cart page
current: cms/pages?pageType=ContentPage&pageLabelOrId=/cart
required to add some additional query parameter
required: cms/pages?pageType=ContentPage&pageLabelOrId=/cart&staticstorecode=42
what code changes are required to achieve the above scenario?
The page request is made in the load method of the OccCmsPageAdapter. You would need to override this method to add your additional params. You could extend this class and create your own CustomOccCmsPageAdapter and subsequent classes like CustomPage model etc.

WKWebView - replace web action

Inside my app, I'm using the WKWebView to display a website. My goal is, when user is pressing a button on this website, I want to stop an action linked to this event and replace it with my own, natively made (custom action outside the WKWebView). I've been trying to search for any solution to fetch mentioned event but unsuccessful. What more came to my mind, if there is a way to fetch a JavaScript in WKWebView, I have a possibility to add some JS script code to this site (not to delete the action I want to block). Thank you for any help.
First, do you have a permission to mess with this web site's behaviour? I assume you do, otherwise it is likely illegal.
Second, try using Safari Web Inspector with a device/simulator, and use the DOM tree and console tools to find out what is the HTML/javascript that is involved with this action on this site.
If you can't find what happens in HTML/JS yourself, feel free to post a new separate question on SO with your target URL, some HTML/JS code, and which link/action you want to replace. Tag the question with "javascript" and ask if it is possible to write some javascript to replace that particular action to some custom JS code.
Usually there are 2 types of actions: either it is something that provokes AJAX calls to a server API triggered by an event handler, or it is a plain HTML link that results in a web navigation. For both cases it is possible to write a JS script that overrides the action.
Finally, use WKUserScript to inject javascript into the page, and override the action. Use window.webkit.messageHandlers to send an event from your custom action to the app side. Use WKScriptMessageHandler to process the event in the Objective-C or Swift code.
See an example here: http://nshipster.com/wkwebkit/

How to do a listener on every page load

I'm trying to limit the session access to a Struts application so the users will only be able to use 1 tab at the time. To do this, I have to create an ID everytime a new page is loaded and assign that ID to the user's session. By doing so, if the user uses a page with a different ID than the one registered in his session, the action will be rejected.
How can I do a listener on every page load? Which interface should I use?
Or do you have any other idea of how I could manage multiple tabs?
I'm Using Struts 1 and Java 4.
You could use Spring MVC Interceptors and override the preHandle method.
Returning false inside should cancel your request for not allowed additional tabs.
You can use an interceptor to do this. You will need to define it on your interceptor stack in your struts.xml and code the interceptor to check the JEE role information provided by your web application server. The interceptor can be coded to give a redirect result on the other tab if there was recently an action called however you will probably need to coordinate it via JS generated ids and AJAX.
https://struts.apache.org/docs/interceptors.html

Jive 7: How to change profile data / action?

I am writing a plugin for Jive (SBS) 7 and want to add more data to the template for the user profile Overview page (i.e. /people/admin ). In Jive 6 I did overwrite the profile path in struts and added my own ViewProfile action. But this action seems to be called no more.
I also cannot even figure out where the templates I changed get their data from (soy/people/profile/{userProfile, header, head}.soy) or what action is responsible for.
So how can I add another property to the soy file that gets a custom property for the targetUser? (custom property = property saved in the database table jiveuserprop)
You need to create a plugin and then use the option. Then, you simply use jquery to add the extra stuff.
you can create an action that takes in information using getters or post and throw it into the user's extended properties. You can create another action that'll retrieve that info in json.
then, simply use jquery's getJson to grab the info and use selectors to show the data in the user profile.
Don't forget to use the $j(document).ready(function(){ // your code here }); to show the info
simple example:
<scipt>
$j(document).ready(function(){
$j("div#j-profile-header-details").append("<p>hello World</p>");
});
</script>
will append "hello world" under the user's email address / job title.
hope this helps. feel free to ask more questions if it doesn't make sense. here's a good link on writing the javascript part of the plugin: http://docs.jivesoftware.com/jive/7.0/community_admin/index.jsp?topic=/com.jivesoftware.help.sbs.online/developer/PluginXMLReference.html
I got an answer in the Jive Developer community:
profile is an action in Struts2. /people/username is a URL Mapper permutation
https://community.jivesoftware.com/thread/263660

Best way to create user notifications on webpage in ASP.NET MVC 4 Razor

tl:dr -> User notification system on website. Can you avoid the need to call a javascript script to render notifications after ajax loads? (a base view that calls it would work, but there are no base views afaik)
I am looking for a way to add a User Notification System to my website. Such system would be responsible for displaying messages like 'Import success', 'Import failed', 'Session timed out' etc.
I know similar questions have been answered before, but here's my question:
How should I do it to get as close as possible to having the notifications display themselves as soon as possible after being put to TempData? Having them rendered on _layout page would work, but only for requests that ask for whole page. What about loading only parts of website through ajax -> can I avoid having to write JS script in ajax callbacks or partial views?
I am looking for something to prevent writing multiple calls to same function.
Toastr is your notification Friend. Demo Page
you can install it from Nuget Install-Package toastr
See my SO question - for reference