-1){E.push(this.buildColumn(F.name))}},this);Ext.each(A,function(F){if(this.preferredColumns.indexOf(F.name)==-1&&this.ignoreColumns.indexOf(F.name)==-1){E.push(this.buildColumn(F.name))}if(this.wideColumns.indexOf(F.name)){wideColumns.push(F.name)}},this);for(var D=E.length-1;D>=0;D--){var B=E[D];if(this.narrowColumns.indexOf(B.id)>-1){Ext.applyIf(B,{width:this.narrowColumnWidth})}else{if(this.wideColumns.indexOf(B.id)>-1){Ext.applyIf(B,{width:this.wideColumnWidth})}else{Ext.applyIf(B,{width:this.normalColumnWidth})}}}}return E},getFields:function(){if(this.useColumns===undefined){return this.model.prototype.fields.items}else{var A=[];Ext.each(this.useColumns,function(B){A.push({name:B})},this);return A}},buildColumn:function(A){var A=A||{};if(typeof(A)=="string"){A={name:A}}return Ext.applyIf(A,{id:A.name,header:A.name.replace(/_/g," ").titleize(),sortable:true,dataIndex:A.name})},hasAddButton:true,hasEditButton:true,hasDeleteButton:true,buildAddButton:function(A){return new Ext.Button(Ext.applyIf(A||{},{text:"New "+this.model.prototype.singularHumanName,scope:this,iconCls:"add",handler:this.onAdd}))},buildEditButton:function(A){return new Ext.Button(Ext.applyIf(A||{},{text:"Edit selected",scope:this,iconCls:"edit",disabled:true,handler:this.onEdit}))},buildDeleteButton:function(A){return new Ext.Button(Ext.applyIf(A||{},{text:"Delete selected",disabled:true,scope:this,iconCls:"delete",handler:this.onDelete}))},buildTopToolbar:function(){var A=[];if(this.hasAddButton===true){this.addButton=this.buildAddButton();A.push(this.addButton,"-")}if(this.hasEditButton===true){this.editButton=this.buildEditButton();A.push(this.editButton,"-")}if(this.hasDeleteButton===true){this.deleteButton=this.buildDeleteButton();A.push(this.deleteButton,"-")}if(this.hasSearchField===true){this.searchField=this.buildSearchField();A.push(this.searchField,"-")}this.getSelectionModel().on("selectionchange",function(B){if(B.getCount()>0){if(this.deleteButton!=undefined){this.deleteButton.enable()}if(this.editButton!=undefined){this.editButton.enable()}}else{if(this.deleteButton!=undefined){this.deleteButton.disable()}if(this.editButton!=undefined){this.editButton.disable()}}},this);return A},pageSize:25,buildBottomToolbar:function(A){return new Ext.PagingToolbar({store:A,displayInfo:true,pageSize:this.pageSize,emptyMsg:String.format("No {0} to display",this.model.prototype.pluralHumanName)})},hasSearchField:false,searchParamName:"q",buildSearchField:function(){this.searchField=new Ext.form.TwinTriggerField({width:200,validationEvent:false,validateOnBlur:false,hideTrigger1:true,onTrigger1Click:this.clearSearchField.createDelegate(this,[]),onTrigger2Click:this.onSearch.createDelegate(this,[]),trigger1Class:"x-form-clear-trigger",trigger2Class:"x-form-search-trigger"});this.searchField.on("specialkey",function(B,A){if(A.getKey()===A.ESC){this.clearSearchField()}A.stopEvent();if(A.getKey()===A.ENTER){this.onSearch()}},this);return this.searchField},clearSearchField:function(){var A=this.searchField;A.el.dom.value="";A.triggers[0].hide();this.doSearch()},onSearch:function(){var B=this.searchField,A=B.getRawValue();if(A.length<1){this.clearSearchField()}else{B.triggers[0].show();this.doSearch(A)}},doSearch:function(A){A=A||this.searchField.getRawValue()||"";var B={start:0};this.store.baseParams=this.store.baseParams||{};this.store.baseParams[this.searchParamName]=A;this.store.reload({params:B})},onAdd:function(){this.fireEvent("new")},onEdit:function(B){var A=this.getSelectionModel().getSelected();if(A){this.fireEvent("edit",A)}},onDelete:function(){Ext.Msg.confirm("Are you sure?",String.format("Are you sure you want to delete this {0}? This cannot be undone.",this.model.prototype.modelName.titleize()),function(A){if(A=="yes"){var B=this.getSelectionModel().getSelected();if(B){this.fireEvent("delete",B)}}},this)}});Ext.reg("scaffold_index",ExtMVC.view.scaffold.Index);ExtMVC.view.scaffold.New=Ext.extend(ExtMVC.view.scaffold.ScaffoldFormPanel,{initComponent:function(){Ext.applyIf(this,{title:"New "+this.model.prototype.singularHumanName});ExtMVC.view.scaffold.New.superclass.initComponent.apply(this,arguments)}});Ext.reg("scaffold_new",ExtMVC.view.scaffold.New);ExtMVC.view.scaffold.Edit=Ext.extend(ExtMVC.view.scaffold.ScaffoldFormPanel,{initComponent:function(){Ext.applyIf(this,{title:"Edit "+this.model.prototype.singularHumanName});ExtMVC.view.scaffold.Edit.superclass.initComponent.apply(this,arguments)},loadRecord:function(A){this.instance=A;this.getForm().loadRecord(A)},onSave:function(){this.fireEvent("save",this.instance,this.getFormValues(),this)}});Ext.reg("scaffold_edit",ExtMVC.view.scaffold.Edit);ExtMVC.view.HasManyEditorGridPanel=Ext.extend(Ext.grid.EditorGridPanel,{initComponent:function(){Ext.applyIf(this,{autoScroll:true,store:this.association.findAll(),viewConfig:{forceFit:true}});if(this.hasTopToolbar){this.addTopToolbar()}ExtMVC.view.HasManyEditorGridPanel.superclass.initComponent.apply(this,arguments);this.on("afteredit",function(A){A.record.save({success:function(){A.record.commit()}})},this);this.getSelectionModel().on("selectionchange",function(A,B){if(this.deleteButton){this.deleteButton.enable()}},this)},hasTopToolbar:true,hasNewButton:true,hasDeleteButton:true,addTopToolbar:function(B){var A=[];if(this.hasNewButton){this.newButton=new Ext.Toolbar.Button({iconCls:"add",text:"Add",scope:this,handler:this.onAdd});A.push(this.newButton);A.push("-")}if(this.hasDeleteButton){this.deleteButton=new Ext.Toolbar.Button({text:"Remove selected",disabled:true,iconCls:"delete",scope:this,handler:this.onDelete});A.push(this.deleteButton)}Ext.applyIf(this,{tbar:A})},windowConfig:{},onAdd:function(A){if(!this.addWindow){this.addWindow=new Ext.Window(Ext.applyIf(this.windowConfig,{title:"New",layout:"fit",modal:true,height:300,width:400,items:[this.form],closeAction:"hide",buttons:[{text:"Save",iconCls:"save",scope:this,handler:this.onSaveNew},{text:"Cancel",iconCls:"cancel",scope:this,handler:this.onCancelNew}]}))}this.addWindow.show()},onDelete:function(B){var A=this.getSelectionModel().selection.record;if(A){A.destroy({scope:this,success:function(){this.store.reload()},failure:function(){Ext.Msg.alert("Delete failed","Something went wrong while trying to delete - please try again");this.store.reload()}})}this.deleteButton.disable()},onSaveNew:function(){this.association.create(this.form.getForm().getValues(),{scope:this,success:function(B,A){this.store.reload();this.addWindow.hide()},failure:function(B,A){this.form.getForm().clearInvalid();this.form.getForm().markInvalid(B.errors.forForm())}})},onCancelNew:function(A){this.addWindow.hide()}});Ext.reg("hasmany_editorgrid",ExtMVC.view.HasManyEditorGridPanel);ExtMVC.view.FormWindow=Ext.extend(Ext.Window,{modal:true,height:230,width:400,initComponent:function(){this.form=this.buildForm();Ext.apply(this,{items:[this.form],buttons:[{text:"Save",iconCls:"save",scope:this,handler:this.onSave},{text:"Cancel",iconCls:"cancel",scope:this,handler:this.onCancel}],layout:"fit",closeAction:"hide"});ExtMVC.view.FormWindow.superclass.initComponent.apply(this,arguments)},buildForm:function(){return new Ext.form.FormPanel({})},loadRecord:function(A){this.instance=A;this.form.form.loadRecord(A)},onSave:function(){this.fireEvent("save",this.getFormValues(),this)},onCancel:function(){this.hide()},getFormValues:function(){var B=this.form.getForm(),A={};B.items.each(function(D){var C=(typeof D.getSubmitValue=="function")?"getSubmitValue":"getValue";A[D.getName()]=D[C]()},this);return A}});Ext.reg("formwindow",ExtMVC.view.FormWindow);
\ No newline at end of file
diff --git a/ext-mvc-all.js b/ext-mvc-all.js
index 4908a22..9280ca1 100644
--- a/ext-mvc-all.js
+++ b/ext-mvc-all.js
@@ -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);
@@ -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:
*
-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
}
});
*
- */
-ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
+ */
+ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
modal : true,
height : 230,
width : 400,
@@ -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);
},
/**
@@ -4637,7 +4645,7 @@ ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
return values;
}
-});
-
+});
+
Ext.reg('formwindow', ExtMVC.view.FormWindow);
diff --git a/scripts/stats.rb b/scripts/stats.rb
index 3d1a858..46c3b7e 100644
--- a/scripts/stats.rb
+++ b/scripts/stats.rb
@@ -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
@@ -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
@@ -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
@@ -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)
diff --git a/view/FormWindow.js b/view/FormWindow.js
index c622039..3162568 100644
--- a/view/FormWindow.js
+++ b/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:
*
-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
}
});
*
- */
-ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
+ */
+ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
modal : true,
height : 230,
width : 400,
@@ -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);
},
/**
@@ -107,6 +110,6 @@ ExtMVC.view.FormWindow = Ext.extend(Ext.Window, {
return values;
}
-});
-
+});
+
Ext.reg('formwindow', ExtMVC.view.FormWindow);
\ No newline at end of file