2018-03-05 22:57:23 +00:00
|
|
|
/* global i18n: false */
|
|
|
|
/* global Whisper: false */
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
2018-03-05 22:54:33 +00:00
|
|
|
'use strict';
|
2015-09-16 06:28:00 +00:00
|
|
|
|
2018-03-05 22:54:33 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2017-10-04 21:40:35 +00:00
|
|
|
|
2018-03-05 22:54:33 +00:00
|
|
|
Whisper.DebugLogLinkView = Whisper.View.extend({
|
|
|
|
templateName: 'debug-log-link',
|
|
|
|
initialize(options) {
|
|
|
|
this.url = options.url;
|
|
|
|
},
|
|
|
|
render_attributes() {
|
|
|
|
return {
|
|
|
|
url: this.url,
|
|
|
|
reportIssue: i18n('reportIssue'),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
Whisper.DebugLogView = Whisper.View.extend({
|
|
|
|
templateName: 'debug-log',
|
|
|
|
className: 'debug-log modal',
|
|
|
|
initialize() {
|
|
|
|
this.render();
|
|
|
|
this.$('textarea').val(i18n('loading'));
|
2015-09-16 06:28:00 +00:00
|
|
|
|
2018-03-05 22:57:23 +00:00
|
|
|
// eslint-disable-next-line more/no-then
|
2018-04-27 21:25:04 +00:00
|
|
|
window.log.fetch().then(text => {
|
2018-03-05 22:54:33 +00:00
|
|
|
this.$('textarea').val(text);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click .submit': 'submit',
|
|
|
|
'click .close': 'close',
|
|
|
|
},
|
|
|
|
render_attributes: {
|
|
|
|
title: i18n('submitDebugLog'),
|
|
|
|
cancel: i18n('cancel'),
|
|
|
|
submit: i18n('submit'),
|
|
|
|
close: i18n('gotIt'),
|
|
|
|
debugLogExplanation: i18n('debugLogExplanation'),
|
|
|
|
},
|
2018-07-03 22:33:50 +00:00
|
|
|
close() {
|
|
|
|
window.closeDebugLog();
|
2018-03-05 22:54:33 +00:00
|
|
|
},
|
2018-03-05 23:23:59 +00:00
|
|
|
async submit(e) {
|
2018-03-05 22:54:33 +00:00
|
|
|
e.preventDefault();
|
|
|
|
const text = this.$('textarea').val();
|
|
|
|
if (text.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-05 23:23:59 +00:00
|
|
|
|
2018-03-05 22:54:33 +00:00
|
|
|
this.$('.buttons, textarea').remove();
|
|
|
|
this.$('.result').addClass('loading');
|
2018-03-05 23:23:59 +00:00
|
|
|
|
2018-07-19 17:21:53 +00:00
|
|
|
try {
|
|
|
|
const publishedLogURL = await window.log.publish(text);
|
|
|
|
const view = new Whisper.DebugLogLinkView({
|
|
|
|
url: publishedLogURL,
|
|
|
|
el: this.$('.result'),
|
|
|
|
});
|
|
|
|
this.$('.loading').removeClass('loading');
|
|
|
|
view.render();
|
|
|
|
this.$('.link')
|
|
|
|
.focus()
|
|
|
|
.select();
|
|
|
|
} catch (error) {
|
2018-07-21 19:00:08 +00:00
|
|
|
window.log.error(
|
2018-07-19 17:21:53 +00:00
|
|
|
'DebugLogView error:',
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
this.$('.loading').removeClass('loading');
|
|
|
|
this.$('.result').text(i18n('debugLogError'));
|
|
|
|
}
|
2018-03-05 22:54:33 +00:00
|
|
|
},
|
|
|
|
});
|
2018-04-27 21:25:04 +00:00
|
|
|
})();
|