/// <summary>
    /// Loads both field types and control types from inner settings.
    /// </summary>
    public void LoadTypes()
    {
        if (FieldInfo != null)
        {
            // Get control name..
            string item = null;
            // ..from settings..
            if (!string.IsNullOrEmpty(ValidationHelper.GetString(FieldInfo.Settings["controlname"], null)))
            {
                item = Convert.ToString(FieldInfo.Settings["controlname"]).ToLowerCSafe();
            }
            // ..or from field type.
            else
            {
                item = FormHelper.GetFormFieldControlTypeString(FieldInfo.FieldType).ToLowerCSafe();
            }

            // Load and select options
            FormUserControlInfo fi = FormUserControlInfoProvider.GetFormUserControlInfo(item);
            if (fi != null)
            {
                drpControl.ReturnColumnName = FormUserControlInfo.TYPEINFO.CodeNameColumn;
                drpControl.Value            = item;
                drpControl.Reload(true);
            }
        }
    }
Exemple #2
0
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        lblFieldCaption.AssociatedControlClientID     = EditingFormControl.GetInputClientID(txtFieldCaption.NestedControl.Controls);
        lblFieldDescription.AssociatedControlClientID = EditingFormControl.GetInputClientID(txtDescription.NestedControl.Controls);
        lblExplanationText.AssociatedControlClientID  = EditingFormControl.GetInputClientID(txtExplanationText.NestedControl.Controls);
        lblField.AssociatedControlClientID            = drpControl.InputClientID;

        // Check if the form control is allowed for selected data type
        var control = FormUserControlInfoProvider.GetFormUserControlInfo(drpControl.Value.ToString());

        string dataTypeColumn = FormHelper.GetDataTypeColumn(AttributeType);

        if ((control != null) && !String.IsNullOrEmpty(dataTypeColumn))
        {
            bool allowType = ValidationHelper.GetBoolean(control[dataTypeColumn], false);
            if (!allowType)
            {
                var warning = HTMLHelper.HTMLEncode(String.Format(GetString("fieldeditor.controlnotallowedfordatatype"), control.UserControlDisplayName));

                ShowWarning(warning);
            }
        }
    }
Exemple #3
0
    /// <summary>
    /// Creates form control. Called when the "Create control" button is pressed.
    /// </summary>
    private bool CreateFormControl()
    {
        // Create new form control object
        FormUserControlInfo newControl = new FormUserControlInfo();

        // Set the properties
        newControl.UserControlDisplayName       = "My new control";
        newControl.UserControlCodeName          = "MyNewControl";
        newControl.UserControlFileName          = "~/CMSFormControls/Basic/TextBoxControl.ascx";
        newControl.UserControlType              = FormUserControlTypeEnum.Input;
        newControl.UserControlForText           = true;
        newControl.UserControlForLongText       = false;
        newControl.UserControlForInteger        = false;
        newControl.UserControlForLongInteger    = false;
        newControl.UserControlForDecimal        = false;
        newControl.UserControlForDateTime       = false;
        newControl.UserControlForBoolean        = false;
        newControl.UserControlForFile           = false;
        newControl.UserControlForDocAttachments = false;
        newControl.UserControlForGUID           = false;
        newControl.UserControlForVisibility     = false;
        newControl.UserControlShowInBizForms    = false;
        newControl.UserControlDefaultDataType   = "Text";

        // Save the form control
        FormUserControlInfoProvider.SetFormUserControlInfo(newControl);

        return(true);
    }
