Refactoring autocorrect dialog
This commit is contained in:
parent
fd76d435e8
commit
387fb8db85
|
@ -45,6 +45,8 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
'common/main/lib/component/Window',
|
||||
'common/main/lib/component/CheckBox'
|
||||
], function (contentTemplate) { 'use strict';
|
||||
var _mathStore = new Common.UI.DataViewStore();
|
||||
var _functionsStore = new Common.UI.DataViewStore();
|
||||
|
||||
Common.Views.AutoCorrectDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({
|
||||
options: {
|
||||
|
@ -90,8 +92,6 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
].join('')
|
||||
}, options || {});
|
||||
|
||||
this.mathStore = this.options.mathStore || new Common.UI.DataViewStore();
|
||||
this.functionsStore = this.options.functionsStore || new Common.UI.DataViewStore();
|
||||
this.api = this.options.api;
|
||||
|
||||
var path = this.appPrefix + "settings-math-correct";
|
||||
|
@ -168,7 +168,7 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
|
||||
this.mathList = new Common.UI.ListView({
|
||||
el: $window.find('#auto-correct-math-list'),
|
||||
store: new Common.UI.DataViewStore(this.mathStore.slice(0, 9)),
|
||||
store: new Common.UI.DataViewStore(_mathStore.slice(0, 9)),
|
||||
simpleAddMode: false,
|
||||
template: _.template(['<div class="listview inner" style=""></div>'].join('')),
|
||||
itemTemplate: _.template([
|
||||
|
@ -251,7 +251,7 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
|
||||
this.mathRecList = new Common.UI.ListView({
|
||||
el: $window.find('#auto-correct-recognized-list'),
|
||||
store: new Common.UI.DataViewStore(this.functionsStore.slice(0, 9)),
|
||||
store: new Common.UI.DataViewStore(_functionsStore.slice(0, 9)),
|
||||
simpleAddMode: false,
|
||||
template: _.template(['<div class="listview inner" style=""></div>'].join('')),
|
||||
itemTemplate: _.template([
|
||||
|
@ -419,9 +419,9 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
$('input', me.inputReplace.cmpEl).select().focus();
|
||||
},delay ? 50 : 0);
|
||||
|
||||
if (me.mathList.store.length < me.mathStore.length) {
|
||||
if (me.mathList.store.length < _mathStore.length) {
|
||||
_.delay(function(){
|
||||
me.mathList.setStore(me.mathStore);
|
||||
me.mathList.setStore(_mathStore);
|
||||
me.mathList.onResetItems();
|
||||
},delay ? 100 : 10);
|
||||
}
|
||||
|
@ -444,7 +444,7 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
this.btnDelete.setCaption(disabled ? this.textRestore : this.textDelete);
|
||||
disabled ? this.api.asc_deleteFromAutoCorrectMathSymbols(rec.get('replaced')) : this.api.asc_AddOrEditFromAutoCorrectMathSymbols(rec.get('replaced'), rec.get('defaultValue'));
|
||||
} else {
|
||||
this.mathStore.remove(rec);
|
||||
_mathStore.remove(rec);
|
||||
this.mathList.scroller && this.mathList.scroller.update({});
|
||||
this.api.asc_deleteFromAutoCorrectMathSymbols(rec.get('replaced'));
|
||||
}
|
||||
|
@ -466,7 +466,7 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
me.mathList.scrollToRecord(record);
|
||||
};
|
||||
if (!rec) {
|
||||
rec = this.mathStore.findWhere({replaced: this.inputReplace.getValue()})
|
||||
rec = _mathStore.findWhere({replaced: this.inputReplace.getValue()})
|
||||
}
|
||||
if (rec) {
|
||||
var idx = _.findIndex(this.arrAdd, function(item){return (item[0]==rec.get('replaced'));});
|
||||
|
@ -496,7 +496,7 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
});
|
||||
|
||||
} else {
|
||||
rec = this.mathStore.add({
|
||||
rec = _mathStore.add({
|
||||
replaced: this.inputReplace.getValue(),
|
||||
by: this.inputBy.getValue(),
|
||||
defaultDisabled: false
|
||||
|
@ -533,8 +533,8 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
this.arrAdd = [];
|
||||
this.arrRem = [];
|
||||
|
||||
this.mathStore.remove(this.mathStore.where({defaultValue: undefined}));
|
||||
this.mathStore.each(function(item, index){
|
||||
_mathStore.remove(_mathStore.where({defaultValue: undefined}));
|
||||
_mathStore.each(function(item, index){
|
||||
item.set('by', item.get('defaultValueStr'));
|
||||
item.set('defaultDisabled', false);
|
||||
});
|
||||
|
@ -547,9 +547,9 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
},
|
||||
|
||||
onInitList: function() {
|
||||
if (this.mathStore.length>0) return;
|
||||
if (_mathStore.length>0) return;
|
||||
|
||||
this.mathStore.comparator = function(item1, item2) {
|
||||
_mathStore.comparator = function(item1, item2) {
|
||||
var n1 = item1.get('replaced').toLowerCase(),
|
||||
n2 = item2.get('replaced').toLowerCase();
|
||||
if (n1==n2) return 0;
|
||||
|
@ -593,14 +593,14 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
changed.by = item[1];
|
||||
}
|
||||
});
|
||||
this.mathStore.reset(data.concat(dataAdd));
|
||||
_mathStore.reset(data.concat(dataAdd));
|
||||
this.updateControls();
|
||||
},
|
||||
|
||||
onInitRecList: function() {
|
||||
if (this.functionsStore.length>0) return;
|
||||
if (_functionsStore.length>0) return;
|
||||
|
||||
this.functionsStore.comparator = function(item1, item2) {
|
||||
_functionsStore.comparator = function(item1, item2) {
|
||||
var n1 = item1.get('value').toLowerCase(),
|
||||
n2 = item2.get('value').toLowerCase();
|
||||
if (n1==n2) return 0;
|
||||
|
@ -630,7 +630,7 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
});
|
||||
}
|
||||
});
|
||||
this.functionsStore.reset(data.concat(dataAdd));
|
||||
_functionsStore.reset(data.concat(dataAdd));
|
||||
this.updateRecControls();
|
||||
},
|
||||
|
||||
|
@ -660,8 +660,8 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
this.arrAddRec = [];
|
||||
this.arrRemRec = [];
|
||||
|
||||
this.functionsStore.remove(this.functionsStore.where({defaultValue: false}));
|
||||
this.functionsStore.each(function(item, index){
|
||||
_functionsStore.remove(_functionsStore.where({defaultValue: false}));
|
||||
_functionsStore.each(function(item, index){
|
||||
item.set('defaultDisabled', false);
|
||||
});
|
||||
this.mathRecList.deselectAll();
|
||||
|
@ -680,9 +680,9 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
$('input', me.inputRecFind.cmpEl).select().focus();
|
||||
},delay ? 50 : 0);
|
||||
|
||||
if (me.mathRecList.store.length < me.functionsStore.length) {
|
||||
if (me.mathRecList.store.length < _functionsStore.length) {
|
||||
_.delay(function(){
|
||||
me.mathRecList.setStore(me.functionsStore);
|
||||
me.mathRecList.setStore(_functionsStore);
|
||||
me.mathRecList.onResetItems();
|
||||
},delay ? 100 : 10);
|
||||
}
|
||||
|
@ -705,7 +705,7 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
this.btnDeleteRec.setCaption(disabled ? this.textRestore : this.textDelete);
|
||||
disabled ? this.api.asc_deleteFromAutoCorrectMathFunctions(rec.get('value')) : this.api.asc_AddFromAutoCorrectMathFunctions(rec.get('value'));
|
||||
} else {
|
||||
this.functionsStore.remove(rec);
|
||||
_functionsStore.remove(rec);
|
||||
this.mathRecList.scroller && this.mathRecList.scroller.update({});
|
||||
this.api.asc_deleteFromAutoCorrectMathFunctions(rec.get('value'));
|
||||
}
|
||||
|
@ -726,11 +726,11 @@ define([ 'text!common/main/lib/template/AutoCorrectDialog.template',
|
|||
me.mathRecList.scrollToRecord(record);
|
||||
};
|
||||
if (!rec) {
|
||||
rec = this.functionsStore.findWhere({value: this.inputRecFind.getValue()})
|
||||
rec = _functionsStore.findWhere({value: this.inputRecFind.getValue()})
|
||||
}
|
||||
if (!rec) {
|
||||
if (/^[A-Z]+$/i.test(this.inputRecFind.getValue())) {
|
||||
rec = this.functionsStore.add({
|
||||
rec = _functionsStore.add({
|
||||
value: this.inputRecFind.getValue(),
|
||||
defaultValue: false,
|
||||
defaultDisabled: false
|
||||
|
|
|
@ -631,13 +631,7 @@ define([
|
|||
},
|
||||
|
||||
autoCorrect: function() {
|
||||
if (!this._mathCorrect)
|
||||
this._mathCorrect = new Common.UI.DataViewStore();
|
||||
if (!this._funcCorrect)
|
||||
this._funcCorrect = new Common.UI.DataViewStore();
|
||||
(new Common.Views.AutoCorrectDialog({
|
||||
mathStore: this._mathCorrect,
|
||||
functionsStore: this._funcCorrect,
|
||||
api: this.api
|
||||
})).show();
|
||||
},
|
||||
|
|
|
@ -543,13 +543,7 @@ define([
|
|||
},
|
||||
|
||||
autoCorrect: function() {
|
||||
if (!this._mathCorrect)
|
||||
this._mathCorrect = new Common.UI.DataViewStore();
|
||||
if (!this._funcCorrect)
|
||||
this._funcCorrect = new Common.UI.DataViewStore();
|
||||
(new Common.Views.AutoCorrectDialog({
|
||||
mathStore: this._mathCorrect,
|
||||
functionsStore: this._funcCorrect,
|
||||
api: this.api
|
||||
})).show();
|
||||
},
|
||||
|
|
|
@ -1443,13 +1443,7 @@ define([
|
|||
},
|
||||
|
||||
autoCorrect: function() {
|
||||
if (!this._mathCorrect)
|
||||
this._mathCorrect = new Common.UI.DataViewStore();
|
||||
if (!this._funcCorrect)
|
||||
this._funcCorrect = new Common.UI.DataViewStore();
|
||||
(new Common.Views.AutoCorrectDialog({
|
||||
mathStore: this._mathCorrect,
|
||||
functionsStore: this._funcCorrect,
|
||||
api: this.api
|
||||
})).show();
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue