/// <summary> /// Render the widget to current response output. /// </summary> /// <param name="writer"></param> public override void Render(HtmlTextWriter writer) { var locale = App.Get().Context.Locale; if (!string.IsNullOrEmpty(locale)) { App.Get().SetCulture(locale); } bool isPreviewMode = false; Dictionary <string, PropertyDescriptor> propertyDescriptors = null; Dictionary <string, object> userdata = new Dictionary <string, object>(); var bag = Html.ViewContext.Controller.ViewBag; if (bag != null) { if (bag.PropertyDescriptors != null) { propertyDescriptors = bag.PropertyDescriptors as Dictionary <string, PropertyDescriptor>; if (propertyDescriptors != null) { foreach (var key in propertyDescriptors.Keys) { userdata.Add(key, propertyDescriptors[key].Value); } } } if (bag.IsPreview != null) { isPreviewMode = bag.IsPreview; } Model = bag.WidgetInstance; } var widgetHelper = new WidgetHelper() { Model = Model, UserPreferences = userdata, PropertyDescriptors = propertyDescriptors }; if (isPreviewMode) { if (!PreviewTemplate.IsEmpty) { PreviewTemplate.WriteTo(widgetHelper, writer); } else { if (!ContentTemplate.IsEmpty) { ContentTemplate.WriteTo(widgetHelper, writer); } } } else { if (IsDesignMode) { if (userdata.Count > 0 && this.Model.WidgetDescriptor.WidgetType == 1) { var urlhelper = new UrlHelper(Request.RequestContext); writer.WriteBeginTag("form"); writer.WriteAttribute("class", "d-widget-prefs d-tran-fast d-form"); writer.WriteAttribute("data-ajax", "true"); writer.WriteAttribute("data-ajax-url", urlhelper.Content("~/api/" + AppModel.Get().Context.Website + "/widgets/apply")); writer.WriteAttribute("data-ajax-method", "post"); //writer.WriteAttribute("data-ajax-begin", "$.loading()"); writer.WriteAttribute("data-ajax-success", "$('#widget_" + this.Model.ID.ToString() + "').widget('refresh');" + (AutoSave ? "" : "$.closePanels();")); if (this.HideUserPreferences) { writer.WriteAttribute("data-hidden", "true"); } if (this.AutoSave) { writer.WriteAttribute("data-auto-save", "true"); writer.WriteAttribute("onchange", "$(this).submit();"); } // writer.WriteAttribute("data-allow-pop", "false"); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteBeginTag("input"); writer.WriteAttribute("type", "hidden"); writer.WriteAttribute("name", "id"); writer.WriteAttribute("value", Model.ID.ToString()); writer.Write(HtmlTextWriter.SelfClosingTagEnd); if (!UserPreferencesTemplate.IsEmpty) { UserPreferencesTemplate.WriteTo(widgetHelper, writer); } else { foreach (var key in propertyDescriptors.Keys) { if (!propertyDescriptors[key].IsReadonly) { RenderPropertyControl(writer, widgetHelper, propertyDescriptors[key]); } } } writer.WriteEndTag("form"); } if (!DesignTemplate.IsEmpty) { DesignTemplate.WriteTo(widgetHelper, writer); } else if (!ContentTemplate.IsEmpty) { ContentTemplate.WriteTo(widgetHelper, writer); } writer.Write("<script type=\"text/javascript\">$(function(){ $('#widget_" + this.Model.ID.ToString() + "').taoUI(); });</script>"); //writer.Write("<script type=\"text/javascript\">$(function(){ $('#widget_" + this.Model.ID.ToString() + "').unobtrusive_ajax().taoUI(); });</script>"); } else { if (Model.Cached) { //Render cachable widget eg:Html widget var cachedHtml = ""; var cachedKey = "widget" + Model.ID.ToString() + "_caching_html"; if (Context.Cache[cachedKey] != null) { cachedHtml = Context.Cache[cachedKey].ToString(); } else { var cachedBuilder = new StringBuilder(); using (var cachedTextWriter = new System.IO.StringWriter(cachedBuilder)) { using (var cachedWriter = new Html32TextWriter(cachedTextWriter)) { if (!ContentTemplate.IsEmpty) { ContentTemplate.WriteTo(widgetHelper, cachedWriter); } if (!HeaderTemplate.IsEmpty && Model.ShowHeader) { cachedWriter.Write("<div id=\"widget_" + this.Model.ID.ToString() + "_header_holder\" style=\"display:none;\">"); HeaderTemplate.WriteTo(widgetHelper, cachedWriter); cachedWriter.Write("</div>"); cachedWriter.Write("<script type=\"text/javascript\">$(function(){ if ($('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').length) { $('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').empty().append($('#widget_" + this.Model.ID.ToString() + "_header_holder').children());$('#widget_" + this.Model.ID.ToString() + "_header_holder').remove(); } });</script>"); } } } cachedHtml = cachedBuilder.ToString(); Context.Cache.Add(cachedKey, cachedHtml, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); } writer.Write(cachedHtml); } else { if (!ContentTemplate.IsEmpty) { ContentTemplate.WriteTo(widgetHelper, writer); } if (!HeaderTemplate.IsEmpty && Model.ShowHeader) { writer.Write("<div id=\"widget_" + this.Model.ID.ToString() + "_header_holder\" style=\"display:none;\">"); HeaderTemplate.WriteTo(widgetHelper, writer); writer.Write("</div>"); writer.Write("<script type=\"text/javascript\">$(function(){ if ($('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').length) { $('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').empty().append($('#widget_" + this.Model.ID.ToString() + "_header_holder').children());$('#widget_" + this.Model.ID.ToString() + "_header_holder').remove(); } });</script>"); } } } } //writer.Write(System.Web.Optimization.Scripts.Render("~/bundles/jqueryval")); //writer.Write(html.StartupScripts().ToString()); }
/// <summary> /// Get the Request Form Template by RequestCategoryID and RequestTemplateId /// </summary> /// <param name="RequestCategoryID">The Integer Object for RequestCategoryID</param> /// <param name="RequestTemplateID">The Integer Object for RequestTemplateId</param> /// <returns>RequestFormTemplate Object</returns> public RequestFormTemplate GetRequestFormTemplateByCategoryIDAndTemplateID(int RequestCategoryID, int RequestTemplateID) { Logging.LogDebugMessage("Method: GetRequestFormTemplateByCategoryIDAndTemplateID, MethodType: Get, Layer: RequestFormDAL, Parameters: RequestCategoryID = " + RequestCategoryID.ToString() + ", RequestTemplateID =" + RequestTemplateID.ToString()); RequestFormTemplate requestFormTemplate = new RequestFormTemplate(); List <RequestFormTemplateDetails> TemplateDetails = new List <RequestFormTemplateDetails>(); List <RequestTemplateSectionControls> TemplateSectionControls = new List <RequestTemplateSectionControls>(); List <TemplateSectionControls> TemplateControls = new List <TemplateSectionControls>(); PreviewTemplate PreviewTemplateDetails = new PreviewTemplate(); List <PreviewTemplateControl> PreviewTemplateList = new List <PreviewTemplateControl>(); try { using (var command = new SqlCommand()) { command.Connection = new SqlConnection(this.connectionString); command.CommandText = "USP_GetRequestFormTemplateByCategoryIdAndRequestTemplateId"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter() { ParameterName = "@RequestCategoryId", Value = RequestCategoryID }); command.Parameters.Add(new SqlParameter() { ParameterName = "@RequestTemplateId", Value = RequestTemplateID }); using (SqlDataAdapter adapter = new SqlDataAdapter(command)) { DataSet ds = new DataSet(); adapter.Fill(ds); if (ds != null && ds.Tables.Count > 0) { requestFormTemplate = EntityCollectionHelper.ConvertTo <RequestFormTemplate>(ds.Tables[0]).FirstOrDefault(); } if (ds != null && ds.Tables.Count > 1) { TemplateDetails = EntityCollectionHelper.ConvertTo <RequestFormTemplateDetails>(ds.Tables[1]).ToList(); } if (ds != null && ds.Tables.Count > 2) { TemplateSectionControls = EntityCollectionHelper.ConvertTo <RequestTemplateSectionControls>(ds.Tables[2]).ToList(); } List <int> controlGroupList = (from obj in TemplateSectionControls select obj.SeqNo).Distinct().ToList(); int incrCount = 1; for (int count = 0; count < controlGroupList.Count; count++) { List <RequestTemplateSectionControls> GroupSectionControls = TemplateSectionControls.Where(sectionControl => sectionControl.SeqNo == controlGroupList[count]).ToList(); if (GroupSectionControls.Count == 1) { TemplateSectionControls templateControl = new TemplateSectionControls(); templateControl.RequestTemplateSectionId = GroupSectionControls[0].RequestTemplateSectionId; templateControl.Type = GroupSectionControls[0].ControlName.ToLower(); templateControl.Name = GroupSectionControls[0].ControlName.ToLower() + incrCount.ToString(); templateControl.ControlType = GroupSectionControls[0].ControlType; templateControl.RequestTemplateSectionControlId = GroupSectionControls[0].RequestTemplateSectionControlId; templateControl.Label = GroupSectionControls[0].ControlLabel; templateControl.Value = ""; templateControl.Required = GroupSectionControls[0].IsRequired; if (GroupSectionControls[0].ControlName.ToLower() == appConstants.TextArea) { templateControl.Input = "this.inputChange.bind(this)"; } else if (GroupSectionControls[0].ControlName.ToLower() == appConstants.CheckBox) { templateControl.Input = "this.checkValue.bind(this)"; } else if (GroupSectionControls[0].ControlName.ToLower() == appConstants.TextBox) { templateControl.Input = "this.inputChange.bind(this)"; } else { templateControl.Input = ""; } templateControl.SeqNO = GroupSectionControls[0].SeqNo; templateControl.MaxLen = GroupSectionControls[0].MaxLen; templateControl.RowLength = GroupSectionControls[0].RowLength; templateControl.DisplayField = GroupSectionControls[0].DisplayField; templateControl.ValueField = GroupSectionControls[0].ValueField; templateControl.SourceName = GroupSectionControls[0].SourceName; templateControl.IsChecked = GroupSectionControls[0].IsChecked; templateControl.TemplateControlOptions = new List <TemplateSectionControlOptions>(); TemplateControls.Add(templateControl); PreviewTemplateControl PreviewTempDetails = new PreviewTemplateControl(); if (GroupSectionControls[0].ControlName.ToLower() == appConstants.TextArea) { PreviewTempDetails.Type = appConstants.Label; } else if (GroupSectionControls[0].ControlName.ToLower() == appConstants.CheckBox) { PreviewTempDetails.Type = "ul"; } else if (GroupSectionControls[0].ControlName.ToLower() == appConstants.TextBox) { PreviewTempDetails.Type = appConstants.Label; } else { PreviewTempDetails.Type = ""; } PreviewTempDetails.Name = templateControl.Name; PreviewTempDetails.Label = templateControl.Label.Split('(')[0].Split("Example")[0]; if (GroupSectionControls[0].ControlName.ToLower() != appConstants.Label) { PreviewTemplateList.Add(PreviewTempDetails); } incrCount++; } else if (GroupSectionControls.Count > 1) { TemplateSectionControls templateControl = new TemplateSectionControls(); List <TemplateSectionControlOptions> templateControlOptions = new List <TemplateSectionControlOptions>(); RequestTemplateSectionControls requestTemplateSectionControl = GroupSectionControls.Where(sectionControl => sectionControl.ControlName.ToLower() == appConstants.Label).FirstOrDefault(); templateControl.RequestTemplateSectionId = requestTemplateSectionControl.RequestTemplateSectionId; templateControl.RequestTemplateSectionControlId = requestTemplateSectionControl.RequestTemplateSectionControlId; templateControl.Label = requestTemplateSectionControl.ControlLabel; //templateControl.ControlType = requestTemplateSectionControl.ControlType; templateControl.Value = ""; templateControl.Required = requestTemplateSectionControl.IsRequired; templateControl.Input = ""; templateControl.SeqNO = requestTemplateSectionControl.SeqNo; templateControl.MaxLen = requestTemplateSectionControl.MaxLen; templateControl.RowLength = requestTemplateSectionControl.RowLength; templateControl.DisplayField = requestTemplateSectionControl.DisplayField; templateControl.ValueField = requestTemplateSectionControl.ValueField; templateControl.SourceName = requestTemplateSectionControl.SourceName; templateControl.IsChecked = requestTemplateSectionControl.IsChecked; incrCount = incrCount + 1; PreviewTemplateControl PreviewTempDetails = new PreviewTemplateControl(); foreach (RequestTemplateSectionControls item in GroupSectionControls) { if (item.ControlName.ToLower() != appConstants.Label) { if (templateControl.Type == null) { templateControl.Type = item.ControlName.ToLower(); templateControl.Name = item.ControlName.ToLower() + incrCount.ToString(); templateControl.ControlType = item.ControlType; if (item.ControlName.ToLower() == appConstants.TextArea) { PreviewTempDetails.Type = appConstants.Label; } else if (item.ControlName.ToLower() == appConstants.CheckBox) { PreviewTempDetails.Type = "ul"; } else if (item.ControlName.ToLower() == appConstants.TextBox) { PreviewTempDetails.Type = appConstants.Label; } else { PreviewTempDetails.Type = ""; } PreviewTempDetails.Name = templateControl.Name; PreviewTempDetails.Label = templateControl.Label.Split('(')[0].Split("Example")[0]; incrCount = incrCount + 1; } TemplateSectionControlOptions templateSectionControlOptions = new TemplateSectionControlOptions(); templateSectionControlOptions.RequestTemplateSectionControlId = item.RequestTemplateSectionControlId; templateSectionControlOptions.RequestTemplateSectionId = item.RequestTemplateSectionId; templateSectionControlOptions.Value = false; templateSectionControlOptions.Key = string.Join("", item.ControlLabel.ToLower().Split(" ")); templateSectionControlOptions.Label = item.ControlLabel; templateSectionControlOptions.Name = item.ControlName.ToLower() + incrCount.ToString(); incrCount = incrCount + 1; if (item.ControlName.ToLower() == appConstants.CheckBox) { templateControl.Input = "this.checkValue.bind(this)"; } else { templateControl.Input = ""; } templateControlOptions.Add(templateSectionControlOptions); } } PreviewTemplateList.Add(PreviewTempDetails); templateControl.TemplateControlOptions = templateControlOptions; TemplateControls.Add(templateControl); } } foreach (RequestFormTemplateDetails item in TemplateDetails) { List <TemplateSectionControls> templateControls = TemplateControls.Where(control => control.RequestTemplateSectionId == item.RequestTemplateSectionId).ToList(); if (templateControls == null || templateControls.Count == 0) { templateControls = new List <TemplateSectionControls>(); } item.TemplateControls = templateControls; } if (TemplateDetails == null || TemplateDetails.Count == 0) { TemplateDetails = new List <RequestFormTemplateDetails>(); } requestFormTemplate.TemplateDetailsList = TemplateDetails; PreviewTemplateDetails.PreviewTemplateControlsList = PreviewTemplateList; requestFormTemplate.PreviewDetails = PreviewTemplateDetails; } } } catch (SqlException sqlEx) { Logging.LogErrorMessage("Method: GetRequestFormTemplateByCategoryIDAndTemplateID, Layer: RequestFormDAL, Stack Trace: " + sqlEx.ToString()); throw; } catch (Exception ex) { Logging.LogErrorMessage("Method: GetRequestFormTemplateByCategoryIDAndTemplateID, Layer: RequestFormDAL, Stack Trace: " + ex.ToString()); throw; } using (LookupsDAL lookuDAL = new LookupsDAL()) { requestFormTemplate.LookupsList = lookuDAL.GetLookupDetailsByLookupNames("Submit,Track,Request Status"); } return(requestFormTemplate); }