Exemple #4
0
    private void FillPanelWithComponents()
    {
        string value;

        // Try to retrieve data from the cache
        if (!CacheHelper.TryGetItem(CACHE_KEY, out value))
        {
            var           controls = FormUserControlInfoProvider.GetFormUserControls("UserControlDisplayName,UserControlCodeName,UserControlDescription,UserControlThumbnailGUID", "UserControlShowInBizForms = 1 AND UserControlPriority = 100", "UserControlDisplayName");
            StringBuilder content  = new StringBuilder();

            foreach (var control in controls)
            {
                string iconUrl;
                if (control.UserControlThumbnailGUID == Guid.Empty)
                {
                    iconUrl = GetImageUrl("CMSModules/CMS_FormEngine/custom.png");
                }
                else
                {
                    iconUrl = ResolveUrl(MetaFileURLProvider.GetMetaFileUrl(control.UserControlThumbnailGUID, "icon"));
                }

                content.AppendFormat("<div title=\"{0}\"><div class=\"form-component component_{1}\" ondblclick=\"FormBuilder.addNewField('{1}','',-1);FormBuilder.scrollPosition=9999;FormBuilder.showSavingInfo();\"><span class=\"component-label\">{2}</span><img src=\"{3}\" alt=\"{1}\" /></div></div>",
                                     ResHelper.LocalizeString(control.UserControlDescription), control.UserControlCodeName, control.UserControlDisplayName, iconUrl);
            }

            value = content.ToString();

            var dependency = CacheHelper.GetCacheDependency(FormUserControlInfo.OBJECT_TYPE + "|all");

            CacheHelper.Add(CACHE_KEY, value, dependency, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5));
        }

        pnlFormComponents.Controls.Add(new LiteralControl(value));
    }
Exemple #5
0
    /// <summary>
    /// Loads control with new FormInfo data.
    /// </summary>
    /// <param name="type">Selected control type</param>
    /// <param name="defaultValues">Indicates if default values should be loaded</param>
    public void LoadControlSettings(string type, bool defaultValues)
    {
        string selectedFieldType = type;

        if (String.IsNullOrEmpty(type))
        {
            selectedFieldType = drpFieldType.SelectedValue.ToLower();
        }
        if (selectedFieldType.StartsWith(controlPrefix))
        {
            selectedFieldType = selectedFieldType.Substring(controlPrefix.Length);
        }

        FormUserControlInfo control = FormUserControlInfoProvider.GetFormUserControlInfo(selectedFieldType);

        if (control != null)
        {
            // Get form controls' settings
            fi = FormHelper.GetFormControlParameters(selectedFieldType, control.UserControlParameters, true);

            // Simplify the settings - remove advanced ones
            SimplifyControlSettings(control.UserControlCodeName);

            Reload(defaultValues);
        }
    }
    protected void fieldEditor_AfterItemDeleted(object sender, FieldEditorEventArgs e)
    {
        // Update parameters of inherited form user controls if a field or a category was deleted
        if ((e != null))
        {
            // Details of item which was deleted
            string itemName = e.ItemName;
            FieldEditorSelectedItemEnum itemType = e.ItemType;
            int itemOrder = e.ItemOrder;

            // Get form controls inherited from edited one
            var inheritedControls = FormUserControlInfoProvider.GetFormUserControls().WhereEquals("UserControlParentID", FormControlID);
            foreach (FormUserControlInfo control in inheritedControls)
            {
                // Remove deleted item (field/category) from inherited form control parameters
                switch (itemType)
                {
                case FieldEditorSelectedItemEnum.Field:
                    control.UserControlParameters = FormHelper.RemoveFieldFromAlternativeDefinition(control.UserControlParameters, itemName, itemOrder);
                    break;

                case FieldEditorSelectedItemEnum.Category:
                    control.UserControlParameters = FormHelper.RemoveCategoryFromAlternativeDefinition(control.UserControlParameters, itemName, itemOrder);
                    break;
                }

                // Update inherited form control
                FormUserControlInfoProvider.SetFormUserControlInfo(control);
            }
        }
    }
Exemple #7
0
    /// <summary>
    /// Gets and bulk updates form controls. Called when the "Get and bulk update controls" button is pressed.
    /// Expects the CreateFormControl method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateFormControls()
    {
        // Prepare the parameters
        string where = "UserControlCodeName LIKE N'MyNewControl%'";

        // Get the data
        DataSet formcontrols = FormUserControlInfoProvider.GetFormUserControls(where, null);

        if (!DataHelper.DataSourceIsEmpty(formcontrols))
        {
            // Loop through the individual items
            foreach (DataRow formcontrolsDr in formcontrols.Tables[0].Rows)
            {
                // Create object from DataRow
                FormUserControlInfo modifyControl = new FormUserControlInfo(formcontrolsDr);

                // Update the properties
                modifyControl.UserControlDisplayName = modifyControl.UserControlDisplayName.ToUpper();

                // Save the changes
                FormUserControlInfoProvider.SetFormUserControlInfo(modifyControl);
            }

            return(true);
        }

        return(false);
    }
