Odoo - Redirect user to html page - odoo-8

I am using odoo 10e what i want to do is that when a user click a button i want to redirect him to a html page and show him ThankYou msg. Like we see when we submit a survey on google. It show us thankyou page in last and we are even not able to go back and submit the survery again.
According to my knowledge if i want to redirect user to a url we can use following.
return {
'type': 'ir.actions.act_url',
'url': 'www.google.com',
'target': 'self'
}
But i want to show my own page like suppose if i have index.html file in my custome module.

To redirect to another page, you have two ways:
if you do it from a model you have to add a button object typein the view to execute the method of your model and then in the model you redirect it with:
<button name="my_page" string="My text" type="object"/>
Now in the model:
class MyModel(models.Model):
_inherit = "my_module.my_model"
#api.multi
def my_page(self):
return {
"url": "/my_module/my_page/",
"type": "ir.actions.act_url"
}
the other is from the controller:
from werkzeug.utils import redirect
from openerp import http
class main(http.Controller):
#http.route('/my_module/my_page/', auth='public')
def index(self, **kw):
response = redirect("www.google.com")
return response
in this example the button calls the method 'my_page' of the model and this calls the url of the controller '/my_module/my_page/', but you can redirect directly from the model to the url you need, also in the controller. For example, if you need to go directly from the model to an url without going through the controller, you can use:
return {
'url': 'http://google.com',
  'type': 'ir.actions.act_url'   
}

Related

how can i make 4 links to a controller?

i'm setting up a new project in my laravel
The stuffs i have :
1- PostsController
2- Post model
3- Routes:resource('posts','PostsController')
4- after i login i have a create button for post create
after click on it i have below image :
My desire:
i want without changing whole project or whole routes resources have these :
after i login i want to have 4 boxes like this( i made it )
with this property :
after i click any of them i can create post according to their type
for example if i click on video content i enter to a page with 2 form:
like title video and upload video
after i click on text content i enter to page like the image i showed
you at the first
it means if i click on video content, resource route take me to create method in postscontroller and create method check if i came from content video link
return view (posts.create_video) or if i came from sound content link box return view(posts.content_sound) and etc boxes
how can i do all of that please help me thanks
You could structure it as following:
[routes/web.php]
Route::get('posts/create/{type}', 'PostController#create')->name('posts.create');
Route::resource('posts', 'PostController')->except(['create']);
[PostController]
class PostController extends Controller
{
public function create($type)
{
if (in_array($type, ['sound', 'video', 'image', 'text'])) {
return view("posts.content_{$type}");
}
abort(404);
}
}

How to pass variables from view to controller without using forms in Laravel?

