protected override void CreateChildControls()
    {
        base.CreateChildControls();

        if (!RequestHelper.IsCallback())
        {
            plcDrag.Visible = AllowDragAndDrop;

            if (AllowDragAndDrop)
            {
                // Create drag and drop extender
                DragAndDropExtender extDragDrop = new DragAndDropExtender();

                extDragDrop.ID = "extDragDrop";
                extDragDrop.TargetControlID     = "pnlTree";
                extDragDrop.DragItemClass       = "DDItem";
                extDragDrop.DragItemHandleClass = "DDHandle";
                extDragDrop.DropCueID           = "pnlCue";
                extDragDrop.OnClientDrop        = "OnDropNode";

                plcDrag.Controls.Add(extDragDrop);

                pnlCue.Style.Add("display", "none");

                string script =
                    @"
function MoveNodeAsync(nodeId, targetNodeId, position, copy, link) {
    var param = '';
    if (link) {
        if (position) {
            param = 'LinkNodePosition';
        } else {
            param = 'LinkNode';
        }
    } else if (copy) {
        if (position) {
            param = 'CopyNodePosition';
        } else {
            param = 'CopyNode';
        }
    } else {
        if (position) {
            param = 'MoveNodePosition';
        } else {
            param = 'MoveNode';
        }
    }
    param += ';' + nodeId + ';' + targetNodeId;" +
                    GetEventReference("param") + @"
}"
                ;

                ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ContentTree", ScriptHelper.GetScript(script));
            }
            else
            {
                pnlCue.Visible = false;
            }
        }
    }
    /// <summary>
    /// Builds the designer controls structure.
    /// </summary>
    public override void BuildDesigner(bool recursive)
    {
        // Append child groups and expressions
        pnlGroups.Controls.Clear();

        if (CurrentGroup.IsLeaf)
        {
            plcNoItems.Visible = false;

            AddExpression(CurrentGroup.LeftExpression, CurrentGroup.RightExpression, CurrentGroup.Operator, CurrentGroup.IDPath);
        }
        else
        {
            if (CurrentGroup.Level == 0)
            {
                plcNoItems.Visible = true;
            }

            // Add child groups
            foreach (MacroDesignerTree child in CurrentGroup.ChildGroups)
            {
                MacroDesignerGroup ctrl = (MacroDesignerGroup)AddGroup(child.IDPath);
                ctrl.GroupOperator = child.GroupOperator;
                ctrl.CurrentGroup  = child;
                if (recursive)
                {
                    ctrl.BuildDesigner(true);
                }

                plcNoItems.Visible = false;
            }

            // Drop cue
            Panel pnlCue = new Panel();
            pnlCue.ID       = "pnlCue";
            pnlCue.CssClass = "MacroDesignerCue";
            pnlGroups.Controls.Add(pnlCue);

            pnlCue.Controls.Add(new LiteralControl("&nbsp;"));
            pnlCue.Style.Add("display", "none");

            // Create drag and drop extender
            extDragDrop = new DragAndDropExtender();

            extDragDrop.ID = "extDragDrop";
            extDragDrop.TargetControlID     = pnlGroups.ID;
            extDragDrop.DragItemClass       = "MacroElement";
            extDragDrop.DragItemHandleClass = "MacroElementHandle";
            extDragDrop.DropCueID           = pnlCue.ID;
            extDragDrop.OnClientDrop        = "OnDropGroup";

            pnlGroups.Controls.Add(extDragDrop);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Attach events
        btnAutoIndent.Click      += btnAutoIndent_Click;
        btnDelete.Click          += btnDelete_Click;
        btnIndent.Click          += btnIndent_Click;
        btnUnindent.Click        += btnUnindent_Click;
        btnChangeOperator.Click  += btnChangeOperator_Click;
        btnChangeParameter.Click += btnChangeParameter_Click;
        btnMove.Click            += btnMove_Click;
        btnCancel.Click          += btnCancel_Click;
        btnSetParameter.Click    += btnSetParameter_Click;
        btnViewCode.Click        += btnViewCode_Click;
        btnAddClause.Click       += btnAddClause_Click;
        btnClearAll.Click        += btnClearAll_Click;
        txtFilter.TextChanged    += btnFilter_Click;

        btnFilter.Text       = GetString("general.filter");
        btnSetParameter.Text = GetString("macros.macrorule.setparameter");
        btnCodeOK.Text       = GetString("general.ok");
        btnCancel.Text       = GetString("general.cancel");
        btnIndent.ScreenReaderDescription     = btnIndent.ToolTip = GetString("macros.macrorule.indent");
        btnUnindent.ScreenReaderDescription   = btnUnindent.ToolTip = GetString("macros.macrorule.unindent");
        btnAutoIndent.ScreenReaderDescription = btnAutoIndent.ToolTip = GetString("macros.macrorule.autoindent");
        btnDelete.ScreenReaderDescription     = btnDelete.ToolTip = GetString("general.delete");
        btnClearAll.ScreenReaderDescription   = btnClearAll.ToolTip = GetString("macro.macrorule.clearall");
        btnViewCode.ScreenReaderDescription   = btnViewCode.ToolTip = GetString("macros.macrorule.viewcode");

        btnIndent.OnClientClick     = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnUnindent.OnClientClick   = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnDelete.OnClientClick     = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; } else { if (!confirm('" + GetString("macros.macrorule.deleteconfirmation") + "')) { return false; }}";
        btnAutoIndent.OnClientClick = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.deleteautoindent")) + ")) { return false; }";
        btnClearAll.OnClientClick   = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.clearall.confirmation")) + ")) { return false; }";

        lstRules.Attributes.Add("ondblclick", ControlsHelper.GetPostBackEventReference(btnAddClause));

        pnlViewCode.Visible = false;

        // Basic form
        formElem.SubmitButton.Visible = false;
        formElem.SiteName             = SiteContext.CurrentSiteName;

        titleElem.TitleText   = GetString("macros.macrorule.changeparameter");
        btnAddaClause.ToolTip = GetString("macros.macrorule.addclause");
        btnAddaClause.Click  += btnAddClause_Click;

        // Drop cue
        Panel pnlCue = new Panel();

        pnlCue.ID       = "pnlCue";
        pnlCue.CssClass = "MacroRuleCue";
        pnlCondtion.Controls.Add(pnlCue);

        pnlCue.Controls.Add(new LiteralControl("&nbsp;"));
        pnlCue.Style.Add("display", "none");

        // Create drag and drop extender
        extDragDrop    = new DragAndDropExtender();
        extDragDrop.ID = "extDragDrop";
        extDragDrop.TargetControlID     = pnlCondtion.ID;
        extDragDrop.DragItemClass       = "MacroRule";
        extDragDrop.DragItemHandleClass = "MacroRuleHandle";
        extDragDrop.DropCueID           = pnlCue.ID;
        extDragDrop.OnClientDrop        = "OnDropRule";
        pnlCondtion.Controls.Add(extDragDrop);

        // Load the rule set
        if (!RequestHelper.IsPostBack())
        {
            if (ShowGlobalRules || !string.IsNullOrEmpty(RuleCategoryNames))
            {
                var where = GetRulesWhereCondition();

                var ds = MacroRuleInfo.Provider.Get().Where(where).OrderBy("MacroRuleDisplayName")
                         .Columns("MacroRuleID, MacroRuleDisplayName, MacroRuleDescription, MacroRuleRequiredData, MacroRuleAvailability").TypedResult;
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    AddRules(ds);
                }

                if (lstRules.Items.Count > 0)
                {
                    lstRules.SelectedIndex = 0;
                }
            }
        }

        AddTooltips();

        // Make sure that one user click somewhere else than to any rule, selection will disappear
        pnlCondtion.Attributes["onclick"] = "if (!doNotDeselect && !isCTRL) { $cmsj('.RuleSelected').removeClass('RuleSelected'); document.getElementById('" + hdnSelected.ClientID + "').value = ';'; }; doNotDeselect = false;";

        LoadFormDefinition(false);

        // Set the default button for parameter edit dialog so that ENTER key works to submit the parameter value
        pnlParameterPopup.DefaultButton = btnSetParameter.ID;

        // Ensure correct edit dialog show/hide (because of form controls which cause postback)
        btnSetParameter.OnClientClick = "HideParamEdit();";
        btnCancel.OnClientClick       = "HideParamEdit();";
        if (ShowParameterEdit)
        {
            mdlDialog.Show();
        }

        if (!string.IsNullOrEmpty(hdnScroll.Value))
        {
            // Preserve scroll position
            ScriptHelper.RegisterStartupScript(Page, typeof(string), "MacroRulesScroll", "setTimeout('setScrollPosition()', 100);", true);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Attach events
        btnAutoIndent.Click += btnAutoIndent_Click;
        btnDelete.Click += btnDelete_Click;
        btnIndent.Click += btnIndent_Click;
        btnUnindent.Click += btnUnindent_Click;
        btnChangeOperator.Click += btnChangeOperator_Click;
        btnChangeParameter.Click += btnChangeParameter_Click;
        btnMove.Click += btnMove_Click;
        btnCancel.Click += btnCancel_Click;
        btnSetParameter.Click += btnSetParameter_Click;
        btnViewCode.Click += btnViewCode_Click;
        btnAddClause.Click += btnAddClause_Click;
        btnClearAll.Click += btnClearAll_Click;
        txtFilter.TextChanged += btnFilter_Click;

        btnFilter.Text = GetString("general.filter");
        btnSetParameter.Text = GetString("macros.macrorule.setparameter");
        btnCodeOK.Text = GetString("general.ok");
        btnCancel.Text = GetString("general.cancel");
        btnIndent.ScreenReaderDescription = btnIndent.ToolTip = GetString("macros.macrorule.indent");
        btnUnindent.ScreenReaderDescription = btnUnindent.ToolTip = GetString("macros.macrorule.unindent");
        btnAutoIndent.ScreenReaderDescription = btnAutoIndent.ToolTip = GetString("macros.macrorule.autoindent");
        btnDelete.ScreenReaderDescription = btnDelete.ToolTip = GetString("general.delete");
        btnClearAll.ScreenReaderDescription = btnClearAll.ToolTip = GetString("macro.macrorule.clearall");
        btnViewCode.ScreenReaderDescription = btnViewCode.ToolTip = GetString("macros.macrorule.viewcode");

        btnIndent.OnClientClick = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnUnindent.OnClientClick = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnDelete.OnClientClick = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; } else { if (!confirm('" + GetString("macros.macrorule.deleteconfirmation") + "')) { return false; }}";
        btnAutoIndent.OnClientClick = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.deleteautoindent")) + ")) { return false; }";
        btnClearAll.OnClientClick = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.clearall.confirmation")) + ")) { return false; }";

        lstRules.Attributes.Add("ondblclick", ControlsHelper.GetPostBackEventReference(btnAddClause));

        pnlViewCode.Visible = false;

        // Basic form
        formElem.SubmitButton.Visible = false;
        formElem.SiteName = SiteContext.CurrentSiteName;

        titleElem.TitleText = GetString("macros.macrorule.changeparameter");
        btnAddaClause.ToolTip = GetString("macros.macrorule.addclause");
        btnAddaClause.Click += btnAddClause_Click;

        // Drop cue
        Panel pnlCue = new Panel();
        pnlCue.ID = "pnlCue";
        pnlCue.CssClass = "MacroRuleCue";
        pnlCondtion.Controls.Add(pnlCue);

        pnlCue.Controls.Add(new LiteralControl("&nbsp;"));
        pnlCue.Style.Add("display", "none");

        // Create drag and drop extender
        extDragDrop = new DragAndDropExtender();
        extDragDrop.ID = "extDragDrop";
        extDragDrop.TargetControlID = pnlCondtion.ID;
        extDragDrop.DragItemClass = "MacroRule";
        extDragDrop.DragItemHandleClass = "MacroRuleHandle";
        extDragDrop.DropCueID = pnlCue.ID;
        extDragDrop.OnClientDrop = "OnDropRule";
        pnlCondtion.Controls.Add(extDragDrop);

        // Load the rule set
        if (!RequestHelper.IsPostBack())
        {
            if (ShowGlobalRules || !string.IsNullOrEmpty(RuleCategoryNames))
            {
                var where = GetRulesWhereCondition();

                var ds = MacroRuleInfoProvider.GetMacroRules(where, "MacroRuleDisplayName", 0, "MacroRuleID, MacroRuleDisplayName, MacroRuleDescription, MacroRuleRequiredData");
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    AddRules(ds);
                }

                if (lstRules.Items.Count > 0)
                {
                    lstRules.SelectedIndex = 0;
                }
            }
        }

        AddTooltips();

        // Make sure that one user click somewhere else than to any rule, selection will disappear
        pnlCondtion.Attributes["onclick"] = "if (!doNotDeselect && !isCTRL) { $cmsj('.RuleSelected').removeClass('RuleSelected'); document.getElementById('" + hdnSelected.ClientID + "').value = ';'; }; doNotDeselect = false;";

        LoadFormDefinition(false);

        // Set the default button for parameter edit dialog so that ENTER key works to submit the parameter value
        pnlParameterPopup.DefaultButton = btnSetParameter.ID;

        // Ensure correct edit dialog show/hide (because of form controls which cause postback)
        btnSetParameter.OnClientClick = "HideParamEdit();";
        btnCancel.OnClientClick = "HideParamEdit();";
        if (ShowParameterEdit)
        {
            mdlDialog.Show();
        }

        if (!string.IsNullOrEmpty(hdnScroll.Value))
        {
            // Preserve scroll position
            ScriptHelper.RegisterStartupScript(Page, typeof(string), "MacroRulesScroll", "setTimeout('setScrollPosition()', 100);", true);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Attach events
        btnAutoIndent.Click += btnAutoIndent_Click;
        btnDelete.Click += btnDelete_Click;
        btnIndent.Click += btnIndent_Click;
        btnUnindent.Click += btnUnindent_Click;
        btnChangeOperator.Click += btnChangeOperator_Click;
        btnChangeParameter.Click += btnChangeParameter_Click;
        btnMove.Click += btnMove_Click;
        btnCancel.Click += btnCancel_Click;
        btnSetParameter.Click += btnSetParameter_Click;
        btnViewCode.Click += btnViewCode_Click;
        btnAddClause.Click += btnAddClause_Click;
        btnClearAll.Click += btnClearAll_Click;
        txtFilter.TextChanged += btnFilter_Click;

        btnFilter.Text = GetString("general.filter");
        btnSetParameter.Text = GetString("macros.macrorule.setparameter");
        btnCodeOK.Text = GetString("general.ok");
        btnCancel.Text = GetString("general.cancel");
        btnIndent.ScreenReaderDescription = btnIndent.ToolTip = GetString("macros.macrorule.indent");
        btnUnindent.ScreenReaderDescription = btnUnindent.ToolTip = GetString("macros.macrorule.unindent");
        btnAutoIndent.ScreenReaderDescription = btnAutoIndent.ToolTip = GetString("macros.macrorule.autoindent");
        btnDelete.ScreenReaderDescription = btnDelete.ToolTip = GetString("general.delete");
        btnClearAll.ScreenReaderDescription = btnClearAll.ToolTip = GetString("macro.macrorule.clearall");
        btnViewCode.ScreenReaderDescription = btnViewCode.ToolTip = GetString("macros.macrorule.viewcode");

        btnIndent.OnClientClick = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnUnindent.OnClientClick = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnDelete.OnClientClick = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; } else { if (!confirm('" + GetString("macros.macrorule.deleteconfirmation") + "')) { return false; }}";
        btnAutoIndent.OnClientClick = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.deleteautoindent")) + ")) { return false; }";
        btnClearAll.OnClientClick = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.clearall.confirmation")) + ")) { return false; }";

        lstRules.Attributes.Add("ondblclick", ControlsHelper.GetPostBackEventReference(btnAddClause, null));

        pnlViewCode.Visible = false;

        // Basic form
        formElem.SubmitButton.Visible = false;
        formElem.SiteName = SiteContext.CurrentSiteName;

        titleElem.TitleText = GetString("macros.macrorule.changeparameter");
        btnAddaClause.ToolTip = GetString("macros.macrorule.addclause");
        btnAddaClause.Click += btnAddClause_Click;

        // Drop cue
        Panel pnlCue = new Panel();
        pnlCue.ID = "pnlCue";
        pnlCue.CssClass = "MacroRuleCue";
        pnlCondtion.Controls.Add(pnlCue);

        pnlCue.Controls.Add(new LiteralControl("&nbsp;"));
        pnlCue.Style.Add("display", "none");

        // Create drag and drop extender
        extDragDrop = new DragAndDropExtender();
        extDragDrop.ID = "extDragDrop";
        extDragDrop.TargetControlID = pnlCondtion.ID;
        extDragDrop.DragItemClass = "MacroRule";
        extDragDrop.DragItemHandleClass = "MacroRuleHandle";
        extDragDrop.DropCueID = pnlCue.ID;
        extDragDrop.OnClientDrop = "OnDropRule";
        pnlCondtion.Controls.Add(extDragDrop);

        // Load the rule set
        if (!RequestHelper.IsPostBack())
        {
            if (ShowGlobalRules || !string.IsNullOrEmpty(RuleCategoryNames))
            {
                string where = (ShowGlobalRules ? "MacroRuleResourceName IS NULL OR MacroRuleResourceName = ''" : "");

                // Append rules module name condition
                if (!string.IsNullOrEmpty(RuleCategoryNames))
                {
                    bool appendComma = false;
                    StringBuilder sb = new StringBuilder();
                    string[] names = RuleCategoryNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string n in names)
                    {
                        string name = "'" + SqlHelper.GetSafeQueryString(n.Trim(), false) + "'";
                        if (appendComma)
                        {
                            sb.Append(",");
                        }
                        sb.Append(name);
                        appendComma = true;
                    }
                    where = SqlHelper.AddWhereCondition(where, "MacroRuleResourceName IN (" + sb.ToString() + ")", "OR");
                }

                // Append require context condition
                switch (DisplayRuleType)
                {
                    case 1:
                        where = SqlHelper.AddWhereCondition(where, "MacroRuleRequiresContext = 0", "AND");
                        break;

                    case 2:
                        where = SqlHelper.AddWhereCondition(where, "MacroRuleRequiresContext = 1", "AND");
                        break;
                }

                // Select only enabled rules
                where = SqlHelper.AddWhereCondition(where, "MacroRuleEnabled = 1");

                DataSet ds = MacroRuleInfoProvider.GetMacroRules(where, "MacroRuleDisplayName", 0, "MacroRuleID, MacroRuleDisplayName, MacroRuleDescription, MacroRuleRequiredData");
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(ResolverName);
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        bool add = true;
                        if (resolver != null)
                        {
                            // Check the required data, all specified data have to be present in the resolver
                            string requiredData = ValidationHelper.GetString(dr["MacroRuleRequiredData"], "");
                            if (!string.IsNullOrEmpty(requiredData))
                            {
                                string[] required = requiredData.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (var req in required)
                                {
                                    if (!resolver.IsDataItemAvailable(req))
                                    {
                                        add = false;
                                        break;
                                    }
                                }
                            }
                        }

                        if (add)
                        {
                            var ruleId = dr["MacroRuleID"].ToString();
                            ListItem item = new ListItem(dr["MacroRuleDisplayName"].ToString(), ruleId);
                            lstRules.Items.Add(item);

                            // Save the tooltip
                            RulesTooltips[ruleId] = ResHelper.LocalizeString(ValidationHelper.GetString(dr["MacroRuleDescription"], ""));
                        }
                    }
                }
                if (lstRules.Items.Count > 0)
                {
                    lstRules.SelectedIndex = 0;
                }
            }
        }

        // Make sure that one user click somewhere else than to any rule, selection will disappear
        pnlCondtion.Attributes["onclick"] = "if (!doNotDeselect && !isCTRL) { $cmsj('.RuleSelected').removeClass('RuleSelected'); document.getElementById('" + hdnSelected.ClientID + "').value = ';'; }; doNotDeselect = false;";

        LoadFormDefinition(false);

        // Set the default button for parameter edit dialog so that ENTER key works to submit the parameter value
        pnlParameterPopup.DefaultButton = btnSetParameter.ID;

        // Ensure correct edit dialog show/hide (because of form controls which cause postback)
        btnSetParameter.OnClientClick = "HideParamEdit();";
        btnCancel.OnClientClick = "HideParamEdit();";
        if (ShowParameterEdit)
        {
            mdlDialog.Show();
        }

        if (!string.IsNullOrEmpty(hdnScroll.Value))
        {
            // Preserve scroll position
            ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "MacroRulesScroll", "setTimeout('setScrollPosition()', 100);", true);
        }

        // Add tooltips to the rules in the list
        foreach (ListItem item in lstRules.Items)
        {
            if (RulesTooltips.ContainsKey(item.Value))
            {
                item.Attributes.Add("title", RulesTooltips[item.Value]);
            }
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Builds the designer controls structure.
    /// </summary>
    public override void BuildDesigner(bool recursive)
    {
        // Append child groups and expressions
        this.pnlGroups.Controls.Clear();

        if (this.CurrentGroup.IsLeaf)
        {
            plcNoItems.Visible = false;

            this.AddExpression(this.CurrentGroup.LeftExpression, this.CurrentGroup.RightExpression, this.CurrentGroup.Operator, this.CurrentGroup.IDPath);
        }
        else
        {
            if (this.CurrentGroup.Level == 0)
            {
                plcNoItems.Visible = true;
            }

            // Add child groups
            foreach (MacroDesignerTree child in this.CurrentGroup.ChildGroups)
            {
                MacroDesignerGroup ctrl = (MacroDesignerGroup)this.AddGroup(child.IDPath);
                ctrl.GroupOperator = child.GroupOperator;
                ctrl.CurrentGroup = child;
                if (recursive)
                {
                    ctrl.BuildDesigner(true);
                }

                plcNoItems.Visible = false;
            }

            // Drop cue
            Panel pnlCue = new Panel();
            pnlCue.ID = "pnlCue";
            pnlCue.CssClass = "MacroDesignerCue";
            pnlGroups.Controls.Add(pnlCue);

            pnlCue.Controls.Add(new LiteralControl("&nbsp;"));
            pnlCue.Style.Add("display", "none");

            // Create drag and drop extender
            extDragDrop = new DragAndDropExtender();

            extDragDrop.ID = "extDragDrop";
            extDragDrop.TargetControlID = pnlGroups.ID;
            extDragDrop.DragItemClass = "MacroElement";
            extDragDrop.DragItemHandleClass = "MacroElementHandle";
            extDragDrop.DropCueID = pnlCue.ID;
            extDragDrop.OnClientDrop = "OnDropGroup";

            pnlGroups.Controls.Add(extDragDrop);
        }
    }
    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        if (!Page.IsCallback)
        {
            plcDrag.Visible = AllowDragAndDrop;

            if (AllowDragAndDrop)
            {
                // Create drag and drop extender
                DragAndDropExtender extDragDrop = new DragAndDropExtender();

                extDragDrop.ID = "extDragDrop";
                extDragDrop.TargetControlID = "pnlTree";
                extDragDrop.DragItemClass = "DDItem";
                extDragDrop.DragItemHandleClass = "DDHandle";
                extDragDrop.DropCueID = "pnlCue";
                extDragDrop.OnClientDrop = "OnDropNode";

                plcDrag.Controls.Add(extDragDrop);

                pnlCue.Style.Add("display", "none");

                string script =
                    @"
        function MoveNodeAsync(nodeId, targetNodeId, position, copy, link) {
        var param = '';
        if (link) {
        if (position) {
            param = 'LinkNodePosition';
        } else {
            param = 'LinkNode';
        }
        } else if (copy) {
        if (position) {
            param = 'CopyNodePosition';
        } else {
            param = 'CopyNode';
        }
        } else {
        if (position) {
            param = 'MoveNodePosition';
        } else {
            param = 'MoveNode';
        }
        }
        param += ';' + nodeId + ';' + targetNodeId;" +
                    GetEventReference("param") + @"
        }"
                    ;

                ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ContentTree", ScriptHelper.GetScript(script));
            }
            else
            {
                pnlCue.Visible = false;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Attach events
        btnAutoIndent.Click      += btnAutoIndent_Click;
        btnDelete.Click          += (btnDelete_Click);
        btnIndent.Click          += btnIndent_Click;
        btnUnindent.Click        += btnUnindent_Click;
        btnChangeOperator.Click  += new EventHandler(btnChangeOperator_Click);
        btnChangeParameter.Click += new EventHandler(btnChangeParameter_Click);
        btnMove.Click            += new EventHandler(btnMove_Click);
        btnCancel.Click          += new EventHandler(btnCancel_Click);
        btnSetParameter.Click    += new EventHandler(btnSetParameter_Click);
        btnViewCode.Click        += btnViewCode_Click;
        btnAddClause.Click       += new EventHandler(btnAddClause_Click);
        btnClearAll.Click        += btnClearAll_Click;
        txtFilter.TextChanged    += new EventHandler(btnFilter_Click);

        btnFilter.Text       = GetString("general.filter");
        btnSetParameter.Text = GetString("general.ok");
        btnCodeOK.Text       = GetString("general.ok");
        btnCancel.Text       = GetString("general.cancel");
        btnIndent.ScreenReaderDescription     = btnIndent.ToolTip = GetString("macros.macrorule.indent");
        btnUnindent.ScreenReaderDescription   = btnUnindent.ToolTip = GetString("macros.macrorule.unindent");
        btnAutoIndent.ScreenReaderDescription = btnAutoIndent.ToolTip = GetString("macros.macrorule.autoindent");
        btnDelete.ScreenReaderDescription     = btnDelete.ToolTip = GetString("general.delete");
        btnClearAll.ScreenReaderDescription   = btnClearAll.ToolTip = GetString("macro.macrorule.clearall");
        btnViewCode.ScreenReaderDescription   = btnViewCode.ToolTip = GetString("macros.macrorule.viewcode");

        btnIndent.OnClientClick     = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnUnindent.OnClientClick   = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; }";
        btnDelete.OnClientClick     = "if (isNothingSelected()) { alert(" + ScriptHelper.GetString(GetString("macros.macrorule.nothingselected")) + "); return false; } else { if (!confirm('" + GetString("macros.macrorule.deleteconfirmation") + "')) { return false; }}";
        btnAutoIndent.OnClientClick = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.deleteautoindent")) + ")) { return false; }";
        btnClearAll.OnClientClick   = "if (!confirm(" + ScriptHelper.GetString(GetString("macros.macrorule.clearall.confirmation")) + ")) { return false; }";

        lstRules.Attributes.Add("ondblclick", ControlsHelper.GetPostBackEventReference(btnAddClause, null));

        pnlViewCode.Visible = false;

        // Basic form
        formElem.SubmitButton.Visible = false;
        formElem.SiteName             = SiteContext.CurrentSiteName;

        titleElem.TitleText   = GetString("macros.macrorule.changeparameter");
        btnAddaClause.ToolTip = GetString("macros.macrorule.addclause");
        btnAddaClause.Click  += btnAddClause_Click;

        // Drop cue
        Panel pnlCue = new Panel();

        pnlCue.ID       = "pnlCue";
        pnlCue.CssClass = "MacroRuleCue";
        pnlCondtion.Controls.Add(pnlCue);

        pnlCue.Controls.Add(new LiteralControl("&nbsp;"));
        pnlCue.Style.Add("display", "none");

        // Create drag and drop extender
        extDragDrop    = new DragAndDropExtender();
        extDragDrop.ID = "extDragDrop";
        extDragDrop.TargetControlID     = pnlCondtion.ID;
        extDragDrop.DragItemClass       = "MacroRule";
        extDragDrop.DragItemHandleClass = "MacroRuleHandle";
        extDragDrop.DropCueID           = pnlCue.ID;
        extDragDrop.OnClientDrop        = "OnDropRule";
        pnlCondtion.Controls.Add(extDragDrop);

        // Load the rule set
        if (!RequestHelper.IsPostBack())
        {
            if (ShowGlobalRules || !string.IsNullOrEmpty(RuleCategoryNames))
            {
                string where = (ShowGlobalRules ? "MacroRuleResourceName IS NULL OR MacroRuleResourceName = ''" : "");

                // Append rules module name condition
                if (!string.IsNullOrEmpty(RuleCategoryNames))
                {
                    bool          appendComma = false;
                    StringBuilder sb          = new StringBuilder();
                    string[]      names       = RuleCategoryNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string n in names)
                    {
                        string name = "'" + SqlHelper.GetSafeQueryString(n.Trim(), false) + "'";
                        if (appendComma)
                        {
                            sb.Append(",");
                        }
                        sb.Append(name);
                        appendComma = true;
                    }
                    where = SqlHelper.AddWhereCondition(where, "MacroRuleResourceName IN (" + sb.ToString() + ")", "OR");
                }

                // Append require context condition
                switch (DisplayRuleType)
                {
                case 1:
                    where = SqlHelper.AddWhereCondition(where, "MacroRuleRequiresContext = 0", "AND");
                    break;

                case 2:
                    where = SqlHelper.AddWhereCondition(where, "MacroRuleRequiresContext = 1", "AND");
                    break;
                }

                // Select only enabled rules
                where = SqlHelper.AddWhereCondition(where, "MacroRuleEnabled = 1");

                DataSet ds = MacroRuleInfoProvider.GetMacroRules(where, "MacroRuleDisplayName", 0, "MacroRuleID, MacroRuleDisplayName, MacroRuleDescription, MacroRuleRequiredData");
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(ResolverName);
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        bool add = true;
                        if (resolver != null)
                        {
                            // Check the required data, all specified data have to be present in the resolver
                            string requiredData = ValidationHelper.GetString(dr["MacroRuleRequiredData"], "");
                            if (!string.IsNullOrEmpty(requiredData))
                            {
                                string[] required = requiredData.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (var req in required)
                                {
                                    if (!resolver.IsDataItemAvailable(req))
                                    {
                                        add = false;
                                        break;
                                    }
                                }
                            }
                        }

                        if (add)
                        {
                            var      ruleId = dr["MacroRuleID"].ToString();
                            ListItem item   = new ListItem(dr["MacroRuleDisplayName"].ToString(), ruleId);
                            lstRules.Items.Add(item);

                            // Save the tooltip
                            RulesTooltips[ruleId] = ResHelper.LocalizeString(ValidationHelper.GetString(dr["MacroRuleDescription"], ""));
                        }
                    }
                }
                if (lstRules.Items.Count > 0)
                {
                    lstRules.SelectedIndex = 0;
                }
            }
        }

        // Make sure that one user click somewhere else than to any rule, selection will disappear
        pnlCondtion.Attributes["onclick"] = "if (!doNotDeselect && !isCTRL) { jQuery('.RuleSelected').removeClass('RuleSelected'); document.getElementById('" + hdnSelected.ClientID + "').value = ';'; }; doNotDeselect = false;";

        LoadFormDefinition(false);

        // Set the default button for parameter edit dialog so that ENTER key works to submit the parameter value
        pnlParameterPopup.DefaultButton = btnSetParameter.ID;

        // Ensure correct edit dialog show/hide (because of form controls which cause postback)
        btnSetParameter.OnClientClick = "HideParamEdit();";
        btnCancel.OnClientClick       = "HideParamEdit();";
        if (ShowParameterEdit)
        {
            mdlDialog.Show();
        }

        if (!string.IsNullOrEmpty(hdnScroll.Value))
        {
            // Preserve scroll position
            ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "MacroRulesScroll", "setTimeout('setScrollPosition()', 100);", true);
        }

        // Add tooltips to the rules in the list
        foreach (ListItem item in lstRules.Items)
        {
            if (RulesTooltips.ContainsKey(item.Value))
            {
                item.Attributes.Add("title", RulesTooltips[item.Value]);
            }
        }
    }