Refactor newly-added ClearDataView in settings_view.js
This commit is contained in:
parent
ef041b29d0
commit
256b87aa7a
2 changed files with 72 additions and 59 deletions
|
@ -23,6 +23,7 @@ test/views/*.js
|
||||||
!js/views/debug_log_view.js
|
!js/views/debug_log_view.js
|
||||||
!js/views/file_input_view.js
|
!js/views/file_input_view.js
|
||||||
!js/views/inbox_view.js
|
!js/views/inbox_view.js
|
||||||
|
!js/views/settings_view.js
|
||||||
!js/database.js
|
!js/database.js
|
||||||
!main.js
|
!main.js
|
||||||
!prepare_build.js
|
!prepare_build.js
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
/*
|
/* global storage: false */
|
||||||
* vim: ts=4:sw=4:expandtab
|
/* global textsecure: false */
|
||||||
*/
|
/* global i18n: false */
|
||||||
|
/* global Whisper: false */
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
const { OS } = window.Signal;
|
const { Database } = window.Whisper;
|
||||||
|
const { OS, Logs } = window.Signal;
|
||||||
const { Settings } = window.Signal.Types;
|
const { Settings } = window.Signal.Types;
|
||||||
|
|
||||||
var CheckboxView = Whisper.View.extend({
|
var CheckboxView = Whisper.View.extend({
|
||||||
|
@ -119,63 +124,70 @@
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var CLEAR_DATA_STEPS = {
|
/* jshint ignore:start */
|
||||||
CHOICE: 1,
|
/* eslint-enable */
|
||||||
DELETING: 2,
|
|
||||||
};
|
|
||||||
var ClearDataView = Whisper.View.extend({
|
|
||||||
templateName: 'clear-data',
|
|
||||||
className: 'full-screen-flow overlay',
|
|
||||||
events: {
|
|
||||||
'click .cancel': 'onCancel',
|
|
||||||
'click .delete-all-data': 'onDeleteAllData',
|
|
||||||
},
|
|
||||||
initialize: function() {
|
|
||||||
this.step = CLEAR_DATA_STEPS.CHOICE;
|
|
||||||
},
|
|
||||||
onCancel: function() {
|
|
||||||
this.remove();
|
|
||||||
},
|
|
||||||
onDeleteAllData: function() {
|
|
||||||
console.log('Deleting everything!');
|
|
||||||
this.step = CLEAR_DATA_STEPS.DELETING;
|
|
||||||
this.render();
|
|
||||||
|
|
||||||
Whisper.Database.close().then(function() {
|
const CLEAR_DATA_STEPS = {
|
||||||
console.log('All database connections closed. Starting delete.');
|
CHOICE: 1,
|
||||||
this.clearAllData();
|
DELETING: 2,
|
||||||
}.bind(this), function(error) {
|
};
|
||||||
console.log('Something went wrong closing all database connections.');
|
const ClearDataView = Whisper.View.extend({
|
||||||
this.clearAllData();
|
templateName: 'clear-data',
|
||||||
}.bind(this));
|
className: 'full-screen-flow overlay',
|
||||||
},
|
events: {
|
||||||
clearAllData: function() {
|
'click .cancel': 'onCancel',
|
||||||
Promise.all([
|
'click .delete-all-data': 'onDeleteAllData',
|
||||||
Signal.Logs.deleteAll(),
|
},
|
||||||
Whisper.Database.drop(),
|
initialize() {
|
||||||
]).then(function() {
|
this.step = CLEAR_DATA_STEPS.CHOICE;
|
||||||
window.restart();
|
},
|
||||||
}, function(error) {
|
onCancel() {
|
||||||
console.log(
|
this.remove();
|
||||||
'Something went wrong deleting all data:',
|
},
|
||||||
error && error.stack ? error.stack : error
|
async onDeleteAllData() {
|
||||||
);
|
console.log('Deleting everything!');
|
||||||
window.restart();
|
this.step = CLEAR_DATA_STEPS.DELETING;
|
||||||
});
|
this.render();
|
||||||
},
|
|
||||||
render_attributes: function() {
|
|
||||||
return {
|
|
||||||
isStep1: this.step === CLEAR_DATA_STEPS.CHOICE,
|
|
||||||
header: i18n('deleteAllDataHeader'),
|
|
||||||
body: i18n('deleteAllDataBody'),
|
|
||||||
cancelButton: i18n('cancel'),
|
|
||||||
deleteButton: i18n('deleteAllDataButton'),
|
|
||||||
|
|
||||||
isStep2: this.step === CLEAR_DATA_STEPS.DELETING,
|
try {
|
||||||
deleting: i18n('deleteAllDataProgress'),
|
await Database.close();
|
||||||
};
|
console.log('All database connections closed. Starting delete.');
|
||||||
}
|
} catch (error) {
|
||||||
});
|
console.log('Something went wrong closing all database connections.');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.clearAllData();
|
||||||
|
},
|
||||||
|
async clearAllData() {
|
||||||
|
try {
|
||||||
|
await Promise.all([
|
||||||
|
Logs.deleteAll(),
|
||||||
|
Database.drop(),
|
||||||
|
]);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(
|
||||||
|
'Something went wrong deleting all data:',
|
||||||
|
error && error.stack ? error.stack : error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.restart();
|
||||||
|
},
|
||||||
|
render_attributes() {
|
||||||
|
return {
|
||||||
|
isStep1: this.step === CLEAR_DATA_STEPS.CHOICE,
|
||||||
|
header: i18n('deleteAllDataHeader'),
|
||||||
|
body: i18n('deleteAllDataBody'),
|
||||||
|
cancelButton: i18n('cancel'),
|
||||||
|
deleteButton: i18n('deleteAllDataButton'),
|
||||||
|
|
||||||
|
isStep2: this.step === CLEAR_DATA_STEPS.DELETING,
|
||||||
|
deleting: i18n('deleteAllDataProgress'),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
/* jshint ignore:end */
|
||||||
|
|
||||||
var SyncView = Whisper.View.extend({
|
var SyncView = Whisper.View.extend({
|
||||||
templateName: 'syncSettings',
|
templateName: 'syncSettings',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue