extjs_scaffold 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +80 -0
- data/Rakefile +28 -0
- data/extjs_scaffold.gemspec +27 -0
- data/features/scaffold_generator.feature +124 -0
- data/features/step_definitions/aruba_ext_steps.rb +6 -0
- data/features/support/setup.rb +5 -0
- data/lib/extjs_scaffold.rb +1 -0
- data/lib/extjs_scaffold/version.rb +3 -0
- data/lib/generators/extjs_scaffold.rb +15 -0
- data/lib/generators/extjs_scaffold/install/USAGE +28 -0
- data/lib/generators/extjs_scaffold/install/install_generator.rb +82 -0
- data/lib/generators/extjs_scaffold/install/templates/Actionable.js +27 -0
- data/lib/generators/extjs_scaffold/install/templates/App.js +11 -0
- data/lib/generators/extjs_scaffold/install/templates/EditWindow.js +135 -0
- data/lib/generators/extjs_scaffold/install/templates/FormPanel.js +27 -0
- data/lib/generators/extjs_scaffold/install/templates/Format.js +34 -0
- data/lib/generators/extjs_scaffold/install/templates/GridPanel.js +289 -0
- data/lib/generators/extjs_scaffold/install/templates/ParentComboField.js +39 -0
- data/lib/generators/extjs_scaffold/install/templates/Rails.js +162 -0
- data/lib/generators/extjs_scaffold/install/templates/ScrollingToolbar.js +170 -0
- data/lib/generators/extjs_scaffold/install/templates/SearchField.js +104 -0
- data/lib/generators/extjs_scaffold/install/templates/UpdateWindow.js +112 -0
- data/lib/generators/extjs_scaffold/install/templates/Updateable.js +31 -0
- data/lib/generators/extjs_scaffold/install/templates/ext_auth.html.erb +3 -0
- data/lib/generators/extjs_scaffold/install/templates/extjs_scaffold.css.scss +9 -0
- data/lib/generators/extjs_scaffold/install/templates/images/README.txt +1 -0
- data/lib/generators/extjs_scaffold/install/templates/images/add.gif +0 -0
- data/lib/generators/extjs_scaffold/install/templates/images/application_form_edit.png +0 -0
- data/lib/generators/extjs_scaffold/install/templates/images/delete.gif +0 -0
- data/lib/generators/extjs_scaffold/install/templates/images/tick.png +0 -0
- data/lib/generators/extjs_scaffold/scaffold/USAGE +24 -0
- data/lib/generators/extjs_scaffold/scaffold/scaffold_generator.rb +19 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/USAGE +20 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/scaffold_controller_generator.rb +296 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/controller.rb +191 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/js/Controller.js +53 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/js/EditForm.js +17 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/js/EditWindow.js +27 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/js/Grid.js +26 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/js/Model.js +43 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/js/ReferenceStore.js +27 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/js/Store.js +28 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/js/UpdateForm.js +17 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/js/UpdateWindow.js +21 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/model.rb +57 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/tests/controller_spec.rb +197 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/tests/controller_test.rb +85 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/views/erb/index.html.erb +3 -0
- data/lib/generators/extjs_scaffold/scaffold_controller/templates/views/haml/index.html.haml +3 -0
- data/spec/dummy/.gitignore +15 -0
- data/spec/dummy/README +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +7 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +48 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/doc/README_FOR_APP +2 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +241 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/generators/install_spec.rb +140 -0
- data/spec/generators/scaffold_spec.rb +244 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/App.js +12 -0
- data/spec/support/rails_routes.rb +4 -0
- metadata +290 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
/**
|
2
|
+
* @author Mark H Winkler
|
3
|
+
* @class App.ux.window.UpdateWindow
|
4
|
+
* @extends Ext.Window
|
5
|
+
* <p>Ext.Window modal window used for updating all list detail.</p>
|
6
|
+
*/
|
7
|
+
Ext.define('<%= app_name %>.ux.window.UpdateWindow', {
|
8
|
+
extend: 'Ext.Window',
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Config defaults
|
12
|
+
*/
|
13
|
+
width: 600,
|
14
|
+
modal: true,
|
15
|
+
constrainHeader: true,
|
16
|
+
resizable: false,
|
17
|
+
closable: false,
|
18
|
+
title: 'Update All Selected Records',
|
19
|
+
|
20
|
+
// parent grid and child form ids
|
21
|
+
gridId: '',
|
22
|
+
formItemId: '',
|
23
|
+
// array of selected record ids
|
24
|
+
selectedRecords: [],
|
25
|
+
|
26
|
+
initComponent: function() {
|
27
|
+
var me = this;
|
28
|
+
me.buttons = this.buildButtons();
|
29
|
+
me.callParent(arguments);
|
30
|
+
},
|
31
|
+
|
32
|
+
/**
|
33
|
+
* set up bottom window buttons
|
34
|
+
*/
|
35
|
+
buildButtons: function() {
|
36
|
+
var me = this;
|
37
|
+
items = [];
|
38
|
+
items.push({
|
39
|
+
text: 'Cancel',
|
40
|
+
scope: me,
|
41
|
+
handler: me.closeWindow
|
42
|
+
});
|
43
|
+
|
44
|
+
items.push({
|
45
|
+
text: 'Update All',
|
46
|
+
scope: me,
|
47
|
+
handler: me.updateAll
|
48
|
+
});
|
49
|
+
|
50
|
+
return items;
|
51
|
+
},
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Close window called from Cancel button
|
55
|
+
*/
|
56
|
+
closeWindow: function() {
|
57
|
+
var me = this;
|
58
|
+
me.close();
|
59
|
+
},
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Calls the associated grid uses gridId config
|
63
|
+
*/
|
64
|
+
updateAll: function() {
|
65
|
+
var me = this;
|
66
|
+
var grid = Ext.getCmp(me.gridId);
|
67
|
+
var formPanel = me.getComponent(me.formItemId);
|
68
|
+
var form = formPanel.getForm();
|
69
|
+
|
70
|
+
if (form.isValid()) {
|
71
|
+
// get form data
|
72
|
+
var fields = form.getFields().items;
|
73
|
+
var updateObj = {};
|
74
|
+
for(var i=0; i < fields.length; i++) {
|
75
|
+
var field = fields[i];
|
76
|
+
if (!field.isDisabled()) {
|
77
|
+
if (field.getXType() == 'parentcombo') {
|
78
|
+
// handle reference id and display fields
|
79
|
+
// name = id - after []
|
80
|
+
var pos = field.getName().indexOf(']');
|
81
|
+
var idField = field.getName().substring(pos+1);
|
82
|
+
var idValue = field.getValue();
|
83
|
+
// id = display field
|
84
|
+
if (idValue) {
|
85
|
+
var displayField = field.getId();
|
86
|
+
var displayValue = field.getStore().getById(idValue).get(field.displayField);
|
87
|
+
|
88
|
+
updateObj[idField] = idValue;
|
89
|
+
updateObj[displayField] = displayValue;
|
90
|
+
}
|
91
|
+
} else {
|
92
|
+
updateObj[field.getId()] = field.getValue();
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
// update the selected records using updateObj fields
|
98
|
+
var records = [];
|
99
|
+
var record;
|
100
|
+
for(i=0; i < me.selectedRecords.length; i++) {
|
101
|
+
record = me.selectedRecords[i];
|
102
|
+
for (var field in updateObj) {
|
103
|
+
record.set(field, updateObj[field])
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
// call the parent grids updateAll function
|
108
|
+
grid.updateAllRecords(me.selectedRecords);
|
109
|
+
me.closeWindow();
|
110
|
+
}
|
111
|
+
}
|
112
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/**
|
2
|
+
* @author Mark H Winkler
|
3
|
+
* @mixin App.ux.data.Updatable
|
4
|
+
* Required use: Model class
|
5
|
+
*
|
6
|
+
* Adds updateModel function to Model class, which updates the model with field data
|
7
|
+
* from the passed record
|
8
|
+
*
|
9
|
+
* Performs a commit so that the changes are not dirty - so Model should be saved to remote
|
10
|
+
* prior to call (if necessary)
|
11
|
+
*
|
12
|
+
* params:
|
13
|
+
* record (model record) - required - record with changed field data
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
Ext.define('<%= app_name %>.ux.data.Updateable', {
|
17
|
+
updateModel: function(record) {
|
18
|
+
var me = this;
|
19
|
+
var fields = this.fields
|
20
|
+
|
21
|
+
// update all fields except id, but only if data is changed
|
22
|
+
Ext.Array.each(fields.items, function(field) {
|
23
|
+
var name = field.name;
|
24
|
+
if (name != 'id' && record.get(name) != me.get(name)) {
|
25
|
+
me.set(name, record.get(name));
|
26
|
+
}
|
27
|
+
});
|
28
|
+
// clear dirty record - assumes already saved to remote (if necessary)
|
29
|
+
me.commit();
|
30
|
+
}
|
31
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
.add {
|
2
|
+
background-image:image-url("extjs_scaffold/add.gif") !important;
|
3
|
+
}
|
4
|
+
.remove {
|
5
|
+
background-image:image-url("extjs_scaffold/delete.gif") !important;
|
6
|
+
}
|
7
|
+
.updateall {
|
8
|
+
background-image:image-url("extjs_scaffold/application_form_edit.png") !important;
|
9
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
The icons in this folder are from http://www.famfamfam.com/lab/icons/silk/
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Description:
|
2
|
+
Generates an Extjs Scaffold for a given resource
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate extjs_scaffold:scaffold widget name:string quantity:integer
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
app/assets/javascripts/controller/Widgets.js
|
9
|
+
app/assets/javascripts/model/Widget.js
|
10
|
+
app/assets/javascripts/store/Widgets.js
|
11
|
+
app/assets/javascripts/view/widget/EditForm.js
|
12
|
+
app/assets/javascripts/view/widget/EditWindow.js
|
13
|
+
app/assets/javascripts/view/widget/Grid.js
|
14
|
+
app/assets/javascripts/view/widget/UpdateForm.js
|
15
|
+
app/assets/javascripts/view/widget/UpdateWindow.js
|
16
|
+
app/assets/javascripts/widgets.js.coffee
|
17
|
+
app/assets/stylesheets/widgets.css.scss
|
18
|
+
app/controllers/widgets_controller.rb
|
19
|
+
app/models/widget.rb
|
20
|
+
app/views/widgets/index.html.erb
|
21
|
+
db/migrate/timestamp_create_widgets.rb
|
22
|
+
test/fixtures/widgets.yml
|
23
|
+
test/functional/widgets_controller.rb
|
24
|
+
test/unit/widget_test.rb
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "rails/generators/rails/scaffold/scaffold_generator"
|
2
|
+
|
3
|
+
module ExtjsScaffold
|
4
|
+
module Generators
|
5
|
+
class ScaffoldGenerator < Rails::Generators::ScaffoldGenerator
|
6
|
+
remove_hook_for :scaffold_controller
|
7
|
+
|
8
|
+
class_option :test_framework, :desc => "Test framework to be invoked"
|
9
|
+
|
10
|
+
hook_for :scaffold_controller, :required => true
|
11
|
+
|
12
|
+
# override super - route added in scaffold_controller_generator
|
13
|
+
def add_resource_route
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Description:
|
2
|
+
Generates an Extjs Scaffold Controller for a given resource
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate extjs_scaffold:scaffold_controller widget name:string quantity:integer
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
app/assets/javascripts/controller/Widgets.js
|
9
|
+
app/assets/javascripts/model/Widget.js
|
10
|
+
app/assets/javascripts/store/Widgets.js
|
11
|
+
app/assets/javascripts/view/widget/EditForm.js
|
12
|
+
app/assets/javascripts/view/widget/EditWindow.js
|
13
|
+
app/assets/javascripts/view/widget/Grid.js
|
14
|
+
app/assets/javascripts/view/widget/UpdateForm.js
|
15
|
+
app/assets/javascripts/view/widget/UpdateWindow.js
|
16
|
+
app/assets/javascripts/widgets.js.coffee
|
17
|
+
app/assets/stylesheets/widgets.css.scss
|
18
|
+
app/controllers/widgets_controller.rb
|
19
|
+
app/views/widgets/index.html.erb
|
20
|
+
test/functional/widgets_controller.rb
|
@@ -0,0 +1,296 @@
|
|
1
|
+
require 'generators/extjs_scaffold'
|
2
|
+
require 'rails/generators/resource_helpers'
|
3
|
+
|
4
|
+
module ExtjsScaffold
|
5
|
+
module Generators
|
6
|
+
class ScaffoldControllerGenerator < Base
|
7
|
+
|
8
|
+
include Rails::Generators::ResourceHelpers
|
9
|
+
|
10
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
11
|
+
|
12
|
+
class_option :file_name, :desc => "Name of file used to hold Ext.application",
|
13
|
+
:aliases => '-n', :default =>ExtjsScaffold::Generators::Base.rails_app_name
|
14
|
+
class_option :app_name, :desc => "Name of app used in Ext.application",
|
15
|
+
:aliases => '-a', :default => ExtjsScaffold::Generators::Base.rails_app_name
|
16
|
+
|
17
|
+
class_option :orm, :desc => "ORM used to generate the controller"
|
18
|
+
class_option :template_engine, :desc => "Template engine to generate view files"
|
19
|
+
class_option :views, :type => :boolean, :default => true
|
20
|
+
class_option :routes, :type => :boolean, :default => true
|
21
|
+
class_option :pagination, :desc => "Rails pagination gem 'kaminari' or 'will_paginate'", :default => 'kaminari'
|
22
|
+
class_option :reference_fields, :type => :hash, :desc => "Collection of fields to use for one table lookup: --reference_fields parent_table:field_name
|
23
|
+
# Default: parent_table:name"
|
24
|
+
class_option :test_framework, :desc => "Test framework to be invoked"
|
25
|
+
|
26
|
+
# add class method 'search' to model
|
27
|
+
def create_model_methods
|
28
|
+
@pagination = options.pagination
|
29
|
+
if File.exists?("#{destination_root}/app/models/#{singular_table_name}.rb")
|
30
|
+
template "model.rb", "app/models/#{controller_file_name}_tmp.rb"
|
31
|
+
f = File.open "#{destination_root}/app/models/#{controller_file_name}_tmp.rb", "r"
|
32
|
+
model_methods = f.read
|
33
|
+
# insert after belongs_to or inject
|
34
|
+
refs = attributes.select{|attr| attr.reference? }.collect{|a| a.name}
|
35
|
+
if refs.size > 0
|
36
|
+
insert_into_file "app/models/#{singular_table_name}.rb", model_methods, :after => "belongs_to :#{refs.last}"
|
37
|
+
else
|
38
|
+
inject_into_class "app/models/#{singular_table_name}.rb", singular_table_name.capitalize, model_methods
|
39
|
+
end
|
40
|
+
remove_file "app/models/#{controller_file_name}_tmp.rb"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
check_class_collision :suffix => "Controller"
|
45
|
+
|
46
|
+
def create_controller_files
|
47
|
+
template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
|
48
|
+
end
|
49
|
+
|
50
|
+
# create Extjs MVC structure
|
51
|
+
def create_js_root_folder
|
52
|
+
empty_directory File.join("app/assets/javascripts", "controller")
|
53
|
+
empty_directory File.join("app/assets/javascripts", "model")
|
54
|
+
empty_directory File.join("app/assets/javascripts", "store")
|
55
|
+
empty_directory File.join("app/assets/javascripts", "view")
|
56
|
+
# create Extjs controller view folder
|
57
|
+
empty_directory File.join("app/assets/javascripts/view", singular_table_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
# copy over controller js files
|
61
|
+
def copy_js_files
|
62
|
+
available_js.each do |name|
|
63
|
+
filename = [name, :js].compact.join(".")
|
64
|
+
case name
|
65
|
+
when 'Controller'
|
66
|
+
template "js/#{filename}", File.join("app/assets/javascripts/controller", "#{plural_table_name.capitalize}.js")
|
67
|
+
when 'Model'
|
68
|
+
template "js/#{filename}", File.join("app/assets/javascripts/model", "#{singular_table_name.capitalize}.js")
|
69
|
+
when 'Store'
|
70
|
+
template "js/#{filename}", File.join("app/assets/javascripts/store", "#{plural_table_name.capitalize}.js")
|
71
|
+
else
|
72
|
+
template "js/#{filename}", File.join("app/assets/javascripts/view", singular_table_name, filename)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# create stores for any reference lookup combos
|
78
|
+
def create_reference_stores
|
79
|
+
attributes.select {|attr| attr.reference? }.each do |attribute|
|
80
|
+
@reference_attribute = attribute
|
81
|
+
filename = [reference_store, :js].compact.join(".")
|
82
|
+
template "js/#{filename}", File.join("app/assets/javascripts/store", "#{singular_table_name.capitalize}#{attribute.name.capitalize.pluralize}.js")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def update_application_js
|
87
|
+
app_init = "\n"
|
88
|
+
app_init << " // #{plural_table_name.capitalize}: Initialize controller and create list grid \n"
|
89
|
+
app_init << " if (undefined != Ext.get('#{plural_table_name}_list')) { \n"
|
90
|
+
app_init << " var controller = this.getController('#{plural_table_name.capitalize}');\n"
|
91
|
+
app_init << " controller.init();\n"
|
92
|
+
app_init << " Ext.create('#{app_name}.view.#{singular_table_name}.Grid',{renderTo: Ext.getBody() });\n"
|
93
|
+
app_init << " }\n"
|
94
|
+
|
95
|
+
insert_into_file "app/assets/javascripts/#{app_file_name}", app_init, :after => "launch: function() {"
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_resource_route
|
99
|
+
return unless options[:routes]
|
100
|
+
route_config = class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
|
101
|
+
route_config << "resources :#{file_name.pluralize} do \n"
|
102
|
+
route_config << " collection do \n"
|
103
|
+
route_config << " post :destroy_all \n"
|
104
|
+
route_config << " post :update_all \n"
|
105
|
+
route_config << " end\n"
|
106
|
+
route_config << " end"
|
107
|
+
route_config << " end" * class_path.size
|
108
|
+
route route_config
|
109
|
+
end
|
110
|
+
|
111
|
+
# copy view templates or hook to :template_engine
|
112
|
+
|
113
|
+
def copy_view_files
|
114
|
+
return unless options[:views]
|
115
|
+
empty_directory File.join("app/views", controller_file_path)
|
116
|
+
# accept haml or default to erb
|
117
|
+
template = options[:template_engine] == 'haml' ? options[:template_engine] : 'erb'
|
118
|
+
|
119
|
+
available_views.each do |view|
|
120
|
+
filename = filename_with_extensions(view, :html, template)
|
121
|
+
template "views/#{template}/#{filename}", File.join("app/views", controller_file_path, filename)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def copy_test_files
|
126
|
+
case options[:test_framework]
|
127
|
+
when :rspec, 'rspec'
|
128
|
+
template "tests/controller_spec.rb", File.join("spec/controllers", "#{controller_file_name}_controller_spec.rb")
|
129
|
+
when :test_unit, 'test_unit'
|
130
|
+
template "tests/controller_test.rb", File.join("test/functional", "#{controller_file_name}_controller_test.rb")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
protected
|
135
|
+
|
136
|
+
def app_file_name
|
137
|
+
[options.file_name, :js].compact.join(".")
|
138
|
+
end
|
139
|
+
|
140
|
+
def app_name
|
141
|
+
options.app_name
|
142
|
+
end
|
143
|
+
|
144
|
+
def available_views
|
145
|
+
%w(index)
|
146
|
+
end
|
147
|
+
|
148
|
+
def filename_with_extensions(name, prefix, suffix)
|
149
|
+
[name, prefix, suffix].compact.join(".")
|
150
|
+
end
|
151
|
+
|
152
|
+
def available_js
|
153
|
+
%w(Controller Model Store Grid EditForm EditWindow UpdateForm UpdateWindow)
|
154
|
+
end
|
155
|
+
|
156
|
+
def reference_store
|
157
|
+
return 'ReferenceStore'
|
158
|
+
end
|
159
|
+
|
160
|
+
def reference_model
|
161
|
+
return 'ReferenceModel'
|
162
|
+
end
|
163
|
+
|
164
|
+
def reference_field(attribute)
|
165
|
+
if options.reference_fields && options.reference_fields[attribute.name]
|
166
|
+
options.reference_fields[attribute.name]
|
167
|
+
else
|
168
|
+
'name'
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def create_controller_model_list
|
173
|
+
list = []
|
174
|
+
attributes.select {|attr| attr.reference? }.each do |attribute|
|
175
|
+
list << "'#{attribute.name.capitalize}'"
|
176
|
+
end
|
177
|
+
return list.join(',')
|
178
|
+
end
|
179
|
+
|
180
|
+
def create_controller_store_list
|
181
|
+
list = []
|
182
|
+
attributes.select {|attr| attr.reference? }.each do |attribute|
|
183
|
+
list << "'#{singular_table_name.capitalize}#{attribute.name.pluralize.capitalize}'"
|
184
|
+
end
|
185
|
+
return list.join(',')
|
186
|
+
end
|
187
|
+
|
188
|
+
def create_ext_record(attribute)
|
189
|
+
if attribute.reference?
|
190
|
+
return "name: '#{attribute.name}_#{reference_field(attribute)}'"
|
191
|
+
else
|
192
|
+
case attribute.type.to_s
|
193
|
+
when 'boolean'
|
194
|
+
return "name: '#{attribute.name}', type: 'bool'"
|
195
|
+
when 'datetime', 'date'
|
196
|
+
return "type: 'date', sortType: 'asDate', name: '#{attribute.name}', dateFormat: 'c'"
|
197
|
+
else
|
198
|
+
return "name: '#{attribute.name}'"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def create_ext_column(attribute)
|
204
|
+
if attribute.reference?
|
205
|
+
return "dataIndex: '#{attribute.name}_#{reference_field(attribute)}', header: '#{attribute.name.titleize}', width: 120, sortable: true"
|
206
|
+
else
|
207
|
+
case attribute.type.to_s
|
208
|
+
when 'boolean'
|
209
|
+
return "dataIndex: '#{attribute.name}', header: '#{attribute.name.titleize}', width: 80, renderer: #{app_name}.util.Format.booleanRenderer(), sortable: true"
|
210
|
+
when 'datetime', 'date'
|
211
|
+
return "dataIndex: '#{attribute.name}', header: '#{attribute.name.titleize}', width: 100, renderer: #{app_name}.util.Format.dateRenderer(), sortable: true"
|
212
|
+
else
|
213
|
+
return "dataIndex: '#{attribute.name}', header: '#{attribute.name.titleize}', width: 120, sortable: true"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def create_ext_formfield(attribute)
|
219
|
+
if attribute.reference?
|
220
|
+
return "{ id: '#{attribute.name}_#{reference_field(attribute)}',
|
221
|
+
fieldLabel: '#{attribute.name.titleize}',
|
222
|
+
name: '[#{singular_table_name}]#{attribute.name}_id',
|
223
|
+
store: #{app_name}.store.#{singular_table_name.capitalize}#{attribute.name.capitalize.pluralize},
|
224
|
+
displayField:'#{reference_field(attribute)}',
|
225
|
+
emptyText: 'type at least 2 characters from #{reference_field(attribute)}',
|
226
|
+
xtype: 'parentcombo'}"
|
227
|
+
else
|
228
|
+
case attribute.type.to_s
|
229
|
+
when 'boolean'
|
230
|
+
return "{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', fieldLabel: '#{attribute.name.titleize}?', width: 120, xtype: 'checkbox'}"
|
231
|
+
when 'date'
|
232
|
+
return "{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', fieldLabel: '#{attribute.name.titleize}', width: 250, xtype: 'datefield'}"
|
233
|
+
when 'text'
|
234
|
+
return "{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', fieldLabel: '#{attribute.name.titleize}', width: 500, height: 200, xtype: 'textarea'}"
|
235
|
+
when 'integer'
|
236
|
+
return "{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', fieldLabel: '#{attribute.name.titleize}', width: 250, xtype: 'numberfield', allowDecimals: false}"
|
237
|
+
when 'decimal'
|
238
|
+
return "{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', fieldLabel: '#{attribute.name.titleize}', width: 250, xtype: 'numberfield', allowDecimals: true}"
|
239
|
+
else
|
240
|
+
return "{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', fieldLabel: '#{attribute.name.titleize}', width: 500, xtype: 'textfield'}"
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def create_ext_updateformfield(attribute)
|
246
|
+
# build field container with disable checkbox
|
247
|
+
field = "{ xtype: 'fieldcontainer', fieldLabel: '#{field_label(attribute)}', layout: 'hbox', width: #{updatefield_width(attribute)}, combineErrors: true,
|
248
|
+
items:[
|
249
|
+
{ xtype: 'displayfield', hideLabel: true, value: 'Enable'}
|
250
|
+
,{ xtype: 'checkboxfield', width: 20, hideLabel: true, style: 'margin-left: 5px'}
|
251
|
+
"
|
252
|
+
if attribute.reference?
|
253
|
+
field += ",{ id: '#{attribute.name}_#{reference_field(attribute)}',
|
254
|
+
hideLabel: true,
|
255
|
+
name: '[#{singular_table_name}]#{attribute.name}_id',
|
256
|
+
store: #{app_name}.store.#{singular_table_name.capitalize}#{attribute.name.capitalize.pluralize},
|
257
|
+
displayField:'#{reference_field(attribute)}',
|
258
|
+
emptyText: 'type at least 2 characters from #{reference_field(attribute)}',
|
259
|
+
flex: 1,
|
260
|
+
disabled: true,
|
261
|
+
xtype: 'parentcombo'}"
|
262
|
+
else
|
263
|
+
case attribute.type.to_s
|
264
|
+
when 'boolean'
|
265
|
+
field += ",{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', hideLabel: true, width: 120, flex: 1, disabled: true, xtype: 'checkbox'}"
|
266
|
+
when 'date'
|
267
|
+
field += ",{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', hideLabel: true, width: 250, flex: 1, disabled: true, xtype: 'datefield'}"
|
268
|
+
when 'text'
|
269
|
+
field += ",{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', hideLabel: true, width: 500, height: 200, flex: 1, disabled: true, xtype: 'textarea'}"
|
270
|
+
when 'integer'
|
271
|
+
field += ",{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', hideLabel: true, width: 250, flex: 1, disabled: true, xtype: 'numberfield', allowDecimals: false}"
|
272
|
+
when 'decimal'
|
273
|
+
field += ",{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', hideLabel: true, width: 250, flex: 1, disabled: true, xtype: 'numberfield', allowDecimals: true}"
|
274
|
+
else
|
275
|
+
field += ",{id: '#{attribute.name}', name: '[#{singular_table_name}]#{attribute.name}', hideLabel: true, width: 500, flex: 1, disabled: true, xtype: 'textfield'}"
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
field += "
|
280
|
+
]
|
281
|
+
}
|
282
|
+
|
283
|
+
"
|
284
|
+
return field
|
285
|
+
end
|
286
|
+
|
287
|
+
def field_label(attribute)
|
288
|
+
return attribute.type.to_s == 'boolean' ? "#{attribute.name.titleize}?" : attribute.name.titleize
|
289
|
+
end
|
290
|
+
|
291
|
+
def updatefield_width(attribute)
|
292
|
+
return %w(boolean date integer).include?(attribute.type.to_s) ? 275 : 575
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|