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