示例#1
0
        protected override void AddValidation(Control container, Control editor)
        {
            base.AddValidation(container, editor);
            var cv = new CustomValidator();

            cv.ID = Name + "_cv";
            cv.ControlToValidate = editor.ID;
            cv.Display           = ValidatorDisplay.Dynamic;
            cv.Text            = GetLocalizedText("UniqueUrlText") ?? UniqueUrlText;
            cv.ServerValidate += (object source, ServerValidateEventArgs args) =>
            {
                var url     = ((TextBox)editor).Text.TrimEnd('/');
                var selItem = new SelectionUtility(container, Engine).SelectedItem;
                var site    = Engine.Host.GetSite(selItem);
                if (EnableMultiHosts && site != null && !string.IsNullOrWhiteSpace(site.Authority))
                {
                    url = new Web.Url("http", site.Authority, url);
                }
                else
                {
                    url = Engine.RequestContext.Url.HostUrl.Append(url.TrimStart('/'));
                }
                var existing = Engine.UrlParser.FindPath(url);
                if (!existing.IsEmpty() && existing.CurrentItem != selItem && (selItem.VersionOf.ID) != existing.ID)
                {
                    args.IsValid    = false;
                    cv.ErrorMessage = string.Format(GetLocalizedText("UniqueUrlMessage") ?? UniqueUrlMessage, GetLocalizedText("Title") ?? Title, existing.CurrentItem.Title, existing.CurrentItem.ID);
                }
            };
            container.Controls.Add(cv);
        }
示例#2
0
        /// <summary>Renders a script that loads the given action asynchronously from the client.</summary>
        /// <param name="routeParams">The route parameters to use for building the url.</param>
        /// <returns>A content result with a load action script.</returns>
        protected virtual ActionResult AsyncView(RouteValueDictionary routeParams)
        {
            if (!routeParams.ContainsKey(ContentRoute.ContentPartKey))
            {
                routeParams[ContentRoute.ContentPartKey] = CurrentItem.ID;
            }

            var id = "part_" + routeParams[ContentRoute.ContentPartKey];

            Web.Url url = CurrentPage.Url;
            url = url.UpdateQuery(routeParams);

            return(Content(string.Format(@"<div id='{0}' class='async loading'></div><script type='text/javascript'>//<![CDATA[
jQuery('#{0}').load('{1}');//]]></script>", id, url)));
        }