Skip to content

Commit

Permalink
modExt updates
Browse files Browse the repository at this point in the history
Cleans name, caption, and description fields on the front end (js) side before they are submitted to processors.
  • Loading branch information
Jim Graham committed May 6, 2022
1 parent 10f97e8 commit 1aef680
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 3 deletions.
21 changes: 21 additions & 0 deletions manager/assets/modext/util/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ MODx.util.safeHtml = function (input, allowedTags, allowedAttributes) {
return input.replace(eventAttributes, 'on​$1');
};

/**
* Cleans and resets or returns a field's value; typically called:
*
* 1] via an event in a form field component's listeners object (use onChange callback)
* 2] via an event in a grid's column model (use onColumnRender callback)
* 3] directly via run
*/
MODx.util.stripAndEncode = {
onChange: function(cmp, newVal, originalVal) {
const value = cmp.getValue();
cmp.setValue(MODx.util.stripAndEncode.run(value));
},
onColumnRender: function(value, metaData, record, rowIndex, colIndex) {
return MODx.util.stripAndEncode.run(value);
},
run: function(value) {
value = Ext.util.Format.stripTags(value).replace(/\s{2,}/g, ' ');
return Ext.util.Format.htmlEncode(value);
}
}

/****************************************************************************
* Ext-specific overrides/extensions *
****************************************************************************/
Expand Down
21 changes: 21 additions & 0 deletions manager/assets/modext/widgets/element/modx.panel.tv.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ MODx.panel.TV = function(config) {
,maxLength: 50
,enableKeyEvents: true
,allowBlank: false
,blankText: _('tv_err_ns_name')
,value: config.record.name
,tabIndex: 1
,listeners: {
Expand All @@ -98,6 +99,16 @@ MODx.panel.TV = function(config) {
MODx.setStaticElementPath('tv');
}
,scope: this
},
change: {
fn: MODx.util.stripAndEncode.onChange
},
blur: {
fn: function(cmp) {
if (!cmp.getValue()) {
cmp.markInvalid(_('tv_err_ns_name'));
}
}
}
}
},{
Expand Down Expand Up @@ -174,6 +185,11 @@ MODx.panel.TV = function(config) {
,id: 'modx-tv-caption'
,tabIndex: 3
,value: config.record.caption
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: 'modx-tv-caption'
Expand Down Expand Up @@ -236,6 +252,11 @@ MODx.panel.TV = function(config) {
,maxLength: 255
,tabIndex: 5
,value: config.record.description || ''
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: 'modx-tv-description'
Expand Down
27 changes: 24 additions & 3 deletions manager/assets/modext/widgets/fc/modx.panel.fcset.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ MODx.grid.FCSetFields = function(config) {
header: _('label')
,dataIndex: 'label'
,editor: { xtype: 'textfield' }
,renderer: function(v,md) {
return Ext.util.Format.htmlEncode(v);
}
},{
header: _('default_value')
,dataIndex: 'default_value'
Expand All @@ -288,6 +285,14 @@ MODx.grid.FCSetFields = function(config) {
});
MODx.grid.FCSetFields.superclass.constructor.call(this,config);
this.propRecord = Ext.data.Record.create(config.fields);
this.on('afteredit', function(e) {
if (e.field === 'label') {
const value = MODx.util.stripAndEncode.run(e.value);
e.record.set('label', value);
e.record.commit();
}

});
};
Ext.extend(MODx.grid.FCSetFields,MODx.grid.LocalGrid);
Ext.reg('modx-grid-fc-set-fields',MODx.grid.FCSetFields);
Expand Down Expand Up @@ -341,6 +346,14 @@ MODx.grid.FCSetTabs = function(config) {
});
MODx.grid.FCSetTabs.superclass.constructor.call(this,config);
this.propRecord = Ext.data.Record.create(config.fields);
this.on('afteredit', function(e) {
if (e.field === 'label') {
const value = MODx.util.stripAndEncode.run(e.value);
e.record.set('label', value);
e.record.commit();
}

});
};
Ext.extend(MODx.grid.FCSetTabs,MODx.grid.LocalGrid,{
getMenu: function(g,ri) {
Expand Down Expand Up @@ -460,6 +473,14 @@ MODx.grid.FCSetTVs = function(config) {
});
MODx.grid.FCSetTVs.superclass.constructor.call(this,config);
this.propRecord = Ext.data.Record.create(config.fields);
this.on('afteredit', function(e) {
if (e.field === 'label') {
const value = MODx.util.stripAndEncode.run(e.value);
e.record.set('label', value);
e.record.commit();
}

});
};
Ext.extend(MODx.grid.FCSetTVs,MODx.grid.LocalGrid,{
});
Expand Down
79 changes: 79 additions & 0 deletions manager/assets/modext/widgets/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ MODx.window.CreateCategory = function(config) {
,id: 'modx-'+this.ident+'-category'
,xtype: 'textfield'
,anchor: '100%'
,allowBlank: false
,blankText: _('category_err_ns_name')
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
fieldLabel: _('parent')
,name: 'parent'
Expand Down Expand Up @@ -296,6 +303,13 @@ MODx.window.RenameCategory = function(config) {
,width: 150
,value: config.record.category
,anchor: '100%'
,allowBlank: false
,blankText: _('category_err_ns_name')
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
fieldLabel: _('rank')
,name: 'rank'
Expand Down Expand Up @@ -398,6 +412,13 @@ MODx.window.QuickCreateChunk = function(config) {
,name: 'name'
,fieldLabel: _('name')
,anchor: '100%'
,allowBlank: false
,blankText: _('chunk_err_ns_name')
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'modx-combo-category'
,name: 'category'
Expand All @@ -408,6 +429,11 @@ MODx.window.QuickCreateChunk = function(config) {
,name: 'description'
,fieldLabel: _('description')
,anchor: '100%'
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'textarea'
,name: 'snippet'
Expand Down Expand Up @@ -479,6 +505,13 @@ MODx.window.QuickCreateTemplate = function(config) {
,name: 'templatename'
,fieldLabel: _('name')
,anchor: '100%'
,allowBlank: false
,blankText: _('template_err_ns_name')
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'modx-combo-category'
,name: 'category'
Expand All @@ -489,6 +522,11 @@ MODx.window.QuickCreateTemplate = function(config) {
,name: 'description'
,fieldLabel: _('description')
,anchor: '100%'
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'textarea'
,name: 'content'
Expand Down Expand Up @@ -561,6 +599,13 @@ MODx.window.QuickCreateSnippet = function(config) {
,name: 'name'
,fieldLabel: _('name')
,anchor: '100%'
,allowBlank: false
,blankText: _('snippet_err_ns_name')
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'modx-combo-category'
,name: 'category'
Expand All @@ -571,6 +616,11 @@ MODx.window.QuickCreateSnippet = function(config) {
,name: 'description'
,fieldLabel: _('description')
,anchor: '100%'
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'textarea'
,name: 'snippet'
Expand Down Expand Up @@ -644,6 +694,13 @@ MODx.window.QuickCreatePlugin = function(config) {
,name: 'name'
,fieldLabel: _('name')
,anchor: '100%'
,allowBlank: false
,blankText: _('plugin_err_ns_name')
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'modx-combo-category'
,name: 'category'
Expand All @@ -655,6 +712,11 @@ MODx.window.QuickCreatePlugin = function(config) {
,fieldLabel: _('description')
,anchor: '100%'
,rows: 2
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'textarea'
,name: 'plugincode'
Expand Down Expand Up @@ -740,12 +802,24 @@ MODx.window.QuickCreateTV = function(config) {
,name: 'name'
,fieldLabel: _('name')
,anchor: '100%'
,allowBlank: false
,blankText: _('tv_err_ns_name')
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'textfield'
,name: 'caption'
,id: 'modx-'+this.ident+'-caption'
,fieldLabel: _('caption')
,anchor: '100%'
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
},{
xtype: 'label'
,forId: 'modx-'+this.ident+'-caption'
Expand All @@ -761,6 +835,11 @@ MODx.window.QuickCreateTV = function(config) {
,name: 'description'
,fieldLabel: _('description')
,anchor: '100%'
,listeners: {
change: {
fn: MODx.util.stripAndEncode.onChange
}
}
}]
},{
columnWidth: .4
Expand Down

0 comments on commit 1aef680

Please sign in to comment.