Reload existing angularJS page with stateParams intact - javascript

I have a function that shows or hides a button in relation to a value pulled from an API
I load a record with a parameter of 'id' ($stateParams.id)
If this value is 1 a button appears that fires a function that sets it to 0
If this value is 0 a button appears that fires a function that sets it to 1
These functions work fine however after the functions fire I want to reload the existing page but have the button change dynamically. If I leave the page and come back, or set state.go to any other page the button is changing no problem
I am using the following to try and reload the page after the function fires but nothing happens.. not even an error
$state.go($state.current, {id : $stateParams.id}, {reload: true});

Well... that was easier than expected. Just used
$state.reload()

Related

Stop Safari extension from caching messages

I'm having problems with creating a safari extension that has been causing me headaches.
The problem is this: I have created an extension that gets images from a web page using an injected script. I have a function in the popover that displays the web images and allows the user to click and send the selected image to a backend. This all goes through the global page which handles signals and messages. The scenario is this:
When the popover opens, it sends a signal to the global page to initiate the response (image URLs) from the injected script.
When the global page gets the message from the injected script, it calls the function in the popover passing in the data from the injected script as an argument.
The popover shows all images returned from the global page via the injected script.
The problem is that every time I open the popover, it appends the images from the last call instead of giving a fresh list of images. For instance, on first popover open, I get one image (assuming the page has only one image). If I close the popover and open it again, I get two of the same image. If I close and open the popover a third time, it appends the first image with the one from the second time and gives me 3 of the same image. On the fourth open of the popover I get 1 + 1 + 1 + 1, so 4 images. So it seems to be appending the messages and not giving me a fresh message every time.
My question is: how can I destroy the messages that are being cached after each popover closes? I hope I am being clear. Perhaps something else is happening with my code that I am not aware of. Please help if you can. Here is my code from the global HTML:
function popoverHandler(event) {
//check for popover opening
if (event.target.identifier === "MyPopUp") {
//send message to injected script to send page info
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("getContent", '', false);
//this works fine, I get this message every time popover opens
console.log('getContent message sent');
//listen for message containing page info from injected script
safari.application.addEventListener('message', function (messageEvent) {
//only get message from current tab
if (messageEvent.name === "pageInfo" && messageEvent.message.url === safari.application.activeBrowserWindow.activeTab.url) {
pageInfo = messageEvent.message;
//the problem seems to be in here. Every time I open the popover, //I get the current page info plus all the page info messages from //the previous time I open the pover, all duplicates of the previous //messges
console.log(pageInfo);
// call a function in the popover, passing the pageInfo data //received from the injected script
safari.extension.popovers[0].contentWindow.onPageDetailsReceived(pageInfo);
}
});
}
}
Ok, so I was able to solve the problem. First of all, I separated the popoverHandler from the eventListener. For some reason, it was firing the function too many times and returning several lists of the same images. The major issue, however, was that in the popover.js, I was storing the list of images as a var. When I removed the var, the data stopped persisting and I was getting a fresh list every time.

Action method not getting called when I refresh page (MVC/Javascript)

I have a pop up window which uses the following code to call an action method when a checkbox is checked:
window.location.href('#Url.Action("process", "wip")');
This works fine, but I also need the window to refresh itself when the checkbox is checked. So I added the following under the previous line:
window.location.reload(true);
But somehow this causes the first line to not call the action method at all. Are the two "window.location" lines tripping over each other or something?

Automatically Refresh a IRR based on a Checkbox in Oracle APEX

I am using Oracle APEX 4.2.
Now, I have an Oracle APEX page that has an Interactive Report Region (IRR) and what I am attempting to do, is to add a automatic report refresh mechanism with a checkbox that will be used to activate/de-activate the report refresh.
Basically, when the page initially loads, I would like to default the checkbox to being checked (i.e. 'Y') which would initiate say an automatic 10 second refresh of the IRR, at the same time, maintaining the checkbox value of "checked" - perhaps this will need to be in a different region, so when the automatic refresh occurs, the checkbox continues to maintain state of "checked" and only the IRR refreshes, with any new rows/values that may have been added/changed.
At the same time, I would also like to de-activate the automatic 10 second IRR refresh by unchecking the checkbox, which would no longer perform a report refresh.
Hi Please copy below code and paste accorfingly.
Page attributes, Javascript, Function and Global Variable Declaration
var gtReloadPage;
"autorefresh" dynamic action
2 true actions:
Execute PLSQL code
null;
Page Items to Submit : P1_CHECK_BOX
Fire on page load: CHECKED
Execute javascript code
alert('ok - setting timeout');
gtReloadPage = setTimeout("location.reload(true);",8000);
Fire on page load: CHECKED
2 false actions:
Execute PLSQL code
null;
Page Items to Submit : P1_CHECK_BOX
Fire on page load: UNCHECKED
Execute javascript code
clearTimeout(gtReloadPage);
alert("Timeout has been removed!");
Fire on page load: UNCHECKED
I found this thread in the Oracle APEX forums that I must have missed relating to my post:
https://community.oracle.com/thread/2461953

