Form View Based on Access - odoo-9

How can I hide form view based on users access?
For example : If I log with user1
I can see all customers (created by me and user2) in kanban end tree views.
In form view only view my customers.

I think the only way to achieve this is by updating the form view itself. You would put all of the contents into a div and hide it if the user_id (or whichever field you want to base the rule in) is someone else.
Effectively, it would look something like this:
<div attrs="{'invisible': [('user_id', '!=', user.id)]}">
# normal form view fields and formatting
</div>
If the user_id field does not default to the logged in user, it's possible that the form fields would hide by default when creating a new record. You would be able to bypass it with something like this (which allows you to see records that aren't assigned to a user) instead:
<div attrs="{'invisible': [('user_id', 'not in', [user.id, False])]}">

You have to make two groups for that.
First one is for admin and second is for users.
In kanban and tree, you have to give the fields admin rights or apply group 1 on tree and kanban view.
In form view you have to give the second group so, it will perfectly work as per your requirements.

Related

Which resources method should handle this view?

I'm currently using Laravel but i assume this question could also be asked with any framework in any language.
If i have a simple form to create an user, with the most basic fields (firstname, lastname, email...), the resource method i'll use will be create to display the view and store to handle the post logic.
After that, the edit form will be displayed in the edit method and the update managed by the update method.
Eventually, the user sheet will use the show method.
Now, imagine i have a view that combine both the edit and show purposes, i mean like a page with multiple tabs, where each tab display information about the user, some charts, some tables, a lot of stuff... but also an edit form in one of these tabs.
Which method should be used to display this view ? edit or show ? Since it acts like a show but also have a form to edit the user... i'm always asking myself and sometimes i have a hard time to figure out which method i should use.
This case often happens in back offices, where some edit pages looks like a dashboard more than a simple form, i'm sure you see what i mean ;)
Is there a convention about this ? Something like "if there is a form it's an edit, even if it mainly show information" ?

Dynamic list for MailChimp checkboxes

I have a newsletter sign up form on my website that presents the user with a list of checkboxes to select. The checkboxes are generated dynamically from my database. Other standards newsletter sign up fields, such as email, name, phone number, address, etc. exist in the sign up form, as well.
In MailChimp, I have created a List and have added custom fields to match my sign up form (e.g. phone number, address). I then looked at the Embedded Forms -> Naked to see the generated markup. It's easy enough to set the name attributes of the text fields on my sign up form to match those in MailChimp's.
The struggle for me now is the checkboxes. I cannot put the list of items for the checkboxes in MailChimp as they need to be dynamically generated from my database. I have added a checkbox field in MailChimp to see what name attribute it generates in hopes I could use it in my form; I see something like this:
<input id="mce-group[15757]-15757-0" name="group[15757][1]" type="checkbox" value="1">
In my sign up form, I tried something like this:
<input name="group[15757][]" type="checkbox" value="Apple">
When I signed up, "Apple" was not carried over.
How do I capture checkbox items from my signup form into MailChimp?
It looks like you're using interests -- you won't be able to pass custom values to those, as they are simply yes or no. You'd probably be better off using a merge field. Alternately, you can create the interests dynamically, but you'll need to write a script to do that, you won't be able to use the form builder directly.

How to get different custom registration forms for different user groups in Joomla 3.x?

