Skip to content

Commit e446f89

Browse files
rueckstiesskangas
authored andcommitted
only listen to share menu when a schema is loaded
1 parent d4e3467 commit e446f89

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/home/collection.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
.modal-content
66
.modal-header
77
button.close(type='button', data-dismiss='modal', aria-label='Close')
8-
span(aria-hidden='true')×
8+
span(aria-hidden='true') ×
99
h4.modal-title Share Schema
1010
.modal-body
1111
p The schema definition in JSON format has been copied to the clipboard.

src/home/collection.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,21 @@ var MongoDBCollectionView = View.extend({
6969
initialize: function() {
7070
this.model = new MongoDBCollection();
7171
app.statusbar.watch(this, this.schema);
72-
debug('app', app);
73-
app.on('menu-share-schema-json', this.shareSchemaRequested.bind(this));
72+
this.listenTo(this.schema, 'sync', this.schemaIsSynced.bind(this));
73+
this.listenTo(this.schema, 'request', this.schemaIsRequested.bind(this));
7474
this.listenToAndRun(this.parent, 'change:ns', this.onCollectionChanged.bind(this));
7575
},
76-
shareSchemaRequested: function() {
76+
schemaIsSynced: function() {
77+
// only listen to share menu events if we have a sync'ed schema
78+
// @todo enable share menu item here
79+
this.listenTo(app, 'menu-share-schema-json', this.onShareSchema.bind(this));
80+
},
81+
schemaIsRequested: function() {
82+
// while a new schema is requested, don't let the user share via the menu option
83+
// @todo disable share menu item here
84+
this.stopListening(app, 'menu-share-schema-json');
85+
},
86+
onShareSchema: function() {
7787
var clipboard = window.require('clipboard');
7888
clipboard.writeText(JSON.stringify(this.schema.serialize(), null, ' '));
7989
$(this.queryByHook('share-schema-confirmation')).modal('show');

0 commit comments

Comments
 (0)