Exemple #1
0
		private void magix_forms_controls_hidden(object sender, ActiveEventArgs e)
		{
            Node ip = Ip(e.Params);
			if (ShouldInspect(ip))
			{
				Inspect(ip);
				return;
			}

			Hidden ret = new Hidden();
            FillOutParameters(e.Params, ret);

            Node node = ip["_code"].Get<Node>();

            if (node.ContainsValue("value"))
				ret.Value = node["value"].Get<string>();

            ip["_ctrl"].Value = ret;
		}
        private void magix_forms_controls_rating(object sender, ActiveEventArgs e)
        {
            Node ip = Ip(e.Params);
            if (ShouldInspect(ip))
            {
                Inspect(ip);
                return;
            }

            Node codeNode = ip["_code"].Get<Node>();
            Panel ret = new Panel();
            ret.Class = "mux-rating";
            FillOutParameters(e.Params, ret);
            ret.ID += "-wrapper";

            ret.PreRender += delegate
            {
                Hidden hidValue = Selector.FindControl<Hidden>(ret, ret.ID.Replace("-wrapper", ""));
                if (string.IsNullOrEmpty(hidValue.Value))
                    SetChecked(ret, 0);
                else
                    SetChecked(ret, int.Parse(hidValue.Value));
            };

            Hidden hid = new Hidden();
            hid.ID = ret.ID.Replace("-wrapper", "");
            if (codeNode.ContainsValue("value"))
                hid.Value = codeNode["value"].Get<string>();
            ret.Controls.Add(hid);

            int maxValue = 5;
            if (codeNode.Contains("max-value"))
                maxValue = codeNode["max-value"].Get<int>();

            int value = 0;
            if (codeNode.Contains("value"))
                value = codeNode["value"].Get<int>();

            for (int idxNo = 0; idxNo < maxValue; idxNo++)
            {
                int buttonIndex = idxNo + 1;
                LinkButton btn = new LinkButton();
                btn.ID = "star_" + idxNo;
                if (idxNo == maxValue - 1)
                {
                    // last control
                    btn.Class = "last";
                }
                if (!e.Params.ContainsValue("id-prefix"))
                {
                    if (ShouldHandleEvent("onrate", codeNode))
                    {
                        Node onRateCode = codeNode["onrate"].Clone();
                        btn.Click += delegate
                        {
                            SetChecked(ret, buttonIndex);
                            onRateCode["$"]["value"].Value = buttonIndex;
                            hid.Value = buttonIndex.ToString();
                            RaiseActiveEvent(
                                "magix.execute",
                                onRateCode);
                        };
                    }
                    else
                    {
                        btn.Click += delegate
                        {
                            hid.Value = buttonIndex.ToString();
                            SetChecked(ret, buttonIndex);
                        };
                    }
                }
                ret.Controls.Add(btn);
            }

            ip["_ctrl"].Value = ret;
        }