The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

privetik (1) [Avatar] Offline
#1
I have ext_scaffold text:string token:string, I adding token through controller, and i dont wanna sho it in my grid (i will be hidden), user can create only text (token creats automatically in controller). How i can do it?

my index.js (if you need)

ExtScaffold.Question = Ext.extend(Ext.Panel, {
//
// static text properties (override for i18n)
//
labels: {
'id': '#'
,'question[text]': 'Text'
,'question[security_token]': 'Security token'
},
title: 'Questions',
newButtonLabel: 'New...',
newButtonTooltip: 'Create new Question',
editButtonLabel: 'Edit...',
editButtonTooltip: 'Edit selected Question',
selectRowText: 'Please select a row first.',
deleteButtonLabel: 'Delete...',
formToggleButtonLabel: 'Details',
formToggleButtonTooltip: 'Show / Hide Details',
deleteButtonTooltip: 'Delete selected Question...',
deleteConfirmationText: 'Really delete?',
deleteFailedText: 'Delete operation failed. The record might have been deleted by someone else.',
paginationStatusTemplate: 'Record {0} - {1} of {2}',
paginationNoRecordsText: 'No records found',
savingMessage: 'Saving...',
saveFailedText: 'Save operation failed. The record might have been deleted by someone else.',
errorMessageBoxTitle: 'Error',
confirmationMessageBoxTitle: 'Confirmation',

//
// custom properties
//
url: '#',
baseParams: {},
recordsPerPage: 50,

//
// private properties
//
formPanelWasCollapsed: true,
selectedRecordId: undefined,

// defaults for (superclass) config
layout: 'border',
border: false,
cls: 'ext-scaffold',

//
// public instance methods
//
activateGrid: function() {
var gp = this.getGridPanel();
var gv = gp.getView();
var ds = this.getStore();

gp.enable();

if (this.formPanelWasCollapsed) this.getFormPanel().collapse();

// give focus to the grid to enable up/down keys
if (ds.getCount() > 0) {
if (this.selectedRecordId) {
var matchingRecords = ds.query('id', this.selectedRecordId);
if (matchingRecords) {
gv.focusRow(ds.indexOf(matchingRecords.first())); // focus selected row
} else {
gv.focusRow(0); // no matching selection -> focus first row
}
} else {
gv.focusRow(0); // no selection at all -> focus first row
}
}
},

activateForm: function(mode) {
var fp = this.getFormPanel();

fp.setFormMode(mode);

this.formPanelWasCollapsed = fp.collapsed;
if (fp.collapsed) fp.expand();

fp.setWidth(fp.initialConfig.width, true);
this.doLayout(); // re-render border layout to reflect current form width

if(mode == 'new' || mode == 'edit') {
this.getGridPanel().disable(); // make new and edit modal by disabling the gridPanel
// focus first form field -- we need a delay here to allow processing of expand()
fp.getForm().findField('question[text]').focus(true, 400);
}
},

getGridPanel: function() {
return Ext.getCmp('question-grid');
},

getFormPanel: function() {
return Ext.getCmp('question-form');
},

getStore: function() {
return this.getGridPanel().getStore();
},

resetForm: function(activateGrid) {
var fp = this.getFormPanel();
fp.getForm().reset();
fp.setFormMode('show');
if (activateGrid) this.activateGrid();
},

reloadStore: function(resetForm) {
this.getStore().reload();
if (resetForm) this.resetForm(true);
},

refreshFormToggle: function() {
Ext.getCmp('question-form-toggle').toggle(!this.getFormPanel().collapsed);
},

//
// initComponent
//
initComponent: function() {
var scaffoldPanel = this; // save scope for later reference

var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: scaffoldPanel.url + '?format=ext_json',
method: 'GET'
}),
reader: new Ext.data.JsonReader({
root: 'questions',
id: 'id',
totalProperty: 'results'
},[
{ name: 'id', mapping: 'question.id' }
,{ name: 'question[text]', mapping: 'question.text' }
,{ name: 'question[security_token]', mapping: 'question.security_token' }
]),
remoteSort: true, // turn on server-side sorting
sortInfo: {field: 'id', direction: 'ASC'}
});

