2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-10-01 17:54:49 +00:00
|
|
|
*
|
|
|
|
* Whisper.View
|
|
|
|
*
|
|
|
|
* This is the base for most of our views. The Backbone view is extended
|
|
|
|
* with some conveniences:
|
|
|
|
*
|
|
|
|
* 1. Pre-parses all our mustache templates for performance.
|
|
|
|
* https://github.com/janl/mustache.js#pre-parsing-and-caching-templates
|
|
|
|
*
|
|
|
|
* 2. Defines a default definition for render() which allows sub-classes
|
|
|
|
* to simply specify a templateName and renderAttributes which are plugged
|
|
|
|
* into Mustache.render
|
|
|
|
*
|
|
|
|
* 3. Makes all the templates available for rendering as partials.
|
|
|
|
* https://github.com/janl/mustache.js#partials
|
|
|
|
*
|
|
|
|
* 4. Provides some common functionality, e.g. confirmation dialog
|
|
|
|
*
|
2015-03-05 23:25:49 +00:00
|
|
|
*/
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
|
|
|
Whisper.View = Backbone.View.extend({
|
|
|
|
constructor: function() {
|
|
|
|
Backbone.View.apply(this, arguments);
|
|
|
|
Mustache.parse(_.result(this, 'template'));
|
|
|
|
},
|
2015-03-07 01:05:36 +00:00
|
|
|
render_attributes: function() {
|
2015-03-05 23:25:49 +00:00
|
|
|
return _.result(this.model, 'attributes', {});
|
|
|
|
},
|
2015-03-23 21:01:18 +00:00
|
|
|
render_partials: function() {
|
2015-09-03 20:22:52 +00:00
|
|
|
return Whisper.View.Templates;
|
2015-03-23 21:01:18 +00:00
|
|
|
},
|
2015-09-04 20:06:17 +00:00
|
|
|
template: function() {
|
|
|
|
if (this.templateName) {
|
|
|
|
return Whisper.View.Templates[this.templateName];
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
},
|
2015-03-05 23:25:49 +00:00
|
|
|
render: function() {
|
2015-03-07 01:05:36 +00:00
|
|
|
var attrs = _.result(this, 'render_attributes', {});
|
2015-03-05 23:25:49 +00:00
|
|
|
var template = _.result(this, 'template', '');
|
2015-03-23 21:01:18 +00:00
|
|
|
var partials = _.result(this, 'render_partials', '');
|
|
|
|
this.$el.html(Mustache.render(template, attrs, partials));
|
2015-03-05 23:25:49 +00:00
|
|
|
return this;
|
2015-03-23 21:01:18 +00:00
|
|
|
},
|
Full export, migration banner, and full migration workflow - behind flag (#1342)
* Add support for backup and restore
This first pass works for all stores except messages, pending some scaling
improvements.
// FREEBIE
* Import of messages and attachments
Properly sanitize filenames. Logging information that will help with
debugging but won't threaten privacy (no contact or group names),
where the on-disk directories have this information to make things
human-readable
FREEBIE
* First fully operational single-action export and import!
FREEBIE
* Add migration export flow
A banner alert leads to a blocking ui for the migration. We close the socket and
wait for incoming messages to drain before starting the export.
FREEBIE
* A number of updates for the export flow
1. We don't immediately pop the directory selection dialog box, instead
showing an explicit 'choose directory' button after explaining what is
about to happen
2. We show a 'submit debug log' button on most steps of the process
3. We handle export errors and encourage the user to double-check their
filesystem then submit their log
4. We are resilient to restarts during the process
5. We handle the user cancelling out of the directory selection dialog
differently from other errors.
6. The export process is now serialized: non-messages, then messages.
7. After successful export, show where the data is on disk
FREEBUE
* Put migration behind a flag
FREEBIE
* Shut down websocket before proceeding with export
FREEBIE
* Add MigrationView to test/index.html to fix test
FREEBIE
* Remove 'Submit Debug Log' button when the export process is complete
FREEBIE
* Create a 'Signal Export' directory below user-chosen dir
This cleans things up a bit so we don't litter the user's target
directory with lots of stuff.
FREEBIE
* Clarify MessageReceiver.drain() method comments
FREEBIE
* A couple updates for clarity - event names, else handling
Also the removal of wait(), which wasn't used anywhere.
FREEBIE
* A number of wording updates for the export flow
FREEBIE
* Export complete: put dir on its own line, make text selectable
FREEBIE
2017-08-28 20:06:10 +00:00
|
|
|
confirm: function(message, okText) {
|
2015-05-26 23:54:21 +00:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
var dialog = new Whisper.ConfirmationDialogView({
|
|
|
|
message: message,
|
Full export, migration banner, and full migration workflow - behind flag (#1342)
* Add support for backup and restore
This first pass works for all stores except messages, pending some scaling
improvements.
// FREEBIE
* Import of messages and attachments
Properly sanitize filenames. Logging information that will help with
debugging but won't threaten privacy (no contact or group names),
where the on-disk directories have this information to make things
human-readable
FREEBIE
* First fully operational single-action export and import!
FREEBIE
* Add migration export flow
A banner alert leads to a blocking ui for the migration. We close the socket and
wait for incoming messages to drain before starting the export.
FREEBIE
* A number of updates for the export flow
1. We don't immediately pop the directory selection dialog box, instead
showing an explicit 'choose directory' button after explaining what is
about to happen
2. We show a 'submit debug log' button on most steps of the process
3. We handle export errors and encourage the user to double-check their
filesystem then submit their log
4. We are resilient to restarts during the process
5. We handle the user cancelling out of the directory selection dialog
differently from other errors.
6. The export process is now serialized: non-messages, then messages.
7. After successful export, show where the data is on disk
FREEBUE
* Put migration behind a flag
FREEBIE
* Shut down websocket before proceeding with export
FREEBIE
* Add MigrationView to test/index.html to fix test
FREEBIE
* Remove 'Submit Debug Log' button when the export process is complete
FREEBIE
* Create a 'Signal Export' directory below user-chosen dir
This cleans things up a bit so we don't litter the user's target
directory with lots of stuff.
FREEBIE
* Clarify MessageReceiver.drain() method comments
FREEBIE
* A couple updates for clarity - event names, else handling
Also the removal of wait(), which wasn't used anywhere.
FREEBIE
* A number of wording updates for the export flow
FREEBIE
* Export complete: put dir on its own line, make text selectable
FREEBIE
2017-08-28 20:06:10 +00:00
|
|
|
okText: okText,
|
2015-05-26 23:54:21 +00:00
|
|
|
resolve: resolve,
|
|
|
|
reject: reject
|
|
|
|
});
|
2017-05-18 22:30:51 +00:00
|
|
|
this.$el.append(dialog.el);
|
2015-05-26 23:54:21 +00:00
|
|
|
}.bind(this));
|
2016-01-17 10:54:34 +00:00
|
|
|
},
|
2016-09-27 20:33:03 +00:00
|
|
|
i18n_with_links: function() {
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
for (var i=1; i < args.length; ++i) {
|
|
|
|
args[i] = 'class="link" href="' + encodeURI(args[i]) + '" target="_blank"';
|
|
|
|
}
|
|
|
|
return i18n(args[0], args.slice(1));
|
2015-05-26 23:54:21 +00:00
|
|
|
}
|
2015-09-03 20:22:52 +00:00
|
|
|
},{
|
|
|
|
// Class attributes
|
|
|
|
Templates: (function() {
|
|
|
|
var templates = {};
|
|
|
|
$('script[type="text/x-tmpl-mustache"]').each(function(i, el) {
|
|
|
|
var $el = $(el);
|
2015-09-04 20:06:17 +00:00
|
|
|
var id = $el.attr('id');
|
2015-09-03 20:22:52 +00:00
|
|
|
templates[id] = $el.html();
|
|
|
|
});
|
|
|
|
return templates;
|
|
|
|
}())
|
2015-03-05 23:25:49 +00:00
|
|
|
});
|
|
|
|
})();
|