I have a Market stored in a user session in Rails, set via session[:current_market] in my application_controller.rb.
I have my front-end interface served with Backbone.js, and I have a little market selector widget that calls
BackboneApp.data.currentMarket = market.toJSON()
Backbone.history.navigate market.homeUrl(), trigger: true
... when a user selects a market. This works except that if a user hard-navigates to another page, the market reverts to whatever it was set on the initial page load (whatever was originally loaded in session[:current_market] in Rails.
How can I update the user's market in session when a Backbone.js navigation event occurs?
I tried manually doing this by triggering a silent GET:
$.get '/api/v1/reset_current_market', { market_id: market.toJSON().id }
... but that doesn't seem to work.
I assume that when the user switches market then some ajax request will be fired to hit your rails api and fetch the data for that market. What you could do is make the controller action for that route update the current users session to whatever market got requested.
how about wrap this market info to new Model and handling change with that? This is just a pseudo code examlpe.
var marketModel = Backbone.Model.extend({
urlRoot:"/you/url/market",
defaults:{
marker: ""
},
initialize:function () {
}
});
BackboneApp.data.currentMarket = new marketModel(market.toJSON())
Set selected market to this new model, and call save().
At rails change session info at your /your/url/marget POST method. If this object have id property then impelent also PUT method.
Related
I am getting the actions for a Board using the Trello API. In the results, I get "updateCheckItemStateOnCard" when a checkItem is checked, but I do not get something like "checkItemAdded" when a checkItem is added to a checklist.
var parameters = {
fields: 'all',
since: self.lastUpdate
};
var path = '/boards/' + board.id + '/actions/';
Trello.get(path, parameters, getActions);
Is this a problem with the Trello API?
How can I get the actions when a checkItem is added to a checklist.
Note: I don't want to have to send this request to each card on the board. I asume that if I get "updateCheckItemStateOnCard" when a checkItem is checked, when requesting actions for a board, I should also get the action when a checkItem is added to a checklist.
I had this problem when using Zapier and their tech support told me, that there does not seem to be an action addChecklistItemToCard.
Module send only Ajax process to module controller every 5 seconds. After few minutes prestashop automatically logged out employee. How I can keep stay loggin?
In your ajaxProcess function, do this:
$cookie = Context::getContext()->cookie;
$cookie->write();
This will refresh the duration of your admin cookie when your ajaxProcess returns, that is when the headers are sent which is how cookies get set.
Optionally you can include this code above the write() call so that the last activity time is also recorded
if (!Tools::getValue('stay_logged_in')) {
$cookie->last_activity = time();
}
You can see this code in action in /controllers/admin/AdminLoginController.php
We are developing using VS2010 and MVC4, deploying our web app on an IIS 7.5 on Windows7.
Our project has a long running process for which we want to display status and progress.
In order to accomplish this we have a small serializable class with properties that describe the current status. The long operation pseudo code goes like this:
int curentPercentComplete = 0;
EngineStatus status = new EngineStatus();
while (!done) {
status.PercentComplete = curentPercentComplete;
Session['status'] = status;
// do lengthy operation
curentPercentComplete = compute();
done = isJobFinished();
}
We also have an other controller action that tries to retrieve the current status from the session
which then encodes to json and returns it to the browser via an Ajax request.
Our problem is that we always seem to get the last saved data from the previous request, in other words the session object does not seem to update the Session['status'] field during the execution of the while block.
We have tried the session state mode both InProc and StateServer with exactly the same behavior.
Thanks in advance.
It turns out that the MVC framework performs a single update of the session data at the end of the request which means that only the last value is saved.
Since the "lengthy" operation is performed in a single request-response cycle, the idea of storing intermediate status information in the session is plain wrong.
I added a route in my docpad.coffee file to handle form submissions, that I validate using the express-validator middleware. Now depending on the validation, I want to redirect the users to the same contact page but displaying either a success message when validation is successful (here I'll send an email), or display the error messages.
I didn't manage to pass the validation message to the template to display it. I tried almost all combinations of dynamic: true/false, res.locals = validationMessages, res.sessions = validationMessages, res.templateData = validationMessages with no success.
Furthermore, adding dynamic: true made the changes to the content not appear at all, whatever refresh strategy I use (private mode, cleaning cache, relaunching Docpad, refreshing without cache, etc.). I should probable file a bug about it.
How to ?
I'm using Docpad 6.53.0 (latest to date), node 0.10.15, on OS X 10.8.4
I cheated on this one a bit by appending a hash to the redirect url (eg: "www.mywebsite.com/#messagesent"). I then use client side javascript to read the hash and then show the appropriate message. Something like this:
if (location.hash == "#messagesent") {
$('#message-sent').show();
setTimeout(function () {
$('#message-sent').fadeOut(1000);
}, 1000);
}
Not quite what you were asking though :)
I have a Grid, a Store and Model for its data and AJAX proxy for the Store that is pointing to my self-written PHP back-end. The PHP backend writes to log each time it is called.
The system works OK for Read, Update and Delete calls. However now I need to add new field to Store, which I do in such a way:
(here, some new data were generated...)
var newEntry=Ext.ModelManager.create({
id:id,
title: title,
url: '/php/'+fname,
minithumb: '/php/'+small,
thumb:'/php/'+thumb
}, 'MyApp.model.fileListModel');
var store=Ext.getCmp('currGallery').getStore();
store.add(newEntry);
store.sync();
I have the new line appearing in the Grid.
But with or withour sync() call, I have no calls going to my PHP back end. It however reads one more time. Store has parameter autoSync :true and does great updating data automatically when I edit existing line in the Grid.
What am I missing?
Try not to set id when creating new record.
In fact I was missing a
newEntry.phantom = true;
flag. After I set it before adding to store, Store and its Proxy started to send data to server.
Maybe ID solution also works, dunno.