extract Work controller
[angular-mojolicious.git] / public / data / conference / Work.js
1 angular.service('conference', function($resource){
2  this.Work = $resource( '/data/conference/Work/:_id', { _id:'' } );
3 }, {$inject:['$resource'],$creation:'eager'});
4
5 function Work(){
6         this.master = {
7                 type: '',
8                 title: '',
9                 abstract: '',
10                 authors:[ { name:'', surname:'', inst:'', email:'' } ],
11         };
12         this.reset();
13         this.$watch('$location.hashPath', this.hash_change);
14 }
15
16 Work.prototype = {
17         hash_change: function() {
18                 var id = this.$location.hashPath;
19                 if ( id ) {
20                         this.work = this.Work.get({ _id: id });
21                 }
22         },
23         reset: function() {
24                 this.work = new this.Work( this.master );
25         },
26         save: function(){
27                 var l = this.$location;
28                 this.work.$save(function(work){
29                         l.hashPath = work._id;
30                 });
31         }
32 };