Links that reload only a partial - hyperlink

I have a partial in TYPO3 which contain links. I create them in a subroutine in my controller:
public function createLink($args)
{
$uri = $this->controllerContext
->getUriBuilder()
->reset()
->setTargetPageUid($pageUid)
->setAddQueryString(true)
->setArguments($args)
->buildFrontendUri();
return $uri;
}
This function does not create a relative link as I expected it. It should just reload the partial.
The only links that this function creates are of the following form
http://localhost/my-new-project/public/index.php?id
All options (ie. the controller context and the plugin) are missing. I expect that these links are local to the partial and reload only the partial when I click on them.
My TYPO3 Version is 9.5.13 on PHP 7.2.24 on ubuntu 18.04

Related

Can I make a partial template that have readonly fields when used by show and not when used by edit and create?

I've partial templates that are used by the show, edit and create form.
In the show-form I don't want them editable, it can be confusing for the user.
Is there a simple solution for this otherwise I need a different template for the show-form or... why use a template then.
I've tied this and created 2 scripts, one that disables and one that enables.
Script 1.
$(document).ready(function(){
$('.elements').attr('readonly',true);
$('.elements').prop('disabled',true);
});
Script 2.
$(document).ready(function(){
$('.elements').attr('readonly',false);
$('.elements').prop('disabled',false);
});
Then I stored those scripts in assets\javascript.
It worked good in show but both edit and create went read-only too.
It seems like everything that is put in this directory is automatically used in each form, because even though I removed the call from the forms, it was working.
Here I show where I originally added the script-call:
<asset:javascript src="myScript_1.js"/>
</body>
</html>
I was going to add it as a comment but then it started to get long and complicated to follow.
why store it in assets ?
simply add a function block to the templates that need it
_template1.gsp
<script>
$(document).ready(function(){
setReadOnly('${someDefinition}')
function setReadOnly(value) {
if (value==='READONLY') {
$('.elements').attr('readonly',true).prop('disabled',true);
}
}
})
</script>
If this function needs to be shared by a bunch of pages, you could add it to an assets / javascript file but rather than declare it in application.js call the js file <asset:javascript tags specificially on each page
and maybe a variable that you pass to template to say when it should be called
or put that above template1 as a master template and call in each of the other templates that needs the js file (So many options)
Now on the main controller doing action
def MyController {
def view() {
String mode='READONLY'
render view: 'index', model:[instance:params,mode:mode]
}
}
the in index.gsp
if js is there then it will pick up mode and set readonly for that controller action or pass that from one template to another, the controller does not have to define actual mode, the main master view page or index page could define mode too
Maybe you need to play/understand then implement you can't rush these things otherwise you will end up wasting time and rewriting
Just to ensure we are on the same page.
By default the application.js file in the javascript folder has a tree line enabled - this by default then reads in all js files. If you wish to manually call js in different places you will need to remove this line and declare each and every js file that you use like the other lines provided in that file.
So that is the price to pay (no more auto loading js files) until declared in application.js
But then most importantly as you have noticed these are global js functions and really nothing new should be going in there that hasn't got a function something() { } a function call.
They will then react when the actual function is called rather than how you had it which was open for call from any old page since it happened as documents opened regardless

GET request gets triggered instead of template render with AngularJS, Rails and ngModal

I am using Rails, angular-rails-templates gem, Angular 1.4.8 and http://likeastore.github.io/ngDialog/.
My project structure keeps my template files in app/assets/javascripts/templates and my angular project in app/assets/javascripts/angular-app. I have set up ng-modal as:
$scope.callModal = function () {
ngDialog.open({
template: 'tickets/partials/_resolve.html',
controller: 'TicketEditController',
scope: $scope
});
};
I have a template called _resolve.html.erb inside my app/assets/javascripts/templates/partials/_resolve.html.erb. The issue is that whenever I press on the button who ng-click the function, I see a GET request to /tickets/partials/_resolve.html so it doesn't actual render the template but just makes an http request to that uri.
The modal pops up but displays the whole root page (not the template).
How can I make this work?
try moving your html file to a directory app/assets/templates/partials/_resolve.html. Unless you have your templates configured differently than angular rails templates suggests in their documentation

How to stop user loading page that contains RenderBody() directly

I have an Umbraco site with the following structure:
Views/LayoutPageA.cshtml/
Views/ContentPageA.cshtml/
Views/ContentPageB.cshtml/
LayoutPageA contains:
<body>
...
RenderBody()
...
</body>
and ContentPageA and ContentPageB both contain:
#{
Layout = "LayoutPageA.cshtml";
}
Obviously, if I navigate to /LayoutPageA/ContentPageA/ or /LayoutPageA/ContentPageB/ the page loads fine but /LayoutPage/ will crash because:
The file "~/Views/LayoutPageA.cshtml" cannot be requested directly because it calls the "RenderBody" method.
How should I prevent the user from navigating to /LayoutPage/ through the URL?
dont use Views/LayoutPageA.cshtml/
you should use
<a href="/controllerName/actionName"> or <%= Html.ActionLink("menu1", "actionName", "controllerName") %>
The only way this would occur with MVC is if you had an action named LayoutPageA or you explicitly returned LayoutPageA.cshtml as the view, e.g.:
return View("LayoutPageA");
So, just don't do that. Ensure that your action names do not match a layout name, such that it would by convention be the view that would be loaded for the action. A good standard to prevent this from occurring by accident is to prefix your layouts/partials with an underscore, i.e. _LayoutPageA.cshtml. Since action names cannot begin with an underscore, the layout/partial will never be matched by convention.

How to include multiple views in one page?

I'm turning a pure HTML website into a small Rails app and have come across an issue.
Currently I have a index.html page and a translation.html page (which displays index in another language). There is currently a link on index.html to translate the page and vice verse.
I have set index.html as the 'show' action, but am unsure how to handle translate.html page. Both will have the same information/Rails form.
Make the embed-able content in translate.html into a partial, like _translated.html. Then you include the partial _translated.html (that's what the "_" means; a "partial" view) in each of the translate.html and the index.html pages. Read up on partials, and use a code like
render :partial => 'translated'
in each of your main view pages.

AJAX calls action for a partial?

I have a page show.html.erb with a corresponding action 'show'. Lower on the page, a partial is loaded called _filter.html.erb which contains undefined instances (so basically, on the initial load, nothing is displayed there).
In the show.html.erb, I have a form that uses AJAX and submits to an action called "filter" which is supposed to create some instances for use within the _filter partial (so now, the _filter partial within show will have some content).
But when i submit the form, it says Template is missing Missing template results/filter.
But what it should be doing is staying on the same current template (show.html.erb) and just run the filter action and update the partial _fitler.
Any suggestions?
UPDATE
Following some things i found online, i made a file _filter.js.erb withing the views/results directory (same dir as show.html.erb and _filter.html.erb):
$("filter").update("<%= escape_javascript(render("filter"))%>");
But it doesnt seem to be doing anything..
By rails convention if you use the name _filter then you should put this file in shared folder.
So it's should be shared/_filter.html.erb

Resources