My application has a function to save a document, which opens a save dialog to let the user choose where to save the document.
Since that function handles not only state but also a part of the UI/UX through the use of a dialog, is it considered a bad practice to move that piece of code in a saveDocument Vuex action, so that it would be reusable from multiple places in my code?
I don't think it's a bad pratice. Actions can receive parameters and they usually do.
Anyway, you can store the variable which says where to save the document in your state (setting a default value if you want) and change the value (with an action and a mutation) in your UI/UX component. Then in your action, you can get this information from the state via getter.
I hope this helps!
Related
I have a form with a dropdown list of country options like so:
When the user selects an option, the form will load some data from an API so the user can make changes. However, some parts of the form have some deeply nested components where the user can edit additional data on a separate page. The problem is that when the user changes navigation and then clicks the back button on the browser, the drop down list is 'reset' and he has to select again the country that he was editing.
Can someone suggest a way to handle this issue so that if user clicks the back button on his browser (or the page has a "back to results link"), he will go back to the form and it will already be pre-selected with his option?
Should I be handling this via $route.query, localstorage, vuex? I would prefer not to use Vuex but I guess I can if needed.
Is $router query all i need here? I can capture the country's id and run the API call again on navigation back to the drop down selection page?
Example data from API:
{
id: 1,
name: 'Afghanistan'
}
When user selects a country from menu, I run an API get request like so:
async setSelectedCountryObj(value) {
if (value) {
const response = await APIService.tempISOCountryById(value.code)
....snip...
it's possible to handle with router, but that not a good way, you should go with vuex, that best way, just create store, and dispatch after select value, and always get value when come on that component, that essay not that much difficult, let me know if you need but i know you can.
I'm new to Nuxt, but I have a bootstrap header with the standard v-if="authenticated" kinda state for login\logout buttons.
The auth provider is firebase which has a onAuthStateChanged method that I use to set (or reset) the user property in the state store.
So page loads, I see the login button, onAuthStateChanged runs, sets the user, then login disappears and logout button shows up (can see the Vuex events from base->set as well).
Question is, what am I doing fundamentally wrong such that I'm getting this flashing state. Is the only way to handle this to work with localStorage? ...should I NOT be storing the user in the state.store?
You need to save it in the store. But make no mistake because when reloading you have to set the token value using localstorage.
These are very good explanations
I want to modify workflow sales.order using Workflow editor.
I created activities and transitions between them.
After click on button user must transmit to another activity(workflow state) but nothing change.
Next activity in action block has such python action:
write('state': 'maket_completed')
I tried to use server action with set same state sales.order
sales.order state field not changed.
I read for it docs and "Working with Odoo" and can not undestend where is my mistake.
Can you help me?
Re-create document and all works fine.
I am using stateSaveCallback to save a Datatables state into the database. It submits the current state via AJAX to a script so I can save the JSON.
I can attach the save function to a button click like so:
$( ".save_state" ).click(function(e) {
e.preventDefault();
table.state.save();
});
But I cannot find any documentation on how to restore or load that script using a click. The closest reference I can find is on this page
https://datatables.net/reference/api/state.loaded() which references restoring the saved state.
I am using stateLoadCallback but I think this just does it on load. I would like to do it via a click, so users can save their state in the database and click restore to load it back later (we will offer multiple state saves, like a Saved Search, so they click to restore a saved search).
Thanks
After inspecting the source code, it looks like state loading is performed only once during initialization. Therefore your best bet is to use destroy option as destroy: true and re-initialize your data table on click.
I assume you have defined a callback using stateLoadCallback option that query the server upon re-initialization.
We have a Facebook app here which has three boxes with three buttons. Each button, when clicked, should change state once an event (successfully) happens. The buttons are almost all working (a few minor bugs) but they have been done a rather long-winded and inefficient way.
My question is, what is the most efficient way to link events (i.e. page 'liked', personal information submitted, page 'shared') with the state of the buttons?
You can use jQuery and the .trigger() function to fire off events. Then you can use .bind() to listen to the events and do something. For example, when the user logs in, you can trigger a user_logged_in_event, and bind to it. In the function, you can then use JS to change the login button to logout...