Exemple #1
0
    /// <summary>
    /// Creates textboxs.
    /// </summary>
    private void CreateTextBoxs()
    {
        textBoxList = new List <TextBox>(Count);
        pnlAnswer.Controls.Clear();

        int index    = 1;
        int addIndex = 0;

        for (int i = 0; i < Count; i++)
        {
            CMSTextBox txtBox = new CMSTextBox();
            txtBox.ID        = "captcha_" + i;
            txtBox.MaxLength = 1;
            txtBox.CssClass  = "CaptchaTextBoxSmall";

            pnlAnswer.Controls.AddAt(addIndex, txtBox);

            if (index < Count)
            {
                Label sepLabel = new Label();
                sepLabel.Text     = Separator;
                sepLabel.CssClass = "form-control-text";
                addIndex++;
                pnlAnswer.Controls.AddAt(addIndex, sepLabel);
            }
            index++;
            addIndex++;

            textBoxList.Add(txtBox);
        }
    }
    private void editGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.DataItemIndex >= 0)
        {
            CMSTextBox txt = new CMSTextBox();
            txt.TextChanged += txt_TextChanged;
            txt.MaxLength    = 10;

            // Id of the currency displayed in this row
            int curId = ValidationHelper.GetInteger(((DataRowView)e.Row.DataItem)["CurrencyID"], 0);

            // Find exchange rate for this row currency
            string rateValue = "";
            if (mExchangeRates.ContainsKey(curId))
            {
                DataRow row = mExchangeRates[curId];
                rateValue = ValidationHelper.GetDouble(row["ExchangeRateValue"], -1).ToString();
            }

            // Fill and add text box to the "Rate value" column of the grid
            txt.Text = rateValue;
            e.Row.Cells[1].Controls.Add(txt);
            mData[txt.ClientID] = e.Row.DataItem;
        }
    }
    /// <summary>
    /// Gets <c>TextBox</c> control used for key value editing.
    /// </summary>
    /// <param name="groupNo">Number representing index of the processing settings group</param>
    /// <param name="keyNo">Number representing index of the processing SettingsKeyInfo</param>
    /// <param name="text">Text</param>
    /// <param name="enabled">Enabled</param>
    private TextBox GetValueTextBox(int groupNo, int keyNo, string text, bool enabled)
    {
        var txtValue = new CMSTextBox
        {
            ID = string.Format("txtKey{0}{1}", groupNo, keyNo),
            EnableViewState = false,
            Text            = text,
            Enabled         = enabled,
        };

        return(txtValue);
    }
Exemple #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StopProcessing || ((NewsletterID <= 0) && (IssueID <= 0)))
        {
            return;
        }

        mAreCampaignsAvailable = LicenseKeyInfoProvider.IsFeatureAvailable(RequestContext.CurrentDomain, FeatureEnum.CampaignAndConversions);
        ToggleUTMCampaignInput();
        mUTMCampaignTextBox = GetUTMCampaignTextBox();

        ReloadData(false);
    }
Exemple #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StopProcessing || ((NewsletterID <= 0) && (IssueID <= 0)))
        {
            return;
        }

        mAreCampaignsAvailable = LicenseKeyInfoProvider.IsFeatureAvailable(RequestContext.CurrentDomain, FeatureEnum.CampaignAndConversions);
        ToggleUTMCampaignInput();
        mUTMCampaignTextBox = GetUTMCampaignTextBox();

        // Add shadow below header actions
        ScriptHelper.RegisterModule(Page, "CMS/HeaderShadow");

        LoadForm();
    }
    /// <summary>
    /// Creates textboxs.
    /// </summary>
    private void CreateTextBoxs()
    {
        textBoxList = new List <TextBox>(Count);
        pnlAnswer.Controls.Clear();

        for (int i = 0; i < Count; i++)
        {
            LocalizedLabel sepLabel = null;
            var            txtBox   = new CMSTextBox
            {
                ID        = "captcha_" + i,
                MaxLength = 1,
                CssClass  = "CaptchaTextBoxSmall"
            };

            if (i > 0)
            {
                sepLabel = new LocalizedLabel
                {
                    Text     = Separator,
                    CssClass = "form-control-text"
                };

                pnlAnswer.Controls.Add(sepLabel);
            }

            pnlAnswer.Controls.Add(txtBox);

            textBoxList.Add(txtBox);

            if (sepLabel != null)
            {
                // Connect the separator with next textbox so each textbox has its own label
                sepLabel.AssociatedControlClientID = txtBox.ClientID;
            }
            else if (Form == null)
            {
                // If inside form, the label tag is provided by form label, otherwise it has own label
                lblSecurityCode.AssociatedControlClientID = txtBox.ClientID;
            }
        }
    }
    private object gridProducts_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = null;

        switch (sourceName.ToLowerCSafe())
        {
        case "skuname":
            row = (DataRowView)parameter;
            string skuName = ValidationHelper.GetString(row["SKUName"], "");
            int    skuId   = ValidationHelper.GetInteger(row["SKUID"], 0);

            // Create link for adding one item using product name
            LinkButton link = new LinkButton();
            link.Text            = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(skuName));
            link.Click          += btnAddOneUnit_Click;
            link.CommandArgument = skuId.ToString();

            return(link);

        case "price":
            // Format product price
            row = (DataRowView)parameter;
            return(SKUInfoProvider.GetSKUFormattedPrice(new SKUInfo(row.Row), ShoppingCartObj, true, false));

        case "quantity":
            int id = ValidationHelper.GetInteger(parameter, 0);

            // Create textbox for entering quantity
            CMSTextBox tb = new CMSTextBox();
            tb.MaxLength = 9;
            tb.Width     = 50;
            tb.ID        = "txtQuantity" + id;

            // Add textbox to dictionary under SKUID key
            quantityControls.Add(id, tb);

            return(tb);
        }

        return(parameter);
    }
 /// <summary>
 /// Gets <c>TextBox</c> control used for key value editing.
 /// </summary>
 /// <param name="settingsKey"><c>SettingsKeyInfo</c> instance representing the current processing key</param>
 /// <param name="groupNo">Number representing index of the proccesing settings group</param>
 /// <param name="keyNo">Number representing index of the proccesing <c>SettingsKeyInfo</c></param>
 /// <param name="inheritChecked">Output parameter indicating whether the inherit <c>CheckBox</c> should be checked</param>
 /// <param name="chkInherit">Inherit <c>CheckBox</c> instance</param>
 /// <param name="inputControlID">Output parameter representing the ID of the edit control</param>
 /// <param name="value">Output parameter representing the value of the edit control</param>
 /// <returns><c>TextBox</c> object.</returns>
 private TextBox GetTextBox(SettingsKeyInfo settingsKey, int groupNo, int keyNo, out bool inheritChecked, CheckBox chkInherit, out string inputControlID, out string value)
 {
     CMSTextBox tbox = new CMSTextBox();
     tbox.ID = string.Format("txtKey{0}{1}", groupNo, keyNo);
     tbox.CssClass = "TextBoxField";
     tbox.EnableViewState = false;
     if ((settingsKey.KeyValue == null) && (mSiteId > 0))
     {
         inheritChecked = true;
         tbox.Text = SettingsKeyProvider.GetStringValue(settingsKey.KeyName);
     }
     else
     {
         inheritChecked = false;
         tbox.Text = ((chkInherit != null) && (Request.Form[chkInherit.UniqueID] == null)) ? settingsKey.KeyValue : SettingsKeyProvider.GetStringValue(settingsKey.KeyName);
     }
     tbox.Enabled = (URLHelper.IsPostback() && (chkInherit != null)) ? (Request.Form[chkInherit.UniqueID] == null) : !inheritChecked;
     inputControlID = tbox.ID;
     value = tbox.Text;
     return tbox;
 }
    /// <summary>
    /// Adds textbox/dropdown list determining sort column, dropdown list determining sort direction and 'then by' label
    /// </summary>
    /// <param name="i">Index of a control</param>
    /// <param name="sortColumn">Sort column</param>
    /// <param name="sortDirection">Sort direction</param>
    /// <param name="addThenBy">Whether to add 'then by' label</param>
    private void AddRow(int i, string sortColumn, string sortDirection, bool addThenBy)
    {
        hdnIndices.Value += i + ";";

        Panel pnlOrderBy = new Panel
        {
            ID = PNLORDERBY_ID_PREFIX + i
        };

        LocalizedLabel lblThenBy = null;
        if (addThenBy)
        {
            // Add 'Then by' label
            lblThenBy = new LocalizedLabel
            {
                ResourceString = "orderbycontrol.thenby",
                CssClass = "ThenBy",
                EnableViewState = false,
                ID = LBLTHENBY_ID_PREFIX + i
            };
        }

        // Add dropdown list for setting direction
        CMSDropDownList drpDirection = new CMSDropDownList
        {
            ID = DRPDIRECTION_ID_PREFIX + i,
            CssClass = "ShortDropDownList",
            AutoPostBack = true,
            Enabled = Enabled
        };
        drpDirection.Items.Add(new ListItem(GetString("general.ascending"), ASC));
        drpDirection.Items.Add(new ListItem(GetString("general.descending"), DESC));
        if (!String.IsNullOrEmpty(sortDirection))
        {
            drpDirection.SelectedValue = sortDirection;
        }

        Control orderByControl = null;
        switch (Mode)
        {
                // Add textbox for column name
            case SelectorMode.TextBox:
                CMSTextBox txtColumn = new CMSTextBox
                {
                    ID = TXTCOLUMN_ID_PREFIX + i,
                    AutoPostBack = true,
                    Enabled = Enabled
                };
                txtColumn.TextChanged += txtBox_TextChanged;

                if (!String.IsNullOrEmpty(sortColumn))
                {
                    // Set sorting column
                    txtColumn.Text = sortColumn;
                }
                orderByControl = txtColumn;
                break;

                // Add dropdown list for column selection
            case SelectorMode.DropDownList:
                CMSDropDownList drpColumn = new CMSDropDownList
                {
                    ID = DRPCOLUMN_ID_PREFIX + i,
                    CssClass = "ColumnDropDown",
                    AutoPostBack = true,
                    Enabled = Enabled
                };
                drpColumn.SelectedIndexChanged += drpOrderBy_SelectedIndexChanged;
                drpColumn.Items.Add(new ListItem(GetString("orderbycontrol.selectcolumn"), SELECT_COLUMN));
                drpColumn.Items.AddRange(CloneItems(Columns.ToArray()));
                if (!String.IsNullOrEmpty(sortColumn))
                {
                    // Set sorting column
                    drpColumn.SelectedValue = sortColumn;
                }
                orderByControl = drpColumn;
                break;
        }

        // Add controls to panel
        if (lblThenBy != null)
        {
            pnlOrderBy.Controls.Add(WrapControl(lblThenBy));
        }
        if (orderByControl != null)
        {
            pnlOrderBy.Controls.Add(WrapControl(orderByControl));
        }
        pnlOrderBy.Controls.Add(WrapControl(drpDirection));

        // Add panel to place holder
        plcOrderBy.Controls.Add(pnlOrderBy);

        if (Enabled)
        {
            // Setup enable/disable script for direction dropdown list
            if (orderByControl is TextBox)
            {
                ((TextBox)orderByControl).Attributes.Add("onkeyup", SET_DIRECTION_TXT + "('" + orderByControl.ClientID + "')");
                ScriptHelper.RegisterStartupScript(this, typeof (string), "setEnabledTxt" + orderByControl.ClientID, ScriptHelper.GetScript("$cmsj(document).ready(function() {" + SET_DIRECTION_TXT + "('" + orderByControl.ClientID + "');})"));
            }
            else
            {
                ScriptHelper.RegisterStartupScript(this, typeof (string), "setEnabledDrp" + orderByControl.ClientID, ScriptHelper.GetScript("$cmsj(document).ready(function() {" + SET_DIRECTION_DRP + "('" + orderByControl.ClientID + "');})"));
            }
        }

        // Add row to collection
        orderByRows.Add(new OrderByRow(i, lblThenBy, orderByControl, drpDirection, pnlOrderBy));
    }
Exemple #10
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do not process
        }
        else
        {
            SetValidationGroup(btnPasswdRetrieval, "_PasswordRetrieval");
            SetValidationGroup(Login1.FindControl("LoginButton"), "_Logon");

            var rfv = Login1.FindControl("rfvUserNameRequired") as RequiredFieldValidator;
            if (rfv != null)
            {
                SetValidationGroup(rfv, "_Logon");

                if (string.IsNullOrEmpty(rfv.ToolTip))
                {
                    rfv.ToolTip = GetString("LogonForm.NameRequired");
                }

                var enterNameText = GetString("LogonForm.EnterName");
                if (string.IsNullOrEmpty(rfv.Text))
                {
                    rfv.Text = enterNameText;
                }
                if (string.IsNullOrEmpty(rfv.ErrorMessage))
                {
                    rfv.ErrorMessage = enterNameText;
                }
            }

            CMSCheckBox chkItem = (CMSCheckBox)Login1.FindControl("chkRememberMe");
            if ((MFAuthenticationHelper.IsMultiFactorAutEnabled) && (chkItem != null))
            {
                chkItem.Visible = false;
            }

            lnkPasswdRetrieval.Visible = pnlUpdatePasswordRetrieval.Visible = pnlUpdatePasswordRetrievalLink.Visible = AllowPasswordRetrieval;

            CMSTextBox txtUserName = (CMSTextBox)Login1.FindControl("UserName");
            if (txtUserName != null)
            {
                txtUserName.EnableAutoComplete = SecurityHelper.IsAutoCompleteEnabledForLogin(SiteContext.CurrentSiteName);
            }

            if (!RequestHelper.IsPostBack())
            {
                Login1.UserName = QueryHelper.GetString("username", string.Empty);
                // Set SkinID properties
                if (!StandAlone && (PageCycle < PageCycleEnum.Initialized) && (ValidationHelper.GetString(Page.StyleSheetTheme, "") == ""))
                {
                    SetSkinID(SkinID);
                }
            }

            // Register script to update logon error message
            LocalizedLabel failureLit = Login1.FindControl("FailureText") as LocalizedLabel;
            if (failureLit != null)
            {
                StringBuilder sbScript = new StringBuilder();
                sbScript.Append(@"
function UpdateLabel_", ClientID, @"(content, context) {
    var lbl = document.getElementById(context);
    if(lbl)
    {       
        lbl.innerHTML = content;
        lbl.className = ""InfoLabel"";
    }
}");
                ScriptHelper.RegisterClientScriptBlock(this, GetType(), "InvalidLogonAttempts_" + ClientID, sbScript.ToString(), true);
            }
        }
    }
