2017-04-12 21:20:56 +00:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
|
|
|
Whisper.AppView = Backbone.View.extend({
|
|
|
|
initialize: function(options) {
|
|
|
|
this.inboxView = null;
|
|
|
|
this.installView = null;
|
2017-04-25 00:59:11 +00:00
|
|
|
},
|
|
|
|
events: {
|
2017-04-25 01:45:18 +00:00
|
|
|
'click .openInstaller': 'openInstaller',
|
|
|
|
'click .openStandalone': 'openStandalone',
|
2017-04-25 00:59:11 +00:00
|
|
|
'openInbox': 'openInbox',
|
2017-04-12 21:20:56 +00:00
|
|
|
},
|
2017-04-19 17:34:19 +00:00
|
|
|
openView: function(view) {
|
|
|
|
this.el.innerHTML = "";
|
|
|
|
this.el.append(view.el);
|
2017-04-25 00:59:11 +00:00
|
|
|
this.delegateEvents();
|
2017-04-19 17:34:19 +00:00
|
|
|
},
|
2017-07-24 15:09:26 +00:00
|
|
|
openDebugLog: function() {
|
|
|
|
this.closeDebugLog();
|
|
|
|
this.debugLogView = new Whisper.DebugLogView();
|
|
|
|
this.debugLogView.$el.appendTo(this.el);
|
|
|
|
},
|
|
|
|
closeDebugLog: function() {
|
|
|
|
if (this.debugLogView) {
|
|
|
|
this.debugLogView.remove();
|
|
|
|
this.debugLogView = null;
|
|
|
|
}
|
|
|
|
},
|
2017-08-08 00:24:59 +00:00
|
|
|
openInstallChoice: function() {
|
|
|
|
this.closeInstallChoice();
|
|
|
|
var installChoice = this.installChoice = new Whisper.InstallChoiceView();
|
|
|
|
|
|
|
|
this.listenTo(installChoice, 'install-new', this.openInstaller.bind(this));
|
|
|
|
this.listenTo(installChoice, 'install-import', this.openImporter.bind(this));
|
|
|
|
|
|
|
|
this.openView(this.installChoice);
|
|
|
|
},
|
|
|
|
closeInstallChoice: function() {
|
|
|
|
if (this.installChoice) {
|
|
|
|
this.installChoice.remove();
|
|
|
|
this.installChoice = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
openImporter: function() {
|
|
|
|
this.closeImporter();
|
|
|
|
this.closeInstallChoice();
|
|
|
|
var importView = this.importView = new Whisper.ImportView();
|
|
|
|
this.listenTo(importView, 'cancel', this.openInstallChoice.bind(this));
|
|
|
|
this.openView(this.importView);
|
|
|
|
},
|
|
|
|
closeImporter: function() {
|
|
|
|
if (this.importView) {
|
|
|
|
this.importView.remove();
|
|
|
|
this.importView = null;
|
|
|
|
}
|
|
|
|
},
|
2017-04-12 21:20:56 +00:00
|
|
|
openInstaller: function() {
|
2017-04-19 17:34:19 +00:00
|
|
|
this.closeInstaller();
|
2017-08-08 00:24:59 +00:00
|
|
|
this.closeInstallChoice();
|
|
|
|
var installView = this.installView = new Whisper.InstallView();
|
|
|
|
this.listenTo(installView, 'cancel', this.openInstallChoice.bind(this));
|
2017-04-19 17:34:19 +00:00
|
|
|
this.openView(this.installView);
|
|
|
|
},
|
2017-08-08 00:24:59 +00:00
|
|
|
closeInstaller: function() {
|
|
|
|
if (this.installView) {
|
|
|
|
this.installView.remove();
|
|
|
|
this.installView = null;
|
|
|
|
}
|
|
|
|
},
|
2017-04-25 00:59:11 +00:00
|
|
|
openStandalone: function() {
|
|
|
|
if (window.config.environment !== 'production') {
|
|
|
|
this.closeInstaller();
|
|
|
|
this.installView = new Whisper.StandaloneRegistrationView();
|
|
|
|
this.openView(this.installView);
|
|
|
|
}
|
2017-04-19 17:34:19 +00:00
|
|
|
},
|
2017-04-12 21:20:56 +00:00
|
|
|
openInbox: function(options) {
|
|
|
|
options = options || {};
|
|
|
|
_.defaults(options, {initialLoadComplete: false});
|
|
|
|
|
|
|
|
console.log('open inbox');
|
2017-04-19 17:34:19 +00:00
|
|
|
this.closeInstaller();
|
2017-04-12 21:20:56 +00:00
|
|
|
|
|
|
|
if (!this.inboxView) {
|
2017-07-29 00:15:41 +00:00
|
|
|
// We create the inbox immediately to make sure we're ready to receive the
|
|
|
|
// empty event after getting down to zero messages in the queue.
|
|
|
|
this.inboxView = new Whisper.InboxView({
|
|
|
|
model: self,
|
|
|
|
window: window,
|
|
|
|
initialLoadComplete: options.initialLoadComplete
|
|
|
|
});
|
2017-04-12 21:20:56 +00:00
|
|
|
return ConversationController.loadPromise().then(function() {
|
2017-04-19 17:34:19 +00:00
|
|
|
this.openView(this.inboxView);
|
2017-04-12 21:20:56 +00:00
|
|
|
}.bind(this));
|
|
|
|
} else {
|
2017-05-02 23:27:26 +00:00
|
|
|
if (!$.contains(this.el, this.inboxView.el)) {
|
2017-04-19 17:34:19 +00:00
|
|
|
this.openView(this.inboxView);
|
2017-04-12 21:20:56 +00:00
|
|
|
}
|
|
|
|
window.focus(); // FIXME
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onEmpty: function() {
|
|
|
|
var view = this.inboxView;
|
|
|
|
if (view) {
|
|
|
|
view.onEmpty();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onProgress: function(count) {
|
|
|
|
var view = this.inboxView;
|
|
|
|
if (view) {
|
|
|
|
view.onProgress(count);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
openConversation: function(conversation) {
|
|
|
|
if (conversation) {
|
|
|
|
this.openInbox().then(function() {
|
2017-04-21 17:14:03 +00:00
|
|
|
this.inboxView.openConversation(null, conversation);
|
2017-04-12 21:20:56 +00:00
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})();
|