I have 2 groups of users, say Group A and Group B, which both require a different user registration form. So each each form has a different set of form fileds on top of the default Joomla form.
I found out how to create a plugin to override the standard form fields for just one registration form - referring to http://library.logicsistemi.it/en/joomla/general-topics/93-joomla-3-custom-fields-for-user-s-profile.
But I don't know how to setup a user menu with 2 links to 2 different form fields; I dont think its possible to do this via the Joomla administrator site using the Menu manager; for the Menu itemtype in the Menu manager one can only select one standard Registration Form.
So I assume some coding is required, but how to approach this? (my Joomla coding experience is stil limited)
Appreciate your help;-)
You can easily customize your form. Just make one form, and then change the fields using the group ids in $user. (A user can have more than one group).
For example:
$user = JFactory::getUser();
$groups = $user->groups;
if(in_array(YOURGROUPID, $groups)){
// do something for that group
}
It's especially easy with the plugin you made using that tutorial, because you can just include / exclude the form fields you want and it adds it to the #__user_profiles met database.
Good luck
You can use Joom Profile extension for managing user profile fields according to usergroup, on the same page of registration.
You can look for other extensions at JED
You can use a form component to override the registration. Breezing forms is my weapon of choice. You will need two different forms.
Then you can do a hidden field and set the user group ID to stick them in that group.
You might also look at their integrator which may help. Sorry this isn't a comprehensive answer it's late here. See how you get on and comment if you still need help.

MVC3 global predicate filter

I am building an admin console and all controllers depend on a dropdown selection for customer.
I would like to move this customer selection to the layout and persist it across all controllers so that you do not need to select it everywhere.
What is the best way to go about doing this?
Thanks in advance.
Move the dropdown to your _layout.cshtml.
Create a BaseView that all views will inherit from and give it a property to store the Customers & Current Customer.
Create a BaseController method that will fill in a BaseView instance.
Store the currently selected customer on your session.
Create a Global Filter and have it check all views to see if they inherit BaseView. If they do it can convert them to a BaseView and then fill in the properties.
Write some code in the _layout that can use the View to fill in the dropdown. I'm a bit fuzzy here since my coworker actually did this part when we did something similar.
When the user changes the dropdown value you can use JSON to call an action method that will update the current customer in session.
I would consider writing HTML helper. You assume that all the birds can fly, but say one day you have another exceptional scenario and you no longer need this dropdown box. Alternatively include it in a partial view and render that view where you need it - it's only one extra line of code.
E.g.
#section main_content{
#{ Html.RenderPartial("MyPartialViewContainingDropDownBox"); }
}

MVC3-ValidationFailure-RetainValues

I am using MVC3 in ASP.NET. In the Post Action,
I have an View, In which it should let me edit the values. Some fields are read-only and some fields are editable. If there is a validation failure then it should retain the values and display the same View, if there are no error then it should let me to submit the form.
Control1:
Name I have to display as label as It has to be read-only
#Html.DisplayFor(Model => Model.Absentee.Name)
Control2:
I have to display this one as textbox so that it can be edited. This is a required Field.
#Html.TextBoxFor(Model => Model.AbsStart)
#Html.ValidationMessageFor(Model => Model.AbsStart) (This Makes it as a required Field)
Control 3:
This is also a textbox but not required field.
#Html.DisplayFor(Model => Model.AbsEnteredAt)
When there are no validation errors, things works great, but when there is a validation error, then I will be in the same view(Which is what I want) but the value in First control is not retained.
So Basically, when the validation failure, the value is not retained in the DisplayFor Control
What do I do to sort this?
Thank you
As 99% of my answers in the asp.net-mvc tag this one is the same: USE VIEW MODELS. Don't have your controller actions take/pass domain models to/from views. Design view models for each view. View models are classes which are specifically tailored to meet the requirements of this given view. So let's suppose that you have two different views which allow you to edit/update the same domain model. Then you will design two different view models and each view model will contain only the properties that are used by the respective view along with their specific validation requirements.
As far as the DisplatFor helper is concerned, it generates a simple label. Labels are never sent to the server when you submit a form. So you can hope to populate/validate on your controller action only the properties that are contained on the form. For properties that should not be displayed you could use either hidden fields or a single hidden field containing only some unique identifier so that you can fetch from your datastore back the original values (as the user is not supposed to modify them anyways).
As far as the mapping between the view model that you should design and the original domain model is concerned, this mapping is usually performed inside the controller and to simplify it I would recommend you to use AutoMapper.
When there is an error, what is the viewModel you are returning? DisplayFor does not get sent back to the server ... add this under the displayfor:
#Html.HiddenFor(Model => Model.Absentee.Name)

Resources