Exemple #8
0
    /// <summary>
    /// Handles btnOK's OnClick event.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        FormUserControlInfo fi = null;

        // Finds whether required fields are not empty
        string result = new Validator().NotEmpty(txtControlName.Text, rfvControlName.ErrorMessage).NotEmpty(txtControlDisplayName, rfvControlDisplayName.ErrorMessage).Result;

        // Check input file validity
        if (String.IsNullOrEmpty(result))
        {
            if (!tbFileName.IsValid())
            {
                result = tbFileName.ValidationError;
            }
        }

        // Try to create new form control if everything is OK
        if (String.IsNullOrEmpty(result))
        {
            fi = new FormUserControlInfo();
            fi.UserControlDisplayName       = txtControlDisplayName.Text.Trim();
            fi.UserControlCodeName          = txtControlName.Text.Trim();
            fi.UserControlFileName          = tbFileName.Value.ToString();
            fi.UserControlType              = drpTypeSelector.ControlType;
            fi.UserControlForText           = false;
            fi.UserControlForLongText       = false;
            fi.UserControlForInteger        = false;
            fi.UserControlForLongInteger    = false;
            fi.UserControlForDecimal        = false;
            fi.UserControlForDateTime       = false;
            fi.UserControlForBoolean        = false;
            fi.UserControlForFile           = false;
            fi.UserControlForDocAttachments = false;
            fi.UserControlForGUID           = false;
            fi.UserControlForVisibility     = false;
            fi.UserControlShowInBizForms    = false;
            fi.UserControlDefaultDataType   = "Text";
            try
            {
                FormUserControlInfoProvider.SetFormUserControlInfo(fi);
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message.Replace("%%name%%", fi.UserControlCodeName);
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = result;
        }

        // If control was succesfully created then redirect to editing page
        if (String.IsNullOrEmpty(lblError.Text) && (fi != null))
        {
            URLHelper.Redirect("Frameset.aspx?controlId=" + Convert.ToString(fi.UserControlID));
        }
    }
Exemple #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int    controlId   = QueryHelper.GetInteger("controlId", 0);
        string controlName = null;
        bool   isInherited = false;

        if (controlId > 0)
        {
            FormUserControlInfo fuci = FormUserControlInfoProvider.GetFormUserControlInfo(controlId);
            if (fuci != null)
            {
                controlName = fuci.UserControlDisplayName;
                if (fuci.UserControlParentID > 0)
                {
                    isInherited = true;
                }
            }
        }

        // Initializes page title
        string[,] breadcrumbs = new string[2, 3];
        breadcrumbs[0, 0]     = GetString("Development_FormUserControl_Edit.Controls");
        breadcrumbs[0, 1]     = "~/CMSModules/FormControls/Pages/Development/List.aspx";
        breadcrumbs[0, 2]     = "_parent";
        breadcrumbs[1, 0]     = controlName;
        breadcrumbs[1, 1]     = "";
        breadcrumbs[1, 2]     = "";

        // Initialize page
        CurrentMaster.Title.Breadcrumbs   = breadcrumbs;
        CurrentMaster.Title.TitleText     = GetString("Development_FormUserControl_Edit.Edit");
        CurrentMaster.Title.TitleImage    = GetImageUrl("Objects/CMS_FormControl/object.png");
        CurrentMaster.Title.HelpTopicName = "edit_form_control";
        CurrentMaster.Title.HelpName      = "helpTopic";

        if (!RequestHelper.IsPostBack())
        {
            string[,] tabs = new string[2, 4];

            tabs[0, 0] = GetString("general.general");
            tabs[0, 1] = "SetHelpTopic('helpTopic', 'edit_form_control');";
            tabs[0, 2] = "Edit.aspx?controlId=" + controlId;
            tabs[1, 0] = GetString("general.properties");

            if (isInherited)
            {
                tabs[1, 1] = "SetHelpTopic('helpTopic', 'properties_form_control_inherited');";
            }
            else
            {
                tabs[1, 1] = "SetHelpTopic('helpTopic', 'properties_form_control');";
            }

            tabs[1, 2] = "Parameters.aspx?controlId=" + controlId;

            CurrentMaster.Tabs.Tabs      = tabs;
            CurrentMaster.Tabs.UrlTarget = "FormUserControl";
        }
    }
