X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=templates%2Fconference%2FWork.html.ep;h=e1d73c831cc7125c5ce13518093d40041431cc36;hb=ae2c86229c1cd652560d81af023d07a3a53e0ab1;hp=a0eb396db1458108931127df61e9f73509f22959;hpb=28b421095dcb5d2f0e7ea38df2484d3326d448cc;p=angular-mojolicious.git diff --git a/templates/conference/Work.html.ep b/templates/conference/Work.html.ep index a0eb396..e1d73c8 100644 --- a/templates/conference/Work.html.ep +++ b/templates/conference/Work.html.ep @@ -8,11 +8,11 @@ function Work($resource){ title: '', abstract: '', authors:[ { name:'', surname:'', inst:'', email:'' } ], - symposium: { authors: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1, }, - _changes: 0, + symposium: { organizer: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1, }, }; - this.Work = $resource( '/data/conference/Work/:_id', { _id:'' } ); - this.Symposium = $resource( '/data/conference/Symposium/:_id', { _id:'' } ); + this.last_saved_work = {}; + this.Work = $resource( '/data/conference/Work/:id', { id:'' } ); + this.Symposium = $resource( '/data/conference/Symposium/:id', { id:'' } ); this.reset(); this.$watch('$location.hashPath', this.hash_change); } @@ -21,17 +21,17 @@ Work.$inject=['$resource']; Work.prototype = { hash_change: function() { var id = this.$location.hashPath; -console.debug( 'hash_change', id, this.work._id ); - if ( id != this.work._id ) { +console.debug( 'hash_change', id, this.work.$id ); + if ( id != this.work.$id ) { if (id) { var self = this; - this.work = this.Work.get({ _id: id }, function(work) { - work._changes = -1 + this.work = this.Work.get({ id: id }, function(work) { + self.last_saved_work = angular.copy(work); if ( work.type == 'symposium' ) { - var s_id = work.symposium._id || work._id; - // first work doesn't have symposium._id, but we used same _id + var s_id = work.symposium.$id || work.$id; + // first work doesn't have symposium.$id, but we used same $id console.debug( 'load symposium ', s_id ); - self.symposium = self.Symposium.get({ _id: s_id }, function() { self.work._changes-- }); + self.symposium = self.Symposium.get({ id: s_id }); } }); } @@ -43,8 +43,7 @@ console.debug( 'load symposium ', s_id ); var current_symposium = null; if ( this.work && this.work.type == 'symposium' ) { current_symposium = this.work.symposium; - if ( this.work._id ) current_symposium.work_nr++; - // if is required because reset is called twice -- once with saved records and once with new empty one + if ( this.work.$id ) current_symposium.work_nr++; // only if saved console.debug( 'current_symposium', current_symposium, this.work ) } this.work = new this.Work( this.master ); @@ -52,24 +51,27 @@ console.debug( 'current_symposium', current_symposium, this.work ) this.work.symposium = current_symposium; this.work.type = 'symposium'; } + this.last_saved_work = {}; console.debug( 'reset', current_symposium, this.work, this.$location.hashPath ); }, save: function(){ var self = this; this.work.$save(function(work){ - self.$location.hashPath = work._id; - work._changes = -1; // it seems that save call issues one ng:eval + self.$location.hashPath = work.$id; // save symposium to separate resource - if ( work.type != 'symposium' ) return; - if ( ! self.symposium ) { - self.work.symposium._id = work._id; // reuse _id of first work for symposium - self.symposium = new self.Symposium( work.symposium ); - self.symposium.works = []; + if ( work.type == 'symposium' ) { + if ( ! self.symposium ) { + self.work.symposium.$id = work.$id; // reuse $id of first work for symposium + self.symposium = new self.Symposium( work.symposium ); + self.symposium.works = []; + } + self.symposium.works[ work.symposium.work_nr - 1 ] = work; + console.debug('save_symposium', self.symposium ); + self.symposium.$save(); } - self.symposium.works[ work.symposium.work_nr - 1 ] = work; - console.debug('save_symposium', self.symposium ); - self.symposium.$save(function() { work._changes-- }); + + self.last_saved_work = angular.copy(work); }); }, get_symposium: function() { this.symposium }, @@ -78,120 +80,100 @@ console.debug( 'reset', current_symposium, this.work, this.$location.hashPath ); -
work = {{work}}-
master = {{master}}-
+work = {{work}} + +dirty={{! last_saved_work.$equals(work)}} + +last_saved_work = {{last_saved_work}} + +master = {{master}} + $id={{$id}} work.$id={{work.$id}} -work._id={{work._id}} +work.$id={{work.$id}}