[DE] Add warnings when change autocorrection

This commit is contained in:
Julia Radzhabova 2020-07-24 20:13:41 +03:00
parent 58d61f4d87
commit 5785527607

View file

@ -48,6 +48,7 @@ define([
Common.Views.AutoCorrectDialog = Common.UI.Window.extend(_.extend({ Common.Views.AutoCorrectDialog = Common.UI.Window.extend(_.extend({
options: { options: {
width: 448, width: 448,
height: 444,
cls: 'modal-dlg', cls: 'modal-dlg',
buttons: null buttons: null
}, },
@ -302,21 +303,42 @@ define([
onEdit: function() { onEdit: function() {
var rec = this.mathList.getSelectedRec(), var rec = this.mathList.getSelectedRec(),
by = ''; by = '',
me = this,
applySettings = function(by) {
var path = me.appPrefix + "settings-math-correct-add";
var val = JSON.stringify(me.arrAdd);
Common.Utils.InternalSettings.set(path, val);
Common.localStorage.setItem(path, val);
me.api.asc_AddOrEditFromAutoCorrectMathSymbols(rec.get('replaced'), by);
};
if (rec) { if (rec) {
var idx = _.findIndex(this.arrAdd, function(item){return (item[0]==rec.get('replaced'));}); var idx = _.findIndex(this.arrAdd, function(item){return (item[0]==rec.get('replaced'));});
if (!this.inputBy.getValue() && rec.get('defaultValue') && (rec.get('defaultValueStr')!==rec.get('by'))) {// reset to default var restore = !this.inputBy.getValue() && rec.get('defaultValue') && (rec.get('defaultValueStr')!==rec.get('by'));
by = rec.get('defaultValue'); Common.UI.warning({
rec.set('by', rec.get('defaultValueStr')); width: 500,
(idx>=0) && this.arrAdd.splice(idx, 1); msg: restore ? this.warnRestore.replace('%1', rec.get('replaced')) : this.warnReplace.replace('%1', rec.get('replaced')),
} else { // replace buttons: ['yes', 'no'],
by = this.inputBy.getValue(); primary: 'yes',
rec.set('by', by); callback: _.bind(function(btn, dontshow){
if (idx<0) if (btn == 'yes') {
this.arrAdd.push([rec.get('replaced'), by]); if (restore) {// reset to default
else by = rec.get('defaultValue');
this.arrAdd[idx][1] = by; rec.set('by', rec.get('defaultValueStr'));
} (idx>=0) && this.arrAdd.splice(idx, 1);
} else { // replace
by = this.inputBy.getValue();
rec.set('by', by);
if (idx<0)
this.arrAdd.push([rec.get('replaced'), by]);
else
this.arrAdd[idx][1] = by;
}
applySettings(by);
}
}, this)
});
} else { } else {
rec = this.mathStore.add({ rec = this.mathStore.add({
replaced: this.inputReplace.getValue(), replaced: this.inputReplace.getValue(),
@ -327,17 +349,23 @@ define([
this.mathList.scrollToRecord(rec); this.mathList.scrollToRecord(rec);
by = rec.get('by'); by = rec.get('by');
this.arrAdd.push([rec.get('replaced'), by]); this.arrAdd.push([rec.get('replaced'), by]);
applySettings(by);
} }
var path = this.appPrefix + "settings-math-correct-add";
var val = JSON.stringify(this.arrAdd);
Common.Utils.InternalSettings.set(path, val);
Common.localStorage.setItem(path, val);
this.api.asc_AddOrEditFromAutoCorrectMathSymbols(rec.get('replaced'), by);
}, },
onResetToDefault: function() { onResetToDefault: function() {
this.api.asc_resetToDefaultAutoCorrectMathSymbols(); Common.UI.warning({
this.onResetList(); width: 500,
msg: this.warnReset,
buttons: ['yes', 'no'],
primary: 'yes',
callback: _.bind(function(btn, dontshow){
if (btn == 'yes') {
this.api.asc_resetToDefaultAutoCorrectMathSymbols();
this.onResetList();
}
}, this)
});
}, },
onResetList: function() { onResetList: function() {
@ -354,6 +382,7 @@ define([
this.mathStore.remove(this.mathStore.where({defaultValue: undefined})); this.mathStore.remove(this.mathStore.where({defaultValue: undefined}));
this.mathStore.each(function(item, index){ this.mathStore.each(function(item, index){
item.set('by', item.get('defaultValueStr')); item.set('by', item.get('defaultValueStr'));
item.set('defaultDisabled', false);
}); });
this.mathList.deselectAll(); this.mathList.deselectAll();
if (this.mathList.scroller) { if (this.mathList.scroller) {
@ -424,7 +453,10 @@ define([
textDelete: 'Delete', textDelete: 'Delete',
textRestore: 'Restore', textRestore: 'Restore',
textReset: 'Reset', textReset: 'Reset',
textReplaceType: 'Replace text as you type' textReplaceType: 'Replace text as you type',
warnReset: 'Any autocorrect you added will be removed and the changed ones will be restored to their original values. Do you want to continue?',
warnReplace: 'The autocorrect entry for %1 already exists. Do you want to replace it?',
warnRestore: 'The autocorrect entry for %1 will be reset to its original value. Do you want to continue?'
}, Common.Views.AutoCorrectDialog || {})) }, Common.Views.AutoCorrectDialog || {}))
}); });