Created
August 6, 2015 11:31
-
-
Save dejanr/f60d33dcaae94630534e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ko from 'common/ko'; | |
| import validation from 'common/validation'; | |
| import template from 'ui/pages/contract/contract/contract.html!text'; | |
| import contractState from 'ui/pages/contract/contract/contract-state'; | |
| import offerService from 'domain/offer-service'; | |
| import NotFoundError from 'common/not-found-error'; | |
| function createPage(ctx) { | |
| const vm = {}; | |
| const subscriptions = []; | |
| vm.spinnerState = ko.observable(false); | |
| function loadState() { | |
| return offerService.getOfferResult(ctx.params.offerResultId).then(result => { | |
| if (!result) { | |
| throw new NotFoundError(); | |
| } | |
| return result; | |
| }); | |
| } | |
| function applyState(state) { | |
| const offer = state.offers.find(x => x.info.id === ctx.params.tariffId); | |
| if (!offer) { | |
| throw new NotFoundError(); | |
| } | |
| vm.state = contractState.getState(); | |
| vm.submitApplication = function () { | |
| if (!validation.validate(vm.state)) { | |
| return false; | |
| } | |
| }; | |
| } | |
| function releaseState() { | |
| subscriptions.forEach(s => s.dispose()); | |
| } | |
| return { | |
| viewModel: vm, | |
| template, | |
| loadState, | |
| applyState, | |
| releaseState, | |
| id: 'contract' | |
| }; | |
| } | |
| export default { createPage }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment