public virtual ActionResult ChangeFormElementLanguage(long formElementId, String culture) { var formElement = formsElementService.Find(formElementId); if (formElement == null || formElement.Form == null || !permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(), typeof(Form), formElement.Form.Id, IsFormOwner(formElement.Form), PermissionOperationLevel.Object)) { throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this))); } FormElementViewModel model = new FormElementViewModel { FormId = formElement.Form.Id }.MapFrom(formElement); model.SelectedCulture = culture; //get locale var localeService = ServiceLocator.Current.GetInstance <IFormElementLocaleService>(); FormElementLocale locale = localeService.GetLocale(formElementId, culture); if (locale != null) { model.MapLocaleFrom(locale); } return(PartialView("FormElementEditor", model)); }
private void AddElementConfigurationRows(FormGroup group, FormElementViewModel formElement) { switch (formElement) { case ButtonElementViewModel buttonElement: AddButtonConfigurationRows(group, buttonElement); break; case HtmlElementViewModel htmlElement: AddHtmlConfigurationRows(group, htmlElement); break; case CheckBoxFieldViewModel checkBox: AddCheckBoxConfigurationRows(group, checkBox); break; case TextFieldViewModel textField: AddTextConfigurationRows(group, textField); break; case ComboBoxFieldViewModel comboBox: AddComboBoxConfigurationRows(group, comboBox); break; } }
/// <summary> /// Validates the form element. /// </summary> /// <param name="model">The model.</param> /// <param name="modelState">State of the model.</param> public static void ValidateFormElement(FormElementViewModel model, ModelStateDictionary modelState) { var currentType = model.Types.Find(type => type.Type == model.Type.ToString()); if (currentType.IsValuesEnabled && String.IsNullOrEmpty(model.Values)) { modelState.AddModelError(PropertyName.For<FormElementViewModel>(item => item.Values), ResourceHelper.TranslateErrorMessage(new HttpContextWrapper(HttpContext.Current), typeof(FormElementViewModel), PropertyName.For<FormElementViewModel>(item => item.Values), "required", null)); } }
/// <summary> /// Validates the form element. /// </summary> /// <param name="model">The model.</param> /// <param name="modelState">State of the model.</param> public static void ValidateFormElement(FormElementViewModel model, ModelStateDictionary modelState) { var currentType = model.Types.Find(type => type.Type == model.Type.ToString()); if (currentType.IsValuesEnabled && String.IsNullOrEmpty(model.Values)) { modelState.AddModelError(PropertyName.For <FormElementViewModel>(item => item.Values), ResourceHelper.TranslateErrorMessage(new HttpContextWrapper(HttpContext.Current), typeof(FormElementViewModel), PropertyName.For <FormElementViewModel>(item => item.Values), "required", null)); } }
public virtual ActionResult SaveElement(long formId, FormElementViewModel model) { FormsHelper.ValidateFormElement(model, ModelState); if (ModelState.IsValid) { FormsHelper.UpdateFormElement(model); var form = formsService.Find(formId); if (form == null || !permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(), typeof(Form), form.Id, IsFormOwner(form), PermissionOperationLevel.Object)) { throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this))); } var formElement = new FormElement(); bool isEdited = model.Id > 0; if (isEdited) { formElement = formsElementService.Find(model.Id); } else { formElement.Form = form; formElement.OrderNumber = formsElementService.GetLastOrderNumber(formElement.Form.Id); } if (formsElementService.Save(model.MapTo(formElement))) { if (isEdited) { //save locale var localeService = ServiceLocator.Current.GetInstance <IFormElementLocaleService>(); FormElementLocale locale = localeService.GetLocale(formElement.Id, model.SelectedCulture); locale = model.MapLocaleTo(locale ?? new FormElementLocale { FormElement = formElement }); localeService.Save(locale); } Success(HttpContext.Translate("Messages.FormElementSaveSuccess", ResourceHelper.GetControllerScope(this)) /*"Sucessfully save form element."*/); return(RedirectToAction(FormsMVC.Forms.ShowFormElements(formId))); } } Error(HttpContext.Translate("Messages.ElementValidationError", ResourceHelper.GetControllerScope(this)) /*"Validation errors occurred while processing this form. Please take a moment to review the form and correct any input errors before continuing."*/); return(View("EditFormElement", model)); }
/// <summary> /// Updates the form element. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public static FormElementViewModel UpdateFormElement(FormElementViewModel model) { var currentType = model.Types.Find(type => type.Type == model.Type.ToString()); if (currentType != null) { if (!currentType.IsValuesEnabled) { model.Values = null; } if (!currentType.IsMaxLengthEnabled) { model.MaxLength = null; } if (!currentType.IsValidationEnabled) { model.RegexTemplate = null; } } return(model); }
public virtual ActionResult SaveElement(long formId, FormElementViewModel model) { FormsHelper.ValidateFormElement(model, ModelState); if (ModelState.IsValid) { FormsHelper.UpdateFormElement(model); var form = formsService.Find(formId); if (form == null || !permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(), typeof(Form), form.Id, IsFormOwner(form), PermissionOperationLevel.Object)) { throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this))); } var formElement = new FormElement(); bool isEdited = model.Id > 0; if (isEdited) { formElement = formsElementService.Find(model.Id); } else { formElement.Form = form; formElement.OrderNumber = formsElementService.GetLastOrderNumber(formElement.Form.Id); } if (formsElementService.Save(model.MapTo(formElement))) { if (isEdited) { //save locale var localeService = ServiceLocator.Current.GetInstance<IFormElementLocaleService>(); FormElementLocale locale = localeService.GetLocale(formElement.Id, model.SelectedCulture); locale = model.MapLocaleTo(locale ?? new FormElementLocale { FormElement = formElement }); localeService.Save(locale); } Success(HttpContext.Translate("Messages.FormElementSaveSuccess", ResourceHelper.GetControllerScope(this))/*"Sucessfully save form element."*/); return RedirectToAction(FormsMVC.Forms.ShowFormElements(formId)); } } Error(HttpContext.Translate("Messages.ElementValidationError", ResourceHelper.GetControllerScope(this))/*"Validation errors occurred while processing this form. Please take a moment to review the form and correct any input errors before continuing."*/); return View("EditFormElement", model); }
public virtual ActionResult ChangeFormElementLanguage(long formElementId, String culture) { var formElement = formsElementService.Find(formElementId); if (formElement == null || formElement.Form == null || !permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(), typeof(Form), formElement.Form.Id, IsFormOwner(formElement.Form), PermissionOperationLevel.Object)) { throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this))); } FormElementViewModel model = new FormElementViewModel{FormId = formElement.Form.Id}.MapFrom(formElement); model.SelectedCulture = culture; //get locale var localeService = ServiceLocator.Current.GetInstance<IFormElementLocaleService>(); FormElementLocale locale = localeService.GetLocale(formElementId, culture); if (locale != null) model.MapLocaleFrom(locale); return PartialView("FormElementEditor", model); }
/// <summary> /// Updates the form element. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public static FormElementViewModel UpdateFormElement(FormElementViewModel model) { var currentType = model.Types.Find(type => type.Type == model.Type.ToString()); if (currentType!=null) { if (!currentType.IsValuesEnabled) model.Values = null; if (!currentType.IsMaxLengthEnabled) model.MaxLength = null; if (!currentType.IsValidationEnabled) model.RegexTemplate = null; } return model; }