Exemple #10
0
 /// <summary>
 /// Field editor updated event.
 /// </summary>
 void fieldEditor_OnAfterDefinitionUpdate(object sender, EventArgs e)
 {
     // Update Form user control parameters
     if (fuci != null)
     {
         fuci.UserControlParameters = fieldEditor.FormDefinition;
         FormUserControlInfoProvider.SetFormUserControlInfo(fuci);
     }
 }
Exemple #11
0
    /// <summary>
    /// Deletes form control. Called when the "Delete control" button is pressed.
    /// Expects the CreateFormControl method to be run first.
    /// </summary>
    private bool DeleteFormControl()
    {
        // Get the form control
        FormUserControlInfo deleteControl = FormUserControlInfoProvider.GetFormUserControlInfo("MyNewControl");

        // Delete the form control
        FormUserControlInfoProvider.DeleteFormUserControlInfo(deleteControl);

        return(deleteControl != null);
    }
Exemple #12
0
    /// <summary>
    /// Checks whether given form control is available. If so, sets it to referring control name.
    /// </summary>
    /// <param name="formControl">Codename of form control</param>
    /// <param name="controlName">Referring control name to which will be set codename of control, if exists</param>
    private void CheckFormControl(string formControl, ref string controlName)
    {
        // Check if user defined control exists
        FormUserControlInfo fui = FormUserControlInfoProvider.GetFormUserControlInfo(formControl);

        if (fui != null)
        {
            controlName = formControl;
        }
    }
Exemple #13
0
    protected object grdList_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        if (sourceName.ToLower() == "controltype")
        {
            if ((parameter != null) && (parameter != DBNull.Value))
            {
                return(GetString("formcontrolstype." + FormUserControlInfoProvider.GetTypeEnum(ValidationHelper.GetInteger(parameter, 0)).ToString()));
            }
        }

        return(null);
    }
Exemple #14
0
    /// <summary>
    /// Handles external databound event of the unigrid.
    /// </summary>
    private object OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        if (sourceName.EqualsCSafe("controltype", true))
        {
            if ((parameter != null) && (parameter != DBNull.Value))
            {
                return(CoreServices.Localization.GetString("formcontrolstype." + FormUserControlInfoProvider.GetTypeEnum(ValidationHelper.GetInteger(parameter, 0))));
            }
        }

        return(null);
    }
