protected void editElem_OnAfterDefinitionUpdate(object sender, EventArgs e) { // Set the form definition to the FieldEditor if (EditedObject != null) { MacroRuleInfo rule = ((MacroRuleInfo)EditedObject); rule.MacroRuleParameters = editElem.FormDefinition; MacroRuleInfoProvider.SetMacroRuleInfo(rule); } }
/// <summary> /// Initializes inner controls. /// </summary> /// <param name="forceReload">Indicates if form with parameters should be reloaded</param> private void InitializeControl(bool forceReload = false) { // Init rule selector uniSelector.Value = mSelectedRuleName; MacroRuleInfo mri = MacroRuleInfoProvider.GetMacroRuleInfo(mSelectedRuleName); if (mri != null) { // Show rule description ltlDescription.Text = mri.MacroRuleDescription; txtErrorMsg.Value = string.Empty; txtErrorMsg.WatermarkText = String.IsNullOrEmpty(DefaultErrorMessage) ? ResHelper.GetString("basicform.invalidinput") : DefaultErrorMessage; // Prepare form for rule parameters FormInfo fi = new FormInfo(mri.MacroRuleParameters); formProperties.FormInformation = fi; DataRow data = fi.GetDataRow(); formProperties.DataRow = data; fi.LoadDefaultValues(formProperties.DataRow, FormResolveTypeEnum.AllFields); if ((mMacroRule != null) && (mMacroRuleTree != null) && mMacroRuleTree.RuleName.EqualsCSafe(mSelectedRuleName, true)) { // Set params from rule given by Value property foreach (DictionaryEntry entry in mMacroRuleTree.Parameters) { string paramName = ValidationHelper.GetString(entry.Key, String.Empty); MacroRuleParameter param = entry.Value as MacroRuleParameter; if ((param != null) && data.Table.Columns.Contains(paramName)) { data[paramName] = param.Value; } } txtErrorMsg.Value = mMacroRule.ErrorMessage; } if (forceReload) { // Reload params formProperties.ReloadData(); } mParamsInitialized = true; } }
/// <summary> /// Adds a clause according to selected item. /// </summary> private void AddClause() { MacroRuleInfo rule = MacroRuleInfoProvider.GetMacroRuleInfo(ValidationHelper.GetInteger(lstRules.SelectedValue, 0)); if (rule != null) { List <MacroRuleTree> selected = GetSelected(); if (selected.Count == 1) { MacroRuleTree item = selected[0]; if ((item != null) && (item.Parent != null)) { item.Parent.AddRule(rule, item.Position + 1); return; } } // Add the rule at the root level, when no selected item this.RuleTree.AddRule(rule, this.RuleTree.Children.Count); } }
/// <summary> /// Creates new <see cref="FieldMacroRule"/> object based on inputs. /// </summary> private FieldMacroRule CreateMacroRule() { if (!IsValid()) { return(null); } MacroRuleTree main = null; FieldMacroRule fmr = null; MacroRuleInfo mri = MacroRuleInfoProvider.GetMacroRuleInfo(mSelectedRuleName); if (mri != null) { main = new MacroRuleTree(); MacroRuleTree childern = new MacroRuleTree() { RuleText = mri.MacroRuleText, RuleName = mri.MacroRuleName, RuleCondition = mri.MacroRuleCondition, Parent = main }; main.Children.Add(childern); foreach (string paramName in formProperties.Fields) { // Load value from the form control FormEngineUserControl ctrl = formProperties.FieldControls[paramName]; if (ctrl != null) { // Convert value to EN culture var dataType = ctrl.FieldInfo.DataType; var convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, dataType, ctrl.Value); string value = ValidationHelper.GetString(convertedValue, "", CultureHelper.EnglishCulture); string displayName = ctrl.ValueDisplayName; if (String.IsNullOrEmpty(displayName)) { displayName = value; } MacroRuleParameter param = new MacroRuleParameter { Value = value, Text = displayName, ValueType = dataType }; childern.Parameters.Add(paramName, param); } } string macroRule = string.Format("Rule(\"{0}\", \"{1}\")", MacroElement.EscapeSpecialChars(main.GetCondition()), MacroElement.EscapeSpecialChars(main.GetXML())); if (!MacroSecurityProcessor.IsSimpleMacro(macroRule)) { // Sign complex macros macroRule = MacroSecurityProcessor.AddMacroSecurityParams(macroRule, MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser)); } fmr = new FieldMacroRule(); fmr.MacroRule = string.Format("{{%{0}%}}", macroRule); fmr.ErrorMessage = txtErrorMsg.Text; } return(fmr); }
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(" ")); 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]); } } }
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(" ")); 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(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); } }