| /trunk/opportunities/src/com/tearaway_tea/opportunities/data/OpportunityDataProvider.as r3 | /trunk/opportunities/src/com/tearaway_tea/opportunities/data/OpportunityDataProvider.as r11 | ||
| 1 | package com.tearaway_tea.opportunities.data | 1 | package com.tearaway_tea.opportunities.data |
|---|---|---|---|
| 2 | { | 2 | { |
| 3 | import com.asfusion.mate.events.Dispatcher; | 3 | import com.asfusion.mate.events.Dispatcher; |
| 4 | import com.tearaway_tea.opportunities.events.DataProviderEvent; | 4 | import com.tearaway_tea.opportunities.events.DataProviderEvent; |
| 5 | import com.tearaway_tea.opportunities.model.OpportunityVO; | 5 | import com.tearaway_tea.opportunities.model.OpportunityVO; |
| 6 | import com.tearaway_tea.opportunities.services.OpportunitiesMockService; | 6 | import com.tearaway_tea.opportunities.services.OpportunitiesMockService; |
| 7 | 7 | ||
| 8 | import mx.collections.ArrayCollection; | ||
| 9 | |||
| 10 | public class OpportunityDataProvider | 8 | public class OpportunityDataProvider |
| 11 | { | 9 | { |
| 12 | [Bindable] | 10 | [Bindable] |
| 13 | public var opportunity : OpportunityVO; | 11 | public var opportunity : OpportunityVO; |
| 14 | 12 | ||
| 15 | public function createOpportunity() : void | 13 | public function createOpportunity() : void |
| 16 | { | 14 | { |
| 17 | opportunity = new OpportunityVO(); | 15 | opportunity = new OpportunityVO(); |
| 18 | opportunity.items = new ArrayCollection(); | ||
| 19 | new Dispatcher().dispatchEvent( | 16 | new Dispatcher().dispatchEvent( |
| 20 | new DataProviderEvent(DataProviderEvent.OPPORTUNITY_CREATED)); | 17 | new DataProviderEvent(DataProviderEvent.OPPORTUNITY_CREATED)); |
| 21 | } | 18 | } |
| 22 | 19 | ||
| 23 | public function editOpportunity(opportunity : OpportunityVO) : void | 20 | public function editOpportunity(opportunity : OpportunityVO) : void |
| 24 | { | 21 | { |
| 25 | this.opportunity = opportunity; | 22 | this.opportunity = opportunity; |
| 26 | } | 23 | } |
| 27 | 24 | ||
| 28 | public function saveOpportunity() : void | 25 | public function saveOpportunity() : void |
| 29 | { | 26 | { |
| 27 | opportunity.lastUpdate = new Date(); | ||
| 30 | new OpportunitiesMockService(onUpdateOpportunity).updateOpportunity(opportunity); | 28 | new OpportunitiesMockService(onUpdateOpportunity).updateOpportunity(opportunity); |
| 31 | 29 | ||
| 32 | function onUpdateOpportunity(result : OpportunityVO) : void | 30 | function onUpdateOpportunity(result : OpportunityVO) : void |
| 33 | { | 31 | { |
| 34 | opportunity = result; | 32 | opportunity = result; |
| 35 | new Dispatcher().dispatchEvent( | 33 | new Dispatcher().dispatchEvent( |
| 36 | new DataProviderEvent(DataProviderEvent.OPPORTUNITY_SAVED)); | 34 | new DataProviderEvent(DataProviderEvent.OPPORTUNITY_SAVED)); |
| 37 | } | 35 | } |
| 38 | } | 36 | } |
| 39 | } | 37 | } |
| 40 | } | 38 | } |