public DataboundDatagridItemCreatorForm(ISomeService someService) { _view = new DataboundDatagridItemCreatorFormView(); var someText = LocalValueFieldBuilder.Build(_view.SomeText, Validator.IsNotNullRef); var someNumber = LocalValueFieldBuilder.BuildNullableInt(_view.SomeNumber, Validator.IsNotNull, Validator.MustBePositive <int>()); var someBool = LocalValueFieldBuilder.Build(_view.SomeBool); _view.SomeTrait.PermittedValues = EnumExtensions.GetEnumValues <SomeTraitType>().Select(x => (SomeTraitType?)x); var someTrait = LocalValueFieldBuilder.Build(_view.SomeTrait, Validator.IsNotNull); var createProduct = RemoteActionBuilder.Build(_view.CreateAction, () => someService.Create( new SomeDto { SomeNumber = someNumber.Value.GetValueOrDefault(), SomeText = someText.Value, SomeBool = someBool.Value, SomeTrait = someTrait.Value.Value }), x => { CreatedItem = x; Ended?.Invoke(this, Outcome.Created); }); var isFormValid = new AggregatedErrorsValue <bool>(false, self => !self.Errors.Any(), x => { x.Observes(someText); x.Observes(someNumber); x.Observes(someBool); x.Observes(someTrait); }); createProduct.BindEnableAndInitialize(isFormValid); }
public UploaderDemoForm(IHttpRequester httpRequester) { _view = new UploaderDemoFormView(); _view.Attachments.SetImplementation(new ISomeService_OrderAttachment(httpRequester, () => 124, () => true)); _attachments = LocalValueFieldBuilder.Build(new List <RemoteFileDescr>(), _view.Attachments, (newValue, errors) => { errors.IfTrueAdd(newValue.Count > 10, "Maximum 10 files allowed"); }); //TODO this is experimental feature. It should be added by the above statement (if BeforeChange is supported in IView) _view.Attachments.BeforeChange += (newValue, isUser, preventProp) => { if (newValue.Count > 10) { preventProp(new HashSet <string> { "Maximum 10 files allowed" }); } }; var mayConfirm = new AggregatedErrorsValue <bool>( false, self => !self.Errors.Any(), x => x.Observes(_attachments)); var confirm = LocalActionBuilder.Build(_view.Confirm, () => Ended?.Invoke(this, Unit.Instance)); confirm.BindEnableAndInitialize(mayConfirm); }
public TextInputForm( TextInputFormView view, string label, string titleOrNull = null, string defaultValue = null, params Validate <string>[] validators) { Title = titleOrNull ?? I18n.Translate("Input"); _view = view; _msg = new LocalValue <string>(label ?? ""); view.Label.BindReadOnlyAndInitialize(_msg); _input = LocalValueFieldBuilder.Build(defaultValue, view.Input, validators); var isFormValid = new AggregatedErrorsValue <bool>(false, x => !x.Errors.Any(), x => x.Observes(_input)); var confirmInput = LocalActionBuilder.Build(view.Confirm, () => Ended?.Invoke(this, CompletedOrCanceled.Completed)); confirmInput.BindEnableAndInitialize(isFormValid); }
public LoginForm(LoginFormView view, Func <string, string, Task <Tuple <string, UserT> > > service, Action <string, UserT> storeResult) { View = view; var login = new LocalValue <string>("", ""); login.AddValidatorAndRevalidate( (x, errors) => errors.IfTrueAdd(string.IsNullOrWhiteSpace(x), I18n.Translate("Field cannot be empty")) ); view.Login.BindReadWriteAndInitialize(login); var passwd = new LocalValue <string>("", ""); passwd.AddValidatorAndRevalidate( (x, errors) => errors.IfTrueAdd(string.IsNullOrWhiteSpace(x), I18n.Translate("Field cannot be empty")) ); view.Password.BindReadWriteAndInitialize(passwd); var mayAttemptLogin = new AggregatedErrorsValue <bool>(false, self => !self.Errors.Any(), x => { x.Observes(login); x.Observes(passwd); }); var attemptLogin = RemoteActionBuilder.Build(view.AttemptLogin, () => service(login.Value, passwd.Value), x => { storeResult(x.Item1, x.Item2); LoggedUserName = login.Value; ErrorMessageOrNull = null; Ended?.Invoke(this, CompletedOrCanceled.Completed); }, x => { LoggedUserName = null; ErrorMessageOrNull = x.ErrorMessage; Ended?.Invoke(this, CompletedOrCanceled.Canceled); }); attemptLogin.BindEnableAndInitialize(mayAttemptLogin); }
public IntroduceItemForm() { _view = new IntroduceItemFormView(); _someText = LocalValueFieldBuilder.Build(_view.SomeText, Validator.IsNotEmptyOrWhitespaceOnly); _someNumber = LocalValueFieldBuilder.BuildInt(_view.SomeNumber, Validator.MustBePositive); _someBool = LocalValueFieldBuilder.Build(_view.SomeBool); _view.SomeTrait.PermittedValues = EnumExtensions.GetEnumValues <SomeTraitType>().Select(x => (SomeTraitType?)x); _someTrait = LocalValueFieldBuilder.Build(_view.SomeTrait, Validator.IsNotNull); var isFormValid = new AggregatedErrorsValue <bool>(false, self => !self.Errors.Any(), x => { x.Observes(_someText); x.Observes(_someNumber); x.Observes(_someBool); x.Observes(_someTrait); }); LocalActionBuilder .Build(_view.Create, () => Ended?.Invoke(this, Outcome.Saved)) .With(x => x.BindEnableAndInitialize(isFormValid)); }
public RemoteValueChangeByChoiceForm( Func <string> titleProv, Func <T, Task <T> > saveChange, RemoteValueChangeByChoiceFormView <T> view, params Validate <T>[] validators) { _titleProv = titleProv; _view = view; _localValue = LocalValueFieldBuilder.Build(default(T), view.Choosen, validators); var remoteActionModel = RemoteActionBuilder.Build(view.Confirm, () => saveChange(_localValue.Value), x => { SavedValue = x; Ended?.Invoke(this, CompletedOrCanceled.Completed); }); var isFormValid = new AggregatedErrorsValue <bool>(false, self => !self.Errors.Any(), x => { x.Observes(_localValue); }); remoteActionModel.BindEnableAndInitialize(isFormValid); }
public RemoteValueChangeByEntryForm( Func <DomainT, Task <RemoteT> > remoteChanger, IReadWriteValueView <HTMLElement, ViewT> input, Action <string> inputLabelChanger, Func <DomainT, ViewT> domainToViewConverter, Func <ViewT, DomainT> viewToDomainConverter, string label, string titleOrNull = null, DomainT defaultValue = default(DomainT), TextType labelTextType = TextType.TreatAsText, params Validate <DomainT>[] validators) { _inputLabelChanger = inputLabelChanger; Title = titleOrNull ?? I18n.Translate("Input"); _view = new RemoteValueChangeByEntryFormView <ViewT>(input, labelTextType); _inputLabelChanger(label); _msg = new LocalValue <string>(""); _view.Message.BindReadOnlyAndInitialize(_msg); _input = LocalValueFieldBuilder.Build( defaultValue, _view.Input, domainToViewConverter, viewToDomainConverter, validators); var isFormValid = new AggregatedErrorsValue <bool>( false, x => !x.Errors.Any(), x => x.Observes(_input)); var confirmInput = RemoteActionBuilder.Build( _view.Confirm, () => remoteChanger(_input.Value), x => { SavedValue = x; Ended?.Invoke(this, CompletedOrCanceled.Completed); }); confirmInput.BindEnableAndInitialize(isFormValid); }