FAQ
hi, guys,

I think Ajax is cool. With Jemplate, it sounds good that Javascript
templating is possible.
I tried to go chapter 7 of Jon Rockway's book.

Looks good. For my system, I just needed something very basic.
===========================================
1) Load up a data input form

2) user selects loan type from a select box ( bearing values: '',
'personal' , 'commercial' ,'misc')

3) using the "onChange" method in javascript, I would then have an AJAX
call (excuse my terminology please) to load another fragment into the
existing form. This is because each loan type will have different
attributes which I have to have as input. This fragment will be made
out of various input types.

4) User fills up the remaining attribute values (after the specific form
attribute values have been loaded).



Looking at chapter 7(AddressBook Codes of Jon Rockway's book)
===========================================

1) two files, "root/src/person_fragment.tt2" and
"root/src/search/address_results.tt2" would call address_fragment.tt2

2) address_fragment.tt2 would in turn invoke edit_address.tt2 (under the
"root/src/jemplate" directory) with view_only set to true.


For what I need to do (in my own little test project), I figured I get
rid of the intermediate file, "address_fragment.tt2" and just refer to
edit_address.tt2 directly with view_only set to true.

When i tried my changes out, well,
1) view_source keeps getting set all the time
2) the javascript does work when I click on "Edit" in the webpage.


My questions are:
===========================================
1) roughly, what's wrong with cutting off the intermediate file,
"address_fragment.tt2" ?
2) I have been looking (googling) for Jemplates and got no luck really.
Most of the AJAX tutes do not talk about Catalyst enough (what more of
Jemplates)... Any good tutorials for Jemplates especially in terms of
what I want to achieve (as described above)?
3) I used firebug for debugging but kept getting an error saying
Jemplate.js has to be loaded first before anything. Is that normal?? I
mean, I did everything there was to do as per the sample AddressBook
Codes in chapter 7 of Jon Rockway's book.


SOS and thank you in advance,
K. akimoto

