my $c = iCal::Parser->new->parse_strings( $text );
- warn "# iCal::Parser = ",dump($c);
+# warn "# iCal::Parser = ",dump($c);
my $ical = {
cal => $c->{cals}->[0], # FIXME assume single calendar
_render_jsonp( $self, $ical );
};
+get '/reservations/events/:view_name' => sub {
+ my $self = shift;
+
+ my $view = _couchdb_get('/reservations/_design/events/_view/' . $self->param('view_name') . '?group=true');
+ my $hash;
+
+ if ( exists $view->{error} ) {
+ _couchdb_put "/reservations/_design/events", {
+ _id => '_design/events',
+ language => 'javascript',
+ views => {
+ submited => {
+ map => q|
+ function(doc) {
+ if ( doc.event && doc.event.UID ) emit(doc.event.UID, 1)
+ }
+ |,
+ reduce => q|_sum|,
+ }
+ }
+ };
+ }
+
+ _render_jsonp( $self, {} ) unless ref $view->{rows} eq 'ARRAY';
+
+ foreach my $row ( @{ $view->{rows} } ) {
+ $hash->{ $row->{key} } = $row->{value};
+ }
+
+ _render_jsonp( $self, $hash );
+};
+
app->start;
__DATA__
$xhr("GET"
, "/reservations/get/www.google.com/calendar/ical/8tg8ecg285qshtp75813jktqa0%40group.calendar.google.com/private-b9d68b530fde2c6060979f8a05aa0865/basic.ics"
, function(code, response){
- console.log('xhr JSON', code, response);
+ console.log('xhr calendar', code, response);
self.data = response;
}
);
+
+ var load_submited = function() {
+ $xhr("GET"
+ , "/reservations/events/submited"
+ , function(code, response){
+ console.log('xhr submited', code, response);
+ self.submited = response;
+ }
+ );
+ }
+ load_submited();
+
var Reservation = $resource('/data/reservations/prijava/:id');
this.reservation = new Reservation();
<ul>
<li ng:repeat="c in data.events" ng:show="! reservation.UID || reservation.UID == c.UID">
{{c.DTSTART}} - {{c.DTEND}}
-<a href="" ng:click="reservation.UID = c.UID ; reservation.event = c">
-<b>{{c.SUMMARY}}</b>
-</a>
+<a href="" ng:click="reservation.UID = c.UID ; reservation.event = c">{{c.SUMMARY}}</a>
+<b ng:show="submited[c.UID]">
+broj prijava: {{submited[c.UID]}}
+</b>
<div>{{c.LOCATION}}</div>
<div ng:show="c.DESCRIPTION">
{{c.DESCRIPTION}}
<br>
područke/tema zaninimanja: <input name="reservation.porducje">
<br>
-<input type=button ng:click="reservation.$save()" value="Prijavi me">
+<input type=button ng:click="reservation.$save(); load_reservations();" value="Prijavi me">
<pre>{{reservation}}</pre>
</form>