[PE] Refactoring loading of languages: use MenuSimple component

This commit is contained in:
Julia Radzhabova 2019-08-10 17:40:57 +03:00
parent a50379abc6
commit ebe23a3dae
3 changed files with 52 additions and 74 deletions

View file

@ -741,7 +741,6 @@ define([
}; };
this.changeLanguageMenu = function(menu) { this.changeLanguageMenu = function(menu) {
var i;
if (me._currLang.id===null || me._currLang.id===undefined) { if (me._currLang.id===null || me._currLang.id===undefined) {
menu.clearAll(); menu.clearAll();
} else { } else {

View file

@ -692,21 +692,11 @@ define([
}; };
this.changeLanguageMenu = function(menu) { this.changeLanguageMenu = function(menu) {
var i;
if (me._currLang.id===null || me._currLang.id===undefined) { if (me._currLang.id===null || me._currLang.id===undefined) {
for (i=0; i<menu.items.length; i++) menu.clearAll();
menu.items[i].setChecked(false);
menu.currentCheckedItem = undefined;
} else { } else {
for (i=0; i<menu.items.length; i++) { var index = _.findIndex(menu.items, {langid: me._currLang.id});
if (menu.items[i].options.langid === me._currLang.id) { (index>-1) && !menu.items[index].checked && menu.setChecked(index, true);
menu.currentCheckedItem = menu.items[i];
if (!menu.items[i].checked)
menu.items[i].setChecked(true);
break;
} else if (menu.items[i].checked)
menu.items[i].setChecked(false);
}
} }
}; };
@ -2152,13 +2142,21 @@ define([
}) })
}); });
var langTemplate = _.template([
'<a id="<%= id %>" tabindex="-1" type="menuitem" style="padding-left: 28px !important;" langval="<%= value %>" class="<% if (checked) { %> checked <% } %>">',
'<i class="icon <% if (spellcheck) { %> img-toolbarmenu spellcheck-lang <% } %>"></i>',
'<%= caption %>',
'</a>'
].join(''));
me.langTableMenu = new Common.UI.MenuItem({ me.langTableMenu = new Common.UI.MenuItem({
caption : me.langText, caption : me.langText,
menu : new Common.UI.Menu({ menu : new Common.UI.MenuSimple({
cls: 'lang-menu', cls: 'lang-menu',
menuAlign: 'tl-tr', menuAlign: 'tl-tr',
restoreHeight: 300, restoreHeight: 300,
items : [], items : [],
itemTemplate: langTemplate,
search: true search: true
}) })
}); });
@ -2221,11 +2219,12 @@ define([
me.langParaMenu = new Common.UI.MenuItem({ me.langParaMenu = new Common.UI.MenuItem({
caption : me.langText, caption : me.langText,
menu : new Common.UI.Menu({ menu : new Common.UI.MenuSimple({
cls: 'lang-menu', cls: 'lang-menu',
menuAlign: 'tl-tr', menuAlign: 'tl-tr',
restoreHeight: 300, restoreHeight: 300,
items : [], items : [],
itemTemplate: langTemplate,
search: true search: true
}) })
}); });
@ -3324,60 +3323,40 @@ define([
setLanguages: function(langs){ setLanguages: function(langs){
var me = this; var me = this;
if (langs && langs.length > 0 && me.langParaMenu && me.langTableMenu) { if (langs && langs.length > 0 && me.langParaMenu && me.langTableMenu) {
me.langParaMenu.menu.removeAll(); var arrPara = [], arrTable = [];
me.langTableMenu.menu.removeAll(); _.each(langs, function(lang) {
_.each(langs, function(lang, index){ var item = {
me.langParaMenu.menu.addItem(new Common.UI.MenuItem({
caption : lang.displayValue, caption : lang.displayValue,
value : lang.value, value : lang.value,
checkable : true, checkable : true,
toggleGroup : 'popupparalang',
langid : lang.code, langid : lang.code,
spellcheck : lang.spellcheck, spellcheck : lang.spellcheck
template: _.template([ };
'<a id="<%= id %>" tabindex="-1" type="menuitem" style="padding-left: 28px !important;" langval="<%= options.value %>">', arrPara.push(item);
'<i class="icon <% if (options.spellcheck) { %> img-toolbarmenu spellcheck-lang <% } %>"></i>', arrTable.push(_.clone(item));
'<%= caption %>', });
'</a>' me.langParaMenu.menu.resetItems(arrPara);
].join('')) me.langTableMenu.menu.resetItems(arrTable);
}).on('click', function(item, e){
if (me.api){
if (!_.isUndefined(item.options.langid))
me.api.put_TextPrLang(item.options.langid);
me._currLang.paraid = item.options.langid; me.langParaMenu.menu.on('item:click', function(menu, item){
me.langParaMenu.menu.currentCheckedItem = item; if (me.api){
if (!_.isUndefined(item.langid))
me.api.put_TextPrLang(item.langid);
me.fireEvent('editcomplete', me); me._currLang.paraid = item.langid;
} me.fireEvent('editcomplete', me);
})); }
});
me.langTableMenu.menu.addItem(new Common.UI.MenuItem({ me.langTableMenu.menu.on('item:click', function(menu, item, e){
caption : lang.displayValue, if (me.api){
value : lang.value, if (!_.isUndefined(item.langid))
checkable : true, me.api.put_TextPrLang(item.langid);
toggleGroup : 'popuptablelang',
langid : lang.code,
spellcheck : lang.spellcheck,
template: _.template([
'<a id="<%= id %>" tabindex="-1" type="menuitem" style="padding-left: 28px !important;" langval="<%= options.value %>">',
'<i class="icon <% if (options.spellcheck) { %> img-toolbarmenu spellcheck-lang <% } %>"></i>',
'<%= caption %>',
'</a>'
].join(''))
}).on('click', function(item, e){
if (me.api){
if (!_.isUndefined(item.options.langid))
me.api.put_TextPrLang(item.options.langid);
me._currLang.tableid = item.options.langid; me._currLang.tableid = item.langid;
me.langTableMenu.menu.currentCheckedItem = item; me.fireEvent('editcomplete', me);
}
me.fireEvent('editcomplete', me);
}
}));
}); });
} }
}, },

View file

@ -69,7 +69,7 @@ define([
Common.Utils.String.format(this.pageIndexText, model.get('current'), model.get('count')) ); Common.Utils.String.format(this.pageIndexText, model.get('current'), model.get('count')) );
} }
function _clickLanguage(menu, item, state) { function _clickLanguage(menu, item) {
var $parent = menu.$el.parent(); var $parent = menu.$el.parent();
$parent.find('#status-label-lang').text(item.caption); $parent.find('#status-label-lang').text(item.caption);
this.langMenu.prevTip = item.value.value; this.langMenu.prevTip = item.value.value;
@ -248,14 +248,14 @@ define([
this.btnPreview.render($('#slot-status-btn-preview')); this.btnPreview.render($('#slot-status-btn-preview'));
var panelLang = $('.cnt-lang',this.el); var panelLang = $('.cnt-lang',this.el);
this.langMenu = new Common.UI.Menu({ this.langMenu = new Common.UI.MenuSimple({
cls: 'lang-menu', cls: 'lang-menu',
style: 'margin-top:-5px;', style: 'margin-top:-5px;',
restoreHeight: 300, restoreHeight: 300,
itemTemplate: _.template([ itemTemplate: _.template([
'<a id="<%= id %>" tabindex="-1" type="menuitem" style="padding-left: 28px !important;" langval="<%= options.value.value %>">', '<a id="<%= id %>" tabindex="-1" type="menuitem" style="padding-left: 28px !important;" langval="<%= value.value %>" class="<% if (checked) { %> checked <% } %>">',
'<i class="icon <% if (options.spellcheck) { %> img-toolbarmenu spellcheck-lang <% } %>"></i>', '<i class="icon <% if (spellcheck) { %> img-toolbarmenu spellcheck-lang <% } %>"></i>',
'<%= caption %>', '<%= caption %>',
'</a>' '</a>'
].join('')), ].join('')),
menuAlign: 'bl-tl', menuAlign: 'bl-tl',
@ -328,18 +328,18 @@ define([
}, },
reloadLanguages: function(array) { reloadLanguages: function(array) {
this.langMenu.removeAll(); var arr = [],
saved = this.langMenu.saved;
_.each(array, function(item) { _.each(array, function(item) {
this.langMenu.addItem({ arr.push({
caption : item['displayValue'], caption : item['displayValue'],
value : {value: item['value'], code: item['code']}, value : {value: item['value'], code: item['code']},
checkable : true, checkable : true,
checked : this.langMenu.saved == item['displayValue'], checked : saved == item['displayValue'],
spellcheck : item['spellcheck'], spellcheck : item['spellcheck']
toggleGroup : 'language'
}); });
}, this); });
this.langMenu.resetItems(arr);
if (this.langMenu.items.length>0) { if (this.langMenu.items.length>0) {
this.btnLanguage.setDisabled(false || this._state.no_paragraph); this.btnLanguage.setDisabled(false || this._state.no_paragraph);
} }
@ -357,7 +357,7 @@ define([
this.langMenu.saved = info.displayValue; this.langMenu.saved = info.displayValue;
this.langMenu.clearAll(); this.langMenu.clearAll();
} else } else
this.langMenu.items[index].setChecked(true); this.langMenu.setChecked(index, true);
} }
}, },