Skip to content

Instantly share code, notes, and snippets.

@dejanr
Created August 6, 2015 11:31
Show Gist options
  • Select an option

  • Save dejanr/f60d33dcaae94630534e to your computer and use it in GitHub Desktop.

Select an option

Save dejanr/f60d33dcaae94630534e to your computer and use it in GitHub Desktop.
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