dima-restfulx 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/Rakefile +65 -30
  2. data/VERSION.yml +4 -0
  3. data/app_generators/rx_app/rx_app_generator.rb +25 -9
  4. data/app_generators/rx_app/templates/actionscript.properties +3 -3
  5. data/app_generators/rx_app/templates/actionscriptair.properties +3 -3
  6. data/app_generators/rx_app/templates/app.yaml.erb +1 -1
  7. data/app_generators/rx_app/templates/default_tasks.rake +5 -18
  8. data/app_generators/rx_app/templates/generate.rb +1 -1
  9. data/app_generators/rx_app/templates/index.html.erb +1 -1
  10. data/app_generators/rx_app/templates/mainair-app.xml +3 -3
  11. data/app_generators/rx_app/templates/mainapp.mxml +107 -2
  12. data/app_generators/rx_app/templates/project-textmate.erb +4 -4
  13. data/app_generators/rx_app/templates/project.properties +1 -1
  14. data/app_generators/rx_app/templates/projectair.properties +1 -1
  15. data/app_generators/rx_app/templates/restfulx.yml +61 -0
  16. data/lib/restfulx/active_foo.rb +0 -7
  17. data/lib/restfulx/active_record_tasks.rb +10 -0
  18. data/lib/restfulx/configuration.rb +15 -10
  19. data/lib/restfulx/rails/swf_helper.rb +1 -1
  20. data/lib/restfulx/schema_to_yaml/extensions/enumerable.rb +7 -0
  21. data/lib/restfulx/schema_to_yaml/settings/config.rb +16 -0
  22. data/lib/restfulx/schema_to_yaml/settings/core.rb +70 -0
  23. data/lib/restfulx/schema_to_yaml.rb +120 -0
  24. data/lib/restfulx/tasks.rb +68 -42
  25. data/lib/restfulx/uuid_helper.rb +15 -0
  26. data/lib/restfulx.rb +5 -28
  27. data/rails_generators/rx_config/USAGE +2 -1
  28. data/rails_generators/rx_config/rx_config_generator.rb +78 -53
  29. data/rails_generators/rx_config/templates/actionscript.properties +3 -3
  30. data/rails_generators/rx_config/templates/actionscriptair.properties +3 -3
  31. data/rails_generators/rx_config/templates/flex_controller.erb +4 -0
  32. data/rails_generators/rx_config/templates/{index.html.erb → index.erb} +2 -4
  33. data/rails_generators/rx_config/templates/mainair-app.xml +3 -3
  34. data/rails_generators/rx_config/templates/mainapp.mxml +100 -2
  35. data/rails_generators/rx_config/templates/project-textmate.erb +4 -4
  36. data/rails_generators/rx_config/templates/project.properties +1 -1
  37. data/rails_generators/rx_config/templates/projectair.properties +1 -1
  38. data/rails_generators/rx_config/templates/restfulx.erb +39 -0
  39. data/rails_generators/rx_config/templates/restfulx.yml +51 -4
  40. data/rails_generators/rx_config/templates/restfulx_tasks.rake +3 -0
  41. data/rails_generators/rx_config/templates/routes.erb +47 -0
  42. data/rails_generators/rx_controller/rx_controller_generator.rb +9 -6
  43. data/rails_generators/rx_controller/templates/controller.as.erb +7 -9
  44. data/{generators → rails_generators}/rx_main_app/USAGE +0 -0
  45. data/rails_generators/rx_main_app/rx_main_app_generator.rb +60 -0
  46. data/rails_generators/rx_main_app/templates/mainapp.mxml +129 -0
  47. data/rails_generators/rx_scaffold/rx_scaffold_generator.rb +89 -35
  48. data/rails_generators/rx_scaffold/templates/{controller.rb.erb → controllers/default.rb.erb} +29 -1
  49. data/rails_generators/rx_scaffold/templates/controllers/resource_controller.rb.erb +23 -0
  50. data/rails_generators/rx_scaffold/templates/fixtures.yml.erb +9 -5
  51. data/{generators/rx_scaffold/templates/component.mxml.erb → rails_generators/rx_scaffold/templates/layouts/default.erb} +75 -59
  52. data/rails_generators/rx_scaffold/templates/migration.rb.erb +29 -2
  53. data/rails_generators/rx_scaffold/templates/model.as.erb +33 -2
  54. data/rails_generators/rx_scaffold/templates/model.rb.erb +36 -1
  55. data/rails_generators/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +29 -10
  56. data/{generators → rxgen_generators}/rx_config/USAGE +0 -0
  57. data/{generators → rxgen_generators}/rx_config/rx_config_generator.rb +0 -0
  58. data/{generators → rxgen_generators}/rx_controller/USAGE +0 -0
  59. data/{generators → rxgen_generators}/rx_controller/rx_controller_generator.rb +6 -5
  60. data/{generators → rxgen_generators}/rx_controller/templates/assist.py +2 -2
  61. data/{generators → rxgen_generators}/rx_controller/templates/controller.as.erb +8 -6
  62. data/{generators → rxgen_generators}/rx_controller/templates/restful.py +0 -0
  63. data/rxgen_generators/rx_main_app/USAGE +8 -0
  64. data/{generators → rxgen_generators}/rx_main_app/rx_main_app_generator.rb +10 -5
  65. data/{generators → rxgen_generators}/rx_main_app/templates/main.py.erb +0 -0
  66. data/rxgen_generators/rx_main_app/templates/mainapp.mxml +136 -0
  67. data/{generators → rxgen_generators}/rx_scaffold/USAGE +0 -0
  68. data/{generators → rxgen_generators}/rx_scaffold/rx_scaffold_generator.rb +5 -4
  69. data/{rails_generators → rxgen_generators}/rx_scaffold/templates/component.mxml.erb +24 -52
  70. data/{generators → rxgen_generators}/rx_scaffold/templates/controller.py.erb +1 -1
  71. data/{generators → rxgen_generators}/rx_scaffold/templates/model.as.erb +0 -0
  72. data/{generators → rxgen_generators}/rx_scaffold/templates/model.py.erb +0 -0
  73. data/{generators → rxgen_generators}/rx_yaml_scaffold/USAGE +0 -0
  74. data/{generators → rxgen_generators}/rx_yaml_scaffold/rx_yaml_scaffold_generator.rb +0 -0
  75. metadata +104 -66
  76. data/History.txt +0 -7
  77. data/Manifest.txt +0 -127
  78. data/generators/rx_main_app/templates/mainapp.mxml +0 -35
  79. data/rdoc/generators/template/html/jamis.rb +0 -588
  80. data/test/rails/playing_around_in_a_console.txt +0 -71
@@ -61,21 +61,36 @@ module Rails
61
61
  end
62
62
  end
63
63
  end
64
+ module Commands
65
+ class Create
66
+ include SchemaToYaml
67
+ end
68
+ end
64
69
  end
65
70
  end
66
71
 
67
72
  class RxScaffoldGenerator < Rails::Generator::NamedBase
68
- include RestfulX::Configuration
73
+ include RestfulX::Configuration
74
+ include SchemaToYaml
69
75
 
70
76
  attr_reader :project_name,
71
77
  :flex_project_name,
72
78
  :base_package,
73
79
  :base_folder,
74
- :command_controller_name
80
+ :command_controller_name,
81
+ :flex_root,
82
+ :distributed
75
83
 
76
84
  attr_reader :belongs_tos,
77
85
  :has_manies,
78
- :has_ones
86
+ :has_ones,
87
+ :attachment_field,
88
+ :has_many_through,
89
+ :polymorphic,
90
+ :tree_model,
91
+ :layout,
92
+ :ignored_fields,
93
+ :args_for_generation
79
94
 
80
95
  attr_reader :controller_name,
81
96
  :controller_class_path,
@@ -92,9 +107,10 @@ class RxScaffoldGenerator < Rails::Generator::NamedBase
92
107
 
93
108
  def initialize(runtime_args, runtime_options = {})
94
109
  super
95
- @project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder = extract_names
110
+ @project_name, @flex_project_name, @command_controller_name, @base_package, @base_folder, @flex_root,
111
+ @distributed = extract_names
96
112
  @controller_name = @name.pluralize
97
-
113
+
98
114
  base_name, @controller_class_path, @controller_file_path, @controller_class_nesting,
99
115
  @controller_class_nesting_depth = extract_modules(@controller_name)
100
116
  @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
@@ -109,25 +125,27 @@ class RxScaffoldGenerator < Rails::Generator::NamedBase
109
125
  end
110
126
 
111
127
  def manifest
112
- record do |m|
113
- m.dependency 'scaffold', [name] + @args, :skip_migration => true, :collision => :skip unless options[:flex_only]
114
-
115
- # Generate Flex AS model and MXML component based on the
116
- # RestfulX templates.
117
- m.template 'model.as.erb',
118
- File.join("app", "flex", base_folder, "models", "#{@class_name}.as"),
119
- :assigns => { :resource_controller_name => "#{file_name.pluralize}" }
120
-
121
- m.template 'component.mxml.erb',
122
- File.join("app", "flex", base_folder, "components", "generated", "#{@class_name}Box.mxml"),
123
- :assigns => { :resource_controller_name => "#{file_name.pluralize}" }
128
+ record do |m|
129
+ unless options[:flex_view_only]
130
+ m.template 'model.as.erb',
131
+ File.join("#{@flex_root}", base_folder, "models", "#{@class_name}.as"),
132
+ :assigns => { :resource_controller_name => "#{file_name.pluralize}" }
133
+
134
+ m.template "controllers/#{RxSettings.controller_pattern}.rb.erb", File.join("app/controllers",
135
+ controller_class_path, "#{controller_file_name}_controller.rb") unless options[:flex_only]
124
136
 
