[SSE] Spellcheck refactoring

This commit is contained in:
Julia Radzhabova 2019-08-06 00:03:19 +03:00
parent 3286d33058
commit 5efad36585
2 changed files with 32 additions and 22 deletions

View file

@ -126,12 +126,13 @@ define([
var langs = [], info, var langs = [], info,
allLangs = Common.util.LanguageInfo.getLanguages(); allLangs = Common.util.LanguageInfo.getLanguages();
this.languages.forEach(function (code) { this.languages.forEach(function (code) {
if (allLangs.hasOwnProperty(parseInt(code))) { code = parseInt(code);
info = allLangs[parseInt(code)]; if (allLangs.hasOwnProperty(code)) {
info = allLangs[code];
langs.push({ langs.push({
displayValue: info[1], displayValue: info[1],
shortName: info[0], shortName: info[0],
value: parseInt(code) value: code
}); });
} }
}); });
@ -141,14 +142,15 @@ define([
return 0; return 0;
}); });
combo.setData(langs); combo.setData(langs);
if (value) { var item = combo.store.findWhere({value: value});
var item = combo.store.findWhere({value: value}); if (!item && allLangs[value]) {
combo.setValue(item ? item.get('value') : 0x0409); value = allLangs[value][0].split(/[\-\_]/)[0];
value = combo.getValue(); item = combo.store.find(function(model){
} else { return model.get('shortName').indexOf(value)==0;
value = this.mode.lang ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(this.mode.lang)) : 0x0409; });
combo.setValue(Common.util.LanguageInfo.getLocalLanguageName(value)[1]);
} }
combo.setValue(item ? item.get('value') : langs[0].value);
value = combo.getValue();
} else { } else {
combo.setValue(Common.util.LanguageInfo.getLocalLanguageName(value)[1]); combo.setValue(Common.util.LanguageInfo.getLocalLanguageName(value)[1]);
combo.setDisabled(true); combo.setDisabled(true);
@ -201,19 +203,26 @@ define([
onSpellCheckVariantsFound: function (property) { onSpellCheckVariantsFound: function (property) {
this._currentSpellObj = property; this._currentSpellObj = property;
var word = property.get_Word(); var arr = [],
this.panelSpellcheck.currentWord.setValue(word); word;
if (property) {
var variants = property.get_Variants(), word = property.get_Word();
arr = []; var variants = property.get_Variants();
variants.forEach(function (item) { variants.forEach(function (item) {
var rec = new Common.UI.DataViewModel(); var rec = new Common.UI.DataViewModel();
rec.set({ rec.set({
value: item value: item
});
arr.push(rec);
}); });
arr.push(rec); }
}); this.panelSpellcheck.currentWord.setValue(word || '');
this.panelSpellcheck.suggestionList.store.reset(arr); this.panelSpellcheck.suggestionList.store.reset(arr);
this.panelSpellcheck.currentWord.setDisabled(!word);
this.panelSpellcheck.btnChange.setDisabled(arr.length<1);
this.panelSpellcheck.btnIgnore.setDisabled(!word);
this.panelSpellcheck.btnToDictionary.setDisabled(!word);
this.panelSpellcheck.lblComplete.toggleClass('hidden', !property || !!word);
} }
}, SSE.Controllers.Spellcheck || {})); }, SSE.Controllers.Spellcheck || {}));

View file

@ -58,7 +58,7 @@ define([
'<div id="spellcheck-change" style="width: 105px; display: inline-block; padding-bottom: 16px;"></div><div id="spellcheck-ignore" class="padding-large" style="margin-left: 19px; width: 105px; display: inline-block;"></div>', '<div id="spellcheck-change" style="width: 105px; display: inline-block; padding-bottom: 16px;"></div><div id="spellcheck-ignore" class="padding-large" style="margin-left: 19px; width: 105px; display: inline-block;"></div>',
'<button class="btn btn-text-default" id="spellcheck-add-to-dictionary" style="width: 105px; display: block; margin-bottom: 16px;"><%= scope.txtAddToDictionary %></button>', '<button class="btn btn-text-default" id="spellcheck-add-to-dictionary" style="width: 105px; display: block; margin-bottom: 16px;"><%= scope.txtAddToDictionary %></button>',
'<label class="header"><%= scope.txtDictionaryLanguage %></label><div id="spellcheck-dictionary-language" style="margin-top: 3px; padding-bottom: 16px;"></div>', '<label class="header"><%= scope.txtDictionaryLanguage %></label><div id="spellcheck-dictionary-language" style="margin-top: 3px; padding-bottom: 16px;"></div>',
'<div id="spellcheck-complete" style="display: flex;"><i class="img-commonctrl img-complete" style="display: inline-block;margin-right: 10px;"></i><%= scope.txtComplete %></div>', '<div id="spellcheck-complete" style="display: flex;" class="hidden"><i class="img-commonctrl img-complete" style="display: inline-block;margin-right: 10px;"></i><%= scope.txtComplete %></div>',
'</div>' '</div>'
].join('')), ].join('')),
@ -145,6 +145,7 @@ define([
el: $('#spellcheck-add-to-dictionary') el: $('#spellcheck-add-to-dictionary')
}); });
this.lblComplete = this.$el.find('#spellcheck-complete');
this.trigger('render:after', this); this.trigger('render:after', this);
return this; return this;
}, },