fix various bugs
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 1 Nov 2010 15:15:20 +0000 (16:15 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 1 Nov 2010 15:15:20 +0000 (16:15 +0100)
This makes conference submission Work page functional.

angular-server.pl
templates/conference/Work.html.ep [new file with mode: 0644]

index 0896eef..0a6cd75 100755 (executable)
@@ -31,9 +31,9 @@ our $id2nr;
 
 sub _render_jsonp {
        my ( $self, $json ) = @_;
-warn "_render_json ",dump($json);
+#warn "## _render_json ",dump($json);
        my $data = $self->render( json => $json, partial => 1 );
-warn "## $data";
+warn "## _render_json $data";
        if ( my $callback = $self->param('callback') ) {
                $data = "$callback($data)";
        }
@@ -123,10 +123,15 @@ get '/data/:database/:entity/:id' => sub {
 any [ 'post' ] => '/data/:database/:entity' => sub {
        my $self = shift;
        my $json = $self->req->json;
-       my $id = $json->{'$id'} || Time::HiRes::time(); # FIXME UUID?
+       my $id = $json->{'$id'} # XXX we don't get it back from angular.js
+               || $json->{'_id'}  # so we use our version
+               || Time::HiRes::time(); # FIXME UUID?
        warn "## $id body ",dump($self->req->body, $json);
        die "no data" unless $data;
 
+       $json->{'$id'} ||= $id; # angular.js doesn't resend this one
+       $json->{'_id'} = $id;   # but does this one :-)
+
        my $database = $self->param('database');
        my $entity   = $self->param('entity');
 
@@ -135,10 +140,9 @@ any [ 'post' ] => '/data/:database/:entity' => sub {
                $data->{$database}->{$entity}->[$nr] = $json;
                warn "# update $nr $id ",dump($json);
        } else {
-               $json->{'$id'} ||= $id;
                push @{ $data->{$database}->{$entity} }, $json;
                my $nr = $#{ $data->{$database}->{$entity} };
-               $id2nr->{$id} = $nr;
+               $id2nr->{$database}->{$entity}->{$id} = $nr;
                warn "# added $nr $id ",dump($json);
        }
        _render_jsonp( $self,  $json );
diff --git a/templates/conference/Work.html.ep b/templates/conference/Work.html.ep
new file mode 100644 (file)
index 0000000..56a6959
--- /dev/null
@@ -0,0 +1,70 @@
+<script>
+angular.service('conference', function($resource){
+ this.Work = $resource( '/data/conference/Work/' );
+}, {$inject:['$resource'],$creation:'eager'});
+
+function WorkForm(){
+       this.master = {
+               type: '',
+               title: '',
+               abstract: '',
+               authors:[ { name:'', surname:'', inst:'', 'email':'' } ],
+       };
+       this.cancel();
+}
+WorkForm.prototype = {
+       cancel: function() {
+               this.work = angular.copy(this.master);
+       },
+       save: function(){
+               if ( ! this.saved ) {
+                       this.saved = new this.Work( this.work );
+                       console.debug( 'new', this.saved, 'from', this.work );
+                       this.work = this.saved;
+               }
+
+               this.work.$save();
+               console.debug( 'work', this.work );
+       }
+};
+</script>
+
+<div ng:controller="WorkForm">
+<pre>
+$id={{$id}}
+work.$id={{work.$id}}
+work._id={{work._id}}
+</pre>
+       <label>Vrsta rada:</label><br/>
+       <input type="radio" name="work.type" value="simp"> Simpozij <br/>
+       <input type="radio" name="work.type" value="pred"> Predavanje <br/>
+       <input type="radio" name="work.type" value="poster"> Poster <br/>
+       <input type="radio" name="work.type" value="round"> Okrugli stol <br/>
+
+
+<div ng:repeat="author in work.authors">
+[<a href="#" ng:click="work.authors.$remove(author)">X</a>]
+<input name="author.name" ng:required>
+<input name="author.surname" ng:required>
+<input name="author.inst" >
+<input name="author.email" ng:required>
+</div>
+[<a href="#" ng:click="work.authors.$add()">Add another author</a>]
+
+
+
+
+   Naslov: <input name="work.title" size="60"><br/>
+   
+   Sazetak: <br/>
+    <input type="submit" value="Save" ng:click="save()" disabled="{{$invalidWidgets}}">
+
+
+
+
+Debug Information:
+{{$window.location.href}}
+<pre>work = {{work}}</pre>
+<pre>master = {{master}}</pre>
+
+</div>