Commit 2d34c4ad authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add Dbui.form.plugin.Mapper.

parent a6bb2eda
/**
* Mapper for Form, FieldContainer and FieldSet.
*
* Modify a set of fields arranged via a vertical layout into a more complex
* organization like an Accordion or Card layout.
*
* The organisation is defined by the property #layout and #mapFields.
*
* @since 0.9.5
*
*/
Ext.define('Dbui.form.plugin.Mapper', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.pMapper',
/**
* @cfg {String} layout
* The layout for the new organisation of the fields, e.g accordion, card:
*
* {
* 'type': 'accordion',
* 'titleCollapse': True
* }
*
*/
/**
* @cfg {Array} mapFields
* The new organisation for fields.
* for example for an accordion layout:
*
* [{
* title: 'panel1',
* layout: 'fit',
* items: ['fieldname4', 'fieldname2']
* }, {
* title: 'panel2',
* items: ['fieldname3', 'fieldname1']
* }]
*
*/
/**
* Initialize the plugin.
*
* @param {Ext.form.Panel/Ext.form.FieldSet/Ext.form.FieldContainer} cmp
*
*
*/
init: function (cmp) {
"use strict";
var me = this,
mapFields = me.mapFields,
nameToField = {};
// build the dictionary fieldname → fieldconfiguration
cmp.items.each(function (field) {
var name = field.name;
if (!Ext.isEmpty(name)) {
nameToField[name] = field;
}
});
// copy the field configuration into mapFields
mapFields.forEach(function(panel, ipanel) {
panel.items.forEach(function(fieldName, ifield) {
if (fieldName in nameToField) {
mapFields[ipanel].items[ifield] = nameToField[fieldName];
}
});
});
// remove existing items keeping the field configuration
cmp.removeAll(false, false);
// add the new items and change the layout
cmp.add(mapFields);
cmp.setLayout(me.layout);
}
});
\ 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