fix database name in view
[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         };
13         this.last_saved_work = {};
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                                         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 });
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++; // only if saved
47 console.debug( 'current_symposium', current_symposium, this.work )
48                 }
49                 this.work = new this.Work( this.master );
50                 if ( current_symposium ) {
51                         this.work.symposium = current_symposium;
52                         this.work.type = 'symposium';
53                 }
54                 this.last_saved_work = {};
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
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 = [];
68                                 }
69                                 self.symposium.works[ work.symposium.work_nr - 1 ] = work;
70                 console.debug('save_symposium', self.symposium );
71                                 self.symposium.$save();
72                         }
73
74                         self.last_saved_work = angular.copy(work);
75                 });
76         },
77         get_symposium: function() { this.symposium },
78 };
79
80
81 </script>
82
83 <h1>Conference work submission</h1>
84
85 <div ng:controller="Work" ng:init="$window.$root = this;">
86
87 <h2>Type of work:</h2>
88 <label><input type="radio" name="work.type" value="symposium"> Symposium</label>
89
90 <div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
91
92 <label>Topic of symposium: <input name="work.symposium.title" size="60" ng:required></label><br/>
93    
94 <label>Summary: <br/>
95 <textarea name="work.symposium.abstract" cols="50" rows="5"></textarea>
96 </label>
97 <br/>
98
99 Organizer:
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 ng:validate="email">
106 </div>
107 [<a href="" ng:click="work.symposium.organizer.$add()">Add another organizer</a>]
108
109 </div>
110
111 <br/>
112
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/>
116
117 <hr>
118
119 <div ng:show="symposium">
120 Works which are part of this symposium:
121 <ol>
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>
125 </li>
126 </ol>
127
128 </div>
129
130 <h2>Autors<span ng:show="work.type == 'symposium'"> of {{work.symposium.work_nr}}. work </span></h2>
131
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 ng:validate="email">
138 </div>
139 [<a href="" ng:click="work.authors.$add()">Add another author</a>]
140
141 <hr>    
142
143
144 <label>Title: <input name="work.title" size="60" ng:required></label><br/>
145
146 <label>Summary:<br>
147 <textarea name="work.abstract" cols="50" rows="5"></textarea>
148 </label>
149 <br/>
150
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">
154 </span>
155
156 <b ng:show="$invalidWidgets.visible() &gt; 0" style="color:#800">{{$invalidWidgets.visible()}} errors to fix in submission form</b>
157
158 <div ng:show="work.$id">
159 Permalink to <a href="#{{work.$id}}">{{work.title}}</a> which you can bookmark
160 </div>
161
162 <hr>
163 Debug Information:
164 {{$window.location.href}}
165 <pre>
166 work = {{work}}
167
168 dirty={{! last_saved_work.$equals(work)}}
169
170 last_saved_work = {{last_saved_work}}
171
172 master = {{master}}
173
174 $id={{$id}}
175 work.$id={{work.$id}}
176 work.$id={{work.$id}}
177 </pre>
178
179 </div>