Search Discussions

  • Robert Krimen at Aug 13, 2008 at 11:26 pm

    On Wed, Aug 13, 2008 at 2:39 PM, wrote:

    2) I have been looking (googling) for Jemplates and got no luck really.
    Most of the AJAX tutes do not talk about Catalyst enough (what more of
    Jemplates)... Any good tutorials for Jemplates especially in terms of
    what I want to achieve (as described above)?

    I would start out by setting up an API controller
    (MyApplication::Controller::API)
    which is a Catalyst::Controller::REST.

    Flesh out your API methods and have jQuery act as an intermediary between
    your API controller and Jemplate (using $.get, $.post, etc.)

    Rob
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080813/c92a9c23/attachment.htm
  • K. Akimoto at Aug 14, 2008 at 6:57 am
    I have managed to get Jon Rockway's AddressBook application (from
    chapter 7 of the book) to work (ie i managed to log in as I put in the
    SQLs for User,UserRole and Role tables).


    I tried to edit an address and

    1) it does not work (ie. the webpage did not change and present a form
    for edit)
    2) got the extract below from "Error console" of firefox.

    Error: [Exception... "Component returned failure code: 0x80040111
    (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult:
    "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::
    http://gozila-underground.com:3000/static/Jemplate.js :: anonymous ::
    line 791" data: no]
    Source File: http://gozila-underground.com:3000/static/Jemplate.js
    Line: 791





    764
    //------------------------------------------------------------------------------
    765 // Ajax support
    766
    //------------------------------------------------------------------------------
    767 if (! this.Ajax) Ajax = {};
    768
    769 Ajax.get = function(url, callback) {
    770 var req = new XMLHttpRequest();
    771 req.open('GET', url, Boolean(callback));
    772 req.setRequestHeader('Accept', 'text/x-json; q=1.0');
    773 return Ajax._send(req, null, callback);
    774 }
    775
    776 Ajax.post = function(url, data, callback) {
    777 var req = new XMLHttpRequest();
    778 req.open('POST', url, Boolean(callback));
    779 req.setRequestHeader('Accept', 'text/x-json; q=1.0');
    780 req.setRequestHeader(
    781 'Content-Type',
    782 'application/x-www-form-urlencoded'
    783 );
    784 return Ajax._send(req, data, callback);
    785 }
    786
    787 Ajax._send = function(req, data, callback) {
    788 if (callback) {
    789 req.onreadystatechange = function() {
    790 if (req.readyState == 4) {
    791 if(req.status == 200)
    792 callback(req.responseText);
    793 }
    794 };
    795 }
    796 req.send(data);
    797 if (!callback) {
    798 if (req.status != 200)
    799 throw('Request for "' + url +
    800 '" failed with status: ' + req.status);
    801 return req.responseText;
    802 }
    803 }
    804



    I think it would be good if more tutorials were to be given for Jemplate.
    Otherwise, all the fancy new framework and shiny new developments would
    not pick up WITHOUT substantial DOCUMENTATION cause not many people
    would have the time to open up source codes to figure out how they work.


    K. akimoto
  • Ian Tegebo at Aug 16, 2008 at 8:45 pm

    On Wed, Aug 13, 2008 at 3:26 PM, Robert Krimen wrote:
    On Wed, Aug 13, 2008 at 2:39 PM, wrote:


    2) I have been looking (googling) for Jemplates and got no luck really.
    Most of the AJAX tutes do not talk about Catalyst enough (what more of
    Jemplates)... Any good tutorials for Jemplates especially in terms of
    what I want to achieve (as described above)?
    I would start out by setting up an API controller
    (MyApplication::Controller::API)
    which is a Catalyst::Controller::REST.

    Flesh out your API methods and have jQuery act as an intermediary between
    your API controller and Jemplate (using $.get, $.post, etc.)
    I'm trying to get a general understanding of how javascript techniques
    fit into Catalyst; I don't think I'm alone either.

    After a friend had recommend jQuery, I've found I really like it but
    had been under the impression that I wouldn't be able to use Jemplate
    at the same time. A second read of Rockway's Editable Addressbook in
    chapter 7 of the Catalyst book leaves me wondering how TT, Jemplate,
    and jQuery would best "get along". Is it the case that
    Catalyst::View::Jemplate exists to reduce HTML munging within
    client-side javascript?

    If so, then is it correct to think of jQuery, Jemplate, and the
    Catalyst::Controller::REST interface as kind of a browser-side MVC?
    I'm imagining the REST calls through jQuery as accessing the "model"
    while qQuery serves as the controller via its selectors finally
    rendering its "view" through Jemplate.

    BTW, it appears Catalyst::View::Jemplate broke after Jemplate >= 0.21
    changed the behaviour of Jemplate::runtime_source_code (see RT 35609,
    37813). What versions are you running?

    --
    Ian Tegebo
  • Robert Krimen at Aug 16, 2008 at 10:52 pm

    On Sat, Aug 16, 2008 at 12:45 PM, Ian Tegebo wrote:
    After a friend had recommend jQuery, I've found I really like it but
    had been under the impression that I wouldn't be able to use Jemplate
    at the same time.

    No, Jemplate WILL COEXIST with any other javascript you may be running
    client side.
    In fact, the latest Jemplate release has the option of using jQuery (or YUI)
    to perform
    AJAXy stuff (get & post).

    A second read of Rockway's Editable Addressbook in
    chapter 7 of the Catalyst book leaves me wondering how TT, Jemplate,
    and jQuery would best "get along". Is it the case that
    Catalyst::View::Jemplate exists to reduce HTML munging within
    client-side javascript?

    Jemplate in general exists for that purpose. The problem with doing heavy
    HTML/UI-lifting browser-side is that you end up doing things like:

    var html = '<div class="' + styleClass + '"><a href="' + uri ...

    It quickly becomes unwieldy. Jemplate basically creates methods that do the
    above (and more).

    The other option is to use a javascript templating system (interpolating and
    parsing in javascript? probably slow) or
    use a widget system that may not have the specific look & feel you're going
    for.

    If so, then is it correct to think of jQuery, Jemplate, and the
    Catalyst::Controller::REST interface as kind of a browser-side MVC?

    jQuery is a really nice way of manipulating DOM + some convenience
    functions: no MC
    involved (*maybe* the V part)

    Jemplate is just a templating system that plugs into javascript: again, no
    MC involved (just the V part)

    I suppose you can think of C::C::REST as the data-layer for your model, but
    then you're still missing the Controller
    aspect and a way of representing the Model in javascript.

    I'm imagining the REST calls through jQuery as accessing the "model"
    while qQuery serves as the controller via its selectors finally
    rendering its "view" through Jemplate.

    Sounds about right, but it's more like making API calls to your C::C::REST
    data-layer.

    BTW, it appears Catalyst::View::Jemplate broke after Jemplate >= 0.21
    changed the behaviour of Jemplate::runtime_source_code (see RT 35609,
    37813). What versions are you running?

    I'll try and take a look to at Jemplate and see what's going on. What you
    *can* do
    is just do a Jemplate compile via a Makefile or something and then serve the
    Jemplate
    .js as you would any other javascript asset.

    Rob
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080816/76e5e4a1/attachment.htm
  • Robert Krimen at Aug 19, 2008 at 2:47 am
    On Sat, Aug 16, 2008 at 2:52 PM, Robert Krimen wrote:
    On Sat, Aug 16, 2008 at 12:45 PM, Ian Tegebo wrote:


    BTW, it appears Catalyst::View::Jemplate broke after Jemplate >= 0.21
    changed the behaviour of Jemplate::runtime_source_code (see RT 35609,
    37813). What versions are you running?

    I'll try and take a look to at Jemplate and see what's going on. What you
    *can* do
    is just do a Jemplate compile via a Makefile or something and then serve
    the Jemplate
    .js as you would any other javascript asset.

    Rob
    This issue is now taken care of in version 0.23_1

    You can install it with pip:

    pip
    http://search.cpan.org/CPAN/authors/id/R/RK/RKRIMEN/Jemplate-0.23_1.tar.gz
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20080818/2f42f5dd/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedAug 13, '08 at 10:39p
activeAug 19, '08 at 2:47a
posts6
users3
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase