Skip to content

Commit

Permalink
Added optional viewConfig to edit action on Crud Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Spencer committed Aug 10, 2009
1 parent 6b7c656 commit 61ae23c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 34 deletions.
11 changes: 8 additions & 3 deletions controller/CrudController.js
Expand Up @@ -166,17 +166,22 @@ ExtMVC.controller.CrudController = Ext.extend(ExtMVC.controller.Controller, {
* Renders the custom Edit view if present, otherwise falls back to the default scaffold Edit form
* @param {Mixed} instance The model instance to edit. If not given an ExtMVC.model.Base
* instance, a findById() will be called on this controller's associated model
* @param {Object} viewConfig Optional config object to pass to the view class constructor
*/
edit: function(instance) {
edit: function(instance, viewConfig) {
viewConfig = viewConfig || {};

if (instance instanceof Ext.data.Record) {
var editView = this.render('Edit', {
Ext.applyIf(viewConfig, {
model : this.model,
controller : this,
listeners : this.getEditViewListeners(),
viewsPackage: this.viewsPackage,
id : String.format("{0}_edit_{1}", this.name, instance.get(instance.primaryKey))
id : String.format("{0}_edit_{1}", this.name, instance.get(instance.primaryKey))
});

var editView = this.render('Edit', viewConfig);

editView.loadRecord(instance);

this.onEdit(editView, instance);
Expand Down
2 changes: 1 addition & 1 deletion ext-mvc-all-min.js

Large diffs are not rendered by default.

38 changes: 23 additions & 15 deletions ext-mvc-all.js
Expand Up @@ -1497,17 +1497,22 @@ ExtMVC.controller.CrudController = Ext.extend(ExtMVC.controller.Controller, {
* Renders the custom Edit view if present, otherwise falls back to the default scaffold Edit form
* @param {Mixed} instance The model instance to edit. If not given an ExtMVC.model.Base
* instance, a findById() will be called on this controller's associated model
* @param {Object} viewConfig Optional config object to pass to the view class constructor
*/
edit: function(instance) {
edit: function(instance, viewConfig) {
viewConfig = viewConfig || {};

if (instance instanceof Ext.data.Record) {
var editView = this.render('Edit', {
Ext.applyIf(viewConfig, {
model : this.model,
controller : this,
listeners : this.getEditViewListeners(),
viewsPackage: this.viewsPackage,
id : String.format("{0}_edit_{1}", this.name, instance.get(instance.primaryKey))
id : String.format("{0}_edit_{1}", this.name, instance.get(instance.primaryKey))
});

var editView = this.render('Edit', viewConfig);

editView.loadRecord(instance);

this.onEdit(editView, instance);
Expand Down Expand Up @@ -4528,24 +4533,27 @@ ExtMVC.view.HasManyEditorGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {

Ext.reg('hasmany_editorgrid', ExtMVC.view.HasManyEditorGridPanel);

/**
* @class ExtMVC.view.FormWindow
* @extends Ext.Window
/**
* @class ExtMVC.view.FormWindow
* @extends Ext.Window
* Convenience class for creating a window with a default form. Example:
*
<pre>
MyApp.views.MyFormWindow = Ext.extend(ExtMVC.view.FormWindow, {
height: 200,
width : 400,
MyApp.views.MyFormWindow = Ext.extend(ExtMVC.view.FormWindow, {
height: 200,
width : 400,
buildForm: function() {
//return your Ext.form.FormPanel here
}
});
</pre>
*
*/
ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
*/
ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
modal : true,
height : 230,
width : 400,
Expand Down Expand Up @@ -4610,7 +4618,7 @@ ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
* Called when the user clicks the save button
*/
onSave: function() {
this.fireEvent('save', this.getFormValues());
this.fireEvent('save', this.getFormValues(), this);
},

/**
Expand All @@ -4637,7 +4645,7 @@ ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {

return values;
}
});

});

Ext.reg('formwindow', ExtMVC.view.FormWindow);

11 changes: 8 additions & 3 deletions scripts/stats.rb
Expand Up @@ -110,7 +110,7 @@ def column_order

# The lines to show, in order
def line_order
[:controller_files, :model_files, :view_files, :lib_files, :controller_specs, :model_specs]
[:controller_files, :model_files, :view_files, :lib_files, :controller_specs, :model_specs, :view_specs]
end

# The arrays to use when calculating totals for project LOC etc
Expand All @@ -120,7 +120,7 @@ def project_code_arrays

# The arrays to use when calculating totals for project spec LOC etc
def project_spec_arrays
[:controller_specs, :model_specs]
[:controller_specs, :model_specs, :view_specs]
end

# Mappings between method and human names for line headings
Expand All @@ -132,7 +132,8 @@ def line_headings
:lib_files => "Libraries",
:plugin_files => "Plugins",
:controller_specs => "Controller Specs",
:model_specs => "Model Specs"
:model_specs => "Model Specs",
:view_specs => "View Specs"
}
end

Expand Down Expand Up @@ -176,6 +177,10 @@ def controller_specs
def model_specs
files_in('spec/models')
end

def view_specs
files_in('spec/views')
end

private
def files_in(directory)
Expand Down
27 changes: 15 additions & 12 deletions view/FormWindow.js
@@ -1,21 +1,24 @@
/**
* @class ExtMVC.view.FormWindow
* @extends Ext.Window
/**
* @class ExtMVC.view.FormWindow
* @extends Ext.Window
* Convenience class for creating a window with a default form. Example:
*
<pre>
MyApp.views.MyFormWindow = Ext.extend(ExtMVC.view.FormWindow, {
height: 200,
width : 400,
MyApp.views.MyFormWindow = Ext.extend(ExtMVC.view.FormWindow, {
height: 200,
width : 400,
buildForm: function() {
//return your Ext.form.FormPanel here
}
});
</pre>
*
*/
ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
*/
ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
modal : true,
height : 230,
width : 400,
Expand Down Expand Up @@ -80,7 +83,7 @@ ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
* Called when the user clicks the save button
*/
onSave: function() {
this.fireEvent('save', this.getFormValues());
this.fireEvent('save', this.getFormValues(), this);
},

/**
Expand All @@ -107,6 +110,6 @@ ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {

return values;
}
});

});

Ext.reg('formwindow', ExtMVC.view.FormWindow);

0 comments on commit 61ae23c

Please sign in to comment.