Refactoring groups for table in documenteditor
This commit is contained in:
parent
20a25d1c98
commit
fd6bc63637
|
@ -774,25 +774,15 @@ define([
|
||||||
|
|
||||||
onAddTableStylesPreview: function(Templates){
|
onAddTableStylesPreview: function(Templates){
|
||||||
var self = this;
|
var self = this;
|
||||||
var templates = [];
|
var groups = {
|
||||||
var groups = [
|
'menu-table-group-custom': {id: 'menu-table-group-custom', caption: self.txtGroupTable_Custom, index: 0},
|
||||||
{id: 'menu-table-group-custom', caption: self.txtGroupTable_Custom, templates: []},
|
'menu-table-group-plain': {id: 'menu-table-group-plain', caption: self.txtGroupTable_Plain, index: 1},
|
||||||
{id: 'menu-table-group-plain', caption: self.txtGroupTable_Plain, templates: []},
|
'menu-table-group-grid': {id: 'menu-table-group-grid', caption: self.txtGroupTable_Grid, index: 2},
|
||||||
{id: 'menu-table-group-grid', caption: self.txtGroupTable_Grid, templates: []},
|
'menu-table-group-list': {id: 'menu-table-group-list', caption: self.txtGroupTable_List, index: 3},
|
||||||
{id: 'menu-table-group-list', caption: self.txtGroupTable_List, templates: []},
|
'menu-table-group-bordered-and-lined': {id: 'menu-table-group-bordered-and-lined', caption: self.txtGroupTable_BorderedAndLined, index: 4},
|
||||||
{id: 'menu-table-group-bordered-and-lined', caption: self.txtGroupTable_BorderedAndLined, templates: []},
|
'menu-table-group-no-name': {id: 'menu-table-group-no-name', caption: ' ', index: 5},
|
||||||
{id: 'menu-table-group-no-name', caption: ' ', templates: []},
|
};
|
||||||
];
|
|
||||||
|
|
||||||
if (this._state.beginPreviewStyles) {
|
|
||||||
this._state.beginPreviewStyles = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.mnuTableTemplatePicker.store.each(function(template) {
|
|
||||||
groups.filter(function(item){ return item.id == template.get('group') ; })[0].templates.push(template);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_.each(Templates, function(template){
|
_.each(Templates, function(template){
|
||||||
var tip = template.asc_getDisplayName();
|
var tip = template.asc_getDisplayName();
|
||||||
var groupItem = '';
|
var groupItem = '';
|
||||||
|
@ -810,9 +800,10 @@ define([
|
||||||
if(arr[0]){
|
if(arr[0]){
|
||||||
groupItem = 'menu-table-group-' + arr[0].toLowerCase();
|
groupItem = 'menu-table-group-' + arr[0].toLowerCase();
|
||||||
}
|
}
|
||||||
if(groups.some(function(item) {return item.id === groupItem;}) == false) {
|
if(groups.hasOwnProperty(groupItem) == false) {
|
||||||
groupItem = 'menu-table-group-no-name';
|
groupItem = 'menu-table-group-no-name';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
['Table Grid', 'Plain Table', 'Grid Table', 'List Table', 'Light', 'Dark', 'Colorful', 'Accent', 'Bordered & Lined', 'Bordered', 'Lined'].forEach(function(item){
|
['Table Grid', 'Plain Table', 'Grid Table', 'List Table', 'Light', 'Dark', 'Colorful', 'Accent', 'Bordered & Lined', 'Bordered', 'Lined'].forEach(function(item){
|
||||||
|
@ -826,25 +817,34 @@ define([
|
||||||
groupItem = 'menu-table-group-custom'
|
groupItem = 'menu-table-group-custom'
|
||||||
}
|
}
|
||||||
|
|
||||||
groups.filter(function(item){ return item.id == groupItem; })[0].templates.push({
|
var templateObj = {
|
||||||
imageUrl: template.asc_getImage(),
|
imageUrl: template.asc_getImage(),
|
||||||
id : Common.UI.getId(),
|
id : Common.UI.getId(),
|
||||||
group : groupItem,
|
group : groupItem,
|
||||||
templateId: template.asc_getId(),
|
templateId: template.asc_getId(),
|
||||||
tip : tip
|
tip : tip
|
||||||
});
|
};
|
||||||
});
|
var templateIndex = 0;
|
||||||
|
|
||||||
groups = groups.filter(function(item, index){
|
self.mnuTableTemplatePicker.store.each(function(item) {
|
||||||
return item.templates.length > 0
|
if(groups[item.get('group')].index <= groups[groupItem].index) {
|
||||||
|
templateIndex += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (self._state.beginPreviewStyles) {
|
||||||
|
self._state.beginPreviewStyles = false;
|
||||||
|
self.mnuTableTemplatePicker && self.mnuTableTemplatePicker.groups.reset(groups[groupItem]);
|
||||||
|
self.mnuTableTemplatePicker && self.mnuTableTemplatePicker.store.reset(templateObj);
|
||||||
|
self.mnuTableTemplatePicker.groups.comparator = function(item) {
|
||||||
|
return item.get('index');
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.mnuTableTemplatePicker && self.mnuTableTemplatePicker.groups.add(groups[groupItem]);
|
||||||
|
self.mnuTableTemplatePicker && self.mnuTableTemplatePicker.store.add(templateObj, {at: templateIndex});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
groups.forEach(function(item){
|
|
||||||
templates = templates.concat(item.templates);
|
|
||||||
delete item.templates;
|
|
||||||
});
|
|
||||||
|
|
||||||
self.mnuTableTemplatePicker && self.mnuTableTemplatePicker.groups.reset(groups);
|
|
||||||
self.mnuTableTemplatePicker && self.mnuTableTemplatePicker.store.reset(templates);
|
|
||||||
!this._state.currentStyleFound && this.selectCurrentTableStyle();
|
!this._state.currentStyleFound && this.selectCurrentTableStyle();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue