Merge branch 'master' of github.com:dpavlin/angular-mojolicious
[angular-mojolicious.git] / templates / conference / Work.html.ep
1 <script>
2
3 if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug
4
5 function Work($resource){
6         this.master = {
7                 type: '',
8                 title: '',
9                 abstract: '',
10                 authors:[ { name:'', surname:'', inst:'', email:'' } ],
11                 symposium: { authors: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1, },
12         };
13         this.Work = $resource( '/data/conference/Work/:_id', { _id:'' } );
14         this.reset();
15         this.$watch('$location.hashPath', this.hash_change);
16 }
17 Work.$inject=['$resource'];
18
19 Work.prototype = {
20         hash_change: function() {
21                 var id = this.$location.hashPath;
22 console.debug( 'hash_change', id, this.work._id );
23                 if ( id != this.work._id ) {
24                         if (id) this.work = this.Work.get({ _id: id })
25                         else this.reset();
26                 }
27         },
28         reset: function() {
29                 console.debug( this.Work );
30                 var symposium = null;
31                 if ( this.work && this.work.type == 'symposium' ) {
32                         symposium = this.work.symposium;
33                         if ( this.work._id ) symposium.work_nr++;
34                         // if is required because reset is called twice -- once with saved records and once with new empty one
35 console.debug( 'symposium', symposium, this.work )
36                 }
37                 this.work = new this.Work( this.master );
38                 if ( symposium ) {
39                         this.work.symposium = symposium;
40                         this.work.type = 'symposium';
41                 }
42 console.debug( 'reset', symposium, this.work, this.$location.hashPath );
43                 this.$location.hashPath = '';
44         },
45         save: function(){
46                 var l = this.$location;
47                 this.work.$save(function(work){
48                         l.hashPath = work._id;
49                         work._changes = -1;     // it seems that save call issues one ng:eval
50                 });
51         }
52 };
53
54
55 </script>
56
57 <h1>Prijava rada</h1>
58
59 <div ng:controller="Work" ng:init="$window.$root = this; work._changes = 0" ng:eval="work._changes = work._changes + 1">
60
61 <h2>Vrsta rada:</h2>
62 <input type="radio" name="work.type" value="symposium"> Simpozij
63
64 <div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
65 <!--
66 <select name="work.symposium_id" ng:show="work.type == 'symposium'" ng:controller="Symposium">
67 <option ng:repeat="s in symposiums" value="{{s._id}}">{{s.title}}</option>
68 </select>
69 -->
70
71 Tema simpozija: <input name="work.symposium.title" size="60"><br/>
72    
73 Sažetak: <br/>
74 <textarea name="work.symposium.abstract" cols="50" rows="5"></textarea> <br/>
75
76 Organizator:
77 <div ng:repeat="author in work.symposium.authors">
78 [<a href="" ng:click="work.symposium.authors.$remove(author)">X</a>]
79 <input name="author.name" ng:required>
80 <input name="author.surname" ng:required>
81 <input name="author.inst" >
82 <input name="author.email" ng:required>
83 </div>
84 [<a href="" ng:click="work.symposium.authors.$add()">Add another organizer</a>]
85
86 </div>
87
88 <br/>
89
90         <input type="radio" name="work.type" value="lecture"> Predavanje <br/>
91         <input type="radio" name="work.type" value="poster"> Poster <br/>
92         <input type="radio" name="work.type" value="round"> Okrugli stol <br/>
93
94 <hr>
95
96 <h2>Autori <span ng:show="work.type == 'symposium'">{{work.symposium.work_nr}}. </span>rada</h2>
97
98 <div ng:repeat="author in work.authors">
99 [<a href="" ng:click="work.authors.$remove(author)">X</a>]
100 <input name="author.name" ng:required>
101 <input name="author.surname" ng:required>
102 <input name="author.inst" >
103 <input name="author.email" ng:required>
104 </div>
105 [<a href="" ng:click="work.authors.$add()">Add another author</a>]
106 <!--
107
108     <table>
109       <tr>
110         <th> </th>
111         <th>Ime</th>
112         <th>Prezime</th>
113         <th>Ustanova</th>
114         <th>email</th>
115       </tr>
116       <tr ng:repeat="author in work.authors">
117         <td>[<a href="" ng:click="work.authors.$remove(author)">X</a>]</td>
118         <td><input name="author.name" ng:required></td>
119         <td><input name="author.surname" ng:required></td>
120         <td><input name="author.inst" ></td>
121         <td><input name="author.email" ng:required></td>
122       </tr>
123       <tr>
124         <td> </td>
125         <td>[<a href="" ng:click="work.authors.$add()">Add another author</a>]</td>
126         <td> </td>
127         <td> </td>
128         <td> </td>
129       </tr>
130     </table>
131
132 -->
133
134 <hr>    
135
136
137    Naslov: <input name="work.title" size="60"><br/>
138
139    Sazetak: <br/>
140     <textarea name="work.abstract" cols="50" rows="5"></textarea> <br/>
141
142         <span ng:show="$invalidWidgets.visible() == 0">
143     <input type="submit" value="Save" ng:click="work.symposium_id=symposium._id; save();" ng:show="work._changes" title="{{work._changes}} changes">
144     <input type="reset" value="Novi rad" ng:click="reset()" ng:show="work && work._id">
145         </span>
146
147         <b ng:show="$invalidWidgets.visible() &gt; 0" style="color:#800">{{$invalidWidgets.visible()}} errors to fix in submission form</b>
148
149         <div ng:show="work._id">
150         <a href="#{{work._id}}">permalink to {{work.title}}</a>
151         </div>
152
153 <hr>
154 Debug Information:
155 {{$window.location.href}}
156 <pre>work = {{work}}</pre>
157 <pre>master = {{master}}</pre>
158
159 <pre>
160 $id={{$id}}
161 work.$id={{work.$id}}
162 work._id={{work._id}}
163 </pre>
164
165 </div>