From ebe23a3dae74cdbd9873360975733e9c17531da2 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Sat, 10 Aug 2019 17:40:57 +0300 Subject: [PATCH] [PE] Refactoring loading of languages: use MenuSimple component --- .../main/app/view/DocumentHolder.js | 1 - .../main/app/view/DocumentHolder.js | 99 ++++++++----------- .../main/app/view/Statusbar.js | 26 ++--- 3 files changed, 52 insertions(+), 74 deletions(-) diff --git a/apps/documenteditor/main/app/view/DocumentHolder.js b/apps/documenteditor/main/app/view/DocumentHolder.js index e88d68ca3..f228b6fe4 100644 --- a/apps/documenteditor/main/app/view/DocumentHolder.js +++ b/apps/documenteditor/main/app/view/DocumentHolder.js @@ -741,7 +741,6 @@ define([ }; this.changeLanguageMenu = function(menu) { - var i; if (me._currLang.id===null || me._currLang.id===undefined) { menu.clearAll(); } else { diff --git a/apps/presentationeditor/main/app/view/DocumentHolder.js b/apps/presentationeditor/main/app/view/DocumentHolder.js index 8b66850f8..e0fe4e7d0 100644 --- a/apps/presentationeditor/main/app/view/DocumentHolder.js +++ b/apps/presentationeditor/main/app/view/DocumentHolder.js @@ -692,21 +692,11 @@ define([ }; this.changeLanguageMenu = function(menu) { - var i; if (me._currLang.id===null || me._currLang.id===undefined) { - for (i=0; i-1) && !menu.items[index].checked && menu.setChecked(index, true); } }; @@ -2152,13 +2142,21 @@ define([ }) }); + var langTemplate = _.template([ + '', + '', + '<%= caption %>', + '' + ].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([ - '', - '', - '<%= caption %>', - '' - ].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([ - '', - '', - '<%= caption %>', - '' - ].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); + } }); } }, diff --git a/apps/presentationeditor/main/app/view/Statusbar.js b/apps/presentationeditor/main/app/view/Statusbar.js index 9dd58ce2d..8b8d3aa07 100644 --- a/apps/presentationeditor/main/app/view/Statusbar.js +++ b/apps/presentationeditor/main/app/view/Statusbar.js @@ -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([ - '', - '', - '<%= caption %>', + '', + '', + '<%= caption %>', '' ].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); } },