From: Dobrica Pavlinusic Date: Fri, 5 Nov 2010 00:14:38 +0000 (+0100) Subject: experiment to serialize whole symposium as resource X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=1fdeef215fbda0277bf8b8821b36953c20e9241e;p=angular-mojolicious.git experiment to serialize whole symposium as resource This work well, but doesn't update until save (which is nice indicator that you didn't press save button), but currently doesn't have code (or data in work) to correctly load full symposium data --- diff --git a/templates/conference/Work.html.ep b/templates/conference/Work.html.ep index 253287d..c17aa3c 100644 --- a/templates/conference/Work.html.ep +++ b/templates/conference/Work.html.ep @@ -9,8 +9,10 @@ function Work($resource){ abstract: '', authors:[ { name:'', surname:'', inst:'', email:'' } ], symposium: { authors: [ {name:'', surname:'', inst:'', email:'' } ], work_nr: 1, }, + _changes: 0, }; 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,34 +23,45 @@ Work.prototype = { var id = this.$location.hashPath; console.debug( 'hash_change', id, this.work._id ); if ( id != this.work._id ) { - if (id) this.work = this.Work.get({ _id: id }) + if (id) this.work = this.Work.get({ _id: id }, function(work) { work._changes = -1 }) else this.reset(); } }, reset: function() { console.debug( this.Work ); - var symposium = null; + var current_symposium = null; if ( this.work && this.work.type == 'symposium' ) { - symposium = this.work.symposium; - if ( this.work._id ) symposium.work_nr++; + 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 -console.debug( 'symposium', symposium, this.work ) +console.debug( 'current_symposium', current_symposium, this.work ) } this.work = new this.Work( this.master ); - if ( symposium ) { - this.work.symposium = symposium; + if ( current_symposium ) { + this.work.symposium = current_symposium; this.work.type = 'symposium'; } -console.debug( 'reset', symposium, this.work, this.$location.hashPath ); +console.debug( 'reset', current_symposium, this.work, this.$location.hashPath ); this.$location.hashPath = ''; }, save: function(){ - var l = this.$location; + var self = this; this.work.$save(function(work){ - l.hashPath = work._id; + self.$location.hashPath = work._id; work._changes = -1; // it seems that save call issues one ng:eval + + // save symposium to separate resource + if ( work.type != 'symposium' ) return; + if ( ! self.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(function() { work._changes-- }); }); - } + }, + get_symposium: function() { this.symposium }, }; @@ -68,7 +81,7 @@ console.debug( 'reset', symposium, this.work, this.$location.hashPath ); --> -Tema simpozija:
+Tema simpozija:
Sažetak:

@@ -93,6 +106,14 @@ Organizator:
+
+Radovi prijavljeni u ovom simpoziju: +
    +
  1. {{w.title}}
  2. +
+ +
+

Autori {{work.symposium.work_nr}}. rada

@@ -134,7 +155,7 @@ Organizator:
- Naslov:
+ Naslov:
Sazetak: