.models.<%= class_name %>; <% for model in belongs_tos -%> import <%= base_package %>.models.<%= model.camelcase %>; <% end -%> [Bindable] private var _<%= class_name.downcase_first_letter %>:<%= class_name %> = new <%= class_name %>(); private function new<%= class_name %>():void { _<%= class_name.downcase_first_letter %> = new <%= class_name %>(); <%= class_name.downcase_first_letter.pluralize %>List.selectedIndex = -1; } private function save<%= class_name %>():void { if (_<%= class_name.downcase_first_letter %>.id) { update<%= class_name %>(); } else { create<%= class_name %>(); } } private function create<%= class_name %>():void { var <%= class_name.downcase_first_letter %>:<%= class_name %> = new <%= class_name %>(); <% for attribute in attributes -%> <% if attribute.type == :boolean -%> <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected; <% elsif attribute.type == :string -%> <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextInput.text; <% elsif attribute.type == :text -%> <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextArea.text; <% elsif attribute.type == :datetime || attribute.type == :time -%> <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateTimeTextInput.date; <% elsif attribute.type == :date -%> <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateField.selectedDate; <% else -%> <%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_type %>(<%= attribute.flex_name %>TextInput.text); <% end -%> <% end -%> <% for model in belongs_tos -%> <%= class_name.downcase_first_letter %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem); <% end -%> <%= class_name.downcase_first_letter %>.create({onSuccess: on<%= class_name %>Create}); } private function update<%= class_name %>():void { <% for attribute in attributes -%> <% if attribute.type == :boolean -%> _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>CheckBox.selected; <% elsif attribute.type == :string -%> _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextInput.text; <% elsif attribute.type == :text -%> _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>TextArea.text; <% elsif attribute.type == :datetime || attribute.type == :time -%> _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateTimeTextInput.date; <% elsif attribute.type == :date -%> _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_name %>DateField.selectedDate; <% else -%> _<%= class_name.downcase_first_letter %>.<%= attribute.flex_name %> = <%= attribute.flex_type %>(<%= attribute.flex_name %>TextInput.text); <% end -%> <% end -%> <% for model in belongs_tos -%> _<%= class_name.downcase_first_letter %>.<%= model.camelcase(:lower) %> = <%= model.camelcase %>(<%= model.camelcase(:lower) %>ComboBox.selectedItem); <% end -%> _<%= class_name.downcase_first_letter %>.update({onSuccess: on<%= class_name %>Update}); } private function destroy<%= class_name %>():void { _<%= class_name.downcase_first_letter %>.destroy({onSuccess: on<%= class_name %>Destroy}); } private function on<%= class_name %>Select():void { _<%= class_name.downcase_first_letter %> = RubossUtils.clone(<%= class_name.downcase_first_letter.pluralize %>List.selectedItem) as <%= class_name %>; } private function on<%= class_name %>Create(<%= class_name.downcase_first_letter %>:<%= class_name %>):void { _<%= class_name.downcase_first_letter %> = new <%= class_name %>; } private function on<%= class_name %>Update(<%= class_name.downcase_first_letter %>:<%= class_name %>):void { <%= class_name.downcase_first_letter.pluralize %>List.selectedItem = <%= class_name.downcase_first_letter %>; _<%= class_name.downcase_first_letter %> = RubossUtils.clone(<%= class_name.downcase_first_letter %>) as <%= class_name %>; } private function on<%= class_name %>Destroy(<%= class_name.downcase_first_letter %>:<%= class_name %>):void { on<%= class_name %>Create(<%= class_name.downcase_first_letter %>); } private function canDelete<%= class_name %>(<%= class_name.downcase_first_letter %>:<%= class_name %>):Boolean { return <%= class_name.downcase_first_letter %> != null && <%= class_name.downcase_first_letter %>.id != 0; } ]]> <% for attribute in attributes -%> <% if attribute.type == :boolean -%> <% elsif attribute.type == :string -%> <% elsif attribute.type == :text -%> <% elsif attribute.type == :datetime || attribute.type == :time -%> <% elsif attribute.type == :date -%> <% else -%> <% end -%> <% end -%> <% for model in belongs_tos -%> <% end -%>