private static void SetChecked(Panel ret, int value) { foreach (Control idxCtrl in ret.Controls) { LinkButton idxBtn = idxCtrl as LinkButton; if (idxBtn != null) { if (int.Parse(idxBtn.ID.Substring(5)) < value) { if (!idxBtn.Class.Contains(" rating-checked")) idxBtn.Class += " rating-checked"; } else if (idxBtn.Class.Contains(" rating-checked")) idxBtn.Class = idxBtn.Class.Replace(" rating-checked", ""); } } }
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; }
private void magix_forms_controls_panel(object sender, ActiveEventArgs e) { Node ip = Ip(e.Params); if (ShouldInspect(ip)) { Inspect(ip); return; } Panel ret = new Panel(); FillOutParameters(e.Params, ret); Node node = ip["_code"].Get<Node>(); if (node.ContainsValue("tag")) ret.Tag = node["tag"].Get<string>(); if (node.ContainsValue("default")) ret.Default = node["default"].Get<string>(); if (node.Contains("controls")) { Dictionary<string, int> _ids = new Dictionary<string, int>(); foreach (Node idxCtrlNode in node["controls"]) { if (idxCtrlNode.Value != null && idxCtrlNode.Get<string>().StartsWith("{")) { // auto assign id type of id string id = idxCtrlNode.Get<string>().Replace("{", "").Replace("}", ""); if (!_ids.ContainsKey(id)) _ids[id] = 0; else _ids[id] = _ids[id] + 1; id += _ids[id]; idxCtrlNode.Value = id; } string ctrlTypeName = idxCtrlNode.Name; bool isControlName = true; foreach (char idxChar in ctrlTypeName) { if ("abcdefghijklmnopqrstuvwxyz-".IndexOf(idxChar) == -1) { isControlName = false; break; } } if (!isControlName) throw new ArgumentException("control '" + ctrlTypeName + "' is not understood while trying to create web controls"); string ctrlEventName = "magix.forms.controls." + ctrlTypeName; Node createChildCtrlNode = new Node(); createChildCtrlNode["_code"].Value = idxCtrlNode; if (e.Params.Contains("_first")) createChildCtrlNode["_first"].Value = e.Params["_first"].Value; RaiseActiveEvent( ctrlEventName, createChildCtrlNode); if (createChildCtrlNode.Contains("_ctrl")) { if (createChildCtrlNode["_ctrl"].Value != null) ret.Controls.Add(createChildCtrlNode["_ctrl"].Value as Control); else { // multiple controls returned ... foreach (Node idxCtrl in createChildCtrlNode["_ctrl"]) { ret.Controls.Add(idxCtrl.Value as Control); } } } else throw new ArgumentException("unknown control type in your template control '" + ctrlTypeName + "'"); } } ip["_ctrl"].Value = ret; }