Skip to content

Commit

Permalink
Make PlaceFormView more generic
Browse files Browse the repository at this point in the history
- Removed some assumptions about the form panel
- This is so we can use this in other contexts
  • Loading branch information
atogle committed Jul 1, 2014
1 parent f68b1c7 commit 53ae6b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 7 additions & 10 deletions src/place-form-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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]);
}
});
Expand Down
10 changes: 10 additions & 0 deletions src/streetview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 53ae6b3

Please sign in to comment.