Merge branch 'master' of github.com:dpavlin/angular-mojolicious
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 5 Nov 2010 12:14:23 +0000 (13:14 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 5 Nov 2010 12:14:23 +0000 (13:14 +0100)
.gitmodules
angular-server.pl
common/mojo [new submodule]
public/angular
public/controller/conference/Symposium.js [new file with mode: 0644]
templates/conference/Symposium.html.ep [new file with mode: 0644]
templates/conference/Work.html.ep

index f4358d5..1912998 100644 (file)
@@ -1,3 +1,6 @@
 [submodule "public/angular"]
        path = public/angular
        url = git://github.com/angular/angular.js.git
+[submodule "common/mojo"]
+       path = common/mojo
+       url = http://github.com/kraih/mojo.git
index 0a6cd75..e9d33ee 100755 (executable)
@@ -1,10 +1,14 @@
 #!/usr/bin/env perl
 
+use lib 'common/mojo/lib';
+
 use Mojolicious::Lite;
 use Data::Dump qw(dump);
-use Time::HiRes qw(time);
+use Time::HiRes;
 use Clone qw(clone);
 
+sub new_uuid { Time::HiRes::time * 100000 }
+
 # based on
 # http://docs.getangular.com/REST.Basic
 # http://angular.getangular.com/data
@@ -125,7 +129,7 @@ any [ 'post' ] => '/data/:database/:entity' => sub {
        my $json = $self->req->json;
        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?
+               || new_uuid;
        warn "## $id body ",dump($self->req->body, $json);
        die "no data" unless $data;
 
@@ -182,6 +186,7 @@ Yea baby!
 <!DOCTYPE HTML>
 <html xmlns:ng="http://angularjs.org">
   <head>
+   <meta charset="utf-8">
 % my $ANGULAR_JS = $ENV{ANGULAR_JS} || ( -e 'public/angular/build/angular.js' ? '/angular/build/angular.js' : '/angular/src/angular-bootstrap.js' );
     <script type="text/javascript"
          src="<%== $ANGULAR_JS %>" ng:autobind></script>
diff --git a/common/mojo b/common/mojo
new file mode 160000 (submodule)
index 0000000..f56f468
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit f56f46879ef7fc32346ca8696270c6d47cb6cc5f
index 9a53200..3b04b48 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 9a532002cf490a3e26a827e2eab9c1c3d834e2b8
+Subproject commit 3b04b48b7cc8f19f3e3ee1720188ea58ebb5d204
diff --git a/public/controller/conference/Symposium.js b/public/controller/conference/Symposium.js
new file mode 100644 (file)
index 0000000..ddb227a
--- /dev/null
@@ -0,0 +1,31 @@
+function Symposium($resource){
+       this.master = {
+               type: '',
+               title: '',
+               abstract: '',
+               authors:[ { name:'', surname:'', inst:'', email:'' } ],
+       };
+       this.Symposium = $resource( '/data/conference/Symposium/:_id', { _id:'' } );
+       this.reset();
+       this.$watch('$location.hashPath', this.hash_change);
+}
+Symposium.$inject=['$resource'];
+
+Symposium.prototype = {
+       hash_change: function() {
+               var id = this.$location.hashPath;
+               if ( id ) {
+                       this.symposium = this.Symposium.get({ _id: id });
+               }
+       },
+       reset: function() {
+               console.debug( this.Symposium );
+               this.symposium = new this.Symposium( this.master );
+       },
+       save: function(){
+               var l = this.$location;
+               this.symposium.$save(function(symposium){
+                       l.hashPath = symposium._id;
+               });
+       }
+};
diff --git a/templates/conference/Symposium.html.ep b/templates/conference/Symposium.html.ep
new file mode 100644 (file)
index 0000000..b51a39b
--- /dev/null
@@ -0,0 +1,31 @@
+<script src="/controller/conference/Symposium.js"></script>
+
+<div ng:controller="Symposium">
+
+<h1>Prijava simpozija</h1>
+
+<div ng:show="symposium._id">
+<a href="#{{symposium._id}}">permalink to {{symposium.title}}</a>
+</div>
+
+   Naslov: <input name="symposium.title" size="60"><br/>
+   
+   Sazetak: <br/>
+    <textarea name="symposium.abstract" cols="50" rows="5"></textarea> <br/>
+
+<div ng:repeat="author in symposium.authors">
+[<a href="" ng:click="symposium.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="symposium.authors.$add()">Add another author</a>]
+
+<hr>    
+
+    <input type="submit" value="Save" ng:click="save();" disabled="{{$invalidWidgets}}">
+    <input type="reset" value="Reset" ng:click="reset()">
+       <a href="Symposium">Novi simpozij</a>
+
+</div>
index 4190fb5..253287d 100644 (file)
 <script>
-angular.service('conference', function($resource){
- this.Work = $resource( '/data/conference/Work/' );
-}, {$inject:['$resource'],$creation:'eager'});
 
-function WorkForm(){
+if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug
+
+function Work($resource){
        this.master = {
                type: '',
                title: '',
                abstract: '',
-               authors:[ { name:'', surname:'', inst:'', 'email':'' } ],
+               authors:[ { name:'', surname:'', inst:'', email:'' } ],
+               symposium: { authors: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1, },
        };
-       this.cancel();
+       this.Work = $resource( '/data/conference/Work/:_id', { _id:'' } );
+       this.reset();
+       this.$watch('$location.hashPath', this.hash_change);
 }
-WorkForm.prototype = {
-       cancel: function() {
-               this.work = angular.copy(this.master);
+Work.$inject=['$resource'];
+
+Work.prototype = {
+       hash_change: function() {
+               var id = this.$location.hashPath;
+console.debug( 'hash_change', id, this.work._id );
+               if ( id != this.work._id ) {
+                       if (id) this.work = this.Work.get({ _id: id })
+                       else this.reset();
+               }
        },
-       save: function(){
-               if ( ! this.saved ) {
-                       this.saved = new this.Work( this.work );
-                       console.debug( 'new', this.saved, 'from', this.work );
-                       this.work = this.saved;
+       reset: function() {
+               console.debug( this.Work );
+               var symposium = null;
+               if ( this.work && this.work.type == 'symposium' ) {
+                       symposium = this.work.symposium;
+                       if ( this.work._id ) symposium.work_nr++;
+                       // if is required because reset is called twice -- once with saved records and once with new empty one
+console.debug( 'symposium', symposium, this.work )
                }
-
-               this.work.$save();
-               console.debug( 'work', this.work );
+               this.work = new this.Work( this.master );
+               if ( symposium ) {
+                       this.work.symposium = symposium;
+                       this.work.type = 'symposium';
+               }
+console.debug( 'reset', symposium, this.work, this.$location.hashPath );
+               this.$location.hashPath = '';
+       },
+       save: function(){
+               var l = this.$location;
+               this.work.$save(function(work){
+                       l.hashPath = work._id;
+                       work._changes = -1;     // it seems that save call issues one ng:eval
+               });
        }
 };
+
+
 </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/>
+<h1>Prijava rada</h1>
+
+<div ng:controller="Work" ng:init="$window.$root = this; work._changes = 0" ng:eval="work._changes = work._changes + 1">
+
+<h2>Vrsta rada:</h2>
+<input type="radio" name="work.type" value="symposium"> Simpozij
+
+<div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
+<!--
+<select name="work.symposium_id" ng:show="work.type == 'symposium'" ng:controller="Symposium">
+<option ng:repeat="s in symposiums" value="{{s._id}}">{{s.title}}</option>
+</select>
+-->
+
+Tema simpozija: <input name="work.symposium.title" size="60"><br/>
+   
+Sažetak: <br/>
+<textarea name="work.symposium.abstract" cols="50" rows="5"></textarea> <br/>
+
+Organizator:
+<div ng:repeat="author in work.symposium.authors">
+[<a href="" ng:click="work.symposium.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.symposium.authors.$add()">Add another organizer</a>]
+
+</div>
+
+<br/>
+
+       <input type="radio" name="work.type" value="lecture"> Predavanje <br/>
        <input type="radio" name="work.type" value="poster"> Poster <br/>
        <input type="radio" name="work.type" value="round"> Okrugli stol <br/>
 
-<!--
+<hr>
+
+<h2>Autori <span ng:show="work.type == 'symposium'">{{work.symposium.work_nr}}. </span>rada</h2>
+
 <div ng:repeat="author in work.authors">
-[<a href="#" ng:click="work.authors.$remove(author)">X</a>]
+[<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>]
--->
+[<a href="" ng:click="work.authors.$add()">Add another author</a>]
+<!--
 
     <table>
       <tr>
@@ -61,7 +114,7 @@ work._id={{work._id}}
         <th>email</th>
       </tr>
       <tr ng:repeat="author in work.authors">
-        <td>[<a href="#" ng:click="work.authors.$remove(author)">X</a>]</td>
+        <td>[<a href="" ng:click="work.authors.$remove(author)">X</a>]</td>
         <td><input name="author.name" ng:required></td>
         <td><input name="author.surname" ng:required></td>
         <td><input name="author.inst" ></td>
@@ -76,18 +129,26 @@ work._id={{work._id}}
       </tr>
     </table>
 
+-->
 
 <hr>    
 
 
    Naslov: <input name="work.title" size="60"><br/>
-   
+
    Sazetak: <br/>
     <textarea name="work.abstract" cols="50" rows="5"></textarea> <br/>
-    <input type="submit" value="Save" ng:click="save()" disabled="{{$invalidWidgets}}">
 
+       <span ng:show="$invalidWidgets.visible() == 0">
+    <input type="submit" value="Save" ng:click="work.symposium_id=symposium._id; save();" ng:show="work._changes" title="{{work._changes}} changes">
+    <input type="reset" value="Novi rad" ng:click="reset()" ng:show="work && work._id">
+       </span>
 
+       <b ng:show="$invalidWidgets.visible() &gt; 0" style="color:#800">{{$invalidWidgets.visible()}} errors to fix in submission form</b>
 
+       <div ng:show="work._id">
+       <a href="#{{work._id}}">permalink to {{work.title}}</a>
+       </div>
 
 <hr>
 Debug Information:
@@ -95,4 +156,10 @@ Debug Information:
 <pre>work = {{work}}</pre>
 <pre>master = {{master}}</pre>
 
+<pre>
+$id={{$id}}
+work.$id={{work.$id}}
+work._id={{work._id}}
+</pre>
+
 </div>