Exemple #11
0
    /// <summary>
    /// Overridden CreateChildControls method.
    /// </summary>
    protected override void CreateChildControls()
    {
        SetupControl();

        Controls.Clear();
        base.CreateChildControls();

        if (!StopProcessing)
        {
            if (!CMSAbstractEditableControl.RequestEditViewMode(ViewMode, ContentID))
            {
                ViewMode = ViewModeEnum.Preview;
            }

            // Create controls by actual page mode
            switch (ViewMode)
            {
            case ViewModeEnum.Edit:
            case ViewModeEnum.EditDisabled:

                // Main editor panel
                pnlEditor          = new Panel();
                pnlEditor.ID       = "pnlEditor";
                pnlEditor.CssClass = "EditableTextEdit EditableText_" + ContentID;
                pnlEditor.Attributes.Add("data-tracksavechanges", "true");
                Controls.Add(pnlEditor);

                // Title label
                lblTitle = new Label();
                lblTitle.EnableViewState = false;
                lblTitle.CssClass        = "EditableTextTitle";
                pnlEditor.Controls.Add(lblTitle);

                // Error label
                lblError = new Label();
                lblError.EnableViewState = false;
                lblError.CssClass        = "EditableTextError";
                pnlEditor.Controls.Add(lblError);

                // Display the region control based on the region type
                switch (RegionType)
                {
                case CMSEditableRegionTypeEnum.HtmlEditor:
                    // HTML Editor
                    Editor                       = new CMSHtmlEditor();
                    Editor.IsLiveSite            = false;
                    Editor.ID                    = "htmlValue";
                    Editor.AutoDetectLanguage    = false;
                    Editor.DefaultLanguage       = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
                    Editor.Title                 = Title;
                    Editor.UseInlineMode         = UseInlineMode;
                    Editor.ContentsLangDirection = CultureHelper.IsPreferredCultureRTL() ? LanguageDirection.RightToLeft : LanguageDirection.LeftToRight;

                    // Set the language
                    try
                    {
                        CultureInfo ci = CultureHelper.GetCultureInfo(DataHelper.GetNotEmpty(MembershipContext.AuthenticatedUser.PreferredUICultureCode, LocalizationContext.PreferredCultureCode));
                        Editor.DefaultLanguage = ci.TwoLetterISOLanguageName;
                    }
                    catch (ArgumentNullException)
                    {
                    }
                    catch (CultureNotFoundException)
                    {
                    }

                    Editor.AutoDetectLanguage = false;
                    Editor.Enabled            = IsEnabled(ViewMode);

                    if (ViewMode == ViewModeEnum.EditDisabled)
                    {
                        pnlEditor.Controls.Add(new LiteralControl("<div style=\"width: 98%\">"));
                        pnlEditor.Controls.Add(Editor);
                        pnlEditor.Controls.Add(new LiteralControl("</div>"));
                    }
                    else
                    {
                        pnlEditor.Controls.Add(Editor);
                    }
                    break;

                case CMSEditableRegionTypeEnum.TextArea:
                case CMSEditableRegionTypeEnum.TextBox:
                    // TextBox
                    txtValue          = new CMSTextBox();
                    txtValue.ID       = "txtValue";
                    txtValue.CssClass = "EditableTextTextBox";
                    txtValue.Enabled  = IsEnabled(ViewMode);
                    pnlEditor.Controls.Add(txtValue);
                    break;
                }
                break;

            default:
                // Display content in non editing modes
                ltlContent    = new Literal();
                ltlContent.ID = "ltlContent";
                ltlContent.EnableViewState = false;
                Controls.Add(ltlContent);
                break;
            }
        }
    }
    /// <summary>
    /// Creates textboxs.
    /// </summary>
    private void CreateTextBoxs()
    {
        textBoxList = new List<TextBox>(Count);
        pnlAnswer.Controls.Clear();

        int index = 1;
        int addIndex = 0;
        for (int i = 0; i < Count; i++)
        {
            CMSTextBox txtBox = new CMSTextBox();
            txtBox.ID = "captcha_" + i;
            txtBox.MaxLength = 1;
            txtBox.CssClass = "CaptchaTextBoxSmall";

            pnlAnswer.Controls.AddAt(addIndex, txtBox);

            if (index < Count)
            {
                Label sepLabel = new Label();
                sepLabel.Text = Separator;
                sepLabel.CssClass = "form-control-text";
                addIndex++;
                pnlAnswer.Controls.AddAt(addIndex, sepLabel);
            }
            index++;
            addIndex++;

            textBoxList.Add(txtBox);
        }
    }
