Angularjs refresh ng:view - refresh

While using Angularjs v0.9 and php to implement my membership system
In this following function, I will call an api to edit the data of the member, on success, the php function will return
{"success":"true"}
and the controller will return to a page that can view the member of the data.
if(response.success==="true") {
window.location="#/register_members";
$('.alert-error').hide();
$('.alert-success').html("Member is updated.");
$('.alert-success').fadeIn();
}
However, at #/register_members, the data still remains as the unchanged data. Is there anyway I can refresh the page partially in angularjs? I am using ng:view and $route.
I have tried using
window.location.reload(true);
but the success message will not be rendered as the whole page is renewed.
Does anyone have any idea?

Found an interesting answer here to refresh a div in the page using Jquery
my page is "#/register_members"
the div i want to update is "#registerlist" which is inside a div called "#browse-box".
so now my controller will be
window.location="#/register_members";
$("#browse-box").load("/#/register_members #registerlist")
$('.alert-error').hide();
$('.alert-success').html("Member is updated.");
$('.alert-success').fadeIn();
works like a charm. :)

Related

How to know if current page comes from Forward or from Back, Ionic2

I am currently working on an Ionic2 project. On one page (e.g. PageB) I am showing a Loader (inside ionViewWillEnter() event) till Ajax request success, after that loader.dismiss() called. It is working perfectly. After ajax request User click on something to goto next page(e.g : PageC). But when user comes back from PageC to PageB, loader is again visible.
I want to know if there is any function, so that On PageB load I can know if the page is transitioned from PageC(from history), and prevent loader loading.
Smaple code for PageB is
ionViewWillEnter()() {
this.presentLoading();
}
presentLoading() {
this.loader = this._loadingCtrl.create({
content: "Please wait..."
});
this.loader.present();
}
Instead of putting the ajax request in ionviewWillEnter you could set the same call and present loading call inside either ngOnInit or ionViewDidLoad.
ngOnInit(){
this.presentLoading();
}
These lifecycle hooks are called only once during initial page load.If it makes sense to put the ajax call in this hook, it will provide the same effect and loader will not be shown when user returns from PageC to PageB.

How to render a Django template with a transient variable?

I have an application that enforces a strict page sequence. If the user clicks the Back button, the application detects an out-of-order page access and sends the user back to the start.
I'd like to make this a bit more friendly, by redirecting the user back to the correct page and displaying a pop-up javascript alert box telling them not to use the Back button.
I'm already using a function that does a lot of validity checking which returns None if the request is okay, or an HttpResponseRedirect to another page (generally the error page or login page) if the request is invalid. All of my views have this code at the top:
response = validate(request)
if response:
return response
So, since I have this validate() function already, it seems like a good place to add this extra code for detecting out-of-order access.
However, since the out-of-order detection flag has to survive across a redirect, I can't just set a view variable; I have to set the flag in the session data. But of course I don't want the flag to be set in the session data permanently; I want to remove the flag from the session data after processing the template.
I could add code like this to all of my render calls:
back_button = request.session.get('back_button', False)
response = render(request, 'foo.html', { 'back_button': back_button } )
if back_button:
del request.session['back_button']
return response
But this seems a bit messy. Is there some way to automatically remove the session key after processing the template? Perhaps a piece of middleware?
I'm using function-based views, not class-based, btw.
The session object uses the dictionary interface, so you can use pop instead of get to retrieve and delete the key at the same time:
back_button = request.session.pop('back_button', False)

Handlebars.SafeString() issue in Meteor?

I have did a sample example of dynamic loading templates using the Handlebars.SafeString(). Everything works fine expect Refresh the browser URL. When ever refresh the browser url i get an error i.e "Uncaught TypeError: Property 'undefined' of object # is not a function".And this error get only this line i.e return new Handlebars.SafeString(Template[Session.get('currentTemplate')]({dataKey: 'somevalue'}));. With out this line Works fine everything even Refresh also.I am using this Handlebars.SafeString() is to load templates dynamically. I didn't have any idea about this So please help me how to?.
And What is the use of dataKey in above Handlebars.SafeString()?
It looks like the Session dict is not populated when the call is made, and therefore Session.get('currentTemplate') is undefined. A simple safeguard should fix the problem, assuming you're in a reactive context:
if(! Session.get('currentTemplate')) return '';
return new Handlebars.SafeString(Template[Session.get('currentTemplate')]({dataKey: 'somevalue'}));

Cannot get onSession Start to fire in Mura

I have a script :
<cfscript>
gf = createObject('component','com.general');
gf.checkIpBlocked();
</cfscript>
that I want to fire onSessionStart.
I added an onSessionStart to /siteID/includes/themes/myTheme/eventHandler.cfc. But the session start NEVER fires. I know there is something managing sessions because of I open the admin, login then close the browser, re-open it I am forced to login again.
If I set a session variable close the browser and and the session.testVar never goes away and seems to hold the initial value for a very long time.
I am not trying to manage mura users or anything I am just trying to set a session variable the first time in a "session". In a typical application.cfc this is easy.
Any insight is appreciated.
Unfortunately, that's a bug. However, one thing to keep in mind is that onSiteSessionStart is unreliable since it only fires when a siteID is defined within the request. For example, if you were to go to the admin and be asked to login your session will have started and there would have been no siteID.
For now I would try using onSiteRequestStart to param the variable instead.
function onSiteRequestStart($){
param name="session.ipChecked" default=false;
if(!session.ipChecked){
var gf = createObject('component','com.general');
gf.checkIpBlocked();
session.ipChecked=true;
}
}
In regard to our documentation we have three Mura 6 books available both printed and digital downloads from Lulu
And are also working to create a systematic way to post the contents of those books on our support site which we are hoping to complete by MuraCon on 9/30. So that the all of our documentation will stay update and in sync.
The Mura docs state that the application events are actually onGlobalSessionStart and/or onSiteSessionStart.
Application Events
onApplicationLoad onSiteSessionStart
onGlobalSessionStart onSiteSessionEnd
onSiteMissingTemplate onSiteError
onGlobalError onBeforeAutoUpdate
onAfterAutoUpdate onGlobalThreatDetect
Note that Events that begin with onGlobal are deļ¬ned on a per-Mura
instance basis.
Mura docs.

How can I force ember-data to refresh an object after committing it?

I'm submitting an object to our API via a POST and then transitioning to a route that displays that object. The API modifies one or more fields in the object in the POST and returns the updated info in the request response.
The data displayed is the original data from before the POST to our API. I can see from the console that ember-data is receiving back the updated information from our API. How can I force ember to "refresh" the object so that it displays the correct info?
Matt. Yehuda Katz posted a reply to a user which provides this functionality:
https://stackoverflow.com/a/14183507/506230
Basically you create a record, apply it, save it, then reload it.
saveMessage: function(text){
var acct = Social.Account.find(this.get("id")),
msg = Social.store.createRecord(
Social.Message,
{
text: text,
account: acct,
created: new Date()
}
);
acct.get("messages").addObject(msg);
Social.store.commit();
var timeoutID = window.setTimeout(function(){
__msg.reload();__
console.log('reloading');
}, 250);
}
It turns out ember was actually behaving properly and no additional work was necessary. The problem is that I was setting a variable on the controller with the same name as a computed property on my model. The value of the variable on the controller was being displayed rather than the computed property. Changing the name of the controller variable resolved the issue without any additional code.