125
- m.template 'controller.rb.erb', File.join("app/controllers", controller_class_path,
126
- "#{controller_file_name}_controller.rb"), :collision => :force unless options[:flex_only]
127
-
128
- # Create a new generated ActiveRecord model based on the RestfulX templates.
129
- m.template 'model.rb.erb', File.join("app", "models", "#{file_name}.rb"),
130
- :collision => :force unless options[:flex_only]
137
+ m.template 'model.rb.erb', File.join("app", "models", "#{file_name}.rb") unless options[:flex_only]
138
+ end
139
+
140
+ if @layout.size > 0
141
+ m.template "layouts/#{@layout}.erb",
142
+ File.join("#{@flex_root}", base_folder, "components", "generated", "#{@class_name}Box.mxml"),
143
+ :assigns => { :resource_controller_name => "#{file_name.pluralize}" }
144
+ else
145
+ m.template "layouts/#{RxSettings.layouts.default}.erb",
146
+ File.join("#{@flex_root}", base_folder, "components", "generated", "#{@class_name}Box.mxml"),
147
+ :assigns => { :resource_controller_name => "#{file_name.pluralize}" }
148
+ end
131
149
 
132
150
  unless options[:skip_fixture]
133
151
  m.template 'fixtures.yml.erb', File.join("test", "fixtures", "#{table_name}.yml"),
@@ -135,11 +153,13 @@ class RxScaffoldGenerator < Rails::Generator::NamedBase
135
153
  end
136
154
 
137
155
  unless options[:skip_migration]
138
- m.directory 'schema/migration'
156
+ FileUtils.rm Dir.glob("db/migrate/[0-9]*_create_#{file_path.gsub(/\//, '_').pluralize}.rb"), :force => true
139
157
  m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => {
140
158
  :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
141
159
  }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" unless options[:flex_only]
142
160
  end
161
+
162
+ m.route_resources controller_file_name
143
163
 
144
164
  m.dependency 'rx_controller', [name] + @args, :collision => :force
145
165
  end
@@ -147,33 +167,67 @@ class RxScaffoldGenerator < Rails::Generator::NamedBase
147
167
 
148
168
  protected
149
169
  def extract_relationships
170
+ # arrays
150
171
  @belongs_tos = []
151
172
  @has_ones = []
152
173
  @has_manies = []
153
- # Figure out has_one, has_many and belongs_to based on args
174
+ @attachment_field = []
175
+ @polymorphic = []
176
+ @tree_model = []
177
+ @layout = []
178
+ @ignored_fields = []
179
+
180
+ # hashes
181
+ @has_many_through = {}
182
+
154
183
  @args.each do |arg|
184
+ # arrays
155
185
  if arg =~ /^has_one:/
156
- # arg = "has_one:arg1,arg2", so all the has_one are together
157
186
  @has_ones = arg.split(':')[1].split(',')
158
187
  elsif arg =~ /^has_many:/
159
- # arg = "has_many:arg1,arg2", so all the has_many are together
160
188
  @has_manies = arg.split(":")[1].split(",")
161
- elsif arg =~ /^belongs_to:/ # belongs_to:arg1,arg2
189
+ elsif arg =~ /^belongs_to:/
162
190
  @belongs_tos = arg.split(":")[1].split(',')
191
+ elsif arg =~ /^attachment_field:/
192
+ @attachment_field = arg.split(":")[1].split(',')
193
+ elsif arg =~ /^polymorphic:/
194
+ @polymorphic = arg.split(":")[1].split(',')
195
+ elsif arg =~ /^tree_model:/
196
+ @tree_model = arg.split(":")[1].split(',')
197
+ elsif arg =~ /^layout:/
198
+ @layout = arg.split(":")[1].split(',')
199
+ elsif arg =~ /^ignored_fields:/
200
+ @ignored_fields = arg.split(":")[1].split(',')
201
+ # hashes
202
+ elsif arg =~ /^has_many_through:/
203
+ hmt_arr = arg.split(":")[1].split(',')
204
+ @has_many_through[hmt_arr.first] = hmt_arr.last
163
205
  end
164
206
  end
165
207
 
166
- # Remove the has_one and has_many arguments since they are
167
- # not for consumption by the scaffold generator, and since
168
- # we have already used them to set the @belongs_tos, @has_ones and
169
- # @has_manies.
170
- @args.delete_if { |elt| elt =~ /^(has_one|has_many|belongs_to):/ }
208
+ # delete special fields from @args ivar
209
+ %w(has_one has_many belongs_to attachment_field has_many_through
210
+ polymorphic tree_model layout ignored_fields).each do |special_field|
211
+ @args.delete_if { |f| f =~ /^(#{special_field}):/ }
212
+ end
213
+
214
+ @args_for_generation = @args.clone
215
+
216
+ # delete ignored_fields from @args ivar
217
+ @ignored_fields.each do |ignored|
218
+ @args.delete_if { |f| f =~ /^(#{ignored}):/ }
219
+ end
220
+
171
221
  end
172
222
 
173
223
  def add_options!(opt)
174
224
  opt.separator ''
175
225
  opt.separator 'Options:'
176
- opt.on("--flex-only", "Scaffold Flex code only",
177
- "Default: false") { |v| options[:flex_only] = v}
226
+ opt.on("-f", "--flex-only", "Only generate the Flex/AIR files",
227
+ "Default: false") { |v| options[:flex_only] = v }
228
+ opt.on("-r", "--rails-only", "Only generate the Rails files",
229
+ "Default: false") { |v| options[:rails_only] = v }
230
+ opt.on("-fv", "--flex-view-only", "Only generate the Flex component files",
231
+ "Default: false") { |v| options[:flex_view_only] = v }
178
232
  end
179
233
  end
@@ -8,7 +8,11 @@ class <%= controller_class_name %>Controller < ApplicationController
8
8
  respond_to do |format|
9
9
  format.html # index.html.erb
10
10
  format.xml { render :xml => @<%= table_name %> }
11
+ <% if attachment_field.size > 0 -%>
12
+ format.fxml { render :fxml => @<%= table_name %>.to_fxml(:methods => [:attachment_url]) }
13
+ <% else -%>
11
14
  format.fxml { render :fxml => @<%= table_name %> }
15
+ <% end -%>
12
16
  end
13
17
  end
14
18
 
@@ -21,7 +25,11 @@ class <%= controller_class_name %>Controller < ApplicationController
21
25
  respond_to do |format|
22
26
  format.html # show.html.erb
23
27
  format.xml { render :xml => @<%= file_name %> }
28
+ <% if attachment_field.size > 0 -%>
29
+ format.fxml { render :fxml => @<%= file_name %>.to_fxml(:methods => [:attachment_url]) }
30
+ <% else -%>
24
31
  format.fxml { render :fxml => @<%= file_name %> }
32
+ <% end -%>
25
33
  end
26
34
  end
27
35
 
@@ -52,7 +60,11 @@ class <%= controller_class_name %>Controller < ApplicationController
52
60
  flash[:notice] = '<%= class_name %> was successfully created.'
53
61
  format.html { redirect_to(@<%= file_name %>) }
54
62
  format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
63
+ <% if attachment_field.size > 0 -%>
64
+ format.fxml { render :fxml => @<%= file_name %>.to_fxml(:methods => [:attachment_url]) }
65
+ <% else -%>
55
66
  format.fxml { render :fxml => @<%= file_name %> }
67
+ <% end -%>
56
68
  else
57
69
  format.html { render :action => "new" }
58
70
  format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
@@ -65,14 +77,30 @@ class <%= controller_class_name %>Controller < ApplicationController
65
77
  # PUT /<%= table_name %>/1.xml
66
78
  # PUT /<%= table_name %>/1.fxml
67
79
  def update
80
+ <% if distributed -%>
81
+ begin
82
+ @<%= file_name %> = <%= class_name %>.find(params[:id])
83
+ @saved = @<%= file_name %>.update_attributes(params[:<%= file_name %>])
84
+ rescue
85
+ @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
86
+ @<%= file_name %>.id = params[:id]
87
+ @saved = @<%= file_name %>.save
88
+ end
89
+ <% else -%>
68
90
  @<%= file_name %> = <%= class_name %>.find(params[:id])
91
+ @saved = @<%= file_name %>.update_attributes(params[:<%= file_name %>])
92
+ <% end -%>
69
93
 
70
94
  respond_to do |format|
71
- if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
95
+ if @saved
72
96
  flash[:notice] = '<%= class_name %> was successfully updated.'
73
97
  format.html { redirect_to(@<%= file_name %>) }
74
98
  format.xml { head :ok }
99
+ <% if attachment_field.size > 0 -%>
100
+ format.fxml { render :fxml => @<%= file_name %>.to_fxml(:methods => [:attachment_url]) }
101
+ <% else -%>
75
102
  format.fxml { render :fxml => @<%= file_name %> }
103
+ <% end -%>
76
104
  else
77
105
  format.html { render :action => "edit" }
78
106
  format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
@@ -0,0 +1,23 @@
1
+ class <%= controller_class_name %>Controller < ResourceController::Base
2
+
3
+ before_filter :load_fxml_params
4
+
5
+ index.wants.fxml { render :fxml => @collection.to_fxml(@fxml_params) }
6
+ show.wants.fxml { render :fxml => @object.to_fxml(@fxml_params) }
7
+ create.wants.fxml { render :fxml => @object.to_fxml(@fxml_params) }
8
+ create.failure.wants.fxml { render :fxml => @object.errors }
9
+ update.wants.fxml { render :fxml => @object.to_fxml(@fxml_params) }
10
+ update.failure.wants.fxml { render :fxml => @object.errors }
11
+ destroy.wants.fxml { render :fxml => @object }
12
+
13
+ private
14
+
15
+ def collection
16
+ @collection = end_of_association_chain.all
17
+ end
18
+
19
+ def load_fxml_params
20
+ @fxml_params = { }
21
+ end
22
+
23
+ end
@@ -2,34 +2,38 @@
2
2
 
3
3
  <% unless attributes.empty? && belongs_tos.empty? -%>
4
4
  <%= class_name.underscore -%>_one:
5
+ id: <%%= Fixtures.identify(:<%= class_name.underscore %>_one) %>
5
6
  <% for attribute in attributes -%>
6
7
  <%= attribute.name %>: <%= attribute.default("#{class_name}1") %>
7
8
  <% end -%>
8
9
  <% for model in belongs_tos -%>
9
- <%= model %>: <%= model %>_one
10
+ <%= model %>_id: <%%= Fixtures.identify(:<%= model %>_one) %>
10
11
  <% end -%>
11
12
 
12
13
  <%= class_name.underscore -%>_two:
14
+ id: <%%= Fixtures.identify(:<%= class_name.underscore %>_two) %>
13
15
  <% for attribute in attributes -%>
14
16
  <%= attribute.name %>: <%= attribute.default("#{class_name}2") %>
15
17
  <% end -%>
16
18
  <% for model in belongs_tos -%>
17
- <%= model %>: <%= model %>_two
19
+ <%= model %>_id: <%%= Fixtures.identify(:<%= model %>_two) %>
18
20
  <% end -%>
19
21
 
20
22
  <%= class_name.underscore -%>_three:
23
+ id: <%%= Fixtures.identify(:<%= class_name.underscore %>_three) %>
21
24
  <% for attribute in attributes -%>
22
25
  <%= attribute.name %>: <%= attribute.default("#{class_name}3") %>
23
26
  <% end -%>
24
27
  <% for model in belongs_tos -%>
25
- <%= model %>: <%= model %>_three
28
+ <%= model %>_id: <%%= Fixtures.identify(:<%= model %>_three) %>
26
29
  <% end -%>
27
30
 
28
31
  <%= class_name.underscore -%>_four:
32
+ id: <%%= Fixtures.identify(:<%= class_name.underscore %>_four) %>
29
33
  <% for attribute in attributes -%>
30
34
  <%= attribute.name %>: <%= attribute.default("#{class_name}4") %>
31
35
  <% end -%>
32
36
  <% for model in belongs_tos -%>
33
- <%= model %>: <%= model %>_four
34
- <% end -%>
37
+ <%= model %>_id: <%%= Fixtures.identify(:<%= model %>_four) %>
35
38
  <% end -%>
39
+ <% end -%>
@@ -8,25 +8,34 @@
8
8
  <% for model in belongs_tos -%>
9
9
  import <%= base_package %>.models.<%= model.camelcase %>;
10
10
  <% end -%>
11
+ <% if attachment_field.size > 0 -%>
12
+ import org.restfulx.utils.RxFileReference;
13
+ <% end -%>
11
14
 
12
15
  [Bindable]
13
- private var _<%= class_name.dcfirst %>:<%= class_name %> = new <%= class_name %>();
16
+ private var <%= class_name.dcfirst %>:<%= class_name %> = new <%= class_name %>();
17
+ <% if attachment_field.size > 0 -%>
18
+ [Bindable]
19
+ private var fileName:String = "None selected";
20
+
21
+ private var file:RxFileReference;
22
+ <% end -%>
14
23
 
15
24
  private function new<%= class_name %>():void {
16
- _<%= class_name.dcfirst %> = new <%= class_name %>();
25
+ <%= class_name.dcfirst %> = new <%= class_name %>();
17
26
  <%= class_name.dcfirst.pluralize %>List.selectedIndex = -1;
18
27
  }
19
28
 
20
29
  private function save<%= class_name %>():void {
21
- if (_<%= class_name.dcfirst %>.id) {
22
- update<%= class_name %>();
30
+ updateModelProperties();
31
+ if (<%= class_name.dcfirst %>.id) {
32
+ <%= class_name.dcfirst %>.update({onSuccess: on<%= class_name %>Update});
23
33
  } else {
24
- create<%= class_name %>();
34
+ <%= class_name.dcfirst %>.create({onSuccess: on<%= class_name %>Create});
25
35
  }
26
36
  }
27
37
 
28
- private function create<%= class_name %>():void {
29
- var <%= class_name.dcfirst %>:<%= class_name %> = new <%= class_name %>();
38
+ private function updateModelProperties():void {
30
39
  <% for attribute in attributes -%>
31
40
  <% if attribute.type == :boolean -%>
32
41
  <%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected;
@@ -41,64 +50,64 @@
41
50
  <% else -%>
42
51
  <%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_type %>(<%= attribute.flex_name %>TextInput.text);
43
52
  <% end -%>
44
- <% end -%>
45
-
53
+ <% end -%>
46
54
  <% for model in belongs_tos -%>
47
55
  <%= class_name.dcfirst %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem);
48
56
  <% end -%>
49
- <%= class_name.dcfirst %>.create({onSuccess: on<%= class_name %>Create});
50
- }
51
-
52
- private function update<%= class_name %>():void {
53
- <% for attribute in attributes -%>
54
- <% if attribute.type == :boolean -%>
55
- _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected;
56
- <% elsif attribute.type == :string -%>
57
- _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextInput.text;
58
- <% elsif attribute.type == :text -%>
59
- _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextArea.text;
60
- <% elsif attribute.type == :datetime || attribute.type == :time -%>
61
- _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateTimeTextInput.date;
62
- <% elsif attribute.type == :date -%>
63
- _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateField.selectedDate;
64
- <% else -%>
65
- _<%= class_name.dcfirst %>.<%= attribute.flex_name %> = <%= attribute.flex_type %>(<%= attribute.flex_name %>TextInput.text);
66
- <% end -%>
57
+ <% if attachment_field.size > 0 -%>
58
+ <%= class_name.dcfirst %>.attachment = file;
67
59
  <% end -%>
68
-
69
- <% for model in belongs_tos -%>
70
- _<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem);
71
- <% end -%>
72
- _<%= class_name.dcfirst %>.update({onSuccess: on<%= class_name %>Update});
73
60
  }
74
-
61
+
75
62
  private function destroy<%= class_name %>():void {
76
- _<%= class_name.dcfirst %>.destroy({onSuccess: on<%= class_name %>Destroy});
63
+ <%= class_name.dcfirst %>.destroy({onSuccess: on<%= class_name %>Destroy});
77
64
  }
78
-
65
+
79
66
  private function on<%= class_name %>Select():void {
80
- _<%= class_name.dcfirst %> = RxUtils.clone(<%= class_name.dcfirst.pluralize %>List.selectedItem) as <%= class_name %>;
67
+ <%= class_name.dcfirst %> = RxUtils.clone(<%= class_name.dcfirst.pluralize %>List.selectedItem) as <%= class_name %>;
81
68
  }
82
-
83
- private function on<%= class_name %>Create(<%= class_name.dcfirst %>:<%= class_name %>):void {
84
- _<%= class_name.dcfirst %> = new <%= class_name %>;
85
- }
86
-
87
- private function on<%= class_name %>Update(<%= class_name.dcfirst %>:<%= class_name %>):void {
88
- <%= class_name.dcfirst.pluralize %>List.selectedItem = <%= class_name.dcfirst %>;
89
- _<%= class_name.dcfirst %> = RxUtils.clone(<%= class_name.dcfirst %>) as <%= class_name %>;
69
+
70
+ private function on<%= class_name %>Create(result:<%= class_name %>):void {
71
+ <%= class_name.dcfirst %> = new <%= class_name %>;
90
72
  }
91
-
92
- private function on<%= class_name %>Destroy(<%= class_name.dcfirst %>:<%= class_name %>):void {
93
- on<%= class_name %>Create(<%= class_name.dcfirst %>);
73
+
74
+ private function on<%= class_name %>Update(result:<%= class_name %>):void {
75
+ <%= class_name.dcfirst.pluralize %>List.selectedItem = result;
76
+ on<%= class_name %>Select();
94
77
  }
78
+
79
+ private function on<%= class_name %>Destroy(result:<%= class_name %>):void {
80
+ on<%= class_name %>Create(result);
81
+ }
82
+ <% if attachment_field.size > 0 -%>
95
83
 
96
- private function canDelete<%= class_name %>(<%= class_name.dcfirst %>:<%= class_name %>):Boolean {
97
- return <%= class_name.dcfirst %> != null && !RxUtils.isEmpty(<%= class_name.dcfirst %>.id);
84
+ private function chooseFile():void {
85
+ file = new RxFileReference("<%= attachment_field[0].camelcase(:lower) %>");
86
+ file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);
87
+ file.addEventListener(Event.SELECT, selectFile, false, 0, true);
88
+ file.addEventListener(Event.CANCEL, cancelBrowse, false, 0, true);
89
+ file.browse();
98
90
  }
91
+
92
+ private function selectFile(event:Event):void {
93
+ fileSelected(event)
94
+ }
95
+
96
+ private function cancelBrowse(event:Event):void {
97
+ file = null;
98
+ }
99
+
100
+ private function fileSelected(event:Event):void {
101
+ fileName = RxFileReference(event.target).name;
102
+ }
103
+
104
+ private function ioErrorHandler(event:Event):void {
105
+ fileChooser.errorString = "Failed to selected a file. Please try again.";
106
+ }
107
+ <% end -%>
99
108
  ]]></mx:Script>
100
109
  <mx:Panel id="<%= class_name.dcfirst.pluralize %>Panel"
101
- title="<%= class_name.pluralize %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
110
+ title="<%= class_name.pluralize %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
102
111
  borderThickness="1" backgroundColor="#EEEEEE" width="25%" height="100%">
103
112
  <mx:List id="<%= class_name.dcfirst.pluralize %>List"
104
113
  width="100%" height="100%"
@@ -109,24 +118,31 @@
109
118
  click="new<%= class_name %>()"/>
110
119
  </mx:ControlBar>
111
120
  </mx:Panel>
112
- <mx:Panel title="Edit <%= class_name %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
121
+ <mx:Panel title="Edit <%= class_name %>" cornerRadius="0" dropShadowEnabled="false" borderStyle="solid"
113
122
  borderThickness="1" backgroundColor="#EEEEEE" width="75%" height="100%">
114
123
  <mx:Form width="100%" height="100%">
115
124
  <% for attribute in attributes -%>
116
125
  <mx:FormItem label="<%= attribute.flex_name.ucfirst %>" width="100%">
117
126
  <% if attribute.type == :boolean -%>
118
- <mx:CheckBox id="<%= attribute.flex_name %>CheckBox" selected="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
127
+ <mx:CheckBox id="<%= attribute.flex_name %>CheckBox" selected="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
119
128
  <% elsif attribute.type == :string -%>
120
- <mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
129
+ <mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
121
130
  <% elsif attribute.type == :text -%>
122
- <mx:TextArea id="<%= attribute.flex_name %>TextArea" width="100%" height="200" text="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
131
+ <mx:TextArea id="<%= attribute.flex_name %>TextArea" width="100%" height="200" text="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
123
132
  <% elsif attribute.type == :datetime || attribute.type == :time -%>
124
- <rx:DateTimeTextInput id="<%= attribute.flex_name %>DateTimeTextInput" width="200" date="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
133
+ <rx:DateTimeTextInput id="<%= attribute.flex_name %>DateTimeTextInput" width="200" date="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
125
134
  <% elsif attribute.type == :date -%>
126
- <mx:DateField id="<%= attribute.flex_name %>DateField" selectedDate="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
135
+ <mx:DateField id="<%= attribute.flex_name %>DateField" selectedDate="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
127
136
  <% else -%>
128
- <mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{_<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
137
+ <mx:TextInput id="<%= attribute.flex_name %>TextInput" width="100%" text="{<%= class_name.dcfirst %>.<%= attribute.flex_name %>}"/>
138
+ <% end -%>
139
+ </mx:FormItem>
129
140
  <% end -%>
141
+ <% if attachment_field.size > 0 -%>
142
+ <mx:FormItem label="<%= attachment_field[0].camelcase %>:" width="100%" id="fileChooser">
143
+ <mx:Button label="Browse…" id="fileBrowseButton" click="chooseFile()"/>
144
+ <mx:Label text="{fileName}" maxWidth="190"/>
145
+ <mx:Image source="{<%= class_name.dcfirst %>.attachmentUrl}"/>
130
146
  </mx:FormItem>
131
147
  <% end -%>
132
148
  <% for model in belongs_tos -%>
@@ -134,7 +150,7 @@
134
150
  <mx:ComboBox id="<%= model.camelcase(:lower) %>ComboBox" width="200"
135
151
  labelField="{<%= model.camelcase %>.LABEL}"
136
152
  dataProvider="{Rx.models.index(<%= model.camelcase %>)}" prompt="<%= model.camelcase %> ..."
137
- selectedItem="{_<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %>}" />
153
+ selectedItem="{<%= class_name.dcfirst %>.<%= model.camelcase(:lower) %>}"/>
138
154
  </mx:FormItem>
139
155
  <% end -%>
140
156
  </mx:Form>
@@ -142,7 +158,7 @@
142
158
  <mx:Button label="Save <%= class_name %>" width="50%" height="30"
143
159
  click="save<%= class_name %>()"/>
144
160
  <mx:Button label="Delete <%= class_name %>" width="50%" height="30"
145
- enabled="{canDelete<%= class_name %>(_<%= class_name.dcfirst %>)}"
161
+ enabled="{RxUtils.canDeleteModel(<%= class_name.dcfirst %>)}"
146
162
  click="destroy<%= class_name %>()"/>
147
163
  </mx:ControlBar>
148
164
  </mx:Panel>
@@ -1,12 +1,39 @@
1
1
  class <%= migration_name %> < ActiveRecord::Migration
2
2
  def self.up
3
+ <% if distributed -%>
4
+ create_table :<%= table_name %>, :id => false do |t|
5
+ t.string :id
6
+ <% else -%>
3
7
  create_table :<%= table_name %> do |t|
4
- <% for attribute in attributes -%>
5
- t.<%= attribute.type %> :<%= attribute.name %>
8
+ <% end -%>
9
+ <% for attribute in args_for_generation -%>
10
+ t.<%= attribute.split(':')[1] %> :<%= attribute.split(':')[0] %>
6
11
  <% end -%>
7
12
  <% for model in belongs_tos -%>
13
+ <% if distributed -%>
14
+ t.string :<%= model %>_id
15
+ <% else -%>
8
16
  t.references :<%= model %>
9
17
  <% end -%>
18
+ <% end -%>
19
+ <% if attachment_field.size > 0 -%>
20
+ <% if RxSettings.attachment_plugin == 'paperclip' -%>
21
+ # For paperclip
22
+ t.column :avatar_file_name, :string
23
+ t.column :avatar_content_type, :string
24
+ t.column :avatar_file_size, :integer
25
+ t.column :avatar_updated_at, :datetime
26
+ <% elsif RxSettings.attachment_plugin == 'attachment_fu' -%>
27
+ # For attachment_fu
28
+ t.column :parent_id, :integer
29
+ t.column :content_type, :string
30
+ t.column :filename, :string
31
+ t.column :thumbnail, :string
32
+ t.column :size, :integer
33
+ t.column :width, :integer
34
+ t.column :height, :integer
35
+ <% end -%>
36
+ <% end -%>
10
37
  <% unless options[:skip_timestamps] %>
11
38
  t.timestamps
12
39
  <% end -%>
@@ -1,12 +1,19 @@
1
1
  package <%= base_package %>.models {
2
- <% if has_manies.length > 0 -%>
2
+ <% if has_manies.length > 0 || has_many_through.length > 0 -%>
3
3
  import org.restfulx.collections.ModelsCollection;
4
4
  <% end -%>
5
+ <% if tree_model.size > 0 -%>
6
+ <% @tree_or_no_tree = 'RxTreeModel' %>
7
+ import org.restfulx.models.RxTreeModel
8
+ <% end -%>
9
+ <% unless tree_model.size > 0 -%>
10
+ <% @tree_or_no_tree = 'RxModel' %>
5
11
  import org.restfulx.models.RxModel;
12
+ <% end -%>
6
13
 
7
14
  [Resource(name="<%= resource_controller_name %>")]
8
15
  [Bindable]
9
- public class <%= class_name %> extends RxModel {
16
+ public class <%= class_name %> extends <%= @tree_or_no_tree %> {
10
17
  <% if attributes && !attributes.empty? && attributes[0].flex_type != "Boolean" -%>
11
18
  public static const LABEL:String = "<%= attributes[0].flex_name %>";
12
19
  <% else -%>
@@ -24,6 +31,25 @@ package <%= base_package %>.models {
24
31
  [BelongsTo]
25
32
  public var <%= model.camelcase(:lower) %>:<%= model.camelcase %>;
26
33
 
34
+ <% end -%>
35
+ <% if tree_model.size > 0 -%>
36
+ [BelongsTo]
37
+ public var <%= tree_model[0].camelcase(:lower) %>:<%= class_name %>;
38
+
39
+ <% end -%>
40
+ <% for model in polymorphic -%>
41
+ [BelongsTo(polymorphic="true", dependsOn="Model1, Model2")]
42
+ public var <%= model.camelcase(:lower) %>:Object;
43
+
44
+ <% end -%>
45
+ <% if has_many_through.size > 0 -%>
46
+ <% has_many_through.each do |k,v| %>
47
+ [HasMany]
48
+ public var <%= k.camelcase(:lower) %>:ModelsCollection;
49
+
50
+ [HasMany(through="<%= k.camelcase %>")]
51
+ public var <%= v.camelcase(:lower) %>:ModelsCollection;
52
+ <% end -%>
27
53
  <% end -%>
28
54
  <% for model in has_ones -%>
29
55
  [HasOne]
@@ -34,6 +60,11 @@ package <%= base_package %>.models {
34
60
  [HasMany]
35
61
  public var <%= model.camelcase(:lower) %>:ModelsCollection;
36
62
 
63
+ <% end -%>
64
+ <% if attachment_field.size > 0 -%>
65
+ [Ignored]
66
+ public var attachmentUrl:String;
67
+
37
68
  <% end -%>
38
69
  public function <%= class_name %>() {
39
70
  super(LABEL);