public DetailViewModel(DetailModel _model) { Model = _model.AddTo(DisposeCollection); InputTitle = Model.ShownTask.Select(t => t?.TitleString ?? "").ToReactiveProperty("", ReactivePropertyMode.DistinctUntilChanged).AddTo(DisposeCollection); InputExplain = Model.ShownTask.Select(t => t?.ExplainString ?? "").ToReactiveProperty("", ReactivePropertyMode.DistinctUntilChanged).AddTo(DisposeCollection); InputStatus = Model.ShownTask.Select(t => t?.Status ?? Status.Ready).ToReactiveProperty(Status.Ready, ReactivePropertyMode.DistinctUntilChanged).AddTo(DisposeCollection); InputTitle.Where(s => (Model.ShownTask.Value?.Title ?? null) != Domain.Title.Create(s)).Subscribe(s => Model.Save(Domain.Title.Create(s))).AddTo(DisposeCollection); InputExplain.Where(s => (Model.ShownTask.Value?.Explain ?? null) != Domain.Explain.Create(s)).Subscribe(s => Model.Save(Domain.Explain.Create(s))).AddTo(DisposeCollection); InputStatus.Where(s => (Model.ShownTask.Value?.Status ?? null) != s).Subscribe(s => Model.Save(s)).AddTo(DisposeCollection); }
/// <summary> /// 将此控件呈现给指定的输出参数。 /// </summary> /// <param name="output"> 要写出到的 HTML 编写器 </param> protected override void Render(HtmlTextWriter output) { if (this.BackColorFocus != "") { base.Attributes.Add("onfocus", "this.style.background='" + this.BackColorFocus + "'"); //if(!HasDropDownList) base.Attributes.Add("onblur", "this.style.background='#ffffff'"); //else // base.Attributes.Add("onblur", "this.style.background='#ffffff';if(!document.getElementById('" + this.ClientID + "List').focused){document.getElementById('" + this.ClientID + "List').style.display='none';}"); } //if (this.CssFocus != "") //{ // base.Attributes.Add("onmousedown", "this.className='" + this.CssFocus + "'"); // base.Attributes.Add("onmouseout", "this.className='" + this.CssClass + "'"); //} if (this.HasDropDownList) { base.Attributes.Add("title", "点击显示下拉框"); base.Attributes.Add("onclick", "ShowList('" + this.ClientID + "');"); } //输出 base.Render(output); output.Write(" "); if (InputExplain.Trim() != "") { this.lblExplain.ID = "lbl" + base.ID; this.lblExplain.RenderControl(output); } if (!this.AllowEmpty) { this.rfvDataInput.ID = "rfv" + base.ID; this.rfvDataInput.ControlToValidate = base.ID; this.rfvDataInput.RenderControl(output); } if (this.ValidType != DataType.Never && this.ValidType != DataType.String) { this.revDataInput.ID = "rev" + base.ID; this.revDataInput.ControlToValidate = base.ID; this.revDataInput.ValidationExpression = this.GetValidRegex(); this.revDataInput.ErrorMessage = error; this.revDataInput.RenderControl(output); } //可调整高度 if (this.IsRegulateHeight) { #region StringBuilder sbscript = new StringBuilder(); sbscript.Append("\n<!--调节输入框高度 begin-->\n"); sbscript.Append(" <script type=\"text/javascript\">\n"); sbscript.Append(" //Plus\n"); sbscript.Append(" function PlusHeight(id)\n"); sbscript.Append(" {\n"); sbscript.Append(" var txtInput = document.getElementById(id);\n"); sbscript.Append(" txtInput.rows = parseInt(txtInput.rows) + "+ this.RegulateRows + ";\n"); //sbscript.Append(" txtInput.style.height = txtInput.style.height+15;\n"); sbscript.Append(" }\n"); sbscript.Append(" //Minus\n"); sbscript.Append(" function MinusHeight(id)\n"); sbscript.Append(" {\n"); sbscript.Append(" var txtInput = document.getElementById(id);\n"); sbscript.Append(" if( parseInt(txtInput.rows) >= "+ (this.RegulateRows + 1) + " )\n"); sbscript.Append(" txtInput.rows = parseInt(txtInput.rows) - "+ this.RegulateRows + ";\n"); sbscript.Append(" }\n"); sbscript.Append(" </script>\n"); sbscript.Append("<!--调节输入框高度 end-->\n"); System.Web.UI.ClientScriptManager client = this.Page.ClientScript; Type cstype = Page.GetType(); if (!client.IsStartupScriptRegistered(cstype, "regulateheight")) { client.RegisterStartupScript(cstype, "regulateheight", sbscript.ToString()); } StringBuilder sbhtml = new StringBuilder(); sbhtml.Append("<div style=\"height:24px;\">"); sbhtml.Append(" " + this.ImageIconMinus + " " + this.ImageIconPlus); sbhtml.Append("</div>"); output.Write(sbhtml.ToString()); #endregion } //下拉框模式 if (this.HasDropDownList) { #region //已经改为点击输入框的时候激发客户端事件 //output.Write("<img id=\"" + this.ClientID + "Icon\" src=\"" + this.ImageIconShowDropDown + "\" border=\"0\" style=\"cursor:hand;\" onclick=\"ShowList('" + this.ClientID + "');\" align=\"absmiddle\" />\n"); int width = Convert.ToInt32(base.Width.Value); width = width == 0 ? 100 : width; output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "display:none;position:absolute;"); output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Id, this.ClientID + "List"); output.RenderBeginTag(HtmlTextWriterTag.Div); output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "margin-left:" + width + "px;"); output.RenderBeginTag(HtmlTextWriterTag.Span); drpList.ID = base.ID + "Items"; drpList.Style.Add("margin-left", "-" + width + "px"); drpList.Attributes.Add("onchange", "document.getElementById('" + this.ClientID + "').value=this.options[this.selectedIndex].text;document.getElementById('" + this.ClientID + "List').style.display='none';"); //drpList.Attributes.Add("onblur", "this.style.display='none'"); if (this.DropDownListDataSource != null && this.DropDownListDataSource.Rows.Count > 0) { drpList.DataTextField = this.DataTextField; drpList.DataValueField = this.DataValueField; drpList.DataSource = this.DropDownListDataSource.DefaultView; drpList.DataBind(); } if (HasDefaultItem) { drpList.Items.Insert(0, new ListItem(this.DefaultItemText, this.DefaultItemValue)); } foreach (ListItem item in drpList.Items) { if (item.Text == base.Text.Trim()) { item.Selected = true; break; } } this.drpList.RenderControl(output); output.RenderEndTag(); output.RenderEndTag(); StringBuilder sbscript = new StringBuilder(); #region js内容 sbscript.Append("\n<script type=\"text/javascript\">\n"); sbscript.Append(" <!--下拉框显示隐藏 begin-->\n"); sbscript.Append(" function ShowList(id)\n"); sbscript.Append(" {\n"); sbscript.Append(" var txtInput = document.getElementById(id);\n"); sbscript.Append(" var drpList = document.getElementById(id+'List');\n"); //sbscript.Append(" var drpIcon = document.getElementById(id+'Icon');\n"); sbscript.Append(" var drpItems = document.getElementById(id+'Items');\n"); //下拉框 sbscript.Append(" if(drpList.style.display == 'block')\n"); sbscript.Append(" {\n"); sbscript.Append(" txtInput.title = '点击显示下拉框';\n"); sbscript.Append(" drpList.style.display = 'none';\n"); //sbscript.Append(" drpIcon.src = '" + this.ImageIconShowDropDown + "';\n"); sbscript.Append(" }\n"); sbscript.Append(" else\n"); sbscript.Append(" {\n"); sbscript.Append(" txtInput.title = '点击关闭下拉框';\n"); sbscript.Append(" drpList.style.display = 'block';\n"); sbscript.Append(" drpList.style.left = GetOffsetLeft(txtInput)+'px';\n"); sbscript.Append(" drpList.style.top = (GetOffsetTop(txtInput)+1)+'px';\n"); sbscript.Append(" drpItems.style.width = txtInput.offsetWidth+'px';\n"); //sbscript.Append(" drpIcon.src = '" + this.ImageIconHideDropDown + "';\n"); sbscript.Append(" }\n"); sbscript.Append(" }\n"); sbscript.Append(" <!--下拉框显示隐藏 end-->\n"); sbscript.Append(" function GetOffsetTop(e) \n"); sbscript.Append(" {\n"); sbscript.Append(" var offsetTop = e.offsetTop;\n"); sbscript.Append(" var offsetParent = e.offsetParent;\n"); sbscript.Append(" while(offsetParent)\n"); sbscript.Append(" {\n"); sbscript.Append(" offsetTop += offsetParent.offsetTop;\n"); sbscript.Append(" offsetParent = offsetParent.offsetParent;\n"); sbscript.Append(" }\n"); sbscript.Append(" return offsetTop+e.offsetHeight;\n"); sbscript.Append(" }\n"); sbscript.Append(" function GetOffsetLeft(e) \n"); sbscript.Append(" {\n"); sbscript.Append(" var offsetLeft = e.offsetLeft;\n"); sbscript.Append(" var offsetParent = e.offsetParent;\n"); sbscript.Append(" while(offsetParent) \n"); sbscript.Append(" {\n"); sbscript.Append(" offsetLeft += offsetParent.offsetLeft;\n"); sbscript.Append(" offsetParent = offsetParent.offsetParent;\n"); sbscript.Append(" }\n"); sbscript.Append(" return offsetLeft;\n"); sbscript.Append(" }\n"); sbscript.Append("</script>\n"); # endregion System.Web.UI.ClientScriptManager client = this.Page.ClientScript; Type cstype = Page.GetType(); if (!client.IsStartupScriptRegistered(cstype, "showlist")) { client.RegisterStartupScript(cstype, "showlist", sbscript.ToString()); } #endregion }