Commit 0805c126 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Merge branch '13-allowblank-list' into 'master'

Add the allowBlank configuration and the handler onEdit to the List widget.

* Close #13

See merge request !9
parents cae5c8a7 57c4091d
/**
* The form field to render the web2py database type list:string.
* The form field renders the web2py database type list:string.
*
* The interface is less rich than the one of the Ext.form.field.Base.
* It contains the basic methods getValue, setValue, reset, ...
* The interface is less rich than the one of the Ext.form.field.Base since
* it only contains the basic methods getErrors, getValue and setValue.
*
* @since 0.4.15.0
*
......@@ -14,11 +14,26 @@ Ext.define('App.form.field.List', {
field: 'Ext.form.field.Field'
},
alias: 'widget.xlistfield',
uses: ['Ext.data.ArrayStore',
'Ext.form.field.Text',
'Ext.grid.Panel',
'Ext.grid.plugin.CellEditing',
'Ext.menu.Menu'],
uses: [
'Ext.data.ArrayStore',
'Ext.form.field.Text',
'Ext.grid.Panel',
'Ext.grid.plugin.CellEditing',
'Ext.menu.Menu'
],
/**
* @cfg {Boolean}
* Specify false to validate that the list should not be empty.
*/
allowBlank: false,
/**
* @cfg {String}
* The error text to display if the allowBlank validation failed.
*/
blankText: "The list can not be empty",
/**
* @cfg {string}
* The label of the column to be shown in the grid widget.
......@@ -68,10 +83,13 @@ Ext.define('App.form.field.List', {
textGoDown: 'Move down',
textGoUp: 'Move up',
// jshint strict: false
// private method requests by the component model of ExtJS
initComponent: function () {
var me = this,
cellEditing,
data = [],
grid,
i;
......@@ -83,7 +101,9 @@ Ext.define('App.form.field.List', {
}
me.store = Ext.create('Ext.data.ArrayStore', {
fields: [{name: 'element'}],
fields: [{
name: 'element'
}],
data: data
});
......@@ -93,7 +113,7 @@ Ext.define('App.form.field.List', {
me.items = [{
columns: [{
dataIndex: 'element',
editor: Ext.create('Ext.form.field.Text', {}),
editor: 'textfield',
flex: 1,
itemId: 'element',
sortable: false,
......@@ -144,14 +164,19 @@ Ext.define('App.form.field.List', {
});
// handler associate to the grid
me.grid = me.child('grid');
grid = me.child('grid');
me.grid.on('containercontextmenu', me.onContainerContextMenu, me);
me.grid.on('itemcontextmenu', me.onItemContextMenu, me);
grid.on('containercontextmenu', me.onContainerContextMenu, me);
grid.on('itemcontextmenu', me.onItemContextMenu, me);
me.grid = grid;
// avoid editing when the menu is visible
me.cellEditing = me.grid.findPlugin('cellediting');
me.cellEditing.on('beforeedit', me.onBeforeEdit, me);
cellEditing = grid.findPlugin('cellediting');
cellEditing.on('beforeedit', me.onBeforeEdit, me);
cellEditing.on('edit', me.onEdit, me);
me.cellEditing = cellEditing;
// initialize the mixin Field
me.initField();
......@@ -163,6 +188,7 @@ Ext.define('App.form.field.List', {
var me = this;
me.cellEditing.un('beforeedit', me.onBeforeEdit, me);
me.cellEditing.un('edit', me.onEdit, me);
me.grid.un('containercontextmenu', me.onContainerContextMenu, me);
me.grid.un('itemcontextmenu', me.onItemContextMenu, me);
......@@ -174,6 +200,32 @@ Ext.define('App.form.field.List', {
me.callParent(arguments);
},
// jshint strict: true
/**
* Validate the field content and return an array of errors.
* The validation is driven by the allowBlank options. The list can not
* be empty when allowBlank is false
*
* @return {String[]} Array of any validation errors
*
*/
getErrors: function () {
"use strict";
var me = this,
li;
if (me.allowBlank === false) {
li = me.getValue();
if (li.length === 0) {
return [me.blankText];
}
}
return [];
},
/**
* Return the value of me field
* Empty string are not copied in the list when #ignoreEmptyRows is true.
......@@ -228,7 +280,7 @@ Ext.define('App.form.field.List', {
"use strict";
var me = this;
if(me.menu.isVisible()) {
if (me.menu.isVisible()) {
return false;
}
},
......@@ -241,7 +293,7 @@ Ext.define('App.form.field.List', {
* @param {Object} eOpts
*
*/
onContainerContextMenu: function (view, event, eOpts) {
onContainerContextMenu: function (view, event) {
"use strict";
var me = this;
......@@ -273,6 +325,20 @@ Ext.define('App.form.field.List', {
}, me);
},
/**
* Validate the Cell content and fire the validitychange event.
* It is required to launch the validation process and to work with
* components using the formBind option.
*
*/
onEdit: function () {
"use strict";
var me = this;
me.validate();
},
/**
* Move the selected element down.
*/
......@@ -330,7 +396,7 @@ Ext.define('App.form.field.List', {
* @param {Object} eOpts
*
*/
onItemContextMenu: function (view, record, item, index, event, eOpts) {
onItemContextMenu: function (view, record, item, index, event) {
"use strict";
var me = this;
......
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