PDA

View Full Version : How do I create a class scoped variable for a controller in Architect?



denisputnam
23 Aug 2013, 1:34 PM
I need to keep track of which record index gets selected in a grid in order to mark a the same record associated with a form as dirty so my controller knows to sync the record to the store. Where can I create a variable to store the index in the controller so I can mark the correct record in Architect 2?


Ext.define('MySchool.controller.SubjectsController', { extend: 'Ext.app.Controller',


models: [
'SubjectsModel'
],
stores: [
'SubjectStore'
],
views: [
'MainPanel',
'SubjectsGridPanel',
'SubjectsForm',
'SubjectsPanel'
],


refs: [
{
ref: 'subjectsForm',
selector: 'form'
}
],


constructor: function(cfg) {
cfg = cfg || {};
this.callParent(this.processSubjectsController(cfg));
},


processSubjectsController: function(config) {
return config;
},


onSubjectsgridSelect: function(rowmodel, record, index, eOpts) {
window.console.log( "selected row in grid." );
window.console.log( "index=" + index );
//debugger;
if ( record ) {
this.getSubjectsForm().getForm().loadRecord(record);
}
},


onSubjectdescriptiontextareaChange: function(field, newValue, oldValue, eOpts) {
// NEED TO MARK THE GRID's RECORD DIRTY HERE BUT I DON'T HOW TO GET A HOLD OF THE RECORD INDEX OR THE RECORD.
},


onSubjectobjectivetextareaChange: function(field, newValue, oldValue, eOpts) {
// NEED TO MARK THE GRID's RECORD DIRTY HERE BUT I DON'T HOW TO GET A HOLD OF THE RECORD INDEX OR THE RECORD.
},


init: function(application) {


this.control({
'subjectsgridpanel': {
selectionchange: this.gridSelectionChange,
viewready: this.onViewReady
},
'subjectsavetool': {
click: this.onSubjectsavetoolidClick
}
});




this.control({
"#subjectsgrid": {
select: this.onSubjectsgridSelect
},
"#subjectdescriptiontextarea": {
change: this.onSubjectdescriptiontextareaChange
},
"#subjectobjectivetextarea": {
change: this.onSubjectobjectivetextareaChange
}
});
},


gridSelectionChange: function(model, records) {


if ( records[0] ) {
this.getSubjectsForm().getForm().loadRecord(records[0]);
}
},


onViewReady: function(grid) {


grid.getSelectionModel().select( 0 );
},


onSubjectsavetoolidClick: function(tool, e, eOpts) {
window.console.log( "Save..." );
//debugger;


var mystore = Ext.getStore("SubjectStore");


var records = mystore.getModifiedRecords();
for( var i = 0; i < records.length; i++ )
{
records[i].set( 'lastUpdated', new Date() );
var form = Ext.getCmp( 'subjectdetailsform' );
var formValues = form.getValues();
records[i].set( 'description', formValues.description );
records[i].set( 'objectives', formValues.objectives );
window.console.log( 'objectives=' + formValues.objectives );
window.console.log( 'description=' + formValues.description );
}


mystore.sync();
//mystore.commmitChanges();


// Last but not least, I can do this (Approach #3)
//Ext.app.Application.fireEvent("saveSubjects", tool );
}


});

denisputnam
24 Aug 2013, 7:42 AM
Never mind. I see that you can add it in the Config window of the Architect IDE.