var cm = new Ext.grid.ColumnModel([
{id: 'id', header: scaffoldPanel.labels['id'], width: 40, dataIndex: 'id'}
,{ header: scaffoldPanel.labels['question[text]'], dataIndex: 'question[text]' }
,{ header: scaffoldPanel.labels['question[security_token]'], dataIndex: 'question[security_token]' }
]);

cm.defaultSortable = true; // all fields are sortable by default

// button handlers

function addButtonHandler() {
scaffoldPanel.selectedRecordId = undefined;
scaffoldPanel.activateForm('new');
scaffoldPanel.getFormPanel().getTopToolbar().hide();
}

function editButtonHandler() {
var selected = scaffoldPanel.getGridPanel().getSelectionModel().getSelected();
if (selected) {
scaffoldPanel.activateForm('edit');
} else {
Ext.Msg.alert(scaffoldPanel.errorMessageBoxTitle,scaffoldPanel.selectRowText);
}
}

function deleteButtonHandler() {
var selected = scaffoldPanel.getGridPanel().getSelectionModel().getSelected();
if (selected) {
Ext.Msg.confirm(scaffoldPanel.confirmationMessageBoxTitle,scaffoldPanel.deleteConfirmationText, function(btn) {
if (btn == 'yes') {
var conn = new Ext.data.Connection({
extraParams: scaffoldPanel.baseParams
});
conn.request({
url: scaffoldPanel.url + '/' + selected.data.id,
method: 'POST',
params: { _method: 'DELETE' },
success: function(response, options) {
scaffoldPanel.reloadStore(true);
},
failure: function(response, options) {
// the delete probably failed because the record is already gone, so let's reload the store
scaffoldPanel.reloadStore(true);
Ext.Msg.alert(scaffoldPanel.errorMessageBoxTitle,scaffoldPanel.deleteFailedText);
}
});
}
});
} else {
Ext.Msg.alert(scaffoldPanel.errorMessageBoxTitle,scaffoldPanel.selectRowText);
}
}

