-<script src="/controller/conference/Work.js"></script>
+<script>
-<div ng:controller="Work">
+if (typeof (console) === 'undefined') console = { debug: function() {} }; // mock console.debug
+
+function Work($resource){
+ this.master = {
+ type: '',
+ title: '',
+ 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);
+}
+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 ) {
+ if (id) {
+ var self = this;
+ this.work = this.Work.get({ _id: id }, function(work) {
+ work._changes = -1
+ if ( work.type == 'symposium' ) {
+ 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-- });
+ }
+ });
+ }
+ else this.reset();
+ }
+ },
+ reset: function() {
+ console.debug( this.Work );
+ 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
+console.debug( 'current_symposium', current_symposium, this.work )
+ }
+ this.work = new this.Work( this.master );
+ if ( current_symposium ) {
+ this.work.symposium = current_symposium;
+ this.work.type = 'symposium';
+ }
+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
+
+ // 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 = [];
+ }
+ 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 },
+};
+
+
+</script>
+
+<h1>Prijava rada</h1>
+
+<div ng:controller="Work" ng:init="$window.$root = this; work._changes = 0" ng:eval="work._changes = work._changes + 1">
+
+<h2>Vrsta rada:</h2>
+<input type="radio" name="work.type" value="symposium"> Simpozij
+
+<div ng:show="work.type == 'symposium'" style="background:#f0f0f0">
+<!--
+<select name="work.symposium_id" ng:show="work.type == 'symposium'" ng:controller="Symposium">
+<option ng:repeat="s in symposiums" value="{{s._id}}">{{s.title}}</option>
+</select>
+-->
+
+Tema simpozija: <input name="work.symposium.title" size="60" ng:required><br/>
+
+Sažetak: <br/>
+<textarea name="work.symposium.abstract" cols="50" rows="5"></textarea> <br/>
+
+Organizator:
+<div ng:repeat="author in work.symposium.authors">
+[<a href="" ng:click="work.symposium.authors.$remove(author)">X</a>]
+<input name="author.name" ng:required>
+<input name="author.surname" ng:required>
+<input name="author.inst" >
+<input name="author.email" ng:required>
+</div>
+[<a href="" ng:click="work.symposium.authors.$add()">Add another organizer</a>]
-<div ng:show="work._id">
-<a href="#{{work._id}}">permalink to {{work.title}}</a>
</div>
- <label>Vrsta rada:</label><br/>
- <input type="radio" name="work.type" value="simp"> Simpozij <br/>
- <input type="radio" name="work.type" value="pred"> Predavanje <br/>
+<br/>
+
+ <input type="radio" name="work.type" value="lecture"> Predavanje <br/>
<input type="radio" name="work.type" value="poster"> Poster <br/>
<input type="radio" name="work.type" value="round"> Okrugli stol <br/>
+<hr>
+
+<div ng:show="symposium">
+Radovi prijavljeni u ovom simpoziju:
+<ol>
+<li ng:repeat="w in symposium.works"><a href="#{{w._id}}">{{w.title}}</a></li>
+</ol>
+
+</div>
+
+<h2>Autori <span ng:show="work.type == 'symposium'">{{work.symposium.work_nr}}. </span>rada</h2>
+
<div ng:repeat="author in work.authors">
[<a href="" ng:click="work.authors.$remove(author)">X</a>]
<input name="author.name" ng:required>
<hr>
- Naslov: <input name="work.title" size="60"><br/>
-
+ Naslov: <input name="work.title" size="60" ng:required><br/>
+
Sazetak: <br/>
<textarea name="work.abstract" cols="50" rows="5"></textarea> <br/>
- <input type="submit" value="Save" ng:click="save();" disabled="{{$invalidWidgets}}">
- <input type="reset" value="Reset" ng:click="reset()">
- <a href="Work">Novi rad</a>
+
+ <span ng:show="$invalidWidgets.visible() == 0">
+ <input type="submit" value="Save" ng:click="work.symposium_id=symposium._id; save();" ng:show="work._changes" title="{{work._changes}} changes">
+ <input type="reset" value="Novi rad" ng:click="reset()" ng:show="work && work._id">
+ </span>
+
+ <b ng:show="$invalidWidgets.visible() > 0" style="color:#800">{{$invalidWidgets.visible()}} errors to fix in submission form</b>
+
+ <div ng:show="work._id">
+ <a href="#{{work._id}}">permalink to {{work.title}}</a>
+ </div>
<hr>
Debug Information: