diff --git a/src/map.js b/src/map.js index 2e50abc..40b4935 100644 --- a/src/map.js +++ b/src/map.js @@ -155,6 +155,16 @@ var Shareabouts = Shareabouts || {}; unfocusLayer(layer, styleRule); }); + // Listen for when a form is shown + $(this).on('openplaceform', function(evt, view) { + view.$el.parent().parent().parent().addClass('panel-form-open'); + }); + + // Listen for when a form is hidden + $(this).on('closeplaceform', function(evt, view) { + view.$el.parent().parent().parent().removeClass('panel-form-open'); + }); + // Init add button object $el.on('click', '.shareabouts-add-button', function(evt) { evt.preventDefault(); diff --git a/src/place-form-view.js b/src/place-form-view.js index 98cb4df..1dd9a77 100644 --- a/src/place-form-view.js +++ b/src/place-form-view.js @@ -20,6 +20,10 @@ var Shareabouts = Shareabouts || {}; if (!this.model) { this.model = new NS.PlaceModel(); + // So we know how to make the model url to save. + this.model.collection = this.collection; + } else { + this.setGeometry(this.model.get('geometry')); } if (options.submitter) { @@ -60,22 +64,19 @@ var Shareabouts = Shareabouts || {}; // add loading/busy class this.$el.addClass('loading'); - // So we know how to make the model url to save. - this.model.collection = this.collection; this.model.save(data, { wait: true, // Explicitly set this. IE9 forgets sometimes. crossDomain: true, success: function(evt) { // Cool, now add it to the collection. - self.collection.add(self.model); + if (!self.model.collection) { + self.collection.add(self.model); + } // Create is not a real event, but we want to know when a new thing // is saved. self.collection.trigger('create', self.model); - - // Reset the form after it is saved successfully - self.ui.form.get(0).reset(); }, complete: function(evt) { // enable the submit button @@ -101,13 +102,9 @@ var Shareabouts = Shareabouts || {}; return this; }, onClose: function() { - // ick - this.$el.parent().parent().parent().removeClass('panel-form-open'); $(this.options.umbrella).trigger('closeplaceform', [this]); }, onShow: function() { - // ick - this.$el.parent().parent().parent().addClass('panel-form-open'); $(this.options.umbrella).trigger('showplaceform', [this]); } }); diff --git a/src/streetview.js b/src/streetview.js index ed5b968..6733963 100644 --- a/src/streetview.js +++ b/src/streetview.js @@ -165,6 +165,16 @@ var Shareabouts = Shareabouts || {}; unfocusLayer(marker, styleRule); }); + // Listen for when a form is shown + $(this).on('openplaceform', function(evt, view) { + view.$el.parent().parent().parent().addClass('panel-form-open'); + }); + + // Listen for when a form is hidden + $(this).on('closeplaceform', function(evt, view) { + view.$el.parent().parent().parent().removeClass('panel-form-open'); + }); + // Init add button object $el.on('click', '.shareabouts-add-button', function(evt) { evt.preventDefault();