Exemple #13
0
    /// <summary>
    /// Loads custom fields collisions.
    /// </summary>
    private void LoadCustomFields()
    {
        // Check if account has any custom fields
        FormInfo formInfo = FormHelper.GetFormInfo(mParentAccount.ClassName, false);
        var      list     = formInfo.GetFormElements(true, false, true);

        if (list.OfType <FormFieldInfo>().Any())
        {
            FormFieldInfo  ffi;
            Literal        content;
            LocalizedLabel lbl;
            CMSTextBox     txt;
            content      = new Literal();
            content.Text = "<div class=\"form-horizontal\">";
            plcCustomFields.Controls.Add(content);

            // Display all custom fields
            foreach (IField item in list)
            {
                ffi = item as FormFieldInfo;
                if (ffi != null)
                {
                    // Display layout
                    content      = new Literal();
                    content.Text = "<div class=\"form-group\"><div class=\"editing-form-label-cell\">";
                    plcCustomFields.Controls.Add(content);
                    lbl                     = new LocalizedLabel();
                    lbl.Text                = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver);
                    lbl.DisplayColon        = true;
                    lbl.EnableViewState     = false;
                    lbl.CssClass            = "control-label";
                    content                 = new Literal();
                    content.Text            = "</div><div class=\"editing-form-control-cell\"><div class=\"control-group-inline-forced\">";
                    txt                     = new CMSTextBox();
                    txt.ID                  = "txt" + ffi.Name;
                    lbl.AssociatedControlID = txt.ID;
                    plcCustomFields.Controls.Add(lbl);
                    plcCustomFields.Controls.Add(content);
                    plcCustomFields.Controls.Add(txt);
                    mCustomFields.Add(ffi.Name, new object[]
                    {
                        txt,
                        ffi.DataType
                    });
                    DataTable dt;

                    // Get grouped dataset
                    if (DataTypeManager.IsString(TypeEnum.Field, ffi.DataType))
                    {
                        dt = SortGroupAccountsByColumn(ffi.Name + SqlHelper.ORDERBY_ASC, ffi.Name + " NOT LIKE ''", ffi.Name);
                    }
                    else
                    {
                        dt = SortGroupAccountsByColumn(ffi.Name + SqlHelper.ORDERBY_ASC, ffi.Name + " IS NOT NULL", ffi.Name);
                    }

                    // Load value into textbox
                    txt.Text = ValidationHelper.GetString(mParentAccount.GetValue(ffi.Name), null);
                    if (string.IsNullOrEmpty(txt.Text) && (dt.Rows.Count > 0))
                    {
                        txt.Text = ValidationHelper.GetString(dt.Rows[0][ffi.Name], null);
                    }

                    // Display tooltip
                    var img = new HtmlGenericControl("i");
                    img.Attributes["class"] = "validation-warning icon-exclamation-triangle form-control-icon";
                    DisplayTooltip(img, dt, ffi.Name, ValidationHelper.GetString(mParentAccount.GetValue(ffi.Name), ""), ffi.DataType);
                    plcCustomFields.Controls.Add(img);
                    content      = new Literal();
                    content.Text = "</div></div></div>";
                    plcCustomFields.Controls.Add(content);
                    mMergedAccounts.Tables[0].DefaultView.RowFilter = null;
                }
            }
            content      = new Literal();
            content.Text = "</div>";
            plcCustomFields.Controls.Add(content);
        }
        else
        {
            tabCustomFields.Visible    = false;
            tabCustomFields.HeaderText = null;
        }
    }
 /// <summary>
 /// Truncates TextBox input based on its MaxLength property.
 /// </summary>
 /// <param name="textBox">TextBox which input will be truncated.</param>
 private string GetTruncatedTextBoxInput(CMSTextBox textBox)
 {
     return(textBox.Text.Trim().Truncate(textBox.MaxLength));
 }
    private object gridProducts_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = null;

        switch (sourceName.ToLowerCSafe())
        {
            case "skuname":
                row = (DataRowView)parameter;
                string skuName = ValidationHelper.GetString(row["SKUName"], "");
                int skuId = ValidationHelper.GetInteger(row["SKUID"], 0);

                // Create link for adding one item using product name
                LinkButton link = new LinkButton();
                link.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(skuName));
                link.Click += btnAddOneUnit_Click;
                link.CommandArgument = skuId.ToString();

                return link;

            case "price":
                // Format product price
                row = (DataRowView)parameter;
                return SKUInfoProvider.GetSKUFormattedPrice(new SKUInfo(row.Row), ShoppingCartObj, true, false);

            case "quantity":
                int id = ValidationHelper.GetInteger(parameter, 0);

                // Create textbox for entering quantity
                CMSTextBox tb = new CMSTextBox();
                tb.MaxLength = 9;
                tb.Width = 50;
                tb.ID = "txtQuantity" + id;

                // Add textbox to dictionary under SKUID key
                quantityControls.Add(id, tb);

                return tb;
        }

        return parameter;
    }
    /// <summary>
    /// Generates row with textboxes for new values
    /// </summary>
    private void GenerateNewRow()
    {
        // New Item tab
        TableRow trNew = new TableRow();

        // Actions
        TableCell tnew = new TableCell();
        tnew.CssClass = "unigrid-actions";

        var imgNew = new CMSGridActionButton();
        imgNew.OnClientClick = String.Format("addNewRow('{0}'); return false;", ClientID);
        imgNew.IconCssClass = "icon-plus";
        imgNew.IconStyle = GridIconStyle.Allow;
        imgNew.ToolTip = GetString("xmleditor.createitem");
        imgNew.ID = "add";

        var imgOK = new CMSGridActionButton();
        imgOK.IconCssClass = "icon-check-circle";
        imgOK.IconStyle = GridIconStyle.Allow;
        imgOK.ID = "newok";
        imgOK.ToolTip = GetString("xmleditor.additem");

        var imgDelete = new CMSGridActionButton();
        imgDelete.OnClientClick = String.Format("if (confirm('" + GetString("xmleditor.confirmcancel") + "')) cancelNewRow('{0}'); return false;", ClientID);
        imgDelete.IconCssClass = "icon-bin";
        imgDelete.IconStyle = GridIconStyle.Critical;
        imgDelete.ID = "newcancel";
        imgDelete.ToolTip = GetString("xmleditor.cancelnewitem");

        tnew.Controls.Add(imgNew);
        tnew.Controls.Add(imgOK);
        tnew.Controls.Add(imgDelete);

        // Textboxes
        CMSTextBox txtNewName = new CMSTextBox();
        txtNewName.ID = "utk_newkey";

        CMSTextBox txtNewValue = new CMSTextBox();
        txtNewValue.ID = "utv_newvalue";
        txtNewValue.Width = Unit.Pixel(490);

        TableCell tcnew = new TableCell();
        tcnew.Controls.Add(txtNewName);

        TableCell tcvnew = new TableCell();
        tcvnew.Controls.Add(txtNewValue);

        trNew.Cells.Add(tnew);
        trNew.Cells.Add(tcnew);
        trNew.Cells.Add(tcvnew);

        tblData.Rows.Add(trNew);

        imgOK.OnClientClick = "if (validateCustomProperties($cmsj('#" + txtNewName.ClientID + "').val(),null))" + ControlsHelper.GetPostBackEventReference(tblData, "add") + " ;return false";

        // Prevent load styles from control state
        imgDelete.AddCssClass("hidden");
        imgOK.AddCssClass("hidden");
        txtNewName.AddCssClass("hidden");
        txtNewValue.AddCssClass("hidden");
        txtNewValue.Text = String.Empty;
        txtNewName.Text = String.Empty;

        if (!isNewValid && RequestHelper.IsPostBack())
        {
            txtNewName.Text = Request.Form[UniqueID + "$utk_newkey"];
            txtNewValue.Text = Request.Form[UniqueID + "$utv_newvalue"];
            txtNewValue.CssClass = String.Empty;
            txtNewName.CssClass = String.Empty;

            imgOK.RemoveCssClass("hidden");
            imgDelete.RemoveCssClass("hidden");
            imgNew.AddCssClass("hidden");

            RegisterEnableScript(false);
        }
    }
    /// <summary>
    /// Generates tables
    /// </summary>
    private void GenerateTable()
    {
        tblData.Controls.Clear();

        Hashtable ht = data.ConvertToHashtable();

        TableHeaderRow th = new TableHeaderRow()
        {
            TableSection = TableRowSection.TableHeader
        };
        TableHeaderCell ha = new TableHeaderCell();
        TableHeaderCell hn = new TableHeaderCell();
        TableHeaderCell hv = new TableHeaderCell();

        th.CssClass = "unigrid-head";

        ha.Text = GetString("unigrid.actions");
        ha.CssClass = "unigrid-actions-header";

        hn.Text = GetString("xmleditor.propertyname");
        hn.Width = Unit.Pixel(180);
        hv.Text = GetString("xmleditor.propertyvalue");
        hv.Width = Unit.Pixel(500);

        th.Cells.Add(ha);
        th.Cells.Add(hn);
        th.Cells.Add(hv);

        tblData.Rows.Add(th);

        ArrayList keys = new ArrayList(ht);
        keys.Sort(new CustomStringComparer());

        foreach (DictionaryEntry okey in keys)
        {
            String key = ValidationHelper.GetString(okey.Key, String.Empty);
            String value = ValidationHelper.GetString(okey.Value, String.Empty);

            bool isInvalid = (key == INVALIDTOKEN);
            key = isInvalid ? invalidKey : key;

            if (value == String.Empty)
            {
                continue;
            }

            TableRow tr = new TableRow();

            // Actions
            TableCell tna = new TableCell();
            tna.CssClass = "unigrid-actions";

            var imgEdit = new CMSGridActionButton();
            imgEdit.OnClientClick = String.Format("displayEdit('{1}','{0}'); return false; ", key, ClientID);
            imgEdit.IconCssClass = "icon-edit";
            imgEdit.IconStyle = GridIconStyle.Allow;
            imgEdit.ID = key + "_edit";
            imgEdit.ToolTip = GetString("xmleditor.edititem");

            var imgOK = new CMSGridActionButton();
            imgOK.IconCssClass = "icon-check";
            imgOK.IconStyle = GridIconStyle.Allow;
            imgOK.OnClientClick = String.Format("approveCustomChanges('{0}','{1}');return false;", ClientID, key);
            imgOK.ID = key + "_ok";
            imgOK.ToolTip = GetString("xmleditor.approvechanges");

            var imgDelete = new CMSGridActionButton();
            imgDelete.OnClientClick = " if (confirm('" + GetString("xmleditor.deleteconfirm") + "')) {" + ControlsHelper.GetPostBackEventReference(tblData, "delete_" + key) + "} ;return false;";
            imgDelete.IconCssClass = "icon-bin";
            imgDelete.IconStyle = GridIconStyle.Critical;
            imgDelete.ID = key + "_del";
            imgDelete.ToolTip = GetString("xmleditor.deleteitem");

            var imgUndo = new CMSGridActionButton();
            imgUndo.OnClientClick = String.Format("if (confirm('" + GetString("xmleditor.confirmcancel") + "')) undoCustomChanges('{0}','{1}'); return false;", ClientID, key);
            imgUndo.IconCssClass = "icon-arrow-crooked-left";
            imgUndo.ID = key + "_undo";
            imgUndo.ToolTip = GetString("xmleditor.undochanges");

            tna.Controls.Add(imgEdit);
            tna.Controls.Add(imgOK);
            tna.Controls.Add(imgDelete);
            tna.Controls.Add(imgUndo);

            value = MacroSecurityProcessor.RemoveSecurityParameters(value, false, null);

            // Labels
            Label lblName = new Label();
            lblName.ID = "sk" + key;
            lblName.Text = key;

            Label lblValue = new Label();
            lblValue.ID = "sv" + key;
            lblValue.Text = value;

            // Textboxes
            CMSTextBox txtName = new CMSTextBox();
            txtName.Text = key;
            txtName.ID = "tk" + key;
            txtName.CssClass = "XmlEditorTextbox";

            CMSTextBox txtValue = new CMSTextBox();
            txtValue.Text = value;
            txtValue.ID = "tv" + key;
            txtValue.CssClass = "XmlEditorTextbox";
            txtValue.Width = Unit.Pixel(490);

            labels.Add(lblName);
            labels.Add(lblValue);

            textboxes.Add(txtName);
            textboxes.Add(txtValue);

            TableCell tcn = new TableCell();
            tcn.Controls.Add(lblName);
            tcn.Controls.Add(txtName);

            TableCell tcv = new TableCell();
            tcv.Controls.Add(lblValue);
            tcv.Controls.Add(txtValue);

            tr.Cells.Add(tna);
            tr.Cells.Add(tcn);
            tr.Cells.Add(tcv);

            tblData.Rows.Add(tr);

            lblValue.CssClass = String.Empty;
            lblName.CssClass = "CustomEditorKeyClass";

            if (isInvalid)
            {
                imgDelete.AddCssClass("hidden");
                imgEdit.AddCssClass("hidden");

                lblName.AddCssClass("hidden");
                lblValue.AddCssClass("hidden");

                RegisterEnableScript(false);
            }
            else
            {
                imgOK.AddCssClass("hidden");
                imgUndo.AddCssClass("hidden");

                txtName.CssClass += " hidden";
                txtValue.CssClass += " hidden";
            }
        }
    }
    /// <summary>
    /// Generates row with textboxes for new values
    /// </summary>
    private void GenerateNewRow()
    {
        // New Item tab
        TableRow trNew = new TableRow();

        // Actions
        TableCell tnew = new TableCell();

        tnew.CssClass = "unigrid-actions";

        var imgNew = new CMSGridActionButton();

        imgNew.OnClientClick = String.Format("addNewRow('{0}'); return false;", ClientID);
        imgNew.IconCssClass  = "icon-plus";
        imgNew.IconStyle     = GridIconStyle.Allow;
        imgNew.ToolTip       = GetString("xmleditor.createitem");
        imgNew.ID            = "add";

        var imgOK = new CMSGridActionButton();

        imgOK.IconCssClass = "icon-check-circle";
        imgOK.IconStyle    = GridIconStyle.Allow;
        imgOK.ID           = "newok";
        imgOK.ToolTip      = GetString("xmleditor.additem");

        var imgDelete = new CMSGridActionButton();

        imgDelete.OnClientClick = String.Format("if (confirm('" + GetString("xmleditor.confirmcancel") + "')) cancelNewRow('{0}'); return false;", ClientID);
        imgDelete.IconCssClass  = "icon-bin";
        imgDelete.IconStyle     = GridIconStyle.Critical;
        imgDelete.ID            = "newcancel";
        imgDelete.ToolTip       = GetString("xmleditor.cancelnewitem");

        tnew.Controls.Add(imgNew);
        tnew.Controls.Add(imgOK);
        tnew.Controls.Add(imgDelete);

        // Textboxes
        CMSTextBox txtNewName = new CMSTextBox();

        txtNewName.ID = "utk_newkey";

        CMSTextBox txtNewValue = new CMSTextBox();

        txtNewValue.ID    = "utv_newvalue";
        txtNewValue.Width = Unit.Pixel(490);

        TableCell tcnew = new TableCell();

        tcnew.Controls.Add(txtNewName);

        TableCell tcvnew = new TableCell();

        tcvnew.Controls.Add(txtNewValue);

        trNew.Cells.Add(tnew);
        trNew.Cells.Add(tcnew);
        trNew.Cells.Add(tcvnew);

        tblData.Rows.Add(trNew);

        imgOK.OnClientClick = "if (validateCustomProperties($cmsj('#" + txtNewName.ClientID + "').val(),null))" + ControlsHelper.GetPostBackEventReference(tblData, "add") + " ;return false";

        // Prevent load styles from control state
        imgDelete.AddCssClass("hidden");
        imgOK.AddCssClass("hidden");
        txtNewName.AddCssClass("hidden");
        txtNewValue.AddCssClass("hidden");
        txtNewValue.Text = String.Empty;
        txtNewName.Text  = String.Empty;

        if (!isNewValid && RequestHelper.IsPostBack())
        {
            txtNewName.Text      = Request.Form[UniqueID + "$utk_newkey"];
            txtNewValue.Text     = Request.Form[UniqueID + "$utv_newvalue"];
            txtNewValue.CssClass = String.Empty;
            txtNewName.CssClass  = String.Empty;

            imgOK.RemoveCssClass("hidden");
            imgDelete.RemoveCssClass("hidden");
            imgNew.AddCssClass("hidden");

            RegisterEnableScript(false);
        }
    }
    /// <summary>
    /// Generates tables
    /// </summary>
    private void GenerateTable()
    {
        tblData.Controls.Clear();

        Hashtable ht = data.ConvertToHashtable();

        TableHeaderRow th = new TableHeaderRow()
        {
            TableSection = TableRowSection.TableHeader
        };
        TableHeaderCell ha = new TableHeaderCell();
        TableHeaderCell hn = new TableHeaderCell();
        TableHeaderCell hv = new TableHeaderCell();

        th.CssClass = "unigrid-head";

        ha.Text     = GetString("unigrid.actions");
        ha.CssClass = "unigrid-actions-header";

        hn.Text  = GetString("xmleditor.propertyname");
        hn.Width = Unit.Pixel(180);
        hv.Text  = GetString("xmleditor.propertyvalue");
        hv.Width = Unit.Pixel(500);

        th.Cells.Add(ha);
        th.Cells.Add(hn);
        th.Cells.Add(hv);

        tblData.Rows.Add(th);

        ArrayList keys = new ArrayList(ht);

        keys.Sort(new CustomStringComparer());

        foreach (DictionaryEntry okey in keys)
        {
            String key   = ValidationHelper.GetString(okey.Key, String.Empty);
            String value = ValidationHelper.GetString(okey.Value, String.Empty);

            bool isInvalid = (key == INVALIDTOKEN);
            key = isInvalid ? invalidKey : key;

            if (value == String.Empty)
            {
                continue;
            }

            TableRow tr = new TableRow();

            // Actions
            TableCell tna = new TableCell();
            tna.CssClass = "unigrid-actions";

            var imgEdit = new CMSGridActionButton();
            imgEdit.OnClientClick = String.Format("displayEdit('{1}','{0}'); return false; ", key, ClientID);
            imgEdit.IconCssClass  = "icon-edit";
            imgEdit.IconStyle     = GridIconStyle.Allow;
            imgEdit.ID            = key + "_edit";
            imgEdit.ToolTip       = GetString("xmleditor.edititem");

            var imgOK = new CMSGridActionButton();
            imgOK.IconCssClass  = "icon-check";
            imgOK.IconStyle     = GridIconStyle.Allow;
            imgOK.OnClientClick = String.Format("approveCustomChanges('{0}','{1}');return false;", ClientID, key);
            imgOK.ID            = key + "_ok";
            imgOK.ToolTip       = GetString("xmleditor.approvechanges");

            var imgDelete = new CMSGridActionButton();
            imgDelete.OnClientClick = " if (confirm('" + GetString("xmleditor.deleteconfirm") + "')) {" + ControlsHelper.GetPostBackEventReference(tblData, "delete_" + key) + "} ;return false;";
            imgDelete.IconCssClass  = "icon-bin";
            imgDelete.IconStyle     = GridIconStyle.Critical;
            imgDelete.ID            = key + "_del";
            imgDelete.ToolTip       = GetString("xmleditor.deleteitem");

            var imgUndo = new CMSGridActionButton();
            imgUndo.OnClientClick = String.Format("if (confirm('" + GetString("xmleditor.confirmcancel") + "')) undoCustomChanges('{0}','{1}'); return false;", ClientID, key);
            imgUndo.IconCssClass  = "icon-arrow-crooked-left";
            imgUndo.ID            = key + "_undo";
            imgUndo.ToolTip       = GetString("xmleditor.undochanges");

            tna.Controls.Add(imgEdit);
            tna.Controls.Add(imgOK);
            tna.Controls.Add(imgDelete);
            tna.Controls.Add(imgUndo);

            value = MacroSecurityProcessor.RemoveSecurityParameters(value, false, null);

            // Labels
            Label lblName = new Label();
            lblName.ID   = "sk" + key;
            lblName.Text = key;

            Label lblValue = new Label();
            lblValue.ID   = "sv" + key;
            lblValue.Text = value;

            // Textboxes
            CMSTextBox txtName = new CMSTextBox();
            txtName.Text     = key;
            txtName.ID       = "tk" + key;
            txtName.CssClass = "XmlEditorTextbox";

            CMSTextBox txtValue = new CMSTextBox();
            txtValue.Text     = value;
            txtValue.ID       = "tv" + key;
            txtValue.CssClass = "XmlEditorTextbox";
            txtValue.Width    = Unit.Pixel(490);

            labels.Add(lblName);
            labels.Add(lblValue);

            textboxes.Add(txtName);
            textboxes.Add(txtValue);

            TableCell tcn = new TableCell();
            tcn.Controls.Add(lblName);
            tcn.Controls.Add(txtName);

            TableCell tcv = new TableCell();
            tcv.Controls.Add(lblValue);
            tcv.Controls.Add(txtValue);

            tr.Cells.Add(tna);
            tr.Cells.Add(tcn);
            tr.Cells.Add(tcv);

            tblData.Rows.Add(tr);

            lblValue.CssClass = String.Empty;
            lblName.CssClass  = "CustomEditorKeyClass";

            if (isInvalid)
            {
                imgDelete.AddCssClass("hidden");
                imgEdit.AddCssClass("hidden");

                lblName.AddCssClass("hidden");
                lblValue.AddCssClass("hidden");

                RegisterEnableScript(false);
            }
            else
            {
                imgOK.AddCssClass("hidden");
                imgUndo.AddCssClass("hidden");

                txtName.CssClass  += " hidden";
                txtValue.CssClass += " hidden";
            }
        }
    }
