Custom Portal - Development

Sorry for all the questions but I've another one..

I can see that the insert is updating the DB so happy days but the fetch is not giving me anything.. What exactly does fetch return?

Should it be something like:
Code:
[
{"id": 1, "uri": "http://humaxportal.com", "name": "Humax Portal", "img": "img/humax.png"},
{"id": 2, "uri": "http://iplayer.co.uk", "name": "BBC iPlayer", "img": "img/iplayer.png"},
{"id": 3, "uri": "http://twitter.com", "name": "Twitter", "img": "img/twitter.png"}
];

I am trying to read it as follows in my showRecords function:
Code:
$.each(data, function(i, item) {
    var id = data[i].id;
    var uri = data[i].uri;
    var name = data[i].name;
    var img = data[i].img;
}

Am I getting this all wrong?
 
Yes, it should be something like you've said. That's the bit that I'm least confident in but if you run the script from the command line it should show you what it would return.
 
The script is throwing an error while fetching the table data but for the life of me I don't know what the issue is... Fair play for knowing this jim syntax, maybe it's not too bad when yah get to know it!!

Anyway, getting this error in the console:
Code:
humax# /mod/webif/html/portal/jim/script.jim
Content-Type: application/json; charset="UTF-8"; no-cache
Expires: -1
Pragma: no-cache
Cache-Control: no-cache
 
Runtime Error: /mod/webif/html/portal/jim/script.jim:42: invalid command name "
        foreach rec {id 1 uri https://www.humaxtvportal.com/ name {Humax Portal} img app/img/humax_logo.png} {id 2 uri http://az341951.vo.msecnd.net:80/webapps/iplayer/default.htm name {BBC iPlayer} img app/img/bbciplayer_logo.png} {
                if {0} { puts ,""
at file "/mod/webif/html/portal/jim/script.jim", line 42

Line 42 however seems to be only spitting out a square bracket so it must be an issue further down the code. Here is line 42:
Code:
puts "["

The line where the error above stops is as follows:
Code:
if {$flag} { puts "," }

I don't get this jim enough to figure it out. I might have to wait for you to debug this later unless you can spot something obvious?
 
Try this one: http://hpkg.tv/script.jim

Code:
humax# ./script.jim
Content-Type: application/json; charset="UTF-8"; no-cache
Expires: -1
Pragma: no-cache
Cache-Control: no-cache
 
[
{
  "uri": "test",
  "img": "test",
  "id": "1",
  "name": "test"
},
{
  "uri": "test",
  "img": "test",
  "id": "2",
  "name": "test"
}
]

If you want to quickly install it on your box you can just do something like:

Code:
humax# cd /mod/webif/html/portal/jim
humax# rm script.jim
humax# wget http://hpkg.tv/script.jim

Prevents problems with line endings and the like.
 
Cheers, great stuff! I'm out at the minute but I'll try when I get in...

BTW, what does this \* mean in the select do?
 
BTW, what does this \* mean in the select do?
It probably isn't needed - it just escapes the * so that it is treated literally. I added it when debugging but the main problem was that I hadn't escaped the [ and [ is a special character in TCL.
 
It probably isn't needed - it just escapes the * so that it is treated literally. I added it when debugging but the main problem was that I hadn't escaped the [ and [ is a special character in TCL.

Cheers, I was curious what that did!
 
Try this one: http://hpkg.tv/script.jim

Code:
humax# ./script.jim
Content-Type: application/json; charset="UTF-8"; no-cache
Expires: -1
Pragma: no-cache
Cache-Control: no-cache
 
[
{
  "uri": "test",
  "img": "test",
  "id": "1",
  "name": "test"
},
{
  "uri": "test",
  "img": "test",
  "id": "2",
  "name": "test"
}
]

If you want to quickly install it on your box you can just do something like:

Code:
humax# cd /mod/webif/html/portal/jim
humax# rm script.jim
humax# wget http://hpkg.tv/script.jim

Prevents problems with line endings and the like.

Worked a treat, thanks a mill.. I will try and get a look at the rest again tomorrow.
 
@af123

I haven't been able to get near this the last week or so with a family bereavement and then work commitments..

I was able to get pretty much all the functionality working for a copied version of the official portal. I had one issue though, the timings of the calls to the jim functions would return after my jQuery commands attempted to apply the html lists. I tried to add setTimeout commands but it didn't really fully resolve the problem 100% of the time.

I was thinking of using $.ajax calls with callback functions to apply the html but I wasn't sure what format the jim functions would need to be in.

What exactly does the $.ajax command need to be returned for success: complete: error: etc.?

I was going to try later if I get a chance to simply fire your jim URL's into ajax calls to see what happened but thought I'd run it past you first to see what your thinking would be.. I want to finish up this new portal soon enough so I can get back to the OD players..

Cheers,
mcquaim
 
Don't worry, I think I have it... I think that is all taking care of by jQuery although I might have to try and add status codes to notify successful insert/delete/update etc.
 
The jquery ajax call can accept the returned response in any format, plain text, html, xml, json. i think it can even take a binary response to read in images etc.
As long as the server responds with a 200 response code (OK) then it should activate the success callback function and anything either output by your script or served by the server will be passed back as the response parameter.
The error callback would activated if the server responded with an error code, 404 not found for example.

The web server should handle all response codes so your jim code shouldn't have to (i've never used jim files so don't hold me to that!).

You can specify the type of data format you require (xml, json etc) using dataType: "json". jquery will then parse the response accordingly.

I would normally do any calls with json and pass back and database status from an insert/update etc as a json object.
This would always be picked up by the success callback function, examine the json object to see if the insert/update worked and do what you need from there.

Hope that made sense

Keep up the good work

Zico
 
The jquery ajax call can accept the returned response in any format, plain text, html, xml, json. i think it can even take a binary response to read in images etc.
As long as the server responds with a 200 response code (OK) then it should activate the success callback function and anything either output by your script or served by the server will be passed back as the response parameter.
The error callback would activated if the server responded with an error code, 404 not found for example.

The web server should handle all response codes so your jim code shouldn't have to (i've never used jim files so don't hold me to that!).

You can specify the type of data format you require (xml, json etc) using dataType: "json". jquery will then parse the response accordingly.

I would normally do any calls with json and pass back and database status from an insert/update etc as a json object.
This would always be picked up by the success callback function, examine the json object to see if the insert/update worked and do what you need from there.

Hope that made sense

Keep up the good work

Zico

Cheers, thanks for the explanation. I managed to figure that out earlier but the explanation was sound all the same!!
 
@af123

Another day, another question....

Is it possible to pass a list to jim to be processed?

Code:
[
{"uri": "http://humaxportal.com", "name": "Humax Portal", "img": "img/humax.png"},
{"uri": "http://iplayer.co.uk", "name": "BBC iPlayer", "img": "img/iplayer.png"},
{"uri": "http://twitter.com", "name": "Twitter", "img": "img/twitter.png"}
];

If I passed something like above to the jim script how would I declare the variable and step through each element?

I would like to be able to rebuild the table by firstly dropping the table and then re-inserting the data based on what has been passed back, possible?

#### Edit ####

Also, does jim have anything like a try catch? I'd like to check for insert/delete/update failures and pass back a status. I tried it but getting errors...
 
Sorry, I'm only after seeing your jim reference manual link on the webif, blind... I should get most of my info from that hopefully!!

The first part of my last question still looks like being trouble though...
 
@af123

Another day, another question....

Is it possible to pass a list to jim to be processed?

You can post data like that to a Jim script and have it parse it. There is probably no need to use JSON though as you'd have to write a JSON parser in Jim. CSV format would be simple enough.
 
You can post data like that to a Jim script and have it parse it. There is probably no need to use JSON though as you'd have to write a JSON parser in Jim. CSV format would be simple enough.

Cheers, yeah any format at all really as long as I could pass the favorites in and re-create the table..
 
The CGI library I added to Jim supports post handling and array variables too - want an example?
 
Something like:

Code:
switch $action {
...
    replace {
        $db query { delete from favourites }
        foreach line [split [cgi_get data ""] ";"] {
                lassign [split $line ","] uri name img
        }
        $db query {
            insert into favourites(uri, name, img) values('%s','%s','%s')
        } $uri $name $img
    }
...
}

Called from Javascript like:

Code:
$.post('/.../script.jim', {
    'action': 'replace',
    'data': 'http://humaxportal.com,Humax Portal,img/humax.png;http://iplayer.co.uk,BBC IPlayer,img/iplayer.png;http://twitter.com,Twitter,img/twitter.png'
}, function() {
    alert('database update completed');
});

I haven't tested this but it should be fairly close.
 
Back
Top