REBOL [
	Title: "Vote on RAMBO tickets"
	Author: "Gabriele Santilli"
	Version: 1.0.0
]

url: http://www.rebol.net/cgi-bin/services.r

votes: [["" "Downloading client code..." ""]]

view/new center-face layout [
	title "RAMBO Votes"
	l: list 500x300 [
		across
		text 50 right [show-ticket face/data]
		text 380 [show-ticket face/data]
		text 42 right [vote-ticket face/data]
	] supply [
		face/text: pick votes count
		if face/text [
			face/data: pick face/text 1
			face/text: pick face/text index
		]
	]
	across text 100 right "Ticket #" id: field 150 btn "Vote!" [vote-ticket attempt [to integer! id/text]] return
	text 500 {To vote, either click on the ticket votes, or enter the ticket id
				and click on "Vote!".}
]

do http://www.rebol.net/rebservices/client.r

port: open-service url

votes/1/2: "Fetching ticket list..." show l

do refresh: has [res] [
	res: do-service port [rambo/get-votes with-summary 10]
	clear votes
	foreach [id summary voters] next res/4 [
		repend/only votes [id summary voters]
	]
	show l
]

vote-ticket: func [id] [
	if integer? id [
		do-service port compose [rambo/vote (id)]
		refresh
	]
]

show-ticket: func [id] [
	if integer? id [
		browse join http://www.rebol.net/cgi-bin/rambo.r?id= id
	]
]

do-events