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: { organizer: [ {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() {
35                                                         self.work._changes--;
36                                                 });
37                                         }
38                                 });
39                         }
40                         else this.reset();
41                 }
42         },
43         reset: function() {
44                 console.debug( this.Work );
45                 var current_symposium = null;
46                 if ( this.work && this.work.type == 'symposium' ) {
47                         current_symposium = this.work.symposium;
48                         if ( this.work._id ) current_symposium.work_nr++; // only if saved
49 console.debug( 'current_symposium', current_symposium, this.work )
50                 }
51                 this.work = new this.Work( this.master );
52                 if ( current_symposium ) {
53                         this.work.symposium = current_symposium;
54                         this.work.type = 'symposium';
55                 }
56 console.debug( 'reset', current_symposium, this.work, this.$location.hashPath );
57         },
58         save: function(){
59                 var self = this;
60                 this.work.$save(function(work){
61                         self.$location.hashPath = work._id;
62                         work._changes = -1;     // it seems that save call issues one ng:eval
63
64                         // save symposium to separate resource
65                         if ( work.type != 'symposium' ) return;
66                         if ( ! self.symposium ) { 
67                                 self.work.symposium._id = work._id; // reuse _id of first work for symposium
68                                 self.symposium = new self.Symposium( work.symposium );
69                                 self.symposium.works = [];
70                         }
71                         self.symposium.works[ work.symposium.work_nr - 1 ] = work;
72         console.debug('save_symposium', self.symposium );
73                         self.symposium.$save(function() { work._changes-- });
74                 });
75         },
76         get_symposium: function() { this.symposium },
77 };
78
79
80 </script>
81
82 <h1>Conference work submission</h1>
83
84 <div ng:controller="Work" ng:init="$window.$root = this; work._changes = 0" ng:eval="work._changes = work._changes + 1">
85
86 <h2>Type of work:</h2>
87 <label><input type="radio" name="work.type" value="symposium"> Symposium</label>
88
89 <div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
90 <!--
91 <select name="work.symposium_id" ng:show="work.type == 'symposium'" ng:controller="Symposium">
92 <option ng:repeat="s in symposiums" value="{{s._id}}">{{s.title}}</option>
93 </select>
94 -->
95
96 <label>Topic of symposium: <input name="work.symposium.title" size="60" ng:required></label><br/>
97    
98 <label>Summary: <br/>
99 <textarea name="work.symposium.abstract" cols="50" rows="5"></textarea>
100 </label>
101 <br/>
102
103 Organizer:
104 <div ng:repeat="author in work.symposium.organizer">
105 [<a href="" ng:click="work.symposium.organizer.$remove(author)">X</a>]
106 <input name="author.name" ng:required>
107 <input name="author.surname" ng:required>
108 <input name="author.inst" >
109 <input name="author.email" ng:required>
110 </div>
111 [<a href="" ng:click="work.symposium.organizer.$add()">Add another organizer</a>]
112
113 </div>
114
115 <br/>
116
117 <label><input type="radio" name="work.type" value="lecture"> Lecture</label><br/>
118 <label><input type="radio" name="work.type" value="poster"> Poster</label><br/>
119 <label><input type="radio" name="work.type" value="round"> Round table</label><br/>
120
121 <hr>
122
123 <div ng:show="symposium">
124 Works which are part of this symposium:
125 <ol>
126 <li ng:repeat="w in symposium.works"><a href="#{{w._id}}">{{w.title}}</a></li>
127 </ol>
128
129 </div>
130
131 <h2>Autors<span ng:show="work.type == 'symposium'"> of {{work.symposium.work_nr}}. work </span></h2>
132
133 <div ng:repeat="author in work.authors">
134 [<a href="" ng:click="work.authors.$remove(author)">X</a>]
135 <input name="author.name" ng:required>
136 <input name="author.surname" ng:required>
137 <input name="author.inst" >
138 <input name="author.email" ng:required>
139 </div>
140 [<a href="" ng:click="work.authors.$add()">Add another author</a>]
141
142 <hr>    
143
144
145 <label>Title: <input name="work.title" size="60" ng:required></label><br/>
146
147 <label>Summary:<br>
148 <textarea name="work.abstract" cols="50" rows="5"></textarea>
149 </label>
150 <br/>
151
152 <span ng:show="$invalidWidgets.visible() == 0">
153 <input type="submit" value="Save" ng:click="work.symposium_id=symposium._id; save();" ng:show="work._changes" title="{{work._changes}} changes">
154 <input type="reset" value="Add another work" ng:click="reset()" ng:show="work && work._id">
155 </span>
156
157 <b ng:show="$invalidWidgets.visible() &gt; 0" style="color:#800">{{$invalidWidgets.visible()}} errors to fix in submission form</b>
158
159 <div ng:show="work._id">
160 Permalink to <a href="#{{work._id}}">{{work.title}}</a> which you can bookmark
161 </div>
162
163 <hr>
164 Debug Information:
165 {{$window.location.href}}
166 <pre>work = {{work}}</pre>
167 <pre>master = {{master}}</pre>
168
169 <pre>
170 $id={{$id}}
171 work.$id={{work.$id}}
172 work._id={{work._id}}
173 </pre>
174
175 </div>