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.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-- });
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 )
50 this.work = new this.Work( this.master );
51 if ( current_symposium ) {
52 this.work.symposium = current_symposium;
53 this.work.type = 'symposium';
55 console.debug( 'reset', current_symposium, this.work, this.$location.hashPath );
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
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 = [];
70 self.symposium.works[ work.symposium.work_nr - 1 ] = work;
71 console.debug('save_symposium', self.symposium );
72 self.symposium.$save(function() { work._changes-- });
75 get_symposium: function() { this.symposium },
83 <div ng:controller="Work" ng:init="$window.$root = this; work._changes = 0" ng:eval="work._changes = work._changes + 1">
86 <label><input type="radio" name="work.type" value="symposium"> Simpozij</label>
88 <div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
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>
95 Tema simpozija: <input name="work.symposium.title" size="60" ng:required><br/>
98 <textarea name="work.symposium.abstract" cols="50" rows="5"></textarea> <br/>
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>
108 [<a href="" ng:click="work.symposium.authors.$add()">Add another organizer</a>]
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/>
120 <div ng:show="symposium">
121 Radovi prijavljeni u ovom simpoziju:
123 <li ng:repeat="w in symposium.works"><a href="#{{w._id}}">{{w.title}}</a></li>
128 <h2>Autori <span ng:show="work.type == 'symposium'">{{work.symposium.work_nr}}. </span>rada</h2>
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>
137 [<a href="" ng:click="work.authors.$add()">Add another author</a>]
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>
157 <td>[<a href="" ng:click="work.authors.$add()">Add another author</a>]</td>
169 Naslov: <input name="work.title" size="60" ng:required><br/>
172 <textarea name="work.abstract" cols="50" rows="5"></textarea> <br/>
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">
179 <b ng:show="$invalidWidgets.visible() > 0" style="color:#800">{{$invalidWidgets.visible()}} errors to fix in submission form</b>
181 <div ng:show="work._id">
182 <a href="#{{work._id}}">permalink to {{work.title}}</a>
187 {{$window.location.href}}
188 <pre>work = {{work}}</pre>
189 <pre>master = {{master}}</pre>
193 work.$id={{work.$id}}
194 work._id={{work._id}}