[PE] Refactoring loading of languages: use MenuSimple component
This commit is contained in:
parent
a50379abc6
commit
ebe23a3dae
|
@ -741,7 +741,6 @@ define([
|
|||
};
|
||||
|
||||
this.changeLanguageMenu = function(menu) {
|
||||
var i;
|
||||
if (me._currLang.id===null || me._currLang.id===undefined) {
|
||||
menu.clearAll();
|
||||
} else {
|
||||
|
|
|
@ -692,21 +692,11 @@ define([
|
|||
};
|
||||
|
||||
this.changeLanguageMenu = function(menu) {
|
||||
var i;
|
||||
if (me._currLang.id===null || me._currLang.id===undefined) {
|
||||
for (i=0; i<menu.items.length; i++)
|
||||
menu.items[i].setChecked(false);
|
||||
menu.currentCheckedItem = undefined;
|
||||
menu.clearAll();
|
||||
} else {
|
||||
for (i=0; i<menu.items.length; i++) {
|
||||
if (menu.items[i].options.langid === me._currLang.id) {
|
||||
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);
|
||||
}
|
||||
var index = _.findIndex(menu.items, {langid: me._currLang.id});
|
||||
(index>-1) && !menu.items[index].checked && menu.setChecked(index, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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({
|
||||
caption : me.langText,
|
||||
menu : new Common.UI.Menu({
|
||||
menu : new Common.UI.MenuSimple({
|
||||
cls: 'lang-menu',
|
||||
menuAlign: 'tl-tr',
|
||||
restoreHeight: 300,
|
||||
items : [],
|
||||
itemTemplate: langTemplate,
|
||||
search: true
|
||||
})
|
||||
});
|
||||
|
@ -2221,11 +2219,12 @@ define([
|
|||
|
||||
me.langParaMenu = new Common.UI.MenuItem({
|
||||
caption : me.langText,
|
||||
menu : new Common.UI.Menu({
|
||||
menu : new Common.UI.MenuSimple({
|
||||
cls: 'lang-menu',
|
||||
menuAlign: 'tl-tr',
|
||||
restoreHeight: 300,
|
||||
items : [],
|
||||
itemTemplate: langTemplate,
|
||||
search: true
|
||||
})
|
||||
});
|
||||
|
@ -3324,60 +3323,40 @@ define([
|
|||
|
||||
setLanguages: function(langs){
|
||||
var me = this;
|
||||
|
||||
if (langs && langs.length > 0 && me.langParaMenu && me.langTableMenu) {
|
||||
me.langParaMenu.menu.removeAll();
|
||||
me.langTableMenu.menu.removeAll();
|
||||
_.each(langs, function(lang, index){
|
||||
me.langParaMenu.menu.addItem(new Common.UI.MenuItem({
|
||||
var arrPara = [], arrTable = [];
|
||||
_.each(langs, function(lang) {
|
||||
var item = {
|
||||
caption : lang.displayValue,
|
||||
value : lang.value,
|
||||
checkable : true,
|
||||
toggleGroup : 'popupparalang',
|
||||
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);
|
||||
spellcheck : lang.spellcheck
|
||||
};
|
||||
arrPara.push(item);
|
||||
arrTable.push(_.clone(item));
|
||||
});
|
||||
me.langParaMenu.menu.resetItems(arrPara);
|
||||
me.langTableMenu.menu.resetItems(arrTable);
|
||||
|
||||
me._currLang.paraid = item.options.langid;
|
||||
me.langParaMenu.menu.currentCheckedItem = item;
|
||||
me.langParaMenu.menu.on('item:click', function(menu, 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({
|
||||
caption : lang.displayValue,
|
||||
value : lang.value,
|
||||
checkable : true,
|
||||
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.langTableMenu.menu.on('item:click', function(menu, item, e){
|
||||
if (me.api){
|
||||
if (!_.isUndefined(item.langid))
|
||||
me.api.put_TextPrLang(item.langid);
|
||||
|
||||
me._currLang.tableid = item.options.langid;
|
||||
me.langTableMenu.menu.currentCheckedItem = item;
|
||||
|
||||
me.fireEvent('editcomplete', me);
|
||||
}
|
||||
}));
|
||||
me._currLang.tableid = item.langid;
|
||||
me.fireEvent('editcomplete', me);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -69,7 +69,7 @@ define([
|
|||
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();
|
||||
$parent.find('#status-label-lang').text(item.caption);
|
||||
this.langMenu.prevTip = item.value.value;
|
||||
|
@ -248,14 +248,14 @@ define([
|
|||
this.btnPreview.render($('#slot-status-btn-preview'));
|
||||
|
||||
var panelLang = $('.cnt-lang',this.el);
|
||||
this.langMenu = new Common.UI.Menu({
|
||||
this.langMenu = new Common.UI.MenuSimple({
|
||||
cls: 'lang-menu',
|
||||
style: 'margin-top:-5px;',
|
||||
restoreHeight: 300,
|
||||
itemTemplate: _.template([
|
||||
'<a id="<%= id %>" tabindex="-1" type="menuitem" style="padding-left: 28px !important;" langval="<%= options.value.value %>">',
|
||||
'<i class="icon <% if (options.spellcheck) { %> img-toolbarmenu spellcheck-lang <% } %>"></i>',
|
||||
'<%= caption %>',
|
||||
'<a id="<%= id %>" tabindex="-1" type="menuitem" style="padding-left: 28px !important;" langval="<%= value.value %>" class="<% if (checked) { %> checked <% } %>">',
|
||||
'<i class="icon <% if (spellcheck) { %> img-toolbarmenu spellcheck-lang <% } %>"></i>',
|
||||
'<%= caption %>',
|
||||
'</a>'
|
||||
].join('')),
|
||||
menuAlign: 'bl-tl',
|
||||
|
@ -328,18 +328,18 @@ define([
|
|||
},
|
||||
|
||||
reloadLanguages: function(array) {
|
||||
this.langMenu.removeAll();
|
||||
var arr = [],
|
||||
saved = this.langMenu.saved;
|
||||
_.each(array, function(item) {
|
||||
this.langMenu.addItem({
|
||||
arr.push({
|
||||
caption : item['displayValue'],
|
||||
value : {value: item['value'], code: item['code']},
|
||||
checkable : true,
|
||||
checked : this.langMenu.saved == item['displayValue'],
|
||||
spellcheck : item['spellcheck'],
|
||||
toggleGroup : 'language'
|
||||
checked : saved == item['displayValue'],
|
||||
spellcheck : item['spellcheck']
|
||||
});
|
||||
}, this);
|
||||
|
||||
});
|
||||
this.langMenu.resetItems(arr);
|
||||
if (this.langMenu.items.length>0) {
|
||||
this.btnLanguage.setDisabled(false || this._state.no_paragraph);
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ define([
|
|||
this.langMenu.saved = info.displayValue;
|
||||
this.langMenu.clearAll();
|
||||
} else
|
||||
this.langMenu.items[index].setChecked(true);
|
||||
this.langMenu.setChecked(index, true);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue