Re: DOM messed up after loading new, #app-content as TemplateResponse via Ajax

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: DOM messed up after loading new, #app-content as TemplateResponse via Ajax

marmuDev
"You have to pass in the renderAs parameter which needs to be blank"
I was already looking into the parameters of TemplateResponse. Thanks
for making that clear to me!
Did so, but now none of the JS files the templates depend on are loaded,
therefore no function at all, but the pure HTML is replaced correctly.

Also changed as much as I could based on your hints. But some of the
"fancy" stuff like client-side templates will be postponed, since I need
to get my app up and running.

Is it correct to use something like:
     $notFound = new NotFoundResponse();
     $notFound.setStatus(404);
     return $notFound;
instead of:
     header("HTTP/1.0 404 Not Found");

And regarding "* You should get rid of private apis like OC_Log"
I'll have to read up on this, no clue for now

Thanks a lot Bernhard!
_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: DOM messed up after loading new, #app-content as TemplateResponse via Ajax

Bernhard Posselt-2
It fully depends on what you want to do. If you want to make a full page
reload you do not want to  use a blank template. If you however just
want to replace content in the content area, you want to have a blank
template response for the loaded html (not the initial page load).
Because this is just a partial template, there is no head tag and
therefore no script tag, so loading scripts in blank template responses
wont work.

I suppose you want to have a full ownCloud page when a user loads the
app, and when he clicks something in the navigation, you want to load
html into the content area. In that case you return a normal
TemplateResponse for the index page. Via JavaScript you then load blank
template responses via ajax and put them into the content are. In that
case your JS is already loaded by the initial page.

As for the 404 response:

$response = new \OCP\AppFramework\Http\Response();
$response->setStatus(\OCP\AppFramework\Http::STATUS_NOT_FOUND);
return $response;

If you find that you are using this very often and dont want to return
content, you can ofc create your own response class (see
https://doc.owncloud.org/server/8.0/developer_manual/app/controllers.html#creating-custom-responses):

class NotFoundResponse extends \OCP\AppFramework\Http\Response {
    public function __construct() {
        $this->setStatus(\OCP\AppFramework\Http::STATUS_NOT_FOUND);
    }
}

then you can do:

return new NotFoundResponse();


PS: there might be typos in my code ;)

On 04/11/2015 12:40 PM, Marcus Mundt wrote:

> "You have to pass in the renderAs parameter which needs to be blank"
> I was already looking into the parameters of TemplateResponse. Thanks
> for making that clear to me!
> Did so, but now none of the JS files the templates depend on are
> loaded, therefore no function at all, but the pure HTML is replaced
> correctly.
>
> Also changed as much as I could based on your hints. But some of the
> "fancy" stuff like client-side templates will be postponed, since I
> need to get my app up and running.
>
> Is it correct to use something like:
>     $notFound = new NotFoundResponse();
>     $notFound.setStatus(404);
>     return $notFound;
> instead of:
>     header("HTTP/1.0 404 Not Found");
>
> And regarding "* You should get rid of private apis like OC_Log"
> I'll have to read up on this, no clue for now
>
> Thanks a lot Bernhard!
> _______________________________________________
> Devel mailing list
> [hidden email]
> http://mailman.owncloud.org/mailman/listinfo/devel

_______________________________________________
Devel mailing list
[hidden email]
http://mailman.owncloud.org/mailman/listinfo/devel