Exemple #15
0
    /// <summary>
    /// Loads data of edited form user control.
    /// </summary>
    protected void LoadData()
    {
        // Load drop-down list with default data types
        if (drpDataType.Items.Count <= 0)
        {
            drpDataType.Items.Add(new ListItem("Text", "Text"));
            drpDataType.Items.Add(new ListItem("Long Text", "LongText"));
            drpDataType.Items.Add(new ListItem("Integer", "Integer"));
            drpDataType.Items.Add(new ListItem("Decimal", "Decimal"));
            drpDataType.Items.Add(new ListItem("DateTime", "DateTime"));
            drpDataType.Items.Add(new ListItem("Boolean", "Boolean"));
            drpDataType.Items.Add(new ListItem("File", "File"));
        }

        FormUserControlInfo fi = FormUserControlInfoProvider.GetFormUserControlInfo(controlId);

        EditedObject = fi;
        if (fi != null)
        {
            // Set properties
            tbCodeName.Text             = fi.UserControlCodeName;
            tbDisplayName.Text          = fi.UserControlDisplayName;
            tbFileName.Value            = fi.UserControlFileName;
            drpTypeSelector.ControlType = fi.UserControlType;

            drpModule.Value = fi.UserControlResourceID;

            // Set types
            chkForBizForms.Checked    = fi.UserControlShowInBizForms;
            chkForBoolean.Checked     = fi.UserControlForBoolean;
            chkForDateTime.Checked    = fi.UserControlForDateTime;
            chkForDecimal.Checked     = fi.UserControlForDecimal;
            chkForFile.Checked        = fi.UserControlForFile;
            chkForInteger.Checked     = fi.UserControlForInteger;
            chkForLongInteger.Checked = fi.UserControlForLongInteger;
            chkForLongText.Checked    = fi.UserControlForLongText;
            chkForText.Checked        = fi.UserControlForText;
            chkForGuid.Checked        = fi.UserControlForGUID;
            chkForVisibility.Checked  = fi.UserControlForVisibility;
            chkForDocAtt.Checked      = fi.UserControlForDocAttachments;

            // Set modules
            chkShowInDocumentTypes.Checked = fi.UserControlShowInDocumentTypes;
            chkShowInSystemTables.Checked  = fi.UserControlShowInSystemTables;
            chkShowInControls.Checked      = fi.UserControlShowInWebParts;
            chkShowInReports.Checked       = fi.UserControlShowInReports;
            chkShowInCustomTables.Checked  = fi.UserControlShowInCustomTables;

            tbColumnSize.Text         = fi.UserControlDefaultDataTypeSize.ToString();
            drpDataType.SelectedValue = fi.UserControlDefaultDataType;
        }
    }
Exemple #16
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that threw event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void grdList_OnAction(string actionName, object actionArgument)
    {
        switch (actionName)
        {
        case "edit":
            URLHelper.Redirect("Frameset.aspx?controlid=" + actionArgument.ToString());
            break;

        case "delete":
            FormUserControlInfoProvider.DeleteFormUserControlInfo(ValidationHelper.GetInteger(actionArgument, 0));
            break;
        }
    }
Exemple #17
0
    /// <summary>
    /// Initializes item selector form control based on selected conversion definition.
    /// </summary>
    /// <param name="force">Forces reload of the selector if <c>true</c></param>
    private void InitializeItemSelector(bool force)
    {
        var conversionDefinition = ABTestConversionDefinitionRegister.Instance.Get(SelectedConversion);
        var controlName          = conversionDefinition?.FormControlDefinition?.FormControlName;
        var formControlType      = conversionDefinition?.FormControlDefinition?.FormControlType;

        if (force)
        {
            plcItemControl.Controls.Clear();
            mItemSelector = null;
        }

        var formUserControl = FormUserControlInfoProvider.GetFormUserControlInfo(controlName);

        if (formUserControl == null && formControlType == null)
        {
            return;
        }

        mItemSelector = formControlType != null
            ? (FormEngineUserControl)Activator.CreateInstance(formControlType)
            : FormUserControlLoader.LoadFormControl(Page, controlName, "", loadDefaultProperties: false);

        if (mItemSelector != null)
        {
            mItemSelector.ID         = "item" + SelectedConversion;
            mItemSelector.IsLiveSite = false;

            var controlParameters = FormHelper.GetFormControlParameters(controlName, formUserControl?.UserControlMergedParameters, false);
            if (controlParameters != null)
            {
                mItemSelector.LoadDefaultProperties(controlParameters);
            }

            var parameters = conversionDefinition?.FormControlDefinition?.FormControlParameters;
            if (parameters != null)
            {
                foreach (var parameter in parameters)
                {
                    mItemSelector.SetValue(parameter.Key, parameter.Value);
                }
            }

            plcItemControl.Controls.Clear();
            plcItemControl.Controls.Add(mItemSelector);

            lblItem.AssociatedControlID = mItemSelector.ID;
            SetItemSelectorCaption(conversionDefinition?.FormControlDefinition?.FormControlCaption);
        }
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        // Load form control
        int controlId            = QueryHelper.GetInteger("controlId", 0);
        FormUserControlInfo fuci = FormUserControlInfoProvider.GetFormUserControlInfo(controlId);

        EditedObject = fuci;
        if (fuci != null)
        {
            ctrlView.FormControlName = fuci.UserControlCodeName;
        }

        btnSubmit.Click += btnSubmit_Click;
    }
Exemple #19
0
    /// <summary>
    /// Reload control.
    /// </summary>
    /// <param name="defaultValues">Indicates if default values should be loaded</param>
    public void Reload(bool defaultValues)
    {
        // Prepare basic form
        if (fi != null)
        {
            form.SubmitButton.Visible = false;
            form.SiteName             = CMSContext.CurrentSiteName;
            form.FormInformation      = fi;
            form.Data = GetData();
            form.ShowPrivateFields = true;
        }
        else
        {
            form.DataRow = null;
        }
        form.ReloadData();
        form.FormType = CMS.FormControls.FormTypeEnum.BizForm;

        // Display or hide controls for default values
        DisplayDefaultControls();

        // Load controls with values
        if (this.FieldInfo != null)
        {
            txtColumnName.Text             = this.FieldInfo.Name;
            chkPublicField.Checked         = this.FieldInfo.PublicField;
            txtFieldCaption.Text           = this.FieldInfo.Caption;
            chkAllowEmpty.Checked          = this.FieldInfo.AllowEmpty;
            chkIsSystem.Checked            = this.FieldInfo.System;
            txtSimpleTextBoxMaxLength.Text = ValidationHelper.GetString(this.FieldInfo.Size, null);
        }
        // Get default maximum length for text fields
        else if (defaultValues)
        {
            txtSimpleTextBoxMaxLength.Text = FormUserControlInfoProvider.GetUserControlDefaultDataType(this.FieldType)[1];
        }

        // Primary key not allowed to change
        // System field not allowed to change unless development mode
        if ((this.FieldInfo != null) && ((this.FieldInfo.PrimaryKey) || (this.FieldInfo.System && !DevelopmentMode)))
        {
            DisableFieldEditing();
        }
        // Enable to change settings for new items and non-primary items
        else
        {
            EnableFieldEditing();
        }
    }
Exemple #20
0
    protected void Page_Init(object sender, EventArgs e)
    {
        // Load form control
        int controlId            = QueryHelper.GetInteger("controlId", 0);
        FormUserControlInfo fuci = FormUserControlInfoProvider.GetFormUserControlInfo(controlId);

        EditedObject = fuci;
        if (fuci != null)
        {
            ctrlView.FormControlName = fuci.UserControlCodeName;
            headTitle.Text           = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(fuci.UserControlDisplayName));
        }

        btnSubmit.Click += btnSubmit_Click;
    }
Exemple #21
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that threw event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void grdList_OnAction(string actionName, object actionArgument)
    {
        switch (actionName)
        {
        case "edit":
            string url = UIContextHelper.GetElementUrl("CMS.Form", "Edit", false);
            url = URLHelper.AddParameterToUrl(url, "objectid", ValidationHelper.GetInteger(actionArgument, 0).ToString());
            URLHelper.Redirect(url);
            break;

        case "delete":
            FormUserControlInfoProvider.DeleteFormUserControlInfo(ValidationHelper.GetInteger(actionArgument, 0));
            break;
        }
    }