how to stop reloading parent window while child window gets open

I have a form submit, where it get the values from the form and goes
to next page... here I have a hyperlink to open a child window, while
I click, it opens the child window and simultaneously it reloads the
parent window. I have a action configured to the parent window which
has a Database insert statement too.
The problem is that while I click the link it call my action
again(because of page reload), in this action I wrote if condition to
check null/empty string from the previous page form submit. since this
is the second time the action loads it looks of the fields(but
actually those fields are in my previous page form). so it take null
while checking my if condition.
Another problem is that when I solve the above problem here comes the
SQL insert statement, which is about to execute 2nd time. I dont want
this to happen or I dont want my action to execute while I open the
popup window and I want to populate the selected value from the popup
to the parent window.
code used for opening the popup
function select_reactant()
{
window.open ("SeriesTab.action?component=reactant",
"mywindow","scrollbars=1,resizable=1,width=1000,height=1000");
};
This is the place where I open the popup and want to populate the value selected from the popup to the textfiled here
<tr>
<td>reactant</td>
<td><s:textfield name="reactant" id="reactantId" readonly="true" theme="simple"/></td>
</tr>
jquery to get back the value form popup to parent window
$(window.opener.document).find('#reactantId').val(rxn);
the code inside action below is what the action that I mention at the beginning
if(Rxn!=null||!Rxn.equals("")) //Rxn is the field variable for previous page
{
//my insert statement
}
while I run I get nullpointer error since the value for Rxn is reset to null by the page reload due to popup opening done by
window.open
You can do something like this
HTML
reactant
jQuery
$(function(){
$("#anchSelectReactant").click(function(){
select_reactant();
return false;
});
});

jQuery Mobile showPageLoadingMsg()/hidePageLoadingMsg() methods not working on initial page loadn

I am writing a webapp using jQuery Mobile that calls a function to load records into localStorage and create a listview from a remote JSON file when the page is initially created (using the live.pagecreate() event for the page). At the beginning of this function is the jQuery Mobile method $.mobile.showPageLoadingMsg() and $.mobile.hidePageLoadingMsg() is at the end of the function.
On the initial pagecreate, the loading message does not appear (on iPhone 4 with iOS 4.3 Safari, Chrome 13 and Firefox 5). However, I also have a refresh button on the page; this button clears the associated records in localStorage then calls the same function used to initially populate the listview. However, when calling the same function from the refresh button the showPageLoadingMsg() and hidePageLoadingMsg() both work correctly and the Loading screen appears and disappears as it should. Am I missing something here?
ETA Here is the gist of the code (not in front of the actual code right now, if you need more I will put it in tonight). I also should mention that I've tried to put showPageLoadingMsg in (document).ready and have tried to bind it to mobileinit and neither have worked:
function loadListView(){
$.mobile.showPageLoadingMsg();
//ajax call to pull JSON
//$.each loop to load localStorage and listview
$.listview.refresh('list');
$.mobile.hidePageLoadingMsg();
}
$(#listpage).live('pagecreate', function(event){
loadListView(); // showPageLoadingMsg() and hidePageLoadingMsg do not work when the function is called here
});
function clearList(){
//for loop that clears each item in localStorage that matches the key prefix set in loadListView
}
//runs when refresh button is clicked
$('listrefresh').live('click',function(){
clearList();
loadListView(); //showPageLoadingMsg() and hidePageLoadingMsg() work when the function is called here
});
For these handlers to be invoked during the initial page
load, you must bind them before jQuery Mobile executes. This can be
done in the mobileinit handler, as described on the global config
page.
Docs:
http://jquerymobile.com/demos/1.0b2/#/demos/1.0b2/docs/api/events.html
Triggered on the page being initialized, after initialization occurs.
We recommend binding to this event instead of DOM ready() because this
will work regardless of whether the page is loaded directly or if the
content is pulled into another page as part of the Ajax navigation
system.
Example:
http://jsfiddle.net/phillpafford/mKn8Y/8/
In the example none of the live events fire on initial page load, you have to configure this type of action in the mobileinit:
http://jquerymobile.com/demos/1.0b2/#/demos/1.0b2/docs/api/globalconfig.html

Categories

Resources