private static string CreateLink(this HtmlHelper html, DialogSubmitOption option) { var url = option.URL; // check if has ReloadID and ReloadURL param var param = html.ViewContext.RequestContext.HttpContext.Request.Params; if (param.Get("ReloadID") != null && param.Get("ReloadURL") != null) { url = Javascript.addParamToURL(url, "ReloadID", param.Get("ReloadID")); url = Javascript.addParamToURL(url, "ReloadURL", param.Get("ReloadURL")); } var onClick = String.Format("$.post('{0}', $(this).parents('form').serialize(), Core.DialogCallback)", url); if (option.CausesValidation) { onClick = string.Format("if ($(this).parents('form').valid()) {{{0}}}", onClick); } if (option.ConfirmMessage != null) { onClick = String.Format("if ({0}){{{1}}}", String.Format(@"confirm(""{0}"")", option.ConfirmMessage), onClick); } else if (option.CallBefore != null) { onClick = String.Format("if ({0}){{{1}}}", option.CallBefore, onClick); } return(onClick); }
/// <summary> /// Button to open a dialog /// </summary> /// <param name="html"></param> /// <param name="name"></param> /// <param name="url"></param> /// <returns></returns> public static String ButtonToRemoteDialogHaveReload(this HtmlHelper html, string name, string url, string reloadID, string reloadURL) { url = Javascript.addParamToURL(url, "reloadID", reloadID); url = Javascript.addParamToURL(url, "reloadURL", reloadURL); return(String.Format(@"<input type='button' value='{0}' onclick=""Core.openDialog('{1}')"" />", name, url)); }
/// <summary> /// dialog submit button /// </summary> /// <param name="html"></param> /// <param name="option"></param> /// <returns></returns> public static String DialogSubmit(this HtmlHelper html, DialogSubmitOption option, Object htmlAttributes) { var url = option.URL; // check if has ReloadID and ReloadURL param var param = html.ViewContext.RequestContext.HttpContext.Request.Params; if (param.Get("ReloadID") != null) { url = Javascript.addParamToURL(url, "ReloadID", param.Get("ReloadID")); } if (param.Get("ReloadURL") != null) { url = Javascript.addParamToURL(url, "ReloadURL", param.Get("ReloadURL")); } if (param.Get("RunJS") != null) { url = Javascript.addParamToURL(url, "RunJS", param.Get("RunJS")); } var onClick = String.Format("$.post('{0}', $(this).parents('form').serialize(), Core.DialogCallback)", url); if (option.CausesValidation) { onClick = string.Format("if ($(this).parents('form').valid()) {{{0}}}", onClick); } if (option.ConfirmMessage != null) { onClick = String.Format("if ({0}){{{1}}}", String.Format(@"confirm(""{0}"")", option.ConfirmMessage), onClick); } else if (option.CallBefore != null) { onClick = String.Format("if ({0}){{{1}}}", option.CallBefore, onClick); } // Create tag builder var builder = new TagBuilder("button"); builder.MergeAttribute("class", "form-button ui-corner-all next"); builder.MergeAttribute("type", "button"); builder.MergeAttribute("onClick", onClick); builder.SetInnerText(option.Name); if (htmlAttributes != null) { builder.MergeAttributes(new RouteValueDictionary(htmlAttributes)); } return(builder.ToString()); }
/// <summary> /// ajax pagination /// </summary> /// <typeparam name="T"></typeparam> /// <param name="html"></param> /// <param name="pager"></param> /// <param name="option"></param> /// <returns></returns> public static String AjaxPagination <T>(this HtmlHelper html, WebPager <T> pager, AjaxPaginationOption option) { var param = html.ViewContext.HttpContext.Request.Form; // merge data of ajax pagination option and request var data = new RouteValueDictionary(option.Data); if (option.AutoLoadParam == true) { foreach (var key in param.AllKeys) { if (key != null && !data.ContainsKey(key)) { data.Add(key, param[key]); } } } var dataObj = Json.Decode <Object>(Json.EncodeDictionary(data)); // autload htmlID var HtmlID = option.HtmlID; if (option.AutoLoadHtmlID == true && param["HtmlID"] != null) { HtmlID = param["HtmlID"]; } var url = Javascript.addParamToURL(option.URL, "page", WebPager <T> .PageValue); string hiddenRefresh = html.ButtonToRemote(WebPager <T> .PageName, "cmdRefresh", new RemoteOption { URL = url, Update = HtmlID, Data = dataObj }, new { style = "display:none" }).Replace(WebPager <T> .PageValue, pager.GetPage().ToString()); if (!pager.HaveToPagination()) { return(hiddenRefresh); } var ret = new List <String>(); var linkPattern = html.LinkToRemote(WebPager <T> .PageName, new RemoteOption { URL = url, Update = HtmlID, Data = dataObj }); var linkPagePattern = linkPattern.Replace(WebPager <T> .PageName, WebPager <T> .PageValue); pager.LinkPattern = linkPagePattern; pager.CurrentLinkPattern = "<b>" + WebPager <T> .PageValue + "</b>"; // first page if (pager.GetPage() != pager.GetFirstPage()) { ret.Add(linkPattern.Replace(WebPager <T> .PageName, "First").Replace(WebPager <T> .PageValue, pager.GetFirstPage().ToString())); } // previous page if (pager.GetPreviousPage() > 0) { ret.Add(linkPattern.Replace(WebPager <T> .PageName, "Previous").Replace(WebPager <T> .PageValue, pager.GetPreviousPage().ToString())); } // pages foreach (var link in pager.GetLinks()) { ret.Add(link); } // next page if (pager.GetNextPage() > 0) { ret.Add(linkPattern.Replace(WebPager <T> .PageName, "Next").Replace(WebPager <T> .PageValue, pager.GetNextPage().ToString())); } // last page if (pager.GetPage() != pager.GetLastPage()) { ret.Add(linkPattern.Replace(WebPager <T> .PageName, "Last").Replace(WebPager <T> .PageValue, pager.GetLastPage().ToString())); } return(String.Join(" ", ret.ToArray()) + hiddenRefresh); }
/// <summary> /// Build table header for sorting /// </summary> /// <typeparam name="T"></typeparam> /// <param name="html"></param> /// <param name="gridOption"></param> /// <param name="column"></param> /// <returns></returns> public static TagBuilder BuildSortHeaderTag <T>(this HtmlHelper html, GridOption <T> gridOption, ColumnOption <T> column) { string sortColumn = column.FieldName; string sortOptionValue = ""; bool currentSort = false; string sortButton = ""; string upButtonCSS = "sorted-asc"; string downButtonCSS = "sorted-desc"; string unsortedCSS = "unsorted"; GetSortParams(html, ref sortColumn, ref sortOptionValue); if (string.IsNullOrEmpty(sortColumn) || string.IsNullOrEmpty(sortOptionValue)) { if (!string.IsNullOrEmpty(gridOption.DefaultSortColumn) && gridOption.DefaultSortColumn.Equals(column.FieldName)) { currentSort = true; sortOptionValue = gridOption.DefaultSortOption; } else { sortColumn = column.FieldName; sortOptionValue = column.DefaultSortOption; } } else { if (sortColumn.Equals(column.FieldName)) { currentSort = true; } else { sortOptionValue = column.DefaultSortOption; } } #region build parameter list var param = html.ViewContext.HttpContext.Request.Form; //paging param var data = new RouteValueDictionary(); foreach (var key in param.AllKeys) { if (!data.ContainsKey(key) && !key.Equals("SortColumn") && !key.Equals("SortOption")) { string[] values = param.GetValues(key); data.Add(key, values); } } int page = 1; string pageKey = "Page"; if (html.ViewContext.HttpContext.Request.Params[pageKey] != null) { int.TryParse(html.ViewContext.HttpContext.Request.Params[pageKey], out page); } #endregion var dataObj = Json.Decode <Object>(Json.EncodeDictionary(data)); var HtmlID = gridOption.HtmlID; //parameters for sorting if (string.IsNullOrEmpty(sortOptionValue)) { sortOptionValue = SortOption.Asc.ToString(); } if (sortOptionValue.Equals(SortOption.Asc.ToString())) { sortOptionValue = SortOption.Desc.ToString(); sortButton = upButtonCSS; } else { sortOptionValue = SortOption.Asc.ToString(); sortButton = downButtonCSS; } var url = Javascript.addParamToURL(gridOption.URL, "SortColumn", column.FieldName); url = Javascript.addParamToURL(url, "SortOption", sortOptionValue); url = Javascript.addParamToURL(url, pageKey, page.ToString()); //build sort header TagBuilder header = null; if (currentSort) { header = JavascriptHelper.TableHeaderForSort(column.Name, new RemoteOption { URL = url, Update = HtmlID, Data = dataObj }); header.AddCssClass(sortButton); } else { header = JavascriptHelper.TableHeaderForSort(column.Name, new RemoteOption { URL = url, Update = HtmlID, Data = dataObj }); header.AddCssClass(unsortedCSS); } return(header); }