Exemple #22
0
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentMaster.BodyClass += " FieldEditorBody";

        // Load form control
        int controlId = QueryHelper.GetInteger("controlId", 0);

        fuci         = FormUserControlInfoProvider.GetFormUserControlInfo(controlId);
        EditedObject = fuci;
        if (fuci != null)
        {
            // Initialize field editor
            fieldEditor.Mode                     = FieldEditorModeEnum.FormControls;
            fieldEditor.FormDefinition           = fuci.UserControlParameters;
            fieldEditor.OnAfterDefinitionUpdate += fieldEditor_OnAfterDefinitionUpdate;
        }
    }
    /// <summary>
    /// Gets FormInfo from current or parent form control.
    /// </summary>
    /// <returns>User control form info</returns>
    private FormInfo GetFormInfo()
    {
        FormInfo fi = null;

        // Control has parent
        if (fuci.UserControlParentID > 0)
        {
            FormUserControlInfo fuc = FormUserControlInfoProvider.GetFormUserControlInfo(fuci.UserControlParentID);
            fi = FormHelper.GetFormControlParameters(fuc.UserControlCodeName, fuc.UserControlParameters, true);
        }
        else
        {
            fi = FormHelper.GetFormControlParameters(fuci.UserControlCodeName, fuci.UserControlParameters, true);
        }

        return(fi);
    }
    /// <summary>
    /// Prepares new field.
    /// </summary>
    /// <param name="controlName">Code name of used control</param>
    private FormFieldInfo PrepareNewField(string controlName)
    {
        FormFieldInfo ffi = new FormFieldInfo();

        string[] controlDefaultDataType = FormUserControlInfoProvider.GetUserControlDefaultDataType(controlName);
        ffi.DataType  = controlDefaultDataType[0];
        ffi.Size      = ValidationHelper.GetInteger(controlDefaultDataType[1], 0);
        ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;

        FormUserControlInfo control = FormUserControlInfoProvider.GetFormUserControlInfo(controlName);

        if (control != null)
        {
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, control.UserControlDisplayName);
        }

        ffi.AllowEmpty              = true;
        ffi.PublicField             = true;
        ffi.Name                    = GetUniqueFieldName(controlName);
        ffi.Settings["controlname"] = controlName;

        // For list controls create three default options
        if (FormHelper.HasListControl(ffi))
        {
            SpecialFieldsDefinition optionDefinition = new SpecialFieldsDefinition();

            for (int i = 1; i <= 3; i++)
            {
                optionDefinition.Add(new SpecialField
                {
                    Value = OptionsDesigner.DEFAULT_OPTION + i,
                    Text  = OptionsDesigner.DEFAULT_OPTION + i
                });
            }

            ffi.Settings["Options"] = optionDefinition.ToString();
        }

        if (controlName.EqualsCSafe("CalendarControl"))
        {
            ffi.Settings["EditTime"] = false;
        }

        return(ffi);
    }
Exemple #25
0
    /// <summary>
    /// Gets and updates form control. Called when the "Get and update control" button is pressed.
    /// Expects the CreateFormControl method to be run first.
    /// </summary>
    private bool GetAndUpdateFormControl()
    {
        // Get the form control
        FormUserControlInfo updateControl = FormUserControlInfoProvider.GetFormUserControlInfo("MyNewControl");

        if (updateControl != null)
        {
            // Update the properties
            updateControl.UserControlDisplayName = updateControl.UserControlDisplayName.ToLower();

            // Save the changes
            FormUserControlInfoProvider.SetFormUserControlInfo(updateControl);

            return(true);
        }

        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        FormUserControlInfo fci = FormUserControlInfoProvider.GetFormUserControlInfo(FormControlID);

        UIContext.EditedObject = fci;

        if (fci != null)
        {
            // Set form definition
            fieldEditor.FormDefinition = fci.UserControlMergedParameters;

            // Set field editor settings
            fieldEditor.Mode = (fci.UserControlParentID > 0) ? FieldEditorModeEnum.InheritedFormControl : FieldEditorModeEnum.FormControls;
            fieldEditor.DisplayedControls        = FieldEditorControlsEnum.ModeSelected;
            fieldEditor.OnAfterDefinitionUpdate += fieldEditor_OnAfterDefinitionUpdate;
            fieldEditor.AfterItemDeleted        += fieldEditor_AfterItemDeleted;

            if (fieldEditor.Mode == FieldEditorModeEnum.InheritedFormControl)
            {
                // Allow extra fields for inherited form controls
                fieldEditor.AllowExtraFields = true;

                // Set original form definition from parent form control
                FormUserControlInfo parentFci = FormUserControlInfoProvider.GetFormUserControlInfo(fci.UserControlParentID);
                if (parentFci != null)
                {
                    fieldEditor.OriginalFormDefinition = parentFci.UserControlParameters;
                }
            }
            else
            {
                // Add custom delete confirmation message
                string confirmScript = String.Format(@"
var confirmElem = document.getElementById('confirmdelete');
if (confirmElem != null) {{ confirmElem.value = '{0}'; }}", ScriptHelper.GetString(GetString("formcontrolparams.confirmdelete"), false));

                ScriptHelper.RegisterStartupScript(this, typeof(string), "FormControlConfirmDelete_" + ClientID, confirmScript, true);
            }
        }
        else
        {
            ShowError(GetString("general.invalidid"));
        }
    }
    /// <summary>
    /// XML created, save it.
    /// </summary>
    protected void defaultValueEditor_XMLCreated(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(defaultValueEditor.ErrorMessage))
        {
            ShowError(defaultValueEditor.ErrorMessage);
            return;
        }

        if ((fuci != null) && (fuci.UserControlParentID > 0))
        {
            fuci.UserControlParameters = defaultValueEditor.DefaultValueXMLDefinition;
            FormUserControlInfoProvider.SetFormUserControlInfo(fuci);
        }

        // Redirect with saved assign
        string url = URLHelper.UpdateParameterInUrl(URLRewriter.CurrentURL, "saved", "1");

        URLHelper.Redirect(url);
    }
Exemple #28
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        if (StopProcessing)
        {
            return;
        }

        InitControls();

        // Load the form data
        if (!URLHelper.IsPostback())
        {
            LoadData();
        }
        else
        {
            ucSettingsKeyControlSelector.SetSelectorProperties(drpKeyType.SelectedValue);
        }

        // Set edited object
        EditedObject = (mSettingsKeyId > 0) ? SettingsKeyObj : new SettingsKeyInfo();

        // Init form control settings
        var controlCodeName = ValidationHelper.GetString(ucSettingsKeyControlSelector.Value, null);
        var controlInfo     = FormUserControlInfoProvider.GetFormUserControlInfo(controlCodeName);

        if (controlInfo != null)
        {
            pnlControlSettings.Visible = true;

            ucControlSettings.FormInfo = FormHelper.GetFormControlParameters(controlCodeName, controlInfo.UserControlMergedParameters, true);
            ucControlSettings.Reload(true);

            pnlControlSettings.Visible = ucControlSettings.CheckVisibility();
        }
        else
        {
            pnlControlSettings.Visible = false;
        }
    }
    /// <summary>
    /// Loads control with new FormInfo data.
    /// </summary>
    /// <param name="type">Selected control type</param>
    /// <param name="defaultValues">Indicates if default values should be loaded</param>
    public void LoadControlSettings(string type, bool defaultValues)
    {
        string selectedFieldType = type;

        if (String.IsNullOrEmpty(type))
        {
            selectedFieldType = drpControl.Text.ToLowerCSafe();
        }
        if (selectedFieldType.StartsWithCSafe(controlPrefix))
        {
            selectedFieldType = selectedFieldType.Substring(controlPrefix.Length);
        }

        FormUserControlInfo control = FormUserControlInfoProvider.GetFormUserControlInfo(selectedFieldType);

        if (control != null)
        {
            string controlParameters = "";

            if (control.UserControlParentID == 0)
            {
                // Get normal form control parameters
                controlParameters = control.UserControlParameters;
            }
            else
            {
                // Get merged form info from inherited and parent control
                controlParameters = control.MergedFormInfo;
            }

            // Get form controls' settings
            fi = FormHelper.GetFormControlParameters(selectedFieldType, controlParameters, true);

            controlSettings.FormInfo = fi;

            Reload(defaultValues);
        }

        controlSettings.Visible = fi.ItemsList.OfType <FormFieldInfo>().Any(x => x.DisplayInSimpleMode);
    }
    protected void fieldEditor_OnAfterDefinitionUpdate(object sender, EventArgs e)
    {
        // Update Form user control parameters
        if (EditedFormControl != null)
        {
            if (EditedFormControl.UserControlParentID > 0)
            {
                FormUserControlInfo parent = FormUserControlInfoProvider.GetFormUserControlInfo(EditedFormControl.UserControlParentID);
                // Get only differences
                EditedFormControl.UserControlParameters = FormHelper.GetFormDefinitionDifference(parent.UserControlParameters, fieldEditor.FormDefinition, true);
            }
            else
            {
                EditedFormControl.UserControlParameters = fieldEditor.FormDefinition;
            }

            FormUserControlInfoProvider.SetFormUserControlInfo(EditedFormControl);

            // Clear cached data
            FormUserControlInfoProvider.Clear(true);
        }
    }