a0cd25dceea1458d51b5c34d1630cddd2983a2a7
[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                 _changes: 0,
13         };
14         this.Work = $resource( '/data/conference/Work/:_id', { _id:'' } );
15         this.Symposium = $resource( '/data/conference/Symposium/:_id', { _id:'' } );
16         this.reset();
17         this.$watch('$location.hashPath', this.hash_change);
18 }
19 Work.$inject=['$resource'];
20
21 Work.prototype = {
22         hash_change: function() {
23                 var id = this.$location.hashPath;
24 console.debug( 'hash_change', id, this.work._id );
25                 if ( id != this.work._id ) {
26                         if (id) {
27                                 var self = this;
28                                 this.work = this.Work.get({ _id: id }, function(work) {
29                                         work._changes = -1
30                                         if ( work.symposium._id ) {
31                                                 self.symposium = self.Symposium.get({ _id: work.symposium._id }, function() { self.work._changes-- });
32                                         }
33                                 });
34                         }
35                         else this.reset();
36                 }
37         },
38         reset: function() {
39                 console.debug( this.Work );
40                 var current_symposium = null;
41                 if ( this.work && this.work.type == 'symposium' ) {
42                         current_symposium = this.work.symposium;
43                         if ( this.work._id ) current_symposium.work_nr++;
44                         // if is required because reset is called twice -- once with saved records and once with new empty one
45 console.debug( 'current_symposium', current_symposium, this.work )
46                 }
47                 this.work = new this.Work( this.master );
48                 if ( current_symposium ) {
49                         this.work.symposium = current_symposium;
50                         this.work.type = 'symposium';
51                 }
52 console.debug( 'reset', current_symposium, this.work, this.$location.hashPath );
53         },
54         save: function(){
55                 var self = this;
56                 this.work.$save(function(work){
57                         self.$location.hashPath = work._id;
58                         work._changes = -1;     // it seems that save call issues one ng:eval
59
60                         // save symposium to separate resource
61                         if ( work.type != 'symposium' ) return;
62                         if ( ! self.symposium ) { 
63                                 self.work.symposium._id = work._id; // reuse _id of first work for symposium
64                                 self.symposium = new self.Symposium( work.symposium );
65                                 self.symposium.works = [];
66                         }
67                         self.symposium.works[ work.symposium.work_nr - 1 ] = work;
68         console.debug('save_symposium', self.symposium );
69                         self.symposium.$save(function() { work._changes-- });
70                 });
71         },
72         get_symposium: function() { this.symposium },
73 };
74
75
76 </script>
77
78 <h1>Prijava rada</h1>
79
80 <div ng:controller="Work" ng:init="$window.$root = this; work._changes = 0" ng:eval="work._changes = work._changes + 1">
81
82 <h2>Vrsta rada:</h2>
83 <input type="radio" name="work.type" value="symposium"> Simpozij
84
85 <div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
86 <!--
87 <select name="work.symposium_id" ng:show="work.type == 'symposium'" ng:controller="Symposium">
88 <option ng:repeat="s in symposiums" value="{{s._id}}">{{s.title}}</option>
89 </select>
90 -->
91
92 Tema simpozija: <input name="work.symposium.title" size="60" ng:required><br/>
93    
94 Sažetak: <br/>
95 <textarea name="work.symposium.abstract" cols="50" rows="5"></textarea> <br/>
96
97 Organizator:
98 <div ng:repeat="author in work.symposium.authors">
99 [<a href="" ng:click="work.symposium.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.symposium.authors.$add()">Add another organizer</a>]
106
107 </div>
108
109 <br/>
110
111         <input type="radio" name="work.type" value="lecture"> Predavanje <br/>
112         <input type="radio" name="work.type" value="poster"> Poster <br/>
113         <input type="radio" name="work.type" value="round"> Okrugli stol <br/>
114
115 <hr>
116
117 <div ng:show="symposium">
118 Radovi prijavljeni u ovom simpoziju:
119 <ol>
120 <li ng:repeat="w in symposium.works"><a href="#{{w._id}}">{{w.title}}</a></li>
121 </ol>
122
123 </div>
124
125 <h2>Autori <span ng:show="work.type == 'symposium'">{{work.symposium.work_nr}}. </span>rada</h2>
126
127 <div ng:repeat="author in work.authors">
128 [<a href="" ng:click="work.authors.$remove(author)">X</a>]
129 <input name="author.name" ng:required>
130 <input name="author.surname" ng:required>
131 <input name="author.inst" >
132 <input name="author.email" ng:required>
133 </div>
134 [<a href="" ng:click="work.authors.$add()">Add another author</a>]
135 <!--
136
137     <table>
138       <tr>
139         <th> </th>
140         <th>Ime</th>
141         <th>Prezime</th>
142         <th>Ustanova</th>
143         <th>email</th>
144       </tr>
145       <tr ng:repeat="author in work.authors">
146         <td>[<a href="" ng:click="work.authors.$remove(author)">X</a>]</td>
147         <td><input name="author.name" ng:required></td>
148         <td><input name="author.surname" ng:required></td>
149         <td><input name="author.inst" ></td>
150         <td><input name="author.email" ng:required></td>
151       </tr>
152       <tr>
153         <td> </td>
154         <td>[<a href="" ng:click="work.authors.$add()">Add another author</a>]</td>
155         <td> </td>
156         <td> </td>
157         <td> </td>
158       </tr>
159     </table>
160
161 -->
162
163 <hr>    
164
165
166    Naslov: <input name="work.title" size="60" ng:required><br/>
167
168    Sazetak: <br/>
169     <textarea name="work.abstract" cols="50" rows="5"></textarea> <br/>
170
171         <span ng:show="$invalidWidgets.visible() == 0">
172     <input type="submit" value="Save" ng:click="work.symposium_id=symposium._id; save();" ng:show="work._changes" title="{{work._changes}} changes">
173     <input type="reset" value="Novi rad" ng:click="reset()" ng:show="work && work._id">
174         </span>
175
176         <b ng:show="$invalidWidgets.visible() &gt; 0" style="color:#800">{{$invalidWidgets.visible()}} errors to fix in submission form</b>
177
178         <div ng:show="work._id">
179         <a href="#{{work._id}}">permalink to {{work.title}}</a>
180         </div>
181
182 <hr>
183 Debug Information:
184 {{$window.location.href}}
185 <pre>work = {{work}}</pre>
186 <pre>master = {{master}}</pre>
187
188 <pre>
189 $id={{$id}}
190 work.$id={{work.$id}}
191 work._id={{work._id}}
192 </pre>
193
194 </div>