show reset button only for saved work
[angular-mojolicious.git] / templates / conference / Work.html.ep
1 <script>
2
3 function Work($resource){
4         this.master = {
5                 type: '',
6                 title: '',
7                 abstract: '',
8                 authors:[ { name:'', surname:'', inst:'', email:'' } ],
9                 symposium: { authors: [ {name:''} ] },
10         };
11         this.Work = $resource( '/data/conference/Work/:_id', { _id:'' } );
12         this.reset();
13         this.$watch('$location.hashPath', this.hash_change);
14 }
15 Work.$inject=['$resource'];
16
17 Work.prototype = {
18         hash_change: function() {
19                 var id = this.$location.hashPath;
20 console.debug( 'hash_change', id, this.work._id );
21                 if ( id != this.work._id ) {
22                         if (id) this.work = this.Work.get({ _id: id })
23                         else this.reset();
24                 }
25         },
26         reset: function() {
27                 console.debug( this.Work );
28                 var symposium = null;
29                 if ( this.work && this.work.type == 'symposium' ) symposium = this.work.symposium;
30                 this.work = new this.Work( this.master );
31                 if ( symposium ) {
32                         this.work.symposium = symposium;
33                         this.work.type = 'symposium';
34                 }
35 console.debug( 'reset', symposium, this.work, this.$location.hashPath );
36                 this.$location.hashPath = '';
37         },
38         save: function(){
39                 var l = this.$location;
40                 this.work.$save(function(work){
41                         l.hashPath = work._id;
42                 });
43         }
44 };
45
46
47 </script>
48
49 <h1>Prijava rada</h1>
50
51 <div ng:controller="Work" ng:init="$window.$root = this">
52
53 <h2>Vrsta rada:</h2>
54 <input type="radio" name="work.type" value="symposium"> Simpozij
55
56 <div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
57 <!--
58 <select name="work.symposium_id" ng:show="work.type == 'symposium'" ng:controller="Symposium">
59 <option ng:repeat="s in symposiums" value="{{s._id}}">{{s.title}}</option>
60 </select>
61 -->
62
63 Tema simpozija: <input name="work.symposium.title" size="60"><br/>
64    
65 Sažetak: <br/>
66 <textarea name="work.symposium.abstract" cols="50" rows="5"></textarea> <br/>
67
68 Organizator:
69 <div ng:repeat="author in work.symposium.authors">
70 [<a href="" ng:click="work.symposium.authors.$remove(author)">X</a>]
71 <input name="author.name" ng:required>
72 <input name="author.surname" ng:required>
73 <input name="author.inst" >
74 <input name="author.email" ng:required>
75 </div>
76 [<a href="" ng:click="work.symposium.authors.$add()">Add another organizer</a>]
77
78 </div>
79
80 <br/>
81
82         <input type="radio" name="work.type" value="lecture"> Predavanje <br/>
83         <input type="radio" name="work.type" value="poster"> Poster <br/>
84         <input type="radio" name="work.type" value="round"> Okrugli stol <br/>
85
86 <hr>
87
88 <h2>Autori rada</h2>
89
90 <div ng:repeat="author in work.authors">
91 [<a href="" ng:click="work.authors.$remove(author)">X</a>]
92 <input name="author.name" ng:required>
93 <input name="author.surname" ng:required>
94 <input name="author.inst" >
95 <input name="author.email" ng:required>
96 </div>
97 [<a href="" ng:click="work.authors.$add()">Add another author</a>]
98 <!--
99
100     <table>
101       <tr>
102         <th> </th>
103         <th>Ime</th>
104         <th>Prezime</th>
105         <th>Ustanova</th>
106         <th>email</th>
107       </tr>
108       <tr ng:repeat="author in work.authors">
109         <td>[<a href="" ng:click="work.authors.$remove(author)">X</a>]</td>
110         <td><input name="author.name" ng:required></td>
111         <td><input name="author.surname" ng:required></td>
112         <td><input name="author.inst" ></td>
113         <td><input name="author.email" ng:required></td>
114       </tr>
115       <tr>
116         <td> </td>
117         <td>[<a href="" ng:click="work.authors.$add()">Add another author</a>]</td>
118         <td> </td>
119         <td> </td>
120         <td> </td>
121       </tr>
122     </table>
123
124 -->
125
126 <hr>    
127
128
129    Naslov: <input name="work.title" size="60"><br/>
130
131    Sazetak: <br/>
132     <textarea name="work.abstract" cols="50" rows="5"></textarea> <br/>
133     <input type="submit" value="Save" ng:click="work.symposium_id=symposium._id; save();" disabled="{{$invalidWidgets}}">
134     <input type="reset" value="Novi rad" ng:click="reset()" ng:show="work && work._id">
135
136         <div ng:show="work._id">
137         <a href="#{{work._id}}">permalink to {{work.title}}</a>
138         </div>
139
140 <hr>
141 Debug Information:
142 {{$window.location.href}}
143 <pre>work = {{work}}</pre>
144 <pre>master = {{master}}</pre>
145
146 <pre>
147 $id={{$id}}
148 work.$id={{work.$id}}
149 work._id={{work._id}}
150 </pre>
151
152 </div>