Ext.apply(this, {
items: [{
// add the grid panel to center region
region: 'center',
xtype: 'grid',
id: 'question-grid',
ds: ds,
cm: cm,
sm: new Ext.grid.RowSelectionModel({
singleSelect:true,
listeners: {
// populate form fields when a row is selected
'rowselect': function(sm, row, rec) {
scaffoldPanel.selectedRecordId = rec.data.id;
scaffoldPanel.getFormPanel().getForm().loadRecord(rec);
}
}
}),
stripeRows: true,

// inline toolbars
tbar: [
{
text: scaffoldPanel.newButtonLabel,
tooltip: scaffoldPanel.newButtonTooltip,
handler: addButtonHandler,
iconCls: 'add'
},{
text: scaffoldPanel.editButtonLabel,
tooltip: scaffoldPanel.editButtonTooltip,
handler: editButtonHandler,
iconCls: 'edit'
},{
text: scaffoldPanel.deleteButtonLabel,
tooltip: scaffoldPanel.deleteButtonTooltip,
handler: deleteButtonHandler,
iconCls: 'remove'
}, '->', {
id: 'question-form-toggle',
iconCls: 'details',
text: scaffoldPanel.formToggleButtonLabel,
tooltip: scaffoldPanel.formToggleButtonTooltip,
enableToggle: true,
handler: function() {
scaffoldPanel.getFormPanel().toggleCollapse();
}
}, '->'
],
bbar: new Ext.PagingToolbar({
pageSize: scaffoldPanel.recordsPerPage,
store: ds,
displayInfo: true,
displayMsg: scaffoldPanel.paginationStatusTemplate,
emptyMsg: scaffoldPanel.paginationNoRecordsText
}),
plugins:[new Ext.ux.grid.Search({
position:'top'
})],
listeners: {
// show form with record on double-click
'rowdblclick': function(grid, row, e) { scaffoldPanel.activateForm('show'); }
}

},{

// add the form to east region
region: 'east',
xtype: 'extscaffoldform',
id: 'question-form',
width: 340,
collapseMode: 'mini',
collapsed: true,
collapsible: true,
titleCollapse: false,
hideCollapseTool: true,
border: false,
frame: true,
listeners: {
// update form-toggle button with new pressed/depressed state
'expand': function() { scaffoldPanel.refreshFormToggle(); },
'collapse': function() { scaffoldPanel.refreshFormToggle(); },

// prevent collapse when grid is disabled
'beforecollapse': function() { return !scaffoldPanel.getGridPanel().disabled; }
},

tbar: new Ext.Toolbar({
hideMode: 'visibility',
items: ['->',
{
tooltip: scaffoldPanel.editButtonTooltip,
handler: editButtonHandler,
iconCls:'edit'
},{
tooltip: scaffoldPanel.deleteButtonTooltip,
handler: deleteButtonHandler,
iconCls:'remove'
}
]
}),

baseParams: scaffoldPanel.baseParams,
items: [
{ fieldLabel: scaffoldPanel.labels['question[text]'], name: 'question[text]', xtype: 'textfield' },
{ fieldLabel: scaffoldPanel.labels['question[security_token]'], name: 'question[security_token]', xtype: 'textfield' }
],

onOk: function() {
var selected = scaffoldPanel.getGridPanel().getSelectionModel().getSelected();

var submitOptions = {
url: scaffoldPanel.url,
waitMsg: scaffoldPanel.savingMessage,
params: { format: 'ext_json' },
success: function(form, action) {
// remember assigned record id (relevant when creating new records,
// will match the known record id otherwise)
scaffoldPanel.selectedRecordId = action.result.data['question[id]'];
scaffoldPanel.reloadStore(true);
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
case Ext.form.Action.SERVER_INVALID:
// validation errors are handled by the form, so we ignore them here
break;
case Ext.form.Action.CONNECT_FAILURE:
case Ext.form.Action.LOAD_FAILURE:
// these might be 404 Not Found or some 5xx Server Error
Ext.Msg.alert(scaffoldPanel.errorMessageBoxTitle,scaffoldPanel.saveFailedText);
break;
}
}
};

scaffoldPanel.getFormPanel().getTopToolbar().show();

if (scaffoldPanel.getFormPanel().currentMode == 'edit') {
// set up request for Rails create action
submitOptions.params._method = 'PUT';
submitOptions.url = submitOptions.url + '/' + selected.data.id;
}
scaffoldPanel.getFormPanel().getForm().submit(submitOptions);
},

onCancel: function() {
var sm = scaffoldPanel.getGridPanel().getSelectionModel();
var fp = scaffoldPanel.getFormPanel();

scaffoldPanel.getFormPanel().getTopToolbar().show();
scaffoldPanel.activateGrid();

// cancel from show mode should always collapse the form-panel (button label: Close)
if (fp.currentMode == 'show') fp.collapse();

fp.setFormMode('show');
if (sm.hasSelection()) {
fp.getForm().loadRecord(sm.getSelected()); // reload previous record version
} else {
fp.getForm().reset();
}
}
}]
});

// try to re-establish selection after datastore load
ds.on('load', function() {
if (this.selectedRecordId) {
var matchingRecords = ds.query('id', this.selectedRecordId);
if (matchingRecords && matchingRecords.length > 0) {
this.getGridPanel().getSelectionModel().selectRecords([matchingRecords.first()]);
} else {
this.selectedRecordId = undefined;
this.resetForm(false);
}
}
}, this);

// make sure form toggle reflects form collapsed state even on initial load
ds.on('load', function() {
this.refreshFormToggle();
this.resetForm(true);
}, this, { single:true });

ExtScaffold.Question.superclass.initComponent.apply(this, arguments);
},

onRender: function() {
ExtScaffold.Question.superclass.onRender.apply(this, arguments);

// reset form and trigger initial data load
this.getStore().load({params: {start: 0, limit: this.recordsPerPage} });
}
});


What i should delte from this to hide fields that suers should type there something?