I'm using RESTful controller and passing variables (using forms) works just fine here.
Now for some reason I need to use simple link, created with action() and dedicated route for #create action.
My view creates few similar links with different parameters:
<a href="{!! action('\App\Http\Controllers\Admin\Franch\Category\SubCategoryController#create', array('mainCategoryName' => $mainCategoryName)) !!}">
It works, because I can see this in URL:
/create?mainCategoryName=some_sample_name
But the route doesn't pass variables to the #create action OR controller doesn't recieve it for somereason:
Route::get('admin/franch/sub_categories/create', ['uses' => 'Admin\Franch\Category\SubCategoryController#create');
I wonder how can I pass variables from views to specific controllers, using GET and POST methods?
And this is my #create controller:
public function create($mainCategoryName = false)
{
dd($mainCategoryName);
....
Which is always gives false.
Well You can create a function on the link and in that function user Ajax
$.ajax({
type: "POST",//Or Get
url: url,
data: {"var_name":variable},
success: success,
dataType: dataType
});
Now you can send you variables in the data. and then you can get value of the variable in your controller by:
Input::get('var_name');
It would be much better if you make all your "calculations" in the controller and pass a resulting value to the view like so
class SomeController() extends Controller
{
public function getView():View
{
$mainCategoryName = "fix";
$formUrl = action('\App\Http\Controllers\Admin\Franch\Category\SubCategoryController#create', array('mainCategoryName' => $mainCategoryName));
return view('view.show', compact('formUrl'));
}
...
Your mistake is in keeping meaningful data in the view, when the view should only have processed values:
<a href="{!! $formUrl !!}">
And if you really want to go "nuts", you can create a class that would generate HTML using a blade-view and the controller data and then you can execute this class in the controller to have your "partial" ready to be incorporated in a view as HTML. But not the other way round. Keep the calculations out of your views.

How to execute an action without going to another view in grails?

I have a code that starts the server and stops the server. However when i press the button the server gets started but it also redirects me to a new view. The code in controller i have is
def test= amazonWebService.ec2.startInstances(new StartInstancesRequest([InstanceToStart]))
I want to execute test when button is pressed without going to new view. The code I have in my gsp page is
<g:link action="test">
<input type="button" value="Start Server" class="button" id="startServer1" />
</g:link>
If you don't mind the page refreshing, in your test action, redirect to the same view you came from. So assuming you got to your current view via index:
class SomeController {
def index() {
// index.gsp rendered via convention
}
def test() {
// execute your code then
redirect action: index, params: params
}
}
You're other option is to submit an Ajax request when the link is clicked and not have to refresh the page at all.
Use a remote function, see here http://grails.org/doc/2.1.0/ref/Tags/remoteFunction.html
Following is the alternative answer to the question.
By default Grails view resolver tries to find a view similar to the action name. In your case, Grails is trying to find test.gsp and if it is there in your repository it renders that. You can override this behaviour by using the Grails URL mappings feature. There you will get to specify which view should be rendered for a certain action.
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(view:"/index")
"500"(view:'/error')
}
}
For further information visit : http://grails.org/doc/2.2.x/ref/Plug-ins/URL%20mappings.html

Grails call ajax function before redirect?

I have a controller that has an ajax function and a seperate action that redirects the page. I want to know is it possible to make the ajax call when the link is clicked, but wait for the function to finish before the redirect action is called?
E.g.
<g:link controller="myController" action="myRedirectAction" before="saveData">link</g:link>
EDIT Added code
controller
def ajx_saveServiceGroup = {
//Code to save data to object
return
}
def saveConfigToRoLo = {
//code to save object to DB
redirect(action:"displayPDFSummary", id:orderId, params: [origSessionId: params.origSessionId, theSession: tempSession])
}
gsp
<g:link class="buttonSend" action="saveConfigToRoLo" id="${orderDataInstance.id}" params="[origSessionId: origSessionId, orderId: orderDataInstance.id, submitToBT: true]" before="ajx_saveServiceGroup">Submit</g:link>
you can have a remoteLink and then onSuccess callback you can change the windows.location to whatever you want !
A details description of what you are trying to achieve will help us provide better answers.

Passing parameter to same page with CodeIgniter

I have a controller that loads a page view. The page is actually a template of sorts; when a user clicks a button, content is loaded into a div based on the parameters passed through the button link. All button URLs go to the same page, it just passes a parameter. So for example, I have a page controller and a page_view file. When I click on the login button I want to go to the same page, but just pass action="login". If I clicked on "see stats", then I would want to pass action="stats".
Without Codeigniter I know I can just set the URLs on the buttons to "?action=stats" or "thisurl?action=stats", and within the page itself I have code that checks to see what the value of action is, and then generated content based on value.
How can I do this with the CodeIgniter framework?
You can call methods on a controller. So if you call a page like /your_controller/login, then it will call the login method in the controller and you can change the view to match that:
class Main extends CI_Controller {
function Main(){
parent::__construct();
// called when /main is accessed
// load your main view here
}
function login(){
// called when /main/login is accessed
// tweak view to match login view
}
}
More info here: http://codeigniter.com/user_guide/general/urls.html

Resources