From 488753ac57c47addfacca73f110da69d927f1225 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Sat, 5 Oct 2019 16:58:13 +0300 Subject: [PATCH] [SSE] Custom sort: fill list for custom sort --- apps/common/main/lib/component/ComboBox.js | 11 ++ apps/common/main/resources/less/combobox.less | 4 + .../main/app/template/SortDialog.template | 6 +- .../main/app/view/SortDialog.js | 175 +++++++++++------- 4 files changed, 127 insertions(+), 69 deletions(-) diff --git a/apps/common/main/lib/component/ComboBox.js b/apps/common/main/lib/component/ComboBox.js index 5b7a7f4cc..486790967 100644 --- a/apps/common/main/lib/component/ComboBox.js +++ b/apps/common/main/lib/component/ComboBox.js @@ -217,6 +217,11 @@ define([ }); } + var $list = el.find('.dropdown-menu'); + if ($list.hasClass('menu-absolute')) { + $list.css('min-width', el.outerWidth()); + } + el.on('show.bs.dropdown', _.bind(me.onBeforeShowMenu, me)); el.on('shown.bs.dropdown', _.bind(me.onAfterShowMenu, me)); el.on('hide.bs.dropdown', _.bind(me.onBeforeHideMenu, me)); @@ -292,6 +297,12 @@ define([ tip.hide(); } } + + var $list = this.cmpEl.find('ul'); + if ($list.hasClass('menu-absolute')) { + var offset = this.cmpEl.offset(); + $list.css({left: offset.left, top: offset.top + this.cmpEl.outerHeight() + 2}); + } }, onAfterShowMenu: function(e) { diff --git a/apps/common/main/resources/less/combobox.less b/apps/common/main/resources/less/combobox.less index 9b87f75da..e05416470 100644 --- a/apps/common/main/resources/less/combobox.less +++ b/apps/common/main/resources/less/combobox.less @@ -106,4 +106,8 @@ padding-top: 0; padding-bottom: 0; } + + .dropdown-menu.menu-absolute { + position: fixed; + } } diff --git a/apps/spreadsheeteditor/main/app/template/SortDialog.template b/apps/spreadsheeteditor/main/app/template/SortDialog.template index 473525016..3473e8a76 100644 --- a/apps/spreadsheeteditor/main/app/template/SortDialog.template +++ b/apps/spreadsheeteditor/main/app/template/SortDialog.template @@ -13,14 +13,14 @@ - - + + -
+
diff --git a/apps/spreadsheeteditor/main/app/view/SortDialog.js b/apps/spreadsheeteditor/main/app/view/SortDialog.js index 872a6371d..52370aa05 100644 --- a/apps/spreadsheeteditor/main/app/view/SortDialog.js +++ b/apps/spreadsheeteditor/main/app/view/SortDialog.js @@ -88,11 +88,10 @@ define([ 'text!spreadsheeteditor/main/app/template/SortDialog.template', emptyText: '', template: _.template(['
'].join('')), itemTemplate: _.template([ - '
', - '
', - '
<%= name %>
', - '
<%= scopeName %>
', - '
<%= range %>
', + '
', + '
', + '
', + '
', '
' ].join('')) }); @@ -149,76 +148,114 @@ define([ 'text!spreadsheeteditor/main/app/template/SortDialog.template', // sensitive: props.asc_getCaseSensitive(), sort: props.asc_getColumnSort() }; + + // get name from props + this.column_data = [ + { value: 'a', displayValue: 'a' }, + { value: 'b', displayValue: 'b' }, + { value: 'c', displayValue: 'c' } + ]; + this.sort_data = [ + { value: Asc.c_oAscSortOptions.ByValue, displayValue: this.textValues }, + { value: Asc.c_oAscSortOptions.ByColorFill, displayValue: this.textCellColor }, + { value: Asc.c_oAscSortOptions.ByColorFont, displayValue: this.textFontColor }, + { value: Asc.c_oAscSortOptions.ByIcon, displayValue: this.textCellIcon } + ]; + this.order_data = [ + { value: Asc.c_oAscSortOptions.Ascending, displayValue: this.textAZ }, + { value: Asc.c_oAscSortOptions.Descending, displayValue: this.textZA } + ]; + + this.sortList.on('item:add', _.bind(this.addControls, this)); + this.sortList.on('item:change', _.bind(this.addControls, this)); + this.refreshList(props.asc_getLevels()); } }, - refreshRangeList: function(ranges, selectedItem) { - if (ranges) { - this.ranges = ranges; + refreshList: function(levels) { + this.cmbsColumn = []; + this.cmbsSort = []; + this.cmbsOrder = []; + + if (levels) { var arr = []; - for (var i=0; i0) ? this.textnoNames : this.textEmpty); - } - var me = this, - store = this.rangeList.store, - models = this.rangesStore.models, - val = this.cmbFilter.getValue(), - isTableFilter = (val<3) ? (val==2) : -1, - isWorkbook = (val>2) ? (val==4) : -1; - if (val>0) - models = this.rangesStore.filter(function(item) { - if (isTableFilter!==-1) - return (isTableFilter===item.get('isTable')); - if (isWorkbook!==-1) - return (isWorkbook===(item.get('scope')===null)); - return false; + // arr.push({ + // index: 0, + // name: 'a', + // sort: Asc.c_oAscSortOptions.ByValue, + // order: Asc.c_oAscSortOptions.Ascending + // }); + // arr.push({ + // index: 1, + // name: 's', + // sort: Asc.c_oAscSortOptions.ByValue, + // order: Asc.c_oAscSortOptions.Descending + // }); + + arr.sort(function (a, b) { + return a.index - b.index; }); - - store.reset(models, {silent: false}); - - val = store.length; - this.btnEditRange.setDisabled(!val); - this.btnDeleteRange.setDisabled(!val); - if (val>0) { - if (selectedItem===undefined || selectedItem===null) selectedItem = 0; - if (_.isNumber(selectedItem)) { - if (selectedItem>val-1) selectedItem = val-1; - this.rangeList.selectByIndex(selectedItem); - setTimeout(function() { - me.rangeList.scrollToRecord(store.at(selectedItem)); - }, 50); - - } else if (selectedItem){ // object - var rec = store.findWhere({name: selectedItem.asc_getName(true), scope: selectedItem.asc_getScope()}); - if (rec) { - this.rangeList.selectRecord(rec); - setTimeout(function() { - me.rangeList.scrollToRecord(rec); - }, 50); - } - } - - if (this.userTooltip===true && this.rangeList.cmpEl.find('.lock-user').length>0) - this.rangeList.cmpEl.on('mouseover', _.bind(me.onMouseOverLock, me)).on('mouseout', _.bind(me.onMouseOutLock, me)); + this.sortList.store.reset(arr); } - _.delay(function () { - me.rangeList.cmpEl.find('.listview').focus(); - me.rangeList.scroller.update({alwaysVisibleY: true}); - }, 100, this); + }, + + addControls: function(listView, itemView, item) { + if (!item) return; + + var cmpEl = this.sortList.cmpEl; + var i = item.get('index'); + var el = cmpEl.find('#sort-dialog-cmb-col-' + i), + combo = new Common.UI.ComboBox({ + el : el, + editable : false, + cls : 'input-group-nr', + menuCls : 'menu-absolute', + data : this.column_data + }).on('selected', function(combo, record) { + item.set('name', record.value); + }); + var val = item.get('name'); + (val!==null) && combo.setValue(item.get('name')); + this.cmbsColumn[i] = combo; + + el = cmpEl.find('#sort-dialog-cmb-sort-' + i); + combo = new Common.UI.ComboBox({ + el : el, + editable : false, + cls : 'input-group-nr', + menuCls : 'menu-absolute', + data : this.sort_data + }).on('selected', function(combo, record) { + item.set('sort', record.value); + }); + val = item.get('sort'); + (val!==null) && combo.setValue(val); + this.cmbsSort[i] = combo; + + el = cmpEl.find('#sort-dialog-cmb-order-' + i); + combo = new Common.UI.ComboBox({ + el : el, + editable : false, + cls : 'input-group-nr', + menuCls : 'menu-absolute', + data : this.order_data + }).on('selected', function(combo, record) { + item.set('order', record.value); + }); + val = item.get('order'); + (val!==null) && combo.setValue(val); + this.cmbsOrder[i] = combo; }, onOptions: function () { @@ -262,7 +299,13 @@ define([ 'text!spreadsheeteditor/main/app/template/SortDialog.template', textOrder: 'Order', textUp: 'Move level up', textDown: 'Move level down', - textOptions: 'Options' + textOptions: 'Options', + textValues: 'Values', + textCellColor: 'Cell color', + textFontColor: 'Font color', + textCellIcon: 'Cell icon', + textAZ: 'A to Z', + textZA: 'Z to A' }, SSE.Views.SortDialog || {})); }); \ No newline at end of file