diff --git a/apps/common/main/lib/component/DataView.js b/apps/common/main/lib/component/DataView.js index a7d8fa820..b0163ed31 100644 --- a/apps/common/main/lib/component/DataView.js +++ b/apps/common/main/lib/component/DataView.js @@ -1139,15 +1139,22 @@ define([ } else { var idx = _.indexOf(this.store.models, rec); if (idx<0) { + function getFirstItemIndex() { + var first = 0; + while(!this.dataViewItems[first].el.is(':visible')) { + first++; + } + return first; + } if (data.keyCode==Common.UI.Keys.LEFT) { var target = $(e.target).closest('.dropdown-submenu.over'); if (target.length>0) { target.removeClass('over'); target.find('> a').focus(); } else - idx = 0; + idx = getFirstItemIndex.call(this); } else - idx = 0; + idx = getFirstItemIndex.call(this); } else if (this.options.keyMoveDirection == 'both') { if (this._layoutParams === undefined) this.fillIndexesArray(); @@ -1324,9 +1331,9 @@ define([ '', '<% } %>', '
', - '<% _.each(group.groupStore.toJSON(), function(item) { %>', + '<% _.each(group.groupStore.toJSON(), function(item, index) { %>', '<% if (!item.id) item.id = Common.UI.getId(); %>', - '
data-toggle="tooltip" <% } %> ><%= itemTemplate(item) %>
', + '
data-toggle="tooltip" <% } %> ><%= itemTemplate(item) %>
', '<% }); %>', '
', '', @@ -1337,15 +1344,15 @@ define([ var me = this; this.canAddRecents = true; + this._state = { + hideTextRect: options.hideTextRect, + hideLines: options.hideLines + } + var filter = Common.localStorage.getKeysFilter(); this.appPrefix = (filter && filter.length) ? filter.split(',')[0] : ''; me.groups = options.groups.toJSON(); - if (options.isFromImage) { - var store = me.groups[0].groupStore.clone(); - store.shift(); - me.groups[0].groupStore = store; - } // add recent shapes to store var recentStore = new Common.UI.DataViewGroupStore, @@ -1362,31 +1369,33 @@ define([ var count = 12 - me.recentShapes.length, defaultArr = []; - var addItem = function (rec) { + var addItem = function (rec, groupName) { var item = rec.toJSON(), model = { data: item.data, tip: item.tip, allowSelected: item.allowSelected, - selected: false + selected: false, + groupName: groupName }; defaultArr.push(model); }; for (var i = 0; i < me.groups.length && count > 0; i++) { - var groupStore = me.groups[i].groupStore; + var groupStore = me.groups[i].groupStore, + groupName = me.groups[i].groupName; if (i === 0) { - addItem(groupStore.at(1)); + addItem(groupStore.at(1), groupName); count--; if (count > 0) { - addItem(groupStore.at(2)); + addItem(groupStore.at(2), groupName); count--; } } else if (i !== 3 && i !== 6 && i !== 7) { - addItem(groupStore.at(0)); + addItem(groupStore.at(0), groupName); count--; if (count > 0) { - addItem(groupStore.at(1)); + addItem(groupStore.at(1), groupName); count--; } } @@ -1406,8 +1415,14 @@ define([ var store = new Common.UI.DataViewStore(); - _.each(me.groups, function (group) { - store.add(group.groupStore.models); + _.each(me.groups, function (group, index) { + var models = group.groupStore.models; + if (index > 0) { + for (var i = 0; i < models.length; i++) { + models.at(i).set({groupName: group.groupName}) + } + } + store.add(models); }); options.store = store; @@ -1415,9 +1430,14 @@ define([ Common.UI.DataViewSimple.prototype.initialize.call(this, options); me.parentMenu.on('show:before', function() { me.updateRecents(); }); + + if (me._state.hideLines) { + me.hideLinesGroup(); + } }, onAfterShowMenu: function(e) { - var me = this; + var me = this, + updateHideRect = false; if (!me.dataViewItems) { me.dataViewItems = []; _.each(me.cmpEl.find('div.grouped-data'), function (group, indexGroup) { @@ -1439,6 +1459,7 @@ define([ } }); }); + updateHideRect = true; } if (me.updateDataViewItems && me.cmpEl.is(':visible')) { // add recent item in dataViewItems @@ -1472,13 +1493,21 @@ define([ } }); me.dataViewItems = recentViewItems.concat(me.dataViewItems); - me.fillIndexesArray(); if (me.recentShapes.length === 1) { $('.recent-group').show(); } me.updateDataViewItems = false; + + updateHideRect = true; } + if (this._state.hideLines) { + me.hideLines(); + } + if (updateHideRect) { + me.hideTextRect(me._state.hideTextRect); + } + me.fillIndexesArray(); }, onClickItem: function(e) { @@ -1487,7 +1516,7 @@ define([ window._event = e; // for FireFox only var groupIndex = $(e.currentTarget).closest('div.grouped-data').index(), - itemIndex = $(e.currentTarget).closest('div.item').index(); + itemIndex = $(e.currentTarget).closest('div.item').data('index'); var index = _.findIndex(this.dataViewItems, function (item) { return (item.groupIndex === groupIndex && item.index === itemIndex); }); @@ -1508,7 +1537,8 @@ define([ addRecentItem: function (rec) { var me = this, exist = false, - type = rec.get('data').shapeType; + type = rec.get('data').shapeType, + groupName = rec.get('groupName'); for (var i = 0; i < me.recentShapes.length; i++) { if (me.recentShapes[i].data.shapeType === type) { exist = true; @@ -1522,7 +1552,8 @@ define([ data: item.data, tip: item.tip, allowSelected: item.allowSelected, - selected: false + selected: false, + groupName: groupName }; me.recentShapes.unshift(model); if (me.recentShapes.length > 12) { @@ -1558,9 +1589,9 @@ define([ me.store = store; var template = _.template([ - '<% _.each(items, function(item) { %>', + '<% _.each(items, function(item, index) { %>', '<% if (!item.id) item.id = Common.UI.getId(); %>', - '
data-toggle="tooltip" <% } %> ><%= itemTemplate(item) %>
', + '
data-toggle="tooltip" <% } %> ><%= itemTemplate(item) %>
', '<% }) %>' ].join('')); me.cmpEl && me.cmpEl.find('.recent-items').html(template({ @@ -1571,6 +1602,72 @@ define([ me.updateDataViewItems = true; } + }, + fillIndexesArray: function() { + if (this.dataViewItems.length<=0) return; + + this._layoutParams = { + itemsIndexes: [], + columns: 0, + rows: 0 + }; + + var el = this.dataViewItems[0].el, + first = 0; + while (!this.dataViewItems[first].el.is(":visible")) { // if first elem is hidden + first++; + el = this.dataViewItems[first].el; + } + + var itemW = el.outerWidth() + parseInt(el.css('margin-left')) + parseInt(el.css('margin-right')), + offsetLeft = this.$el.offset().left, + offsetTop = el.offset().top, + prevtop = -1, topIdx = 0, leftIdx = first; + + for (var i=0; i prevtop) { + prevtop = top; + this._layoutParams.itemsIndexes.push([]); + topIdx = this._layoutParams.itemsIndexes.length - 1; + } + this._layoutParams.itemsIndexes[topIdx][leftIdx] = i; + item.topIdx = topIdx; + item.leftIdx = leftIdx; + if (this._layoutParams.columns < leftIdx) this._layoutParams.columns = leftIdx; + } else { + item.topIdx = -1; + item.leftIdx = -1; + } + } + this._layoutParams.rows = this._layoutParams.itemsIndexes.length; + this._layoutParams.columns++; + }, + hideTextRect: function (hide) { + var me = this; + this.store.each(function(item, index){ + if (item.get('data').shapeType === 'textRect') { + me.dataViewItems[index].el[hide ? 'addClass' : 'removeClass']('hidden'); + } + }, this); + this._state.hideTextRect = hide; + }, + hideLinesGroup: function () { + $(this.cmpEl.find('div.grouped-data')[9]).hide(); + }, + hideLines: function () { + var me = this; + this.store.each(function(item, index){ + if (item.get('groupName') === 'Lines') { + var el = me.dataViewItems[index].el; + if (el.is(':visible')) { + el.addClass('hidden'); + } + } + }, this); } })); diff --git a/apps/documenteditor/main/app/view/ShapeSettings.js b/apps/documenteditor/main/app/view/ShapeSettings.js index dffc80ac4..740278d67 100644 --- a/apps/documenteditor/main/app/view/ShapeSettings.js +++ b/apps/documenteditor/main/app/view/ShapeSettings.js @@ -817,8 +817,7 @@ define([ this._state.isFromImage = !!shapeprops.get_FromImage(); this._state.isFromSmartArtInternal = !!shapeprops.get_FromSmartArtInternal(); if (!hidechangetype && this.btnChangeShape.menu.items.length) { - this.btnChangeShape.menu.items[0].setVisible(shapeprops.get_FromImage() || shapeprops.get_FromSmartArtInternal()); - this.btnChangeShape.menu.items[1].setVisible(!shapeprops.get_FromImage() && !shapeprops.get_FromSmartArtInternal()); + this.btnChangeShape.shapePicker.hideTextRect(shapeprops.get_FromImage() || shapeprops.get_FromSmartArtInternal()); } var value = props.get_WrappingStyle(); @@ -1824,34 +1823,30 @@ define([ var me = this, recents = Common.localStorage.getItem('de-recent-shapes'); - for (var i = 0; i < 2; i++) { - var menuitem = new Common.UI.MenuItem({ - template: _.template(''), - index: i - }); - me.btnChangeShape.menu.addItem(menuitem); + var menuitem = new Common.UI.MenuItem({ + template: _.template(''), + }); + me.btnChangeShape.menu.addItem(menuitem); - var shapePicker = new Common.UI.DataViewShape({ - el: $('#id-change-shape-menu-' + i), - itemTemplate: _.template('
\">
'), - groups: me.application.getCollection('ShapeGroups'), - parentMenu: me.btnChangeShape.menu, - restoreHeight: 640, - textRecentlyUsed: me.textRecentlyUsed, - recentShapes: recents ? JSON.parse(recents) : null, - isFromImage: i === 0 - }); - shapePicker.on('item:click', function(picker, item, record, e) { - if (me.api) { - me.api.ChangeShapeType(record.get('data').shapeType); - me.fireEvent('editcomplete', me); - } - if (e.type !== 'click') - me.btnChangeShape.menu.hide(); - }); - } - me.btnChangeShape.menu.items[0].setVisible(me._state.isFromImage || me._state.isFromSmartArtInternal); - me.btnChangeShape.menu.items[1].setVisible(!me._state.isFromImage && !me._state.isFromSmartArtInternal); + me.btnChangeShape.shapePicker = new Common.UI.DataViewShape({ + el: $('#id-change-shape-menu'), + itemTemplate: _.template('
\">
'), + groups: me.application.getCollection('ShapeGroups'), + parentMenu: me.btnChangeShape.menu, + restoreHeight: 640, + textRecentlyUsed: me.textRecentlyUsed, + recentShapes: recents ? JSON.parse(recents) : null, + hideTextRect: me._state.isFromImage || me._state.isFromSmartArtInternal, + hideLines: true + }); + me.btnChangeShape.shapePicker.on('item:click', function(picker, item, record, e) { + if (me.api) { + me.api.ChangeShapeType(record.get('data').shapeType); + me.fireEvent('editcomplete', me); + } + if (e.type !== 'click') + me.btnChangeShape.menu.hide(); + }); }, UpdateThemeColors: function() { diff --git a/apps/presentationeditor/main/app/view/ShapeSettings.js b/apps/presentationeditor/main/app/view/ShapeSettings.js index 0f7589b5b..49a27fc3c 100644 --- a/apps/presentationeditor/main/app/view/ShapeSettings.js +++ b/apps/presentationeditor/main/app/view/ShapeSettings.js @@ -776,8 +776,7 @@ define([ this._state.isFromImage = !!props.get_FromImage(); this._state.isFromSmartArtInternal = !!props.get_FromSmartArtInternal(); if (!hidechangetype && this.btnChangeShape.menu.items.length) { - this.btnChangeShape.menu.items[0].setVisible(props.get_FromImage() || props.get_FromSmartArtInternal()); - this.btnChangeShape.menu.items[1].setVisible(!props.get_FromImage() && !props.get_FromSmartArtInternal()); + this.btnChangeShape.shapePicker.hideTextRect(props.get_FromImage() || props.get_FromSmartArtInternal()); } // background colors @@ -1685,36 +1684,31 @@ define([ var me = this, recents = Common.localStorage.getItem('pe-recent-shapes'); - for (var i = 0; i < 2; i++) { - var menuitem = new Common.UI.MenuItem({ - template: _.template(''), - index: i + var menuitem = new Common.UI.MenuItem({ + template: _.template(''), }); - me.btnChangeShape.menu.addItem(menuitem); + me.btnChangeShape.menu.addItem(menuitem); - var shapePicker = new Common.UI.DataViewShape({ - el: $('#id-change-shape-menu-' + i), - itemTemplate: _.template('
\">
'), - groups: me.application.getCollection('ShapeGroups'), - parentMenu: me.btnChangeShape.menu, - restoreHeight: 640, - textRecentlyUsed: me.textRecentlyUsed, - recentShapes: recents ? JSON.parse(recents) : null, - isFromImage: i === 0 - }); - shapePicker.on('item:click', function(picker, item, record, e) { - if (me.api) { - PE.getController('Toolbar').toolbar.cmbInsertShape.updateComboView(record); - me.api.ChangeShapeType(record.get('data').shapeType); - me.fireEvent('editcomplete', me); - } - if (e.type !== 'click') - me.btnChangeShape.menu.hide(); - }); - } - - me.btnChangeShape.menu.items[0].setVisible(me._state.isFromImage || me._state.isFromSmartArtInternal); - me.btnChangeShape.menu.items[1].setVisible(!me._state.isFromImage && !me._state.isFromSmartArtInternal); + me.btnChangeShape.shapePicker = new Common.UI.DataViewShape({ + el: $('#id-change-shape-menu'), + itemTemplate: _.template('
\">
'), + groups: me.application.getCollection('ShapeGroups'), + parentMenu: me.btnChangeShape.menu, + restoreHeight: 640, + textRecentlyUsed: me.textRecentlyUsed, + recentShapes: recents ? JSON.parse(recents) : null, + hideTextRect: me._state.isFromImage || me._state.isFromSmartArtInternal, + hideLines: true + }); + me.btnChangeShape.shapePicker.on('item:click', function(picker, item, record, e) { + if (me.api) { + PE.getController('Toolbar').toolbar.cmbInsertShape.updateComboView(record); + me.api.ChangeShapeType(record.get('data').shapeType); + me.fireEvent('editcomplete', me); + } + if (e.type !== 'click') + me.btnChangeShape.menu.hide(); + }); }, UpdateThemeColors: function() { diff --git a/apps/spreadsheeteditor/main/app/view/ShapeSettings.js b/apps/spreadsheeteditor/main/app/view/ShapeSettings.js index d30d74bf9..a58b5616c 100644 --- a/apps/spreadsheeteditor/main/app/view/ShapeSettings.js +++ b/apps/spreadsheeteditor/main/app/view/ShapeSettings.js @@ -772,8 +772,7 @@ define([ this._state.isFromImage = !!shapeprops.get_FromImage(); this._state.isFromSmartArtInternal = !!shapeprops.asc_getFromSmartArtInternal(); if (!hidechangetype && this.btnChangeShape.menu.items.length) { - this.btnChangeShape.menu.items[0].setVisible(shapeprops.get_FromImage() || shapeprops.asc_getFromSmartArtInternal()); - this.btnChangeShape.menu.items[1].setVisible(!shapeprops.get_FromImage() && !shapeprops.asc_getFromSmartArtInternal()); + this.btnChangeShape.shapePicker.hideTextRect(shapeprops.get_FromImage() || shapeprops.asc_getFromSmartArtInternal()); } // background colors @@ -1694,34 +1693,30 @@ define([ var me = this, recents = Common.localStorage.getItem('sse-recent-shapes'); - for (var i = 0; i < 2; i++) { - var menuitem = new Common.UI.MenuItem({ - template: _.template(''), - index: i - }); - me.btnChangeShape.menu.addItem(menuitem); + var menuitem = new Common.UI.MenuItem({ + template: _.template('') + }); + me.btnChangeShape.menu.addItem(menuitem); - var shapePicker = new Common.UI.DataViewShape({ - el: $('#id-change-shape-menu-' + i), - itemTemplate: _.template('
\">
'), - groups: me.application.getCollection('ShapeGroups'), - parentMenu: me.btnChangeShape.menu, - restoreHeight: 640, - textRecentlyUsed: me.textRecentlyUsed, - recentShapes: recents ? JSON.parse(recents) : null, - isFromImage: i === 0 - }); - shapePicker.on('item:click', function(picker, item, record, e) { - if (me.api) { - me.api.asc_changeShapeType(record.get('data').shapeType); - Common.NotificationCenter.trigger('edit:complete', me); - } - if (e.type !== 'click') - me.btnChangeShape.menu.hide(); - }); - } - me.btnChangeShape.menu.items[0].setVisible(me._state.isFromImage || me._state.isFromSmartArtInternal); - me.btnChangeShape.menu.items[1].setVisible(!me._state.isFromImage && !me._state.isFromSmartArtInternal); + me.btnChangeShape.shapePicker = new Common.UI.DataViewShape({ + el: $('#id-change-shape-menu'), + itemTemplate: _.template('
\">
'), + groups: me.application.getCollection('ShapeGroups'), + parentMenu: me.btnChangeShape.menu, + restoreHeight: 640, + textRecentlyUsed: me.textRecentlyUsed, + recentShapes: recents ? JSON.parse(recents) : null, + hideTextRect: me._state.isFromImage || me._state.isFromSmartArtInternal, + hideLines: true + }); + me.btnChangeShape.shapePicker.on('item:click', function(picker, item, record, e) { + if (me.api) { + me.api.asc_changeShapeType(record.get('data').shapeType); + Common.NotificationCenter.trigger('edit:complete', me); + } + if (e.type !== 'click') + me.btnChangeShape.menu.hide(); + }); }, onBtnRotateClick: function(btn) {