Commit 3c8ac1fb authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

All MathJax processing is performed by a single plugin pMathJax.

parent 9285585d
......@@ -20,7 +20,7 @@
#
#-------------------------------------------------------------------------------
gridModifier = dbui.GridModifier('categories')
gridModifier.configure(plugins=['pGridPaging', 'pGridMathJax'])
gridModifier.configure(plugins=['pGridPaging', 'pMathJax'])
gridModifier.configure_column('code', width=10)
gridModifier.set_rownumbering(True)
......
......@@ -101,7 +101,7 @@ tpl = ['<b>{PublicationsTitle}</b><br>',
]
gridModifier = dbui.GridModifier('publications')
gridModifier.configure(plugins=['pGridMathJax'])
gridModifier.configure(plugins=['pMathJax'])
gridModifier.merge_columns('title',
'authors',
'id_collaborations',
......
......@@ -50,7 +50,7 @@ leaf_1 = dbui.Panel(html="salut ma poule")
leaf_2 = dbui.to_panelWithUrlSelector(virtdb.foo1,
baseUrl=URL('reports', 'report_2'),
extField='my_format',
isMathJax=True)
plugins=['pMathJax'])
leaf_3 = dbui.to_panelWithUrlSelector(virtdb.harvester_selector,
baseUrl=URL('reports', 'report_3'),
......
......@@ -779,8 +779,7 @@ def to_panelWithUrlSelector(table, selectorTitle='Select', **kwargs):
title=current.T(selectorTitle))
# build the configuration for the PanelWithUrlSelector
default = dict(isMathJax=False,
selectorItems=selector)
default = dict(selectorItems=selector)
default.update(kwargs)
cfg = PanelWithUrlSelector(**default)
......
......@@ -26,6 +26,7 @@ HEAD
GridModifier.set_rownumbering(False) to inhibit it.
+ pGridExperMenu → pGridToolbar
+ pGridMathJax → pMathJax
+ GridModifier.set_filters → configure_filters
+ GridModifier.configure_gridWithFilter
......@@ -37,6 +38,9 @@ HEAD
+ Remove IFRAME stuff in controller and define extField in
the PanelWithUrlSelector configuration.
+ Replace the configuration parameter PanelWithUrlSelector.isMathJax
by plugins=['pMathJax'].
0.4.15.2 (Oct 2013)
- Release only compatible with ExtJS 3.4.1.1 but identical to 0.4.15.1.
- Deploy the limited part of new ExtJS class model available in 3.4.1.1.
......
......@@ -25,7 +25,7 @@ Ext.define('App.grid.button.ExpertMenu', {
// private method requests by the component model of ExtJS
initComponent: function () {
var pGridMathJax,
var pMathJax,
tableName = App.getTableName(this.grid.getStore());
// the menu configuration
......@@ -43,10 +43,10 @@ Ext.define('App.grid.button.ExpertMenu', {
};
// add check item to activate deactivate MathJax processing
pGridMathJax = this.grid.findPlugin('pGridMathJax');
if (pGridMathJax) {
pMathJax = this.grid.findPlugin('pMathJax');
if (pMathJax) {
this.menu.items.push({
checked: pGridMathJax.activated,
checked: pMathJax.activated,
itemId: 'buttonMathJax',
text: this.textMathJax,
xtype: 'menucheckitem'
......@@ -57,9 +57,9 @@ Ext.define('App.grid.button.ExpertMenu', {
this.callParent(arguments);
// process checkItem event
if (pGridMathJax) {
if (pMathJax) {
this.buttonMathJax = this.menu.getComponent('buttonMathJax');
this.buttonMathJax.on('checkchange', this.onCheckItemChange, pGridMathJax);
this.buttonMathJax.on('checkchange', this.onCheckItemChange, pMathJax);
}
},
......@@ -76,17 +76,17 @@ Ext.define('App.grid.button.ExpertMenu', {
"use strict";
var pGridMathJax = this;
var pMathJax = this;
pGridMathJax.activated = checked;
pMathJax.activated = checked;
// process equation
if (checked) {
pGridMathJax.onProcessMath();
pMathJax.onProcessMath();
// refresh the grid
} else {
pGridMathJax.getCmp().getView().refresh();
pMathJax.getCmp().getView().refresh();
}
},
......
/**
* The plugin to render mathematics formula embedded in grid content.
* The processing is performed by [MathJax](http://www.mathjax.org/).
* The MathJax library is loaded by the framework
*
*/
Ext.define('App.grid.plugin.MathJax', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.pGridMathJax',
/**
* @property {Boolean}
* False to deactivate the MathJax processing.
*/
activated: true,
// Private attributes for internationalization
textMask: 'Processing symbols',
/**
* Initialize the plugin
*
* @param {App.grid.Panel} grid
*
*/
init: function (grid) {
"use strict";
this.setCmp(grid);
// process latex formula each time the grid is refreshed.
//
// NOTE: MathJax processing is lost when the gridView is
// modified (sort, filter, add, remove or delete).
//
grid.getView().on('refresh', this.onProcessMath, this);
},
/**
* destroy the plugin
*/
destroy: function () {
"use strict";
this.getCmp().getView().un('refresh', this.onProcessMath, this);
},
/**
* Process maths objects
*
*/
onProcessMath: function () {
"use strict";
var grid = this.getCmp(),
domEl,
loadMask,
target;
if (!this.activated) {
return;
}
// mask the grid / gridWithFilter during MathJax processing
target = grid.up('xgridwithfilter');
if (!target) {
target = grid;
}
loadMask = Ext.create('Ext.LoadMask', {
target: target,
msg: this.textMask
});
loadMask.show();
// push in the MatJax queue the processing followed by the unmasking
domEl = Ext.getDom(grid.getView().getEl());
MathJax.Hub.Queue(["Typeset", MathJax.Hub, domEl]);
MathJax.Hub.Queue([function (mask) {mask.hide(); }, loadMask]);
}
});
\ No newline at end of file
......@@ -8,12 +8,8 @@
* The URL display in the main panel is defined by the #baseUrl option.
* It can be modified dynamically by extracting the name of the
* *controller*, *function* and/or *extension* from the selector fields.
* The options #ctrlField, #extField and #funcField are used to determine
* the associated fields.
*
* Mathematical symbols will be interpreted when the javascript library
* [MathJax](http://www.mathjax.org/) is load and when the #isMathJax
* property is true.
* The options #ctrlField, #extField and #funcField determine
* the field mappings.
*
*/
Ext.define('App.panel.WithUrlSelector', {
......@@ -48,12 +44,6 @@ Ext.define('App.panel.WithUrlSelector', {
*/
funcField: undefined,
/**
* @cfg {Boolean}
* Set the value to true when the mathjax library is installed.
*/
isMathJax: false,
/**
* @cfg {Number}
* The time out for the {@link Ext.Ajax Ajax request} in millisecond.
......@@ -239,44 +229,6 @@ Ext.define('App.panel.WithUrlSelector', {
}
},
/**
* Handler call when the main panel is loaded.
* Process symbols and enable the selector.
*
*/
onLoad: function () {
"use strict";
var domEl,
loadMask;
function enable(mask, selector) {
mask.hide();
selector.enable();
}
// process symbols
if (MathJax && this.isMathJax) {
domEl = Ext.getDom(this.mainPanel.getEl());
loadMask = Ext.create('Ext.LoadMask', {
target: this.mainPanel,
msg: 'Processing symbols'
});
loadMask.show();
MathJax.Hub.Queue(["Typeset", MathJax.Hub, domEl]);
MathJax.Hub.Queue([enable, loadMask, this.selectorPanel]);
} else {
// enable the selector
this.selectorPanel.enable();
}
},
/**
* Handler to reset the selector
*/
......
/**
* the plugin to render mathematics formula embedded in the HTML content.
* The processing is performed by the [MathJax](http://www.mathjax.org/)
* library.
*
*/
Ext.define('App.panel.plugin.MathJax', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.pPanelMathJax',
/**
* Initialize the plugin.
*
* @param {Ext.Panel} panel
*
*/
init: function (panel) {
"use strict";
// register an handler which is activated only once
// when the panel is rendered for the first time
panel.on('render', this.onPanelRender, this, {single: true});
},
/**
* Activate the MathJax processing
* when the HTML content of the panel is loaded.
*
* @param {Ext.Panel} panel
*/
onPanelRender: function (panel) {
"use strict";
var updater = panel.body.getUpdater();
updater.on('update', this.onProcess);
},
/**
* Run the mathJax processing.
*
* @param {Ext.Element} el
* @param {Object} o the response object
*/
onProcess: function (e, o) {
"use strict";
MathJax.Hub.PreProcess();
MathJax.Hub.Process();
}
});
\ No newline at end of file
/**
* The plugin renders mathematics equation embedded in panel and grid.
* The processing is performed by [MathJax](http://www.mathjax.org/).
* The MathJax library is loaded by the framework.
*
* The plugin works with the classes: Ext.panel.Panel, Ext.grid.GridPanel,
* App.grid.GridPanel, App.panel.BaseWithSelector, App.panel.WithUrlSelector,
* and App.panel.GridWithFilter.
*
* @since 0.6.0.10
*
*/
Ext.define('App.plugin.MathJax', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.pMathJax',
/**
* @property {Boolean}
* False to deactivate the MathJax processing.
*/
activated: true,
// Private short cuts
target: null,
targetDomEl: null,
targetType: undefined,
// Private attributes for internationalization
textMask: 'Processing symbols',
/**
* Initialize the plugin
*
* @param {Ext.grid.GridPanel/Ext.panel.Panel/App.panel.BaseWithSelector} cmp
*
*/
init: function (cmp) {
"use strict";
var parent,
xtype = cmp.getXType();
// protection
if (!MathJax) {
return;
}
this.setCmp(cmp);
// determine the target component to be processed
switch (xtype) {
case 'grid':
this.target = cmp.getView();
this.targetType = 'grid';
break;
case 'panel':
this.target = cmp;
this.targetType = 'panel';
break;
case 'xpanelwithurlselector':
this.target = cmp.mainPanel;
this.targetType = 'panel';
break;
case 'xpanelwithselector':
this.target = cmp.mainPanel;
this.targetType = 'panel';
break;
case 'xgrid':
this.target = cmp.getView();
this.targetType = 'grid';
break;
case 'xgridwithfilter':
this.target = cmp.grid.getView();
this.targetType = 'grid';
break;
}
// the DOM element of the target
this.targetDomEl = Ext.getDom(this.target.getEl());
// listener to trigger the MathJax processing
switch (this.targetType) {
case 'grid':
//
// process equation each time the grid is refreshed.
//
// NOTE: MathJax processing is lost when the gridView is
// modified (sort, filter, add, remove or delete).
//
this.target.on('refresh', this.onProcessMath, this);
break;
case 'panel':
//
// process equation when the panel is loaded
//
this.target.getLoader().on('load', this.onProcessMath, this);
break;
}
},
/**
* destroy the plugin
*/
destroy: function () {
"use strict";
switch (this.targetType) {
case 'grid':
this.target.un('refresh', this.onProcessMath, this);
break;
case 'panel':
this.target.getLoader().un('load', this.onProcessMath, this);
break;
}
},
/**
* Process maths objects
*
*/
onProcessMath: function () {
"use strict";
var cmp = this.getCmp(),
loadMask,
parent,
targetMask = cmp;
if (!this.activated) {
return;
}
// parent of a grid can be gridWithFilter.
// In that case the gridWithFilter should be masked
//
// NOTE: the parent is not define when the plugin is initialized.
//
if ( this.targetType === 'grid') {
parent = cmp.up('xgridwithfilter');
if (parent) {
targetMask = parent;
}
}
// mask the component
loadMask = Ext.create('Ext.LoadMask', {
target: targetMask,
msg: this.textMask
});
loadMask.show();
// MatJax processing followed by the unmasking
MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.targetDomEl]);
MathJax.Hub.Queue([function (mask) {mask.hide(); }, loadMask]);
}
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment