',
'
',
'
',
@@ -90,13 +92,28 @@ define([
'',
'',
'| ',
+ '<% if (type == 1) { %>',
+ '',
+ '',
+ '',
+ '<% } else { %>',
'',
'',
'',
+ '<% } %>',
' | ',
'
',
'',
'',
+ '<% if (type == 1) { %>',
+ '',
+ '',
+ '',
+ '<% } else { %>',
'',
' ',
' ',
@@ -110,6 +127,7 @@ define([
'',
' |
',
'
',
+ '<% } %>',
'',
'
',
'',
@@ -127,6 +145,7 @@ define([
this.api = options.api;
this.handler = options.handler;
this.props = options.props;
+ this.type = options.type || 0; // 0 - TOC, 1 - TOF
this.startLevel = 1;
this.endLevel = 3;
this._noApply = true;
@@ -216,40 +235,161 @@ define([
}
}, this));
- this.radioLevels = new Common.UI.RadioBox({
- el: $('#tableofcontents-radio-levels'),
- labelText: this.textRadioLevels,
- name: 'asc-radio-content-build',
- checked: true
- });
- this.radioLevels.on('change', _.bind(function(field, newValue, eOpts) {
- if (newValue) {
- this.levelsContainer.toggleClass('hidden', !newValue);
- this.stylesContainer.toggleClass('hidden', newValue);
- if (this._needUpdateOutlineLevels)
- this.synchronizeLevelsFromStyles();
- }
- }, this));
+ if (this.type==1) {
+ this.radioCaption = new Common.UI.RadioBox({
+ el: $('#tableofcontents-radio-caption'),
+ labelText: this.textRadioCaption,
+ name: 'asc-radio-content-tof-build',
+ checked: true
+ });
+ this.radioCaption.on('change', _.bind(function(field, newValue, eOpts) {
+ if (newValue) {
+ this.captionContainer.toggleClass('hidden', !newValue);
+ this.styleContainer.toggleClass('hidden', newValue);
+ this.changeCaption(this.cmbCaptions.getSelectedRecord());
+ this.disableButtons();
+ }
+ }, this));
- this.radioStyles = new Common.UI.RadioBox({
- el: $('#tableofcontents-radio-styles'),
- labelText: this.textRadioStyles,
- name: 'asc-radio-content-build'
- });
- this.radioStyles.on('change', _.bind(function(field, newValue, eOpts) {
- if (newValue) {
- this.stylesContainer.toggleClass('hidden', !newValue);
- this.levelsContainer.toggleClass('hidden', newValue);
- if (this._needUpdateStyles)
- this.synchronizeLevelsFromOutline();
- this.stylesList.scroller.update({alwaysVisibleY: true});
- setTimeout(function(){
- var rec = me.stylesLevels.findWhere({checked: true});
- if (rec)
- me.stylesList.scrollToRecord(rec);
- }, 10);
+ this.radioStyle = new Common.UI.RadioBox({
+ el: $('#tableofcontents-radio-style'),
+ labelText: this.textRadioStyle,
+ name: 'asc-radio-content-tof-build'
+ });
+ this.radioStyle.on('change', _.bind(function(field, newValue, eOpts) {
+ if (newValue) {
+ this.styleContainer.toggleClass('hidden', !newValue);
+ this.captionContainer.toggleClass('hidden', newValue);
+ this.changeTOFStyle(this.cmbTOFStyles.getSelectedRecord());
+ this.disableButtons();
+ }
+ }, this));
+
+ this.cmbCaptions = new Common.UI.ComboBox({
+ el: $('#tableofcontents-combo-captions'),
+ cls: 'input-group-nr',
+ menuStyle: 'min-width: 100%;max-height: 233px;',
+ editable: false,
+ data: []
+ });
+ this.cmbCaptions.on('selected', _.bind(function(combo, record) {
+ this.changeCaption(record);
+ this.disableButtons();
+ }, this));
+
+ this.cmbTOFStyles = new Common.UI.ComboBox({
+ el: $('#tableofcontents-combo-tof-styles'),
+ cls: 'input-group-nr',
+ menuStyle: 'min-width: 100%;max-height: 233px;',
+ editable: false,
+ data: []
+ });
+ this.cmbTOFStyles.on('selected', _.bind(function(combo, record) {
+ this.changeTOFStyle(record);
+ }, this));
+
+ this.chFullCaption = new Common.UI.CheckBox({
+ el: $('#tableofcontents-chb-full-caption'),
+ labelText: this.strFullCaption,
+ value: 'checked'
+ });
+ this.chFullCaption.on('change', _.bind(function(field, newValue, oldValue, eOpts){
+ if (this.api && !this._noApply) {
+ var properties = (this._originalProps) ? this._originalProps : new Asc.CTableOfContentsPr();
+ properties.put_IncludeLabelAndNumber(field.getValue()=='checked');
+ this.api.SetDrawImagePlaceContents('tableofcontents-img', properties);
+ this.scrollerY.update();
+ }
+ }, this));
+
+ this.captionContainer = $('#tableofcontents-tof-from-caption');
+ this.styleContainer = $('#tableofcontents-tof-from-style');
+ } else {
+ this.radioLevels = new Common.UI.RadioBox({
+ el: $('#tableofcontents-radio-levels'),
+ labelText: this.textRadioLevels,
+ name: 'asc-radio-content-build',
+ checked: true
+ });
+ this.radioLevels.on('change', _.bind(function(field, newValue, eOpts) {
+ if (newValue) {
+ this.levelsContainer.toggleClass('hidden', !newValue);
+ this.stylesContainer.toggleClass('hidden', newValue);
+ if (this._needUpdateOutlineLevels)
+ this.synchronizeLevelsFromStyles();
+ }
+ }, this));
+
+ this.radioStyles = new Common.UI.RadioBox({
+ el: $('#tableofcontents-radio-styles'),
+ labelText: this.textRadioStyles,
+ name: 'asc-radio-content-build'
+ });
+ this.radioStyles.on('change', _.bind(function(field, newValue, eOpts) {
+ if (newValue) {
+ this.stylesContainer.toggleClass('hidden', !newValue);
+ this.levelsContainer.toggleClass('hidden', newValue);
+ if (this._needUpdateStyles)
+ this.synchronizeLevelsFromOutline();
+ this.stylesList.scroller.update({alwaysVisibleY: true});
+ setTimeout(function(){
+ var rec = me.stylesLevels.findWhere({checked: true});
+ if (rec)
+ me.stylesList.scrollToRecord(rec);
+ }, 10);
+ }
+ }, this));
+ this.spnLevels = new Common.UI.CustomSpinner({
+ el: $('#tableofcontents-spin-levels'),
+ step: 1,
+ width: 85,
+ defaultUnit : "",
+ value: this.endLevel,
+ maxValue: 9,
+ minValue: 1,
+ allowDecimal: false,
+ maskExp: /[1-9]/
+ });
+ this.spnLevels.on('change', _.bind(function(field, newValue, oldValue, eOpts){
+ this._needUpdateStyles = true;
+ this.startLevel = 1;
+ this.endLevel = field.getNumberValue();
+
+ if (this.api && !this._noApply) {
+ var properties = (this._originalProps) ? this._originalProps : new Asc.CTableOfContentsPr();
+ properties.clear_Styles();
+ properties.put_OutlineRange(this.startLevel, this.endLevel);
+ this.api.SetDrawImagePlaceContents('tableofcontents-img', properties);
+ this.scrollerY.update();
+ }
+ }, this));
+
+ this.stylesLevels = new Common.UI.DataViewStore();
+
+ if (this.stylesLevels) {
+ this.stylesList = new Common.UI.ListView({
+ el: $('#tableofcontents-styles-list', this.$window),
+ store: this.stylesLevels,
+ simpleAddMode: true,
+ showLast: false,
+ template: _.template([''].join('')),
+ itemTemplate: _.template([
+ '',
+ ' <%= name %> ',
+ ' ',
+ ' '
+ ].join(''))
+ });
+ this.stylesList.on('item:change', _.bind(this.onItemChange, this));
+ this.stylesList.on('item:add', _.bind(this.addEvents, this));
}
- }, this));
+
+ this.levelsContainer = $('#tableofcontents-from-levels');
+ this.stylesContainer = $('#tableofcontents-from-styles');
+ }
this.cmbStyles = new Common.UI.ComboBox({
el: $('#tableofcontents-combo-styles'),
@@ -275,57 +415,6 @@ define([
}
}, this));
- this.spnLevels = new Common.UI.CustomSpinner({
- el: $('#tableofcontents-spin-levels'),
- step: 1,
- width: 85,
- defaultUnit : "",
- value: this.endLevel,
- maxValue: 9,
- minValue: 1,
- allowDecimal: false,
- maskExp: /[1-9]/
- });
- this.spnLevels.on('change', _.bind(function(field, newValue, oldValue, eOpts){
- this._needUpdateStyles = true;
- this.startLevel = 1;
- this.endLevel = field.getNumberValue();
-
- if (this.api && !this._noApply) {
- var properties = (this._originalProps) ? this._originalProps : new Asc.CTableOfContentsPr();
- properties.clear_Styles();
- properties.put_OutlineRange(this.startLevel, this.endLevel);
- this.api.SetDrawImagePlaceContents('tableofcontents-img', properties);
- this.scrollerY.update();
- }
- }, this));
-
- this.stylesLevels = new Common.UI.DataViewStore();
-
- if (this.stylesLevels) {
- this.stylesList = new Common.UI.ListView({
- el: $('#tableofcontents-styles-list', this.$window),
- store: this.stylesLevels,
- simpleAddMode: true,
- showLast: false,
- template: _.template([''].join('')),
- itemTemplate: _.template([
- '',
- ' <%= name %> ',
- ' ',
- ' '
- ].join(''))
- });
- this.stylesList.on('item:change', _.bind(this.onItemChange, this));
- this.stylesList.on('item:add', _.bind(this.addEvents, this));
- }
-
- this.levelsContainer = $('#tableofcontents-from-levels');
- this.stylesContainer = $('#tableofcontents-from-styles');
-
this.scrollerY = new Common.UI.Scroller({
el: this.$window.find('#tableofcontents-img').parent(),
minScrollbarLength : 20
@@ -333,6 +422,10 @@ define([
this.scrollerY.update();
this.scrollerY.scrollTop(0);
+ this.btnOk = new Common.UI.Button({
+ el: this.$window.find('.primary')
+ });
+
this.afterRender();
},
@@ -353,24 +446,6 @@ define([
_setDefaults: function (props) {
this._noApply = true;
- var me = this,
- docStyles = this.api.asc_GetStylesArray(),
- styles = [],
- checkStyles = false;
- _.each(docStyles, function (style) {
- var name = style.get_Name(),
- level = me.api.asc_GetHeadingLevel(name);
- if (style.get_QFormat() || level>=0) {
- styles.push({
- name: name,
- allowSelected: false,
- checked: false,
- value: '',
- headerLevel: (level>=0) ? level+1 : -1 // -1 if is not header
- });
- }
- });
-
if (props) {
var value = props.get_Hyperlink();
this.chLinks.setValue((value !== null && value !== undefined) ? value : 'indeterminate', true);
@@ -386,7 +461,52 @@ define([
(value!==undefined) && this.cmbLeader.setValue(value);
}
}
+ }
+ (this.type==1) ? this.fillTOFProps(props) : this.fillTOCProps(props);
+
+ // Show Pages is always true when window is opened
+ this._originalProps = (props) ? props : new Asc.CTableOfContentsPr();
+ if (!props) {
+ if (this.type==1) {
+ this._originalProps.put_Caption(this.textFigure);
+ this._originalProps.put_IncludeLabelAndNumber(this.chFullCaption.getValue() == 'checked');
+ } else {
+ this._originalProps.put_OutlineRange(this.startLevel, this.endLevel);
+ }
+ this._originalProps.put_Hyperlink(this.chLinks.getValue() == 'checked');
+ this._originalProps.put_ShowPageNumbers(this.chPages.getValue() == 'checked');
+ if (this.chPages.getValue() == 'checked') {
+ this._originalProps.put_RightAlignTab(this.chAlign.getValue() == 'checked');
+ this._originalProps.put_TabLeader(this.cmbLeader.getValue());
+ }
+ }
+
+ this.api.SetDrawImagePlaceContents('tableofcontents-img', this._originalProps);
+ this.scrollerY.update();
+
+ this._noApply = false;
+ },
+
+ fillTOCProps: function(props) {
+ var me = this,
+ docStyles = this.api.asc_GetStylesArray(),
+ styles = [],
+ checkStyles = false;
+ _.each(docStyles, function (style) {
+ var name = style.get_Name(),
+ level = me.api.asc_GetHeadingLevel(name);
+ if (style.get_QFormat() || level>=0) {
+ styles.push({
+ name: name,
+ allowSelected: false,
+ checked: false,
+ value: '',
+ headerLevel: (level>=0) ? level+1 : -1 // -1 if is not header
+ });
+ }
+ });
+ if (props) {
var start = props.get_OutlineStart(),
end = props.get_OutlineEnd(),
count = props.get_StylesCount();
@@ -483,23 +603,64 @@ define([
if (rec)
this.stylesList.scrollToRecord(rec);
}
+ },
- // Show Pages is always true when window is opened
- this._originalProps = (props) ? props : new Asc.CTableOfContentsPr();
- if (!props) {
- this._originalProps.put_OutlineRange(this.startLevel, this.endLevel);
- this._originalProps.put_Hyperlink(this.chLinks.getValue() == 'checked');
- this._originalProps.put_ShowPageNumbers(this.chPages.getValue() == 'checked');
- if (this.chPages.getValue() == 'checked') {
- this._originalProps.put_RightAlignTab(this.chAlign.getValue() == 'checked');
- this._originalProps.put_TabLeader(this.cmbLeader.getValue());
+ fillTOFProps: function(props) {
+ var me = this,
+ isCaption = true;
+ var arr = Common.Utils.InternalSettings.get("de-settings-captions");
+ if (arr==null || arr==undefined) {
+ arr = Common.localStorage.getItem("de-settings-captions") || '';
+ Common.Utils.InternalSettings.set("de-settings-captions", arr);
+ }
+ arr = arr ? JSON.parse(arr) : [];
+
+ // 0 - not removable
+ arr = arr.concat([{ value: this.textEquation, displayValue: this.textEquation },
+ { value: this.textFigure, displayValue: this.textFigure },
+ { value: this.textTable, displayValue: this.textTable }
+ ]);
+ arr.sort(function(a,b){
+ var sa = a.displayValue.toLowerCase(),
+ sb = b.displayValue.toLowerCase();
+ return sa>sb ? 1 : (sa0) && this.cmbCaptions.setValue(value ? value : this.textFigure);
+
+ arr = [];
+ _.each(this.api.asc_getAllUsedParagraphStyles(), function (style, index) {
+ var name = style.get_Name(),
+ level = me.api.asc_GetHeadingLevel(name);
+ arr.push({
+ displayValue: name,
+ value: index,
+ level: level
+ });
+ });
+ this.cmbTOFStyles.setData(arr);
+ value = undefined;
+ if (props) {
+ var count = props.get_StylesCount();
+ if (count>0) {
+ var rec = this.cmbTOFStyles.store.findWhere({displayValue: props.get_StyleName(0)});
+ rec && (value = rec.get('value'));
}
}
+ (arr.length>0) && this.cmbTOFStyles.setValue(value ? value : arr[0].value);
- this.api.SetDrawImagePlaceContents('tableofcontents-img', this._originalProps);
- this.scrollerY.update();
-
- this._noApply = false;
+ if (props) {
+ value = props.get_IncludeLabelAndNumber();
+ this.chFullCaption.setValue((value !== null && value !== undefined) ? value : 'indeterminate', true);
+ }
+ !isCaption && this.radioStyle.setValue(true);
},
synchronizeLevelsFromOutline: function() {
@@ -574,15 +735,25 @@ define([
props.put_StylesType(this.cmbStyles.getValue());
props.clear_Styles();
- if (this._needUpdateOutlineLevels) {
- this.synchronizeLevelsFromStyles();
+ if (this.type==1) {
+ if (this.radioCaption.getValue()) {
+ props.put_Caption(this.cmbCaptions.getValue());
+ } else {
+ props.put_Caption(null);
+ var rec = this.cmbTOFStyles.getSelectedRecord();
+ rec && props.add_Style(rec.displayValue, rec.level);
+ }
+ } else {
+ if (this._needUpdateOutlineLevels) {
+ this.synchronizeLevelsFromStyles();
+ }
+ if (!this._needUpdateStyles) // if this._needUpdateStyles==true - fill only OutlineRange
+ this.stylesLevels.each(function (style) {
+ if (style.get('checked'))
+ props.add_Style(style.get('name'), style.get('value'));
+ });
+ props.put_OutlineRange(this.startLevel, this.endLevel);
}
- if (!this._needUpdateStyles) // if this._needUpdateStyles==true - fill only OutlineRange
- this.stylesLevels.each(function (style) {
- if (style.get('checked'))
- props.add_Style(style.get('name'), style.get('value'));
- });
- props.put_OutlineRange(this.startLevel, this.endLevel);
return props;
},
@@ -633,6 +804,51 @@ define([
}, 10);
},
+ changeCaption: function(record) {
+ if (this.api && !this._noApply && record) {
+ var properties = (this._originalProps) ? this._originalProps : new Asc.CTableOfContentsPr();
+ properties.put_Caption(record.value);
+ properties.clear_Styles();
+ this.api.SetDrawImagePlaceContents('tableofcontents-img', properties);
+ this.scrollerY.update();
+ }
+ },
+
+ changeTOFStyle: function(record) {
+ if (this.api && !this._noApply) {
+ var properties = (this._originalProps) ? this._originalProps : new Asc.CTableOfContentsPr();
+ properties.put_Caption(null);
+ properties.clear_Styles();
+ properties.add_Style(record.displayValue, record.level);
+ this.api.SetDrawImagePlaceContents('tableofcontents-img', properties);
+ this.scrollerY.update();
+ }
+ },
+
+ disableButtons: function() {
+ this.type && this.btnOk.setDisabled(this.radioCaption.getValue() && this.cmbCaptions.getValue()===null || this.radioStyle.getValue() && this.cmbTOFStyles.length<1);
+ },
+
+ onDlgBtnClick: function(event) {
+ this._handleInput(event.currentTarget.attributes['result'].value);
+ },
+
+ onPrimary: function() {
+ this._handleInput('ok');
+ return false;
+ },
+
+ _handleInput: function(state) {
+ if (this.handler) {
+ if (state == 'ok' && this.btnOk.isDisabled()) {
+ return;
+ }
+ this.handler.call(this, state, this.getSettings());
+ }
+
+ this.close();
+ },
+
textTitle: 'Table of Contents',
textLeader: 'Leader',
textBuildTable: 'Build table of contents from',
@@ -651,7 +867,15 @@ define([
txtStandard: 'Standard',
txtModern: 'Modern',
txtClassic: 'Classic',
- txtOnline: 'Online'
+ txtOnline: 'Online',
+ textTitleTOF: 'Table of Figures',
+ textBuildTableOF: 'Build table of figures from',
+ textRadioCaption: 'Caption',
+ textRadioStyle: 'Style',
+ strFullCaption: 'Include label and number',
+ textEquation: 'Equation',
+ textFigure: 'Figure',
+ textTable: 'Table'
}, DE.Views.TableOfContentsSettings || {}))
});
\ No newline at end of file
|