3 if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug
5 function Work($resource){
10 authors:[ { name:'', surname:'', inst:'', email:'' } ],
11 symposium: { organizer: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1, },
13 this.last_saved_work = {};
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) {
29 self.last_saved_work = angular.copy(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 });
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++; // only if saved
47 console.debug( 'current_symposium', current_symposium, this.work )
49 this.work = new this.Work( this.master );
50 if ( current_symposium ) {
51 this.work.symposium = current_symposium;
52 this.work.type = 'symposium';
54 this.last_saved_work = {};
55 console.debug( 'reset', current_symposium, this.work, this.$location.hashPath );
59 this.work.$save(function(work){
60 self.$location.hashPath = work.$id;
62 // save symposium to separate resource
63 if ( work.type == 'symposium' ) {
64 if ( ! self.symposium ) {
65 self.work.symposium.$id = work.$id; // reuse $id of first work for symposium
66 self.symposium = new self.Symposium( work.symposium );
67 self.symposium.works = [];
69 self.symposium.works[ work.symposium.work_nr - 1 ] = work;
70 console.debug('save_symposium', self.symposium );
71 self.symposium.$save();
74 self.last_saved_work = angular.copy(work);
77 get_symposium: function() { this.symposium },
83 <h1>Conference work submission</h1>
85 <div ng:controller="Work" ng:init="$window.$root = this;">
87 <h2>Type of work:</h2>
88 <label><input type="radio" name="work.type" value="symposium"> Symposium</label>
90 <div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
92 <label>Topic of symposium: <input name="work.symposium.title" size="60" ng:required></label><br/>
95 <textarea name="work.symposium.abstract" cols="50" rows="5"></textarea>
100 <div ng:repeat="author in work.symposium.organizer">
101 [<a href="" ng:click="work.symposium.organizer.$remove(author)">X</a>]
102 <input name="author.name" ng:required>
103 <input name="author.surname" ng:required>
104 <input name="author.inst" >
105 <input name="author.email" ng:required>
107 [<a href="" ng:click="work.symposium.organizer.$add()">Add another organizer</a>]
113 <label><input type="radio" name="work.type" value="lecture"> Lecture</label><br/>
114 <label><input type="radio" name="work.type" value="poster"> Poster</label><br/>
115 <label><input type="radio" name="work.type" value="round"> Round table</label><br/>
119 <div ng:show="symposium">
120 Works which are part of this symposium:
122 <li ng:repeat="w in symposium.works">
123 <a ng:show="work.$id != w.$id" href="#{{w.$id}}" >{{w.title}}</a>
124 <b ng:show="work.$id == w.$id">{{w.title}}</b>
130 <h2>Autors<span ng:show="work.type == 'symposium'"> of {{work.symposium.work_nr}}. work </span></h2>
132 <div ng:repeat="author in work.authors">
133 [<a href="" ng:click="work.authors.$remove(author)">X</a>]
134 <input name="author.name" ng:required>
135 <input name="author.surname" ng:required>
136 <input name="author.inst" >
137 <input name="author.email" ng:required>
139 [<a href="" ng:click="work.authors.$add()">Add another author</a>]
144 <label>Title: <input name="work.title" size="60" ng:required></label><br/>
147 <textarea name="work.abstract" cols="50" rows="5"></textarea>
151 <span ng:show="$invalidWidgets.visible() == 0">
152 <input type="submit" value="Save" ng:click="save();" ng:show="! last_saved_work.$equals(work)">
153 <input type="reset" value="Add another work" ng:click="reset()" ng:show="work && work.$id">
156 <b ng:show="$invalidWidgets.visible() > 0" style="color:#800">{{$invalidWidgets.visible()}} errors to fix in submission form</b>
158 <div ng:show="work.$id">
159 Permalink to <a href="#{{work.$id}}">{{work.title}}</a> which you can bookmark
164 {{$window.location.href}}
168 dirty={{! last_saved_work.$equals(work)}}
170 last_saved_work = {{last_saved_work}}
175 work.$id={{work.$id}}
176 work.$id={{work.$id}}