diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 3ee3d89b3..5e4aacf3b 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1805,21 +1805,22 @@ define([ _.each(groupNames, function(groupName, index){ var store = new Backbone.Collection([], { model: DE.Models.ShapeModel - }); + }), + arr = []; var cols = (shapes[index].length) > 18 ? 7 : 6, height = Math.ceil(shapes[index].length/cols) * 35 + 3, width = 30 * cols; _.each(shapes[index], function(shape, idx){ - store.add({ + arr.push({ data : {shapeType: shape.Type}, tip : me['txtShape_' + shape.Type] || (me.textShape + ' ' + (idx+1)), allowSelected : true, selected: false }); }); - + store.add(arr); shapegrouparray.push({ groupName : me.shapeGroupNames[index], groupStore : store, @@ -1829,7 +1830,6 @@ define([ }); shapeStore.add(shapegrouparray); - setTimeout(function(){ me.getApplication().getController('Toolbar').fillAutoShapes(); }, 50); diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 6e39cbe57..ba5f65819 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -2317,6 +2317,35 @@ define([ var me = this, shapesStore = this.getApplication().getCollection('ShapeGroups'); + var onShowAfter = function(menu) { + for (var i = 0; i < shapesStore.length; i++) { + var shapePicker = new Common.UI.DataViewSimple({ + el: $('#id-toolbar-menu-shapegroup' + i), + store: shapesStore.at(i).get('groupStore'), + parentMenu: menu.items[i].menu, + itemTemplate: _.template('
') + }); + shapePicker.on('item:click', function(picker, item, record, e) { + if (me.api) { + if (record) { + me._addAutoshape(true, record.get('data').shapeType); + me._isAddingShape = true; + } + + if (me.toolbar.btnInsertText.pressed) { + me.toolbar.btnInsertText.toggle(false, true); + } + + if (e.type !== 'click') + me.toolbar.btnInsertShape.menu.hide(); + Common.NotificationCenter.trigger('edit:complete', me.toolbar, me.toolbar.btnInsertShape); + Common.component.Analytics.trackEvent('ToolBar', 'Add Shape'); + } + }); + } + me.toolbar.btnInsertShape.menu.off('show:after', onShowAfter); + }; + for (var i = 0; i < shapesStore.length; i++) { var shapeGroup = shapesStore.at(i); @@ -2329,35 +2358,9 @@ define([ ] }) }); - me.toolbar.btnInsertShape.menu.addItem(menuItem); - - var shapePicker = new Common.UI.DataView({ - el: $('#id-toolbar-menu-shapegroup' + i), - store: shapeGroup.get('groupStore'), - parentMenu: menuItem.menu, - showLast: false, - itemTemplate: _.template('') - }); - - shapePicker.on('item:click', function(picker, item, record, e) { - if (me.api) { - if (record) { - me._addAutoshape(true, record.get('data').shapeType); - me._isAddingShape = true; - } - - if (me.toolbar.btnInsertText.pressed) { - me.toolbar.btnInsertText.toggle(false, true); - } - - if (e.type !== 'click') - me.toolbar.btnInsertShape.menu.hide(); - Common.NotificationCenter.trigger('edit:complete', me.toolbar, me.toolbar.btnInsertShape); - Common.component.Analytics.trackEvent('ToolBar', 'Add Shape'); - } - }); } + me.toolbar.btnInsertShape.menu.on('show:after', onShowAfter); }, fillEquations: function() { diff --git a/apps/documenteditor/main/app/view/ShapeSettings.js b/apps/documenteditor/main/app/view/ShapeSettings.js index b856e4a8c..64c8e61cc 100644 --- a/apps/documenteditor/main/app/view/ShapeSettings.js +++ b/apps/documenteditor/main/app/view/ShapeSettings.js @@ -1612,44 +1612,48 @@ define([ fillAutoShapes: function() { var me = this, - shapesStore = this.application.getCollection('ShapeGroups'); + shapesStore = this.application.getCollection('ShapeGroups'), + count = shapesStore.length; + + var onShowAfter = function(menu) { + for (var i=-1; i