Exemple #20
0
    /// <summary>
    /// Creates a field item
    /// </summary>
    /// <param name="ffi">Form field info</param>
    /// <param name="i">Field index</param>
    private void CreateField(FormFieldInfo ffi, ref int i)
    {
        // Check if is defined inherited default value
        bool doNotInherit = IsDefined(ffi.Name);
        // Get default value
        string inheritedDefaultValue = GetDefaultValue(ffi.Name);

        // Current hashtable for client id
        Hashtable currentHashTable = new Hashtable();

        // First item is name
        currentHashTable[0] = ffi.Name;
        currentHashTable[3] = ffi.Caption;

        // Begin new row and column
        Literal table2 = new Literal();

        pnlEditor.Controls.Add(table2);
        table2.Text = "<tr class=\"InheritWebPart\"><td>";

        // Property label
        Label lblName = new Label();

        pnlEditor.Controls.Add(lblName);
        lblName.Text    = ResHelper.LocalizeString(ffi.Caption);
        lblName.ToolTip = ResHelper.LocalizeString(ffi.Description);
        if (!lblName.Text.EndsWithCSafe(":"))
        {
            lblName.Text += ":";
        }

        // New column
        Literal table3 = new Literal();

        pnlEditor.Controls.Add(table3);
        table3.Text = "</td><td>";

        // Type string for JavaScript function
        string jsType = "textbox";

        // Type switcher
        if (FormHelper.IsFieldOfType(ffi, FormFieldControlTypeEnum.CheckBoxControl))
        {
            // Checkbox type field
            CheckBox chk = new CheckBox();
            pnlEditor.Controls.Add(chk);
            chk.Checked = ValidationHelper.GetBoolean(ffi.DefaultValue, false);
            chk.InputAttributes.Add("disabled", "disabled");

            chk.Attributes.Add("id", chk.ClientID + "_upperSpan");

            if (doNotInherit)
            {
                chk.InputAttributes.Remove("disabled");
                chk.Enabled = true;
                chk.Checked = ValidationHelper.GetBoolean(inheritedDefaultValue, false);
            }

            jsType = "checkbox";
            currentHashTable[1] = chk.ClientID;
        }
        else if (FormHelper.IsFieldOfType(ffi, FormFieldControlTypeEnum.CalendarControl))
        {
            // Date time picker
            DateTimePicker dtPick = new DateTimePicker();
            pnlEditor.Controls.Add(dtPick);
            String value = ffi.DefaultValue;
            dtPick.Enabled       = false;
            dtPick.SupportFolder = ResolveUrl("~/CMSAdminControls/Calendar");

            if (doNotInherit)
            {
                dtPick.Enabled = true;
                value          = inheritedDefaultValue;
            }

            if (ValidationHelper.IsMacro(value))
            {
                dtPick.DateTimeTextBox.Text = value;
            }
            else
            {
                dtPick.SelectedDateTime = ValidationHelper.GetDateTime(value, DataHelper.DATETIME_NOT_SELECTED, CultureHelper.EnglishCulture);
            }

            jsType = "calendar";
            currentHashTable[1] = dtPick.ClientID;
        }
        else
        {
            // Other types represent by textbox
            CMSTextBox txt = new CMSTextBox();
            pnlEditor.Controls.Add(txt);

            // Convert from default culture to current culture if needed (type double, datetime)
            txt.Text = (String.IsNullOrEmpty(ffi.DefaultValue) || ValidationHelper.IsMacro(ffi.DefaultValue)) ? ffi.DefaultValue : ValidationHelper.GetString(DataHelper.ConvertValue(ffi.DefaultValue, GetDataType(ffi.Name)), String.Empty);

            txt.CssClass = "TextBoxField";
            txt.Enabled  = ffi.Enabled;
            txt.Enabled  = false;

            if (ffi.DataType == FormFieldDataTypeEnum.LongText)
            {
                txt.TextMode = TextBoxMode.MultiLine;
                txt.Rows     = 3;
            }

            if (doNotInherit)
            {
                txt.Enabled = true;
                txt.Text    = (String.IsNullOrEmpty(inheritedDefaultValue) || ValidationHelper.IsMacro(ffi.DefaultValue)) ? inheritedDefaultValue : ValidationHelper.GetString(DataHelper.ConvertValue(inheritedDefaultValue, GetDataType(ffi.Name)), String.Empty);
            }

            currentHashTable[1] = txt.ClientID;
        }

        // New column
        Literal table4 = new Literal();

        pnlEditor.Controls.Add(table4);
        table4.Text = "</td><td>" + ffi.DataType.ToString() + "</td><td>";


        // Inherit checkbox
        CheckBox chkInher = new CheckBox();

        pnlEditor.Controls.Add(chkInher);
        chkInher.Checked = true;

        // Uncheck checkbox if this property is not inherited
        if (doNotInherit)
        {
            chkInher.Checked = false;
        }

        chkInher.Text = GetString("DefaultValueEditor.Inherited");

        string defValue = (ffi.DefaultValue == null) ? String.Empty : ffi.DefaultValue;

        if (!String.IsNullOrEmpty(ffi.DefaultValue))
        {
            if (!ValidationHelper.IsMacro(ffi.DefaultValue))
            {
                defValue = ValidationHelper.GetString(DataHelper.ConvertValue(defValue, GetDataType(ffi.Name)), String.Empty);
            }
            else
            {
                defValue = MacroResolver.RemoveSecurityParameters(defValue, true, null);
            }
        }

        // Set default value for JavaScript function
        defValue = "'" + defValue.Replace("\r\n", "\\n") + "'";

        if (jsType == "checkbox")
        {
            defValue = ValidationHelper.GetBoolean(ffi.DefaultValue, false).ToString().ToLowerCSafe();
        }

        // Add JavaScript attribute with js function call
        chkInher.Attributes.Add("onclick", "CheckClick(this, '" + currentHashTable[1].ToString() + "', " + defValue + ", '" + jsType + "' );");

        // Insert current checkbox id
        currentHashTable[2] = chkInher.ClientID;

        // Add current hashtable to the controls hashtable
        ((Hashtable)Controls)[i] = currentHashTable;

        // End current row
        Literal table5 = new Literal();

        pnlEditor.Controls.Add(table5);
        table5.Text = "</td></tr>";

        i++;
    }
    /// <summary>
    /// Add filter field to the filter table.
    /// </summary>
    /// <param name="filter">Filter definition</param>
    /// <param name="columnSourceName">Column source field name</param>
    /// <param name="fieldDisplayName">Field display name</param>
    /// <param name="filterWrapperControl">Wrapper control for filter</param>
    /// <param name="filterValue">Filter value</param>
    private void AddFilterField(ColumnFilter filter, string columnSourceName, string fieldDisplayName, Control filterWrapperControl, string filterValue)
    {
        string fieldSourceName = filter.Source ?? columnSourceName;
        if (String.IsNullOrEmpty(fieldSourceName) || (filter == null) || (filterWrapperControl == null))
        {
            return;
        }

        string fieldPath = filter.Path;
        string filterFormat = filter.Format;
        int filterSize = filter.Size;
        Unit filterWidth = filter.Width;

        Panel fieldWrapperPanel = new Panel()
        {
            CssClass = "form-group"
        };

        Panel fieldLabelPanel = new Panel()
        {
            CssClass = "filter-form-label-cell"
        };

        Panel fieldOptionPanel = new Panel()
        {
            CssClass = "filter-form-condition-cell"
        };

        Panel fieldInputPanel = new Panel()
        {
            CssClass = "filter-form-value-cell"
        };

        // Ensure fieldSourceName is JavaScript valid
        fieldSourceName = fieldSourceName.Replace(ALL, "__ALL__");

        int index = GetNumberOfFilterFieldsWithSameSourceColumn(fieldSourceName);
        string filterControlID = fieldSourceName + (index > 0 ? index.ToString() : String.Empty);

        Label textName = new Label
        {
            Text = String.IsNullOrEmpty(fieldDisplayName) ? String.Empty : fieldDisplayName + ":",
            ID = String.Format("{0}Name", filterControlID),
            EnableViewState = false,
            CssClass = "control-label"
        };

        fieldLabelPanel.Controls.Add(textName);
        fieldWrapperPanel.Controls.Add(fieldLabelPanel);

        // Filter value
        string value = null;
        if (filterValue != null)
        {
            value = ValidationHelper.GetString(filterValue, null);
        }

        // Filter definition
        UniGridFilterField filterDefinition = new UniGridFilterField();
        filterDefinition.Type = filter.Type;
        filterDefinition.Label = textName;
        filterDefinition.Format = filterFormat;
        filterDefinition.FilterRow = fieldWrapperPanel;

        // Set the filter default value
        string defaultValue = filter.DefaultValue;

        // Remember default values of filter field controls for potential UniGrid reset
        string optionFilterFieldValue = null;
        string valueFilterFieldValue = null;

        switch (filterDefinition.Type)
        {
            // Text filter
            case UniGridFilterTypeEnum.Text:
                {
                    CMSDropDownList textOptionFilterField = new CMSDropDownList();
                    ControlsHelper.FillListWithTextSqlOperators(textOptionFilterField);
                    textOptionFilterField.ID = filterControlID;

                    // Set the value
                    SetDropdownValue(value, null, textOptionFilterField);
                    optionFilterFieldValue = textOptionFilterField.SelectedValue;

                    LocalizedLabel lblSelect = new LocalizedLabel
                    {
                        EnableViewState = false,
                        CssClass = "sr-only",
                        AssociatedControlID = textOptionFilterField.ID,
                        ResourceString = "filter.mode"
                    };

                    fieldOptionPanel.Controls.Add(lblSelect);
                    fieldOptionPanel.Controls.Add(textOptionFilterField);
                    fieldWrapperPanel.Controls.Add(fieldOptionPanel);

                    CMSTextBox textValueFilterField = new CMSTextBox
                    {
                        ID = String.Format("{0}TextValue", filterControlID)
                    };

                    // Set value
                    SetTextboxValue(value, defaultValue, textValueFilterField);
                    valueFilterFieldValue = textValueFilterField.Text;

                    if (filterSize > 0)
                    {
                        textValueFilterField.MaxLength = filterSize;
                    }
                    if (!filterWidth.IsEmpty)
                    {
                        textValueFilterField.Width = filterWidth;
                    }
                    fieldInputPanel.Controls.Add(textValueFilterField);
                    fieldWrapperPanel.Controls.Add(fieldInputPanel);
                    textName.AssociatedControlID = textValueFilterField.ID;

                    filterDefinition.OptionsControl = textOptionFilterField;
                    filterDefinition.ValueControl = textValueFilterField;
                }
                break;

            // Boolean filter
            case UniGridFilterTypeEnum.Bool:
                {
                    CMSDropDownList booleanOptionFilterField = new CMSDropDownList();

                    booleanOptionFilterField.Items.Add(new ListItem(GetString("general.selectall"), String.Empty));
                    booleanOptionFilterField.Items.Add(new ListItem(GetString("general.yes"), "1"));
                    booleanOptionFilterField.Items.Add(new ListItem(GetString("general.no"), "0"));
                    booleanOptionFilterField.ID = filterControlID;
                    textName.AssociatedControlID = booleanOptionFilterField.ID;

                    // Set the value
                    SetDropdownValue(value, defaultValue, booleanOptionFilterField);
                    valueFilterFieldValue = booleanOptionFilterField.SelectedValue;

                    // Set input panel wide for boolean Drop-down list
                    fieldInputPanel.CssClass = "filter-form-value-cell-wide";

                    fieldInputPanel.Controls.Add(booleanOptionFilterField);
                    fieldWrapperPanel.Controls.Add(fieldInputPanel);

                    filterDefinition.ValueControl = booleanOptionFilterField;
                }
                break;

            // Integer filter
            case UniGridFilterTypeEnum.Integer:
            case UniGridFilterTypeEnum.Double:
                {
                    CMSDropDownList numberOptionFilterField = new CMSDropDownList();
                    numberOptionFilterField.Items.Add(new ListItem(GetString("filter.equals"), "="));
                    numberOptionFilterField.Items.Add(new ListItem(GetString("filter.notequals"), "<>"));
                    numberOptionFilterField.Items.Add(new ListItem(GetString("filter.lessthan"), "<"));
                    numberOptionFilterField.Items.Add(new ListItem(GetString("filter.greaterthan"), ">"));
                    numberOptionFilterField.ID = filterControlID;

                    // Set the value
                    SetDropdownValue(value, null, numberOptionFilterField);
                    optionFilterFieldValue = numberOptionFilterField.SelectedValue;

                    LocalizedLabel lblSelect = new LocalizedLabel
                    {
                        EnableViewState = false,
                        CssClass = "sr-only",
                        AssociatedControlID = numberOptionFilterField.ID,
                        ResourceString = "filter.mode"
                    };

                    // Add filter field
                    fieldOptionPanel.Controls.Add(lblSelect);
                    fieldOptionPanel.Controls.Add(numberOptionFilterField);
                    fieldWrapperPanel.Controls.Add(fieldOptionPanel);

                    CMSTextBox numberValueFilterField = new CMSTextBox
                    {
                        ID = String.Format("{0}NumberValue", filterControlID)
                    };

                    // Set value
                    SetTextboxValue(value, defaultValue, numberValueFilterField);
                    valueFilterFieldValue = numberValueFilterField.Text;

                    if (filterSize > 0)
                    {
                        numberValueFilterField.MaxLength = filterSize;
                    }
                    if (!filterWidth.IsEmpty)
                    {
                        numberValueFilterField.Width = filterWidth;
                    }
                    numberValueFilterField.EnableViewState = false;

                    fieldInputPanel.Controls.Add(numberValueFilterField);
                    fieldWrapperPanel.Controls.Add(fieldInputPanel);

                    filterDefinition.OptionsControl = numberOptionFilterField;
                    filterDefinition.ValueControl = numberValueFilterField;
                }
                break;

            case UniGridFilterTypeEnum.Site:
                {
                    // Site selector
                    fieldPath = "~/CMSFormControls/Filters/SiteFilter.ascx";
                }
                break;

            case UniGridFilterTypeEnum.Custom:
                // Load custom path
                {
                    if (String.IsNullOrEmpty(fieldPath))
                    {
                        throw new Exception("[UniGrid.AddFilterField]: Filter field path is not set");
                    }
                }
                break;

            default:
                // Not supported filter type
                throw new Exception("[UniGrid.AddFilterField]: Filter type '" + filterDefinition.Type + "' is not supported. Supported filter types: integer, double, bool, text, site, custom.");
        }

        // Else if filter path is defined use custom filter
        if (fieldPath != null)
        {
            // Add to the controls collection
            CMSAbstractBaseFilterControl filterControl = LoadFilterControl(fieldPath, filterControlID, value, filterDefinition, filter);
            if (filterControl != null)
            {
                // Set default value
                if (!String.IsNullOrEmpty(defaultValue))
                {
                    filterControl.SelectedValue = defaultValue;
                }

                fieldInputPanel.Controls.Add(filterControl);
            }

            fieldInputPanel.CssClass = "filter-form-value-cell-wide";
            fieldWrapperPanel.Controls.Add(fieldInputPanel);
        }

        RaiseOnFilterFieldCreated(fieldSourceName, filterDefinition);
        FilterFields[String.Format("{0}{1}", fieldSourceName, (index > 0 ? "#" + index : String.Empty))] = filterDefinition;

        filterWrapperControl.Controls.Add(fieldWrapperPanel);

        // Store initial filter state for potential UniGrid reset
        if (filterDefinition.OptionsControl != null)
        {
            InitialFilterStateControls.Add(new KeyValuePair<Control, object>(filterDefinition.OptionsControl, optionFilterFieldValue));
        }
        if (filterDefinition.ValueControl != null)
        {
            if (!(filterDefinition.ValueControl is CMSAbstractBaseFilterControl))
            {
                InitialFilterStateControls.Add(new KeyValuePair<Control, object>(filterDefinition.ValueControl, valueFilterFieldValue));
            }
        }
    }
    /// <summary>
    /// Creates table.
    /// </summary>
    private void CreateTable(bool setAutomatically)
    {
        Table table = new Table();
        table.CssClass = "table table-hover";
        table.CellPadding = -1;
        table.CellSpacing = -1;

        // Create table header
        TableHeaderRow header = new TableHeaderRow();
        header.TableSection = TableRowSection.TableHeader;
        TableHeaderCell thc = new TableHeaderCell();
        thc.Text = GetString("srch.settings.fieldname");
        thc.Scope = TableHeaderScope.Column;
        header.Cells.Add(thc);
        thc = new TableHeaderCell();
        thc.Text = GetString("development.content");
        thc.Scope = TableHeaderScope.Column;
        header.Cells.Add(thc);
        thc = new TableHeaderCell();
        thc.Text = GetString("srch.settings.searchable");
        thc.Scope = TableHeaderScope.Column;
        header.Cells.Add(thc);
        thc = new TableHeaderCell();
        thc.Text = GetString("srch.settings.tokenized");
        thc.Scope = TableHeaderScope.Column;
        header.Cells.Add(thc);

        if (DisplayIField)
        {
            thc = new TableHeaderCell();
            thc.Text = GetString("srch.settings.ifield");
            header.Cells.Add(thc);
        }

        thc = new TableHeaderCell();
        thc.CssClass = "main-column-100";
        header.Cells.Add(thc);

        table.Rows.Add(header);
        pnlContent.Controls.Add(table);

        // Create table content
        if ((mAttributes != null) && (mAttributes.Count > 0))
        {
            // Create row for each field
            foreach (ColumnDefinition column in mAttributes)
            {
                SearchSettingsInfo ssi = null;
                TableRow tr = new TableRow();
                if (!DataHelper.DataSourceIsEmpty(mInfos))
                {
                    DataRow[] dr = mInfos.Tables[0].Select("name = '" + column.ColumnName + "'");
                    if ((dr.Length > 0) && (mSearchSettings != null))
                    {
                        ssi = mSearchSettings.GetSettingsInfo((string)dr[0]["id"]);
                    }
                }

                // Add cell with field name
                TableCell tc = new TableCell();
                Label lbl = new Label();
                lbl.Text = column.ColumnName;
                tc.Controls.Add(lbl);
                tr.Cells.Add(tc);

                // Add cell with 'Content' value
                tc = new TableCell();
                CMSCheckBox chk = new CMSCheckBox();
                chk.ID = column.ColumnName + SearchSettings.CONTENT;

                if (setAutomatically)
                {
                    chk.Checked = SearchHelper.GetSearchFieldDefaultValue(SearchSettings.CONTENT, column.ColumnType);
                }
                else if (ssi != null)
                {
                    chk.Checked = ssi.Content;
                }

                tc.Controls.Add(chk);
                tr.Cells.Add(tc);

                // Add cell with 'Searchable' value
                tc = new TableCell();
                chk = new CMSCheckBox();
                chk.ID = column.ColumnName + SearchSettings.SEARCHABLE;

                if (setAutomatically)
                {
                    chk.Checked = SearchHelper.GetSearchFieldDefaultValue(SearchSettings.SEARCHABLE, column.ColumnType);
                }
                else if (ssi != null)
                {
                    chk.Checked = ssi.Searchable;
                }

                tc.Controls.Add(chk);
                tr.Cells.Add(tc);

                // Add cell with 'Tokenized' value
                tc = new TableCell();
                chk = new CMSCheckBox();
                chk.ID = column.ColumnName + SearchSettings.TOKENIZED;

                if (setAutomatically)
                {
                    chk.Checked = SearchHelper.GetSearchFieldDefaultValue(SearchSettings.TOKENIZED, column.ColumnType);
                }
                else if (ssi != null)
                {
                    chk.Checked = ssi.Tokenized;
                }

                tc.Controls.Add(chk);
                tr.Cells.Add(tc);

                // Add cell with 'iFieldname' value
                if (DisplayIField)
                {
                    tc = new TableCell();
                    CMSTextBox txt = new CMSTextBox();
                    txt.ID = column.ColumnName + SearchSettings.IFIELDNAME;
                    txt.CssClass += " form-control";
                    txt.MaxLength = 200;
                    if (ssi != null)
                    {
                        txt.Text = ssi.FieldName;
                    }
                    tc.Controls.Add(txt);
                    tr.Cells.Add(tc);
                }
                tc = new TableCell();
                tr.Cells.Add(tc);
                table.Rows.Add(tr);
            }
        }
    }
Exemple #23
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SetBrowserClass();
        AddNoCacheTag();
        HideErrorWarnings();

        MainTextResString = "LogonForm.LogOn";

        // Ensure the refresh script
        const string defaultCondition = "((top.frames['cmsdesktop'] != null) || (top.frames['propheader'] != null))";

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "TopWindow", ScriptHelper.GetScript(" if " + defaultCondition + " { try {top.window.location.reload();} catch(err){} }"));

        // Enable caps lock check
        if (ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSUseCapsLockNotification"], true))
        {
            RegisterCAPSLOCKScript();
            TextBox txtPassword = (TextBox)Login1.FindControl("Password");
            if (txtPassword != null)
            {
                txtPassword.Attributes.Add("onkeypress", "CheckCapsLock(event)");
            }
        }

        LocalizedLabel lblItem = (LocalizedLabel)Login1.FindControl("lblUserName");

        if (lblItem != null)
        {
            lblItem.Text = "{$LogonForm.UserName$}";
        }
        lblItem = (LocalizedLabel)Login1.FindControl("lblPassword");
        if (lblItem != null)
        {
            lblItem.Text = "{$LogonForm.Password$}";
        }

        // Display culture link due to value of the key stored in the web.config file
        bool showCultureSelector = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSShowLogonCultureSelector"], true);

        if (showCultureSelector)
        {
            LocalizedLinkButton lnkLanguage = (LocalizedLinkButton)Login1.FindControl("lnkLanguage");
            if (lnkLanguage != null)
            {
                lnkLanguage.Visible = true;

                // Ensure language selection panel functionality
                HtmlGenericControl pnlLanguage = (HtmlGenericControl)Login1.FindControl("pnlLanguage");
                if (pnlLanguage != null)
                {
                    ltlScript.Text = ScriptHelper.GetScript("function ShowLanguage(id){var panel=document.getElementById(id);if(panel!=null){panel.style.display=(panel.style.display == 'block')?'none':'block';}}");
                    lnkLanguage.Attributes.Add("onclick", "ShowLanguage('" + pnlLanguage.ClientID + "'); return false;");
                }
            }
        }

        // Set up forgotten password link
        if (ShowForgottenPassword)
        {
            LocalizedLinkButton lnkPassword = (LocalizedLinkButton)Login1.FindControl("lnkPassword");
            if (lnkPassword != null)
            {
                lnkPassword.Visible = true;
                lnkPassword.Click  += lnkPassword_Click;
            }
        }

        PlaceHolder plcRemeberMe = (PlaceHolder)Login1.FindControl("plcRemeberMe");

        if ((MFAuthenticationHelper.IsMultiFactorAutEnabled) && (plcRemeberMe != null))
        {
            plcRemeberMe.Visible = false;
        }


        LocalizedButton btnItem = (LocalizedButton)Login1.FindControl("LoginButton");

        if (btnItem != null)
        {
            btnItem.Text   = "{$LogonForm.LogOnButton$}";
            btnItem.Click += btnItem_Click;
        }

        // Load UI cultures for the dropdown list
        if (!RequestHelper.IsPostBack())
        {
            LoadCultures();
        }

        Login1.LoggingIn    += Login1_LoggingIn;
        Login1.LoggedIn     += Login1_LoggedIn;
        Login1.LoginError   += Login1_LoginError;
        Login1.Authenticate += Login1_Authenticate;

        if (!RequestHelper.IsPostBack())
        {
            Login1.UserName = QueryHelper.GetString("username", String.Empty);
        }

        // Ensure username textbox focus
        CMSTextBox txtUserName = (CMSTextBox)Login1.FindControl("UserName");

        if (txtUserName != null)
        {
            ScriptHelper.RegisterStartupScript(this, GetType(), "SetFocus", ScriptHelper.GetScript("var txt=document.getElementById('" + txtUserName.ClientID + "');if(txt!=null){txt.focus();}"));
            txtUserName.EnableAutoComplete = SecurityHelper.IsAutoCompleteEnabledForLogin(SiteContext.CurrentSiteName);
        }

        if (QueryHelper.GetBoolean("forgottenpassword", false))
        {
            SetForgottenPasswordMode();
        }

        // Register script to update logon error message
        StringBuilder sbScript = new StringBuilder();

        sbScript.Append(@"
var failedText_", ClientID, "= document.getElementById('", FailureLabel.ClientID, @"');

function UpdateLabel_", ClientID, @"(content, context) {
    var lbl = document.getElementById(context);   
    if(lbl)
    {
        lbl.innerHTML = content;
        lbl.className = """";
    }
}");
        ScriptHelper.RegisterClientScriptBlock(this, GetType(), "InvalidLogonAttempts_" + ClientID, sbScript.ToString(), true);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        SetBrowserClass();
        AddNoCacheTag();

        // Ensure the refresh script
        bool         sameWindow       = (FormStateHelper.PreservePostbackValuesOnLogin && (FormStateHelper.GetSavedState() != null));
        const string defaultCondition = "((top.frames['cmsdesktop'] != null) || (top.frames['propheader'] != null))";

        if (sameWindow)
        {
            ScriptHelper.RegisterStartupScript(this, typeof(string), "TopWindow", ScriptHelper.GetScript(" try {if (((document.body.clientWidth < 510) || (document.body.clientHeight < 300)) && " + defaultCondition + ") { var loginUrl = top.window.location.href.replace(/\\/\\(\\w\\([^\\)]+\\)\\)/g, ''); if (loginUrl.indexOf('restorepost=0') < 0) { if (loginUrl.indexOf('?') >= 0) { loginUrl = loginUrl + '&restorepost=0'; } else { loginUrl = loginUrl + '?restorepost=0'; } } top.window.location.replace(loginUrl); }} catch(err){}"));
        }
        else
        {
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "TopWindow", ScriptHelper.GetScript(" if " + defaultCondition + " { try {top.window.location.replace(top.window.location.href.replace(/\\/\\(\\w\\([^\\)]+\\)\\)/g, ''));} catch(err){} }"));
        }

        // Enable caps lock check
        if (ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSUseCapsLockNotification"], true))
        {
            RegisterCAPSLOCKScript();
            TextBox txtPassword = (TextBox)Login1.FindControl("Password");
            if (txtPassword != null)
            {
                txtPassword.Attributes.Add("onkeypress", "CheckCapsLock(event)");
            }
        }

        // Site manager prefix
        string smPrefix = IsSiteManager ? "SM/" : null;

        // Initialize help
        CMSAdminControls_UI_PageElements_Help ucHelp = (CMSAdminControls_UI_PageElements_Help)Login1.FindControl("ucHelp");

        ucHelp.Tooltip   = GetString("logon.helptooltip");
        ucHelp.IconUrl   = GetImageUrl("Others/LogonForm/" + smPrefix + "HelpButton.png");
        ucHelp.TopicName = "LogonTroubleshooting";

        LocalizedLabel lblItem = (LocalizedLabel)Login1.FindControl("lblUserName");

        if (lblItem != null)
        {
            lblItem.Text = "{$LogonForm.UserName$}";
        }
        lblItem = (LocalizedLabel)Login1.FindControl("lblPassword");
        if (lblItem != null)
        {
            lblItem.Text = "{$LogonForm.Password$}";
        }

        // Display culture link due to value of the key stored in the web.config file
        bool showCultureSelector = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSShowLogonCultureSelector"], true);

        if (showCultureSelector)
        {
            ImageButton lnkLanguage = (ImageButton)Login1.FindControl("lnkLanguage");
            if (lnkLanguage != null)
            {
                lnkLanguage.Visible = true;

                // Ensure language selection panel functionality
                HtmlGenericControl pnlLanguage = (HtmlGenericControl)Login1.FindControl("pnlLanguage");
                if (pnlLanguage != null)
                {
                    lnkLanguage.ImageUrl      = GetImageUrl("Others/LogonForm/" + smPrefix + "LanguageButton.png");
                    lnkLanguage.AlternateText = GetString("LogonForm.SelectLanguage");
                    lnkLanguage.ToolTip       = GetString("LogonForm.SelectLanguage");

                    ltlScript.Text = ScriptHelper.GetScript("function ShowLanguage(id){var panel=document.getElementById(id);if(panel!=null){panel.style.display=(panel.style.display == 'block')?'none':'block';}}");
                    lnkLanguage.Attributes.Add("onclick", "ShowLanguage('" + pnlLanguage.ClientID + "'); return false;");
                }
            }
        }

        // Set up forgotten password link
        if (ShowForgottenPassword)
        {
            ImageButton lnkPassword = (ImageButton)Login1.FindControl("lnkPassword");
            if (lnkPassword != null)
            {
                lnkPassword.Visible       = true;
                lnkPassword.ImageUrl      = GetImageUrl("Others/LogonForm/" + smPrefix + "ForgottenPassword.png");
                lnkPassword.AlternateText = GetString("LogonForm.ForgottenPassword");
                lnkPassword.ToolTip       = GetString("LogonForm.ForgottenPassword");
                lnkPassword.Click        += lnkPassword_Click;
            }
        }

        LocalizedCheckBox chkItem = (LocalizedCheckBox)Login1.FindControl("chkRememberMe");

        if (chkItem != null)
        {
            chkItem.Text = "{$LogonForm.RememberMe$}";
        }

        LocalizedButton btnItem = (LocalizedButton)Login1.FindControl("LoginButton");

        if (btnItem != null)
        {
            btnItem.Text   = "{$LogonForm.LogOnButton$}";
            btnItem.Click += btnItem_Click;
        }

        RequiredFieldValidator rfvUserName = (RequiredFieldValidator)Login1.FindControl("rfvUserNameRequired");

        if (rfvUserName != null)
        {
            rfvUserName.ToolTip      = GetString("LogonForm.NameRequired");
            rfvUserName.ErrorMessage = GetString("LogonForm.NameRequired");
        }

        // Load UI cultures for the dropdown list
        if (!RequestHelper.IsPostBack())
        {
            LoadCultures();
        }

        if (lblVersion != null)
        {
            // Show version only if right key is inserted
            string versionKey = QueryHelper.GetString("versionkey", string.Empty);
            if (EncryptionHelper.VerifyVersionRSA(versionKey))
            {
                lblVersion.Text = ResHelper.GetString("Footer.Version") + "&nbsp;" + CMSContext.GetFriendlySystemVersion(true);
            }
        }

        Login1.LoggingIn  += Login1_LoggingIn;
        Login1.LoggedIn   += Login1_LoggedIn;
        Login1.LoginError += Login1_LoginError;

        if (!RequestHelper.IsPostBack())
        {
            Login1.UserName = QueryHelper.GetString("username", String.Empty);
        }

        // Ensure username textbox focus
        CMSTextBox txtUserName = (CMSTextBox)Login1.FindControl("UserName");

        if (txtUserName != null)
        {
            ScriptHelper.RegisterStartupScript(this, GetType(), "SetFocus", ScriptHelper.GetScript("var txt=document.getElementById('" + txtUserName.ClientID + "');if(txt!=null){txt.focus();}"));
            txtUserName.EnableAutoComplete = SecurityHelper.IsAutoCompleteEnabledForLogin(CMSContext.CurrentSiteName);
        }

        // Ensure different class for Site Manager
        if (IsSiteManager)
        {
            pnlMainContainer.CssClass += " SM";
        }

        if (QueryHelper.GetBoolean("forgottenpassword", false))
        {
            SetForgottenPasswordMode();
        }

        // Register script to update logon error message
        StringBuilder sbScript = new StringBuilder();

        sbScript.Append(@"
var failedText_", ClientID, "= document.getElementById('", FailureLabel.ClientID, @"');

function UpdateLabel_", ClientID, @"(content, context) {
    var lbl = document.getElementById(context);   
    if(lbl)
    {
        lbl.innerHTML = content;
        lbl.className = """";
    }
}");
        ScriptHelper.RegisterClientScriptBlock(this, GetType(), "InvalidLogonAttempts_" + ClientID, sbScript.ToString(), true);
    }
    /// <summary>
    /// Creates table.
    /// </summary>
    private void CreateTable(bool setAutomatically)
    {
        Table table = new Table();

        table.CssClass    = "table table-hover";
        table.CellPadding = -1;
        table.CellSpacing = -1;

        // Create table header
        TableHeaderRow header = new TableHeaderRow();

        header.TableSection = TableRowSection.TableHeader;
        TableHeaderCell thc = new TableHeaderCell();

        thc.Text  = GetString("srch.settings.fieldname");
        thc.Scope = TableHeaderScope.Column;
        header.Cells.Add(thc);
        thc       = new TableHeaderCell();
        thc.Text  = GetString("development.content");
        thc.Scope = TableHeaderScope.Column;
        header.Cells.Add(thc);
        thc       = new TableHeaderCell();
        thc.Text  = GetString("srch.settings.searchable");
        thc.Scope = TableHeaderScope.Column;
        header.Cells.Add(thc);
        thc       = new TableHeaderCell();
        thc.Text  = GetString("srch.settings.tokenized");
        thc.Scope = TableHeaderScope.Column;
        header.Cells.Add(thc);

        if (DisplayIField)
        {
            thc      = new TableHeaderCell();
            thc.Text = GetString("srch.settings.ifield");
            header.Cells.Add(thc);
        }

        thc          = new TableHeaderCell();
        thc.CssClass = "main-column-100";
        header.Cells.Add(thc);

        table.Rows.Add(header);
        pnlContent.Controls.Add(table);

        // Create table content
        if ((mAttributes != null) && (mAttributes.Count > 0))
        {
            // Create row for each field
            foreach (ColumnDefinition column in mAttributes)
            {
                SearchSettingsInfo ssi = null;
                TableRow           tr  = new TableRow();
                if (!DataHelper.DataSourceIsEmpty(mInfos))
                {
                    DataRow[] dr = mInfos.Tables[0].Select("name = '" + column.ColumnName + "'");
                    if ((dr.Length > 0) && (mSearchSettings != null))
                    {
                        ssi = mSearchSettings.GetSettingsInfo((string)dr[0]["id"]);
                    }
                }

                // Add cell with field name
                TableCell tc  = new TableCell();
                Label     lbl = new Label();
                lbl.Text = column.ColumnName;
                tc.Controls.Add(lbl);
                tr.Cells.Add(tc);

                // Add cell with 'Content' value
                tc = new TableCell();
                CMSCheckBox chk = new CMSCheckBox();
                chk.ID = column.ColumnName + SearchSettings.CONTENT;

                if (setAutomatically)
                {
                    chk.Checked = SearchHelper.GetSearchFieldDefaultValue(SearchSettings.CONTENT, column.ColumnType);
                }
                else if (ssi != null)
                {
                    chk.Checked = ssi.Content;
                }

                tc.Controls.Add(chk);
                tr.Cells.Add(tc);

                // Add cell with 'Searchable' value
                tc     = new TableCell();
                chk    = new CMSCheckBox();
                chk.ID = column.ColumnName + SearchSettings.SEARCHABLE;

                if (setAutomatically)
                {
                    chk.Checked = SearchHelper.GetSearchFieldDefaultValue(SearchSettings.SEARCHABLE, column.ColumnType);
                }
                else if (ssi != null)
                {
                    chk.Checked = ssi.Searchable;
                }

                tc.Controls.Add(chk);
                tr.Cells.Add(tc);

                // Add cell with 'Tokenized' value
                tc     = new TableCell();
                chk    = new CMSCheckBox();
                chk.ID = column.ColumnName + SearchSettings.TOKENIZED;

                if (setAutomatically)
                {
                    chk.Checked = SearchHelper.GetSearchFieldDefaultValue(SearchSettings.TOKENIZED, column.ColumnType);
                }
                else if (ssi != null)
                {
                    chk.Checked = ssi.Tokenized;
                }

                tc.Controls.Add(chk);
                tr.Cells.Add(tc);

                // Add cell with 'iFieldname' value
                if (DisplayIField)
                {
                    tc = new TableCell();
                    CMSTextBox txt = new CMSTextBox();
                    txt.ID        = column.ColumnName + SearchSettings.IFIELDNAME;
                    txt.CssClass += " form-control";
                    txt.MaxLength = 200;
                    if (ssi != null)
                    {
                        txt.Text = ssi.FieldName;
                    }
                    tc.Controls.Add(txt);
                    tr.Cells.Add(tc);
                }
                tc = new TableCell();
                tr.Cells.Add(tc);
                table.Rows.Add(tr);
            }
        }
    }
    /// <summary>
    /// Creates a field item
    /// </summary>
    /// <param name="ffi">Form field info</param>
    /// <param name="i">Field index</param>
    private void CreateField(FormFieldInfo ffi, ref int i)
    {
        // Check if is defined inherited default value
        bool doNotInherit = IsDefined(ffi.Name);
        // Get default value
        string inheritedDefaultValue = GetDefaultValue(ffi.Name);

        // Current hashtable for client id
        Hashtable currentHashTable = new Hashtable();

        // First item is name
        currentHashTable[0] = ffi.Name;
        currentHashTable[3] = ffi.Caption;

        // Begin new row and column
        Literal table2 = new Literal();
        pnlEditor.Controls.Add(table2);
        table2.Text = "<tr class=\"InheritWebPart\"><td>";

        // Property label
        Label lblName = new Label();
        pnlEditor.Controls.Add(lblName);
        lblName.Text = ResHelper.LocalizeString(ffi.Caption);
        lblName.ToolTip = ResHelper.LocalizeString(ffi.Description);
        if (!lblName.Text.EndsWithCSafe(":"))
        {
            lblName.Text += ":";
        }

        // New column
        Literal table3 = new Literal();
        pnlEditor.Controls.Add(table3);
        table3.Text = "</td><td>";

        // Type string for JavaScript function
        string jsType = "textbox";

        // Type switcher
        if (FormHelper.IsFieldOfType(ffi, FormFieldControlTypeEnum.CheckBoxControl))
        {
            // Checkbox type field
            CheckBox chk = new CheckBox();
            pnlEditor.Controls.Add(chk);
            chk.Checked = ValidationHelper.GetBoolean(ffi.DefaultValue, false);
            chk.InputAttributes.Add("disabled", "disabled");

            chk.Attributes.Add("id", chk.ClientID + "_upperSpan");

            if (doNotInherit)
            {
                chk.InputAttributes.Remove("disabled");
                chk.Enabled = true;
                chk.Checked = ValidationHelper.GetBoolean(inheritedDefaultValue, false);
            }

            jsType = "checkbox";
            currentHashTable[1] = chk.ClientID;
        }
        else if (FormHelper.IsFieldOfType(ffi, FormFieldControlTypeEnum.CalendarControl))
        {
            // Date time picker
            DateTimePicker dtPick = new DateTimePicker();
            pnlEditor.Controls.Add(dtPick);
            String value = ffi.DefaultValue;
            dtPick.Enabled = false;
            dtPick.SupportFolder = ResolveUrl("~/CMSAdminControls/Calendar");

            if (doNotInherit)
            {
                dtPick.Enabled = true;
                value = inheritedDefaultValue;
            }

            if (ValidationHelper.IsMacro(value))
            {
                dtPick.DateTimeTextBox.Text = value;
            }
            else
            {
                dtPick.SelectedDateTime = ValidationHelper.GetDateTime(value, DataHelper.DATETIME_NOT_SELECTED, CultureHelper.EnglishCulture);
            }

            jsType = "calendar";
            currentHashTable[1] = dtPick.ClientID;
        }
        else
        {
            // Other types represent by textbox
            CMSTextBox txt = new CMSTextBox();
            pnlEditor.Controls.Add(txt);

            // Convert from default culture to current culture if needed (type double, datetime)
            txt.Text = (String.IsNullOrEmpty(ffi.DefaultValue) || ValidationHelper.IsMacro(ffi.DefaultValue)) ? ffi.DefaultValue : ValidationHelper.GetString(DataHelper.ConvertValue(ffi.DefaultValue, GetDataType(ffi.Name)), String.Empty);

            txt.CssClass = "TextBoxField";
            txt.Enabled = ffi.Enabled;
            txt.Enabled = false;

            if (ffi.DataType == FormFieldDataTypeEnum.LongText)
            {
                txt.TextMode = TextBoxMode.MultiLine;
                txt.Rows = 3;
            }

            if (doNotInherit)
            {
                txt.Enabled = true;
                txt.Text = (String.IsNullOrEmpty(inheritedDefaultValue) || ValidationHelper.IsMacro(ffi.DefaultValue)) ? inheritedDefaultValue : ValidationHelper.GetString(DataHelper.ConvertValue(inheritedDefaultValue, GetDataType(ffi.Name)), String.Empty);
            }

            currentHashTable[1] = txt.ClientID;
        }

        // New column
        Literal table4 = new Literal();
        pnlEditor.Controls.Add(table4);
        table4.Text = "</td><td>" + ffi.DataType.ToString() + "</td><td>";

        // Inherit checkbox
        CheckBox chkInher = new CheckBox();
        pnlEditor.Controls.Add(chkInher);
        chkInher.Checked = true;

        // Uncheck checkbox if this property is not inherited
        if (doNotInherit)
        {
            chkInher.Checked = false;
        }

        chkInher.Text = GetString("DefaultValueEditor.Inherited");

        string defValue = (ffi.DefaultValue == null) ? String.Empty : ffi.DefaultValue;

        if (!String.IsNullOrEmpty(ffi.DefaultValue))
        {
            if (!ValidationHelper.IsMacro(ffi.DefaultValue))
            {
                defValue = ValidationHelper.GetString(DataHelper.ConvertValue(defValue, GetDataType(ffi.Name)), String.Empty);
            }
            else
            {
                defValue = MacroResolver.RemoveSecurityParameters(defValue, true, null);
            }
        }

        // Set default value for JavaScript function
        defValue = "'" + defValue.Replace("\r\n", "\\n") + "'";

        if (jsType == "checkbox")
        {
            defValue = ValidationHelper.GetBoolean(ffi.DefaultValue, false).ToString().ToLowerCSafe();
        }

        // Add JavaScript attribute with js function call
        chkInher.Attributes.Add("onclick", "CheckClick(this, '" + currentHashTable[1].ToString() + "', " + defValue + ", '" + jsType + "' );");

        // Insert current checkbox id
        currentHashTable[2] = chkInher.ClientID;

        // Add current hashtable to the controls hashtable
        ((Hashtable)Controls)[i] = currentHashTable;

        // End current row
        Literal table5 = new Literal();
        pnlEditor.Controls.Add(table5);
        table5.Text = "</td></tr>";

        i++;
    }
Exemple #27
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            rqValue.Visible = false;
            // Do not process
        }
        else
        {
            // Set failure text
            if (FailureText != "")
            {
                Login1.FailureText = ResHelper.LocalizeString(FailureText);
            }
            else
            {
                Login1.FailureText = GetString("Login_FailureText");
            }

            // Set strings
            lnkPasswdRetrieval.Text = GetString("LogonForm.lnkPasswordRetrieval");
            lblPasswdRetrieval.Text = GetString("LogonForm.lblPasswordRetrieval");
            btnPasswdRetrieval.Text = GetString("LogonForm.btnPasswordRetrieval");
            rqValue.ErrorMessage    = GetString("LogonForm.rqValue");
            rqValue.ValidationGroup = ClientID + "_PasswordRetrieval";

            // Set logon strings
            LocalizedLabel lblItem = (LocalizedLabel)Login1.FindControl("lblUserName");
            if (lblItem != null)
            {
                lblItem.Text = "{$LogonForm.UserName$}";
            }
            lblItem = (LocalizedLabel)Login1.FindControl("lblPassword");
            if (lblItem != null)
            {
                lblItem.Text = "{$LogonForm.Password$}";
            }
            LocalizedCheckBox chkItem = (LocalizedCheckBox)Login1.FindControl("chkRememberMe");
            if (chkItem != null)
            {
                chkItem.Text = "{$LogonForm.RememberMe$}";
            }
            LocalizedButton btnItem = (LocalizedButton)Login1.FindControl("LoginButton");
            if (btnItem != null)
            {
                btnItem.Text            = "{$LogonForm.LogOnButton$}";
                btnItem.ValidationGroup = ClientID + "_Logon";
            }

            RequiredFieldValidator rfv = (RequiredFieldValidator)Login1.FindControl("rfvUserNameRequired");
            if (rfv != null)
            {
                rfv.ValidationGroup = ClientID + "_Logon";
                rfv.ToolTip         = GetString("LogonForm.NameRequired");
            }

            CMSTextBox txtUserName = (CMSTextBox)Login1.FindControl("UserName");
            if (txtUserName != null)
            {
                txtUserName.EnableAutoComplete = SecurityHelper.IsAutoCompleteEnabledForLogin(CMSContext.CurrentSiteName);
            }

            lnkPasswdRetrieval.Visible = AllowPasswordRetrieval;

            Login1.LoggedIn   += new EventHandler(Login1_LoggedIn);
            Login1.LoggingIn  += new LoginCancelEventHandler(Login1_LoggingIn);
            Login1.LoginError += new EventHandler(Login1_LoginError);

            btnPasswdRetrieval.Click          += new EventHandler(btnPasswdRetrieval_Click);
            btnPasswdRetrieval.ValidationGroup = ClientID + "_PasswordRetrieval";

            if (!RequestHelper.IsPostBack())
            {
                Login1.UserName = ValidationHelper.GetString(Request.QueryString["username"], "");
                // Set SkinID properties
                if (!StandAlone && (PageCycle < PageCycleEnum.Initialized) && (ValidationHelper.GetString(Page.StyleSheetTheme, "") == ""))
                {
                    SetSkinID(SkinID);
                }
            }

            if (!AllowPasswordRetrieval)
            {
                pnlPasswdRetrieval.Visible = false;
            }

            // Register script to update logon error message
            LocalizedLabel failureLit = Login1.FindControl("FailureText") as LocalizedLabel;
            if (failureLit != null)
            {
                StringBuilder sbScript = new StringBuilder();
                sbScript.Append(@"
function UpdateLabel_", ClientID, @"(content, context) {
    var lbl = document.getElementById(context);
    if(lbl)
    {       
        lbl.innerHTML = content;
        lbl.className = ""InfoLabel"";
    }
}");
                ScriptHelper.RegisterClientScriptBlock(this, GetType(), "InvalidLogonAttempts_" + ClientID, sbScript.ToString(), true);
            }
        }
    }
    /// <summary>
    /// Adds textbox/dropdown list determining sort column, dropdown list determining sort direction and 'then by' label
    /// </summary>
    /// <param name="i">Index of a control</param>
    /// <param name="sortColumn">Sort column</param>
    /// <param name="sortDirection">Sort direction</param>
    /// <param name="addThenBy">Whether to add 'then by' label</param>
    private void AddRow(int i, string sortColumn, string sortDirection, bool addThenBy)
    {
        hdnIndices.Value += i + ";";

        Panel pnlOrderBy = new Panel
        {
            ID = PNLORDERBY_ID_PREFIX + i
        };

        LocalizedLabel lblThenBy = null;

        if (addThenBy)
        {
            // Add 'Then by' label
            lblThenBy = new LocalizedLabel
            {
                ResourceString  = "orderbycontrol.thenby",
                CssClass        = "ThenBy",
                EnableViewState = false,
                ID = LBLTHENBY_ID_PREFIX + i
            };
        }

        // Add dropdown list for setting direction
        CMSDropDownList drpDirection = new CMSDropDownList
        {
            ID           = DRPDIRECTION_ID_PREFIX + i,
            CssClass     = "ShortDropDownList",
            AutoPostBack = true,
            Enabled      = Enabled
        };

        drpDirection.Items.Add(new ListItem(GetString("general.ascending"), ASC));
        drpDirection.Items.Add(new ListItem(GetString("general.descending"), DESC));
        if (!String.IsNullOrEmpty(sortDirection))
        {
            drpDirection.SelectedValue = sortDirection;
        }

        Control orderByControl = null;

        switch (Mode)
        {
        // Add textbox for column name
        case SelectorMode.TextBox:
            CMSTextBox txtColumn = new CMSTextBox
            {
                ID           = TXTCOLUMN_ID_PREFIX + i,
                AutoPostBack = true,
                Enabled      = Enabled
            };
            txtColumn.TextChanged += txtBox_TextChanged;

            if (!String.IsNullOrEmpty(sortColumn))
            {
                // Set sorting column
                txtColumn.Text = sortColumn;
            }
            orderByControl = txtColumn;
            break;

        // Add dropdown list for column selection
        case SelectorMode.DropDownList:
            CMSDropDownList drpColumn = new CMSDropDownList
            {
                ID           = DRPCOLUMN_ID_PREFIX + i,
                CssClass     = "ColumnDropDown",
                AutoPostBack = true,
                Enabled      = Enabled
            };
            drpColumn.SelectedIndexChanged += drpOrderBy_SelectedIndexChanged;
            drpColumn.Items.Add(new ListItem(GetString("orderbycontrol.selectcolumn"), SELECT_COLUMN));
            drpColumn.Items.AddRange(CloneItems(Columns.ToArray()));
            if (!String.IsNullOrEmpty(sortColumn))
            {
                // Set sorting column
                drpColumn.SelectedValue = sortColumn;
            }
            orderByControl = drpColumn;
            break;
        }

        // Add controls to panel
        if (lblThenBy != null)
        {
            pnlOrderBy.Controls.Add(WrapControl(lblThenBy));
        }
        if (orderByControl != null)
        {
            pnlOrderBy.Controls.Add(WrapControl(orderByControl));
        }
        pnlOrderBy.Controls.Add(WrapControl(drpDirection));

        // Add panel to place holder
        plcOrderBy.Controls.Add(pnlOrderBy);

        if (Enabled)
        {
            // Setup enable/disable script for direction dropdown list
            if (orderByControl is TextBox)
            {
                ((TextBox)orderByControl).Attributes.Add("onkeyup", SET_DIRECTION_TXT + "('" + orderByControl.ClientID + "')");
                ScriptHelper.RegisterStartupScript(this, typeof(string), "setEnabledTxt" + orderByControl.ClientID, ScriptHelper.GetScript("$cmsj(document).ready(function() {" + SET_DIRECTION_TXT + "('" + orderByControl.ClientID + "');})"));
            }
            else
            {
                ScriptHelper.RegisterStartupScript(this, typeof(string), "setEnabledDrp" + orderByControl.ClientID, ScriptHelper.GetScript("$cmsj(document).ready(function() {" + SET_DIRECTION_DRP + "('" + orderByControl.ClientID + "');})"));
            }
        }

        // Add row to collection
        orderByRows.Add(new OrderByRow(i, lblThenBy, orderByControl, drpDirection, pnlOrderBy));
    }
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            // WAI validation
            lblUserName = (LocalizedLabel)loginElem.FindControl("lblUserName");
            if (lblUserName != null)
            {
                lblUserName.Text = GetString("general.username");
                if (!ShowUserNameLabel)
                {
                    lblUserName.Attributes.Add("style", "display: none;");
                }
            }
            lblPassword = (LocalizedLabel)loginElem.FindControl("lblPassword");
            if (lblPassword != null)
            {
                lblPassword.Text = GetString("general.password");
                if (!ShowPasswordLabel)
                {
                    lblPassword.Attributes.Add("style", "display: none;");
                }
            }

            // Set properties for validator
            rfv                 = (RequiredFieldValidator)loginElem.FindControl("rfvUserNameRequired");
            rfv.ToolTip         = GetString("LogonForm.NameRequired");
            rfv.Text            = rfv.ErrorMessage = GetString("LogonForm.EnterName");
            rfv.ValidationGroup = ClientID + "_MiniLogon";

            // Set visibility of buttons
            login = (LocalizedButton)loginElem.FindControl("btnLogon");
            if (login != null)
            {
                login.Visible         = !ShowImageButton;
                login.ValidationGroup = ClientID + "_MiniLogon";
            }

            loginImg = (ImageButton)loginElem.FindControl("btnImageLogon");
            if (loginImg != null)
            {
                loginImg.Visible         = ShowImageButton;
                loginImg.ImageUrl        = ImageUrl;
                loginImg.ValidationGroup = ClientID + "_MiniLogon";
            }

            // Ensure display control as inline and is used right default button
            container = (Panel)loginElem.FindControl("pnlLogonMiniForm");
            if (container != null)
            {
                container.Attributes.Add("style", "display: inline;");
                if (ShowImageButton)
                {
                    if (loginImg != null)
                    {
                        container.DefaultButton = loginImg.ID;
                    }
                    else if (login != null)
                    {
                        container.DefaultButton = login.ID;
                    }
                }
            }

            CMSTextBox txtUserName = (CMSTextBox)loginElem.FindControl("UserName");
            if (txtUserName != null)
            {
                txtUserName.EnableAutoComplete = SecurityHelper.IsAutoCompleteEnabledForLogin(SiteContext.CurrentSiteName);
            }

            if (!string.IsNullOrEmpty(UserNameText))
            {
                // Initialize javascript for focus and blur UserName textbox
                user = (TextBox)loginElem.FindControl("UserName");
                user.Attributes.Add("onfocus", "MLUserFocus_" + ClientID + "('focus');");
                user.Attributes.Add("onblur", "MLUserFocus_" + ClientID + "('blur');");
                string focusScript = "function MLUserFocus_" + ClientID + "(type)" +
                                     "{" +
                                     "var userNameBox = document.getElementById('" + user.ClientID + "');" +
                                     "if(userNameBox.value == '" + UserNameText + "' && type == 'focus')" +
                                     "{userNameBox.value = '';}" +
                                     "else if (userNameBox.value == '' && type == 'blur')" +
                                     "{userNameBox.value = '" + UserNameText + "';}" +
                                     "}";

                ScriptHelper.RegisterClientScriptBlock(this, GetType(), "MLUserNameFocus_" + ClientID,
                                                       ScriptHelper.GetScript(focusScript));
            }
            loginElem.LoggedIn     += loginElem_LoggedIn;
            loginElem.LoggingIn    += loginElem_LoggingIn;
            loginElem.LoginError   += loginElem_LoginError;
            loginElem.Authenticate += loginElem_Authenticate;

            if (!RequestHelper.IsPostBack())
            {
                // Set SkinID properties
                if (!StandAlone && (PageCycle < PageCycleEnum.Initialized) && (ValidationHelper.GetString(Page.StyleSheetTheme, string.Empty) == string.Empty))
                {
                    SetSkinID(SkinID);
                }
            }

            if (string.IsNullOrEmpty(loginElem.UserName))
            {
                loginElem.UserName = UserNameText;
            }

            // Register script to update logon error message
            LocalizedLabel failureLit = loginElem.FindControl("FailureText") as LocalizedLabel;
            if (failureLit != null)
            {
                StringBuilder sbScript = new StringBuilder();
                sbScript.Append(@"
function UpdateLabel_", ClientID, @"(content, context) {
    var lbl = document.getElementById(context);
    if(lbl)
    {
        lbl.innerHTML = content;
        lbl.className = ""InfoLabel"";      
    }
}");
                ScriptHelper.RegisterClientScriptBlock(this, GetType(), "InvalidLogonAttempts_" + ClientID, sbScript.ToString(), true);
            }
        }
    }
    /// <summary>
    /// Overridden CreateChildControls method.
    /// </summary>
    protected override void CreateChildControls()
    {
        SetupControl();

        Controls.Clear();
        base.CreateChildControls();

        if (!StopProcessing)
        {
            if (!CMSAbstractEditableControl.RequestEditViewMode(ViewMode, ContentID))
            {
                ViewMode = ViewModeEnum.Preview;
            }

            // Create controls by actual page mode
            switch (ViewMode)
            {
                case ViewModeEnum.Edit:
                case ViewModeEnum.EditDisabled:

                    // Main editor panel
                    pnlEditor = new Panel();
                    pnlEditor.ID = "pnlEditor";
                    pnlEditor.CssClass = "EditableTextEdit EditableText_" + ContentID;
                    pnlEditor.Attributes.Add("data-tracksavechanges", "true");
                    Controls.Add(pnlEditor);

                    // Title label
                    lblTitle = new Label();
                    lblTitle.EnableViewState = false;
                    lblTitle.CssClass = "EditableTextTitle";
                    pnlEditor.Controls.Add(lblTitle);

                    // Error label
                    lblError = new Label();
                    lblError.EnableViewState = false;
                    lblError.CssClass = "EditableTextError";
                    pnlEditor.Controls.Add(lblError);

                    // Display the region control based on the region type
                    switch (RegionType)
                    {
                        case CMSEditableRegionTypeEnum.HtmlEditor:
                            // HTML Editor
                            Editor = new CMSHtmlEditor();
                            Editor.IsLiveSite = false;
                            Editor.ID = "htmlValue";
                            Editor.AutoDetectLanguage = false;
                            Editor.DefaultLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
                            Editor.Title = Title;
                            Editor.UseInlineMode = UseInlineMode;
                            Editor.ContentsLangDirection = CultureHelper.IsPreferredCultureRTL() ? LanguageDirection.RightToLeft : LanguageDirection.LeftToRight;

                            // Set the language
                            try
                            {
                                CultureInfo ci = CultureHelper.GetCultureInfo(DataHelper.GetNotEmpty(MembershipContext.AuthenticatedUser.PreferredUICultureCode, LocalizationContext.PreferredCultureCode));
                                Editor.DefaultLanguage = ci.TwoLetterISOLanguageName;
                            }
                            catch (ArgumentNullException)
                            {
                            }
                            catch (CultureNotFoundException)
                            {
                            }

                            Editor.AutoDetectLanguage = false;
                            Editor.Enabled = IsEnabled(ViewMode);

                            if (ViewMode == ViewModeEnum.EditDisabled)
                            {
                                pnlEditor.Controls.Add(new LiteralControl("<div style=\"width: 98%\">"));
                                pnlEditor.Controls.Add(Editor);
                                pnlEditor.Controls.Add(new LiteralControl("</div>"));
                            }
                            else
                            {
                                pnlEditor.Controls.Add(Editor);
                            }
                            break;

                        case CMSEditableRegionTypeEnum.TextArea:
                        case CMSEditableRegionTypeEnum.TextBox:
                            // TextBox
                            txtValue = new CMSTextBox();
                            txtValue.ID = "txtValue";
                            txtValue.CssClass = "EditableTextTextBox";
                            // Do not append macro hash. Macro security is being applied in the CMSAbstractWebPart
                            txtValue.ProcessMacroSecurity = false;
                            txtValue.Enabled = IsEnabled(ViewMode);
                            pnlEditor.Controls.Add(txtValue);
                            break;
                    }
                    break;

                default:
                    // Display content in non editing modes
                    ltlContent = new Literal();
                    ltlContent.ID = "ltlContent";
                    ltlContent.EnableViewState = false;
                    Controls.Add(ltlContent);
                    break;
            }
        }
    }
    private void editGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.DataItemIndex >= 0)
        {
            CMSTextBox txt = new CMSTextBox();
            txt.TextChanged += txt_TextChanged;
            txt.MaxLength = 10;

            // Id of the currency displayed in this row
            int curId = ValidationHelper.GetInteger(((DataRowView)e.Row.DataItem)["CurrencyID"], 0);

            // Find exchange rate for this row currency
            string rateValue = "";
            if (mExchangeRates.ContainsKey(curId))
            {
                DataRow row = mExchangeRates[curId];
                rateValue = ValidationHelper.GetDouble(row["ExchangeRateValue"], -1).ToString();
            }

            // Fill and add text box to the "Rate value" column of the grid
            txt.Text = rateValue;
            e.Row.Cells[1].Controls.Add(txt);
            mData[txt.ClientID] = e.Row.DataItem;
        }
    }
    /// <summary>
    /// Loads custom fields collisions.
    /// </summary>
    private void LoadCustomFields()
    {
        // Check if contact has any custom fields
        FormInfo formInfo = FormHelper.GetFormInfo(mParentContact.ClassName, false);
        var list = formInfo.GetFormElements(true, false, true);
        if (list.OfType<FormFieldInfo>().Any())
        {
            FormFieldInfo ffi;
            Literal content;
            LocalizedLabel lbl;
            CMSTextBox txt;
            content = new Literal();
            content.Text = "<div class=\"form-horizontal form-merge-collisions\">";
            plcCustomFields.Controls.Add(content);

            foreach (IField item in list)
            {
                ffi = item as FormFieldInfo;
                if (ffi != null)
                {
                    // Display layout
                    content = new Literal();
                    content.Text = "<div class=\"form-group\"><div class=\"editing-form-label-cell\">";
                    plcCustomFields.Controls.Add(content);
                    lbl = new LocalizedLabel();
                    lbl.Text = ffi.GetDisplayName(MacroContext.CurrentResolver);
                    lbl.DisplayColon = true;
                    lbl.EnableViewState = false;
                    lbl.CssClass = "control-label";
                    content = new Literal();
                    content.Text = "</div><div class=\"editing-form-value-cell\"><div class=\"control-group-inline-forced\">";
                    txt = new CMSTextBox();
                    txt.ID = "txt" + ffi.Name;
                    lbl.AssociatedControlID = txt.ID;
                    plcCustomFields.Controls.Add(lbl);
                    plcCustomFields.Controls.Add(content);
                    plcCustomFields.Controls.Add(txt);
                    mCustomFields.Add(ffi.Name, new object[]
                    {
                        txt,
                        ffi.DataType
                    });
                    DataTable dt;

                    // Get grouped dataset
                    if (DataTypeManager.IsString(TypeEnum.Field, ffi.DataType))
                    {
                        dt = SortGroupContactsByColumn(ffi.Name + SqlHelper.ORDERBY_ASC, ffi.Name + " NOT LIKE ''", ffi.Name);
                    }
                    else
                    {
                        dt = SortGroupContactsByColumn(ffi.Name + SqlHelper.ORDERBY_ASC, ffi.Name + " IS NOT NULL", ffi.Name);
                    }

                    // Load value into textbox
                    txt.Text = ValidationHelper.GetString(mParentContact.GetValue(ffi.Name), null);
                    if (string.IsNullOrEmpty(txt.Text) && (dt.Rows.Count > 0))
                    {
                        txt.Text = ValidationHelper.GetString(dt.Rows[0][ffi.Name], null);
                    }

                    var img = new HtmlGenericControl("i");
                    img.Attributes["class"] = "validation-warning icon-exclamation-triangle form-control-icon";
                    DisplayTooltip(img, dt, ffi.Name, ValidationHelper.GetString(mParentContact.GetValue(ffi.Name), ""), ffi.DataType);
                    plcCustomFields.Controls.Add(img);
                    content = new Literal();
                    content.Text = "</div></div></div>";
                    plcCustomFields.Controls.Add(content);
                    mMergedContacts.Tables[0].DefaultView.RowFilter = null;
                }
            }
            content = new Literal();
            content.Text = "</div>";
            plcCustomFields.Controls.Add(content);
        }
        else
        {
            tabCustomFields.Visible = false;
            tabCustomFields.HeaderText = null;
        }
    }
    /// <summary>
    /// Gets <c>TextBox</c> control used for key value editing.
    /// </summary>
    /// <param name="groupNo">Number representing index of the processing settings group</param>
    /// <param name="keyNo">Number representing index of the processing SettingsKeyInfo</param>
    /// <param name="text">Text</param>
    /// <param name="enabled">Enabled</param>
    private TextBox GetValueTextBox(int groupNo, int keyNo, string text, bool enabled)
    {
        var txtValue = new CMSTextBox
        {
            ID = string.Format("txtKey{0}{1}", groupNo, keyNo),
            EnableViewState = false,
            Text = text,
            Enabled = enabled,
        };

        return txtValue;
    }
    /// <summary>
    /// Creates table.
    /// </summary>
    private void CreateTable(bool useDefaultValue)
    {
        Table table = new Table();

        table.CssClass    = "table table-hover";
        table.CellPadding = -1;
        table.CellSpacing = -1;

        // Create table header
        TableHeaderRow topHeader = new TableHeaderRow();
        TableHeaderRow header    = new TableHeaderRow();

        topHeader.TableSection = TableRowSection.TableHeader;
        header.TableSection    = TableRowSection.TableHeader;

        AddTableHeaderCell(topHeader, "");
        AddTableHeaderCell(topHeader, GetString("srch.local"), false, 3);

        AddTableHeaderCell(header, GetString("srch.settings.fieldname"), true);
        AddTableHeaderCell(header, GetString("development.content"), true);
        AddTableHeaderCell(header, GetString("srch.settings.searchable"), true);
        AddTableHeaderCell(header, GetString("srch.settings.tokenized"), true);

        if (DisplayAzureFields)
        {
            AddTableHeaderCell(topHeader, GetString("srch.azure"), false, 6);

            AddTableHeaderCell(header, GetString("srch.settings." + AzureSearchFieldFlags.CONTENT), true);
            AddTableHeaderCell(header, GetString("srch.settings." + AzureSearchFieldFlags.RETRIEVABLE), true);
            AddTableHeaderCell(header, GetString("srch.settings." + AzureSearchFieldFlags.SEARCHABLE), true);

            AddTableHeaderCell(header, GetString("srch.settings." + AzureSearchFieldFlags.FACETABLE), true);
            AddTableHeaderCell(header, GetString("srch.settings." + AzureSearchFieldFlags.FILTERABLE), true);
            AddTableHeaderCell(header, GetString("srch.settings." + AzureSearchFieldFlags.SORTABLE), true);
        }

        if (DisplayIField)
        {
            AddTableHeaderCell(topHeader, GetString("general.general"));
            AddTableHeaderCell(header, GetString("srch.settings.ifield"), true);
        }

        var thc = new TableHeaderCell();

        thc.CssClass = "main-column-100";
        topHeader.Cells.Add(thc);

        thc          = new TableHeaderCell();
        thc.CssClass = "main-column-100";
        header.Cells.Add(thc);

        table.Rows.Add(topHeader);
        table.Rows.Add(header);
        pnlContent.Controls.Add(table);

        // Create table content
        if ((mAttributes != null) && (mAttributes.Count > 0))
        {
            // Create row for each field
            foreach (ColumnDefinition column in mAttributes)
            {
                SearchSettingsInfo ssi = null;
                TableRow           tr  = new TableRow();
                if (!DataHelper.DataSourceIsEmpty(mInfos))
                {
                    DataRow[] dr = mInfos.Tables[0].Select("name = '" + column.ColumnName + "'");
                    if ((dr.Length > 0) && (mSearchSettings != null))
                    {
                        ssi = mSearchSettings.GetSettingsInfo((string)dr[0]["id"]);
                    }
                }

                // Add cell with field name
                TableCell tc  = new TableCell();
                Label     lbl = new Label();
                lbl.Text = column.ColumnName;
                tc.Controls.Add(lbl);
                tr.Cells.Add(tc);

                var defaultSearchSettings = useDefaultValue ? SearchHelper.CreateDefaultSearchSettings(column.ColumnName, column.ColumnType) : null;

                tr.Cells.Add(CreateTableCell(SearchSettings.CONTENT, column, useDefaultValue ? defaultSearchSettings.GetFlag(SearchSettings.CONTENT) : ssi?.GetFlag(SearchSettings.CONTENT) ?? false, "development.content"));
                tr.Cells.Add(CreateTableCell(SearchSettings.SEARCHABLE, column, useDefaultValue ? defaultSearchSettings.GetFlag(SearchSettings.SEARCHABLE) : ssi?.GetFlag(SearchSettings.SEARCHABLE) ?? false, "srch.settings.searchable"));
                tr.Cells.Add(CreateTableCell(SearchSettings.TOKENIZED, column, useDefaultValue ? defaultSearchSettings.GetFlag(SearchSettings.TOKENIZED) : ssi?.GetFlag(SearchSettings.TOKENIZED) ?? false, "srch.settings.tokenized"));

                if (DisplayAzureFields)
                {
                    tr.Cells.Add(CreateTableCell(AzureSearchFieldFlags.CONTENT, column, useDefaultValue ? defaultSearchSettings.GetFlag(AzureSearchFieldFlags.CONTENT) : ssi?.GetFlag(AzureSearchFieldFlags.CONTENT) ?? false, "srch.settings." + AzureSearchFieldFlags.CONTENT));
                    tr.Cells.Add(CreateTableCell(AzureSearchFieldFlags.RETRIEVABLE, column, useDefaultValue ? defaultSearchSettings.GetFlag(AzureSearchFieldFlags.RETRIEVABLE) : ssi?.GetFlag(AzureSearchFieldFlags.RETRIEVABLE) ?? false, "srch.settings." + AzureSearchFieldFlags.RETRIEVABLE));
                    tr.Cells.Add(CreateTableCell(AzureSearchFieldFlags.SEARCHABLE, column, useDefaultValue ? defaultSearchSettings.GetFlag(AzureSearchFieldFlags.SEARCHABLE) : ssi?.GetFlag(AzureSearchFieldFlags.SEARCHABLE) ?? false, "srch.settings." + AzureSearchFieldFlags.SEARCHABLE));

                    tr.Cells.Add(CreateTableCell(AzureSearchFieldFlags.FACETABLE, column, useDefaultValue ? defaultSearchSettings.GetFlag(AzureSearchFieldFlags.FACETABLE) : ssi?.GetFlag(AzureSearchFieldFlags.FACETABLE) ?? false, "srch.settings." + AzureSearchFieldFlags.FACETABLE));
                    tr.Cells.Add(CreateTableCell(AzureSearchFieldFlags.FILTERABLE, column, useDefaultValue ? defaultSearchSettings.GetFlag(AzureSearchFieldFlags.FILTERABLE) : ssi?.GetFlag(AzureSearchFieldFlags.FILTERABLE) ?? false, "srch.settings." + AzureSearchFieldFlags.FILTERABLE));
                    tr.Cells.Add(CreateTableCell(AzureSearchFieldFlags.SORTABLE, column, useDefaultValue ? defaultSearchSettings.GetFlag(AzureSearchFieldFlags.SORTABLE) : ssi?.GetFlag(AzureSearchFieldFlags.SORTABLE) ?? false, "srch.settings." + AzureSearchFieldFlags.SORTABLE));
                }

                // Add cell with 'iFieldname' value
                if (DisplayIField)
                {
                    tc = new TableCell();
                    CMSTextBox txt = new CMSTextBox();
                    txt.ID        = column.ColumnName + SearchSettings.IFIELDNAME;
                    txt.CssClass += " form-control";
                    txt.MaxLength = 200;
                    if (ssi != null)
                    {
                        txt.Text = ssi.FieldName;
                    }
                    tc.Controls.Add(txt);
                    tr.Cells.Add(tc);
                }
                tc = new TableCell();
                tr.Cells.Add(tc);
                table.Rows.Add(tr);
            }
        }
    }