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