3 if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug
5 function Work($resource){
10 authors:[ { name:'', surname:'', inst:'', email:'' } ],
11 symposium: { authors: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1, },
14 this.Work = $resource( '/data/conference/Work/:_id', { _id:'' } );
15 this.Symposium = $resource( '/data/conference/Symposium/:_id', { _id:'' } );
17 this.$watch('$location.hashPath', this.hash_change);
19 Work.$inject=['$resource'];
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 ) {
28 this.work = this.Work.get({ _id: id }, function(work) {
30 if ( work.symposium._id ) {
31 self.symposium = self.Symposium.get({ _id: work.symposium._id }, function() { self.work._changes-- });
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 )
47 this.work = new this.Work( this.master );
48 if ( current_symposium ) {
49 this.work.symposium = current_symposium;
50 this.work.type = 'symposium';
52 console.debug( 'reset', current_symposium, this.work, this.$location.hashPath );
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
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 = [];
67 self.symposium.works[ work.symposium.work_nr - 1 ] = work;
68 console.debug('save_symposium', self.symposium );
69 self.symposium.$save(function() { work._changes-- });
72 get_symposium: function() { this.symposium },
80 <div ng:controller="Work" ng:init="$window.$root = this; work._changes = 0" ng:eval="work._changes = work._changes + 1">
83 <input type="radio" name="work.type" value="symposium"> Simpozij
85 <div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
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>
92 Tema simpozija: <input name="work.symposium.title" size="60" ng:required><br/>
95 <textarea name="work.symposium.abstract" cols="50" rows="5"></textarea> <br/>
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>
105 [<a href="" ng:click="work.symposium.authors.$add()">Add another organizer</a>]
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/>
117 <div ng:show="symposium">
118 Radovi prijavljeni u ovom simpoziju:
120 <li ng:repeat="w in symposium.works"><a href="#{{w._id}}">{{w.title}}</a></li>
125 <h2>Autori <span ng:show="work.type == 'symposium'">{{work.symposium.work_nr}}. </span>rada</h2>
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>
134 [<a href="" ng:click="work.authors.$add()">Add another author</a>]
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>
154 <td>[<a href="" ng:click="work.authors.$add()">Add another author</a>]</td>
166 Naslov: <input name="work.title" size="60" ng:required><br/>
169 <textarea name="work.abstract" cols="50" rows="5"></textarea> <br/>
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">
176 <b ng:show="$invalidWidgets.visible() > 0" style="color:#800">{{$invalidWidgets.visible()}} errors to fix in submission form</b>
178 <div ng:show="work._id">
179 <a href="#{{work._id}}">permalink to {{work.title}}</a>
184 {{$window.location.href}}
185 <pre>work = {{work}}</pre>
186 <pre>master = {{master}}</pre>
190 work.$id={{work.$id}}
191 work._id={{work._id}}