예제 #1
0
        private IFiltering GetFilteringFor(jQueryObject row)
        {
            var field = GetFieldFor(row);

            if (field == null)
            {
                return(null);
            }

            IFiltering filtering = (IFiltering)row.GetDataValue("Filtering");

            if (filtering != null)
            {
                return(filtering);
            }

            var filteringType = FilteringTypeRegistry.Get(field.FilteringType ?? "String");

            jQueryObject editorDiv = row.Children("div.v");

            filtering = (IFiltering)Activator.CreateInstance(filteringType);
            ReflectionOptionsSetter.Set(filtering, field.FilteringParams);
            filtering.Container = editorDiv;
            filtering.Field     = field;
            row.Data("Filtering", filtering);

            return(filtering);
        }
예제 #2
0
        public void Refresh()
        {
            if (!PopulateWhenVisible())
            {
                InternalRefresh();
                return;
            }

            if (slickContainer.Is(":visible"))
            {
                slickContainer.Data("needsRefresh", false);
                InternalRefresh();
                return;
            }

            slickContainer.Data("needsRefresh", true);
        }
예제 #3
0
        private void ResizeElement(jQueryObject element)
        {
            var xFactor = GetXFactor(element);

            if (xFactor != 0)
            {
                var initialWidth = element.GetDataValue("flexify-width").As <int?>();
                if (initialWidth == null)
                {
                    var width = element.GetWidth();
                    element.Data("flexify-width", width);
                    initialWidth = width;
                }

                element.Width(Math.Truncate(initialWidth.Value + xFactor * xDifference));
            }

            var yFactor = GetYFactor(element);

            if (yFactor != 0)
            {
                var initialHeight = element.GetDataValue("flexify-height").As <int?>();
                if (initialHeight == null)
                {
                    var height = element.GetHeight();
                    element.Data("flexify-height", height);
                    initialHeight = height;
                }

                element.Height(Math.Truncate(initialHeight.Value + yFactor * yDifference));
            }

            if (element.HasClass("require-layout"))
            {
                element.TriggerHandler("layout");
            }
        }
예제 #4
0
        private IFilterHandler GetFilterHandlerFor(jQueryObject row)
        {
            FilterField field = GetFieldFor(row);

            if (field == null)
            {
                return(null);
            }

            IFilterHandler handler      = (IFilterHandler)row.GetDataValue("FilterHandler");
            string         handlerField = row.GetDataValue("FilterHandlerField").As <string>();

            if (handler != null)
            {
                if (handlerField != field.Name)
                {
                    row.Data("FilterHandler", null);
                    handler = null;
                }
                else
                {
                    return(handler);
                }
            }

            Type handlerType = Type.GetType("Sinerji." + (field.Handler ?? "??") + "FilterHandler");

            if (handlerType == null)
            {
                throw new Exception(String.Format("FilterHandler type Sinerji.{0}FilterHandler is not defined!", field.Handler));
            }

            jQueryObject editorDiv = row.Children("div.v");

            handler = (IFilterHandler)Activator.CreateInstance(handlerType, editorDiv, field);

            return(handler);
        }
예제 #5
0
 private void RemoveFiltering(jQueryObject row)
 {
     row.Data("Filtering", null);
     row.Data("FilteringField", null);
 }
예제 #6
0
 public static jQueryObject FlexYFactor(this jQueryObject element, double flexY)
 {
     return(element.Data("flex-y", flexY));
 }
예제 #7
0
        public TemplateControl(object oTemplate)
        {
            // init static stuff
            if (!_bStaticConstructionFinished)
            {
                StaticConstructor();
            }

            // continue instance setup..
            this._strInstanceId = GenerateNewInstanceId();

            string strTemplate;

            // grab template
            if (Script.IsNullOrUndefined(oTemplate))
            {
                strTemplate = FindTemplate(this);
#if DEBUG
                if (string.IsNullOrEmpty(strTemplate))
                {
                    throw new Exception(this.GetType().FullName + " is missing a Template member and no template was provided.");
                }
#endif
            }
            else
            {
                if (oTemplate is string)
                {
                    strTemplate = (string)oTemplate;
                }
                else
                {
                    jQueryObject jqTemplate = jQuery.FromObject(oTemplate);
                    strTemplate = "<" + jqTemplate[0].TagName + ">" + jqTemplate.GetHtml() + "</" + jqTemplate[0].TagName + ">";
                }
            }

            _hash_oNamedChildControls = new Dictionary();
            _hash_oNamedChildElements = new Dictionary();

            jQueryObject jqHead = jQuery.Select("head");

            // grab template
            if (Script.IsNullOrUndefined(strTemplate))
            {
                strTemplate = (string)Type.GetField(this, "template");
            }
#if DEBUG
            if (string.IsNullOrEmpty(strTemplate))
            {
                throw new Exception(this.GetType().FullName + " is missing a Template member.");
            }
#endif
            // generate an absolute id for this control
            string newId = GenerateNewAutoId();

#if DEBUG
            // is there a conflict in the auto gen'd id?
            {
                int numOtherControlsWithId = jQuery.Select("#" + newId).Length;
                if (numOtherControlsWithId != 0)
                {
                    throw new Exception("Auto generated id conflict.");
                }
            }
#endif

            // parse template
            jQueryObject jqContent = jQuery.FromHtml(strTemplate.Replace("`", "\""));

            // are there style tags?
            string strStyleRules = string.Empty;
            jqContent.Filter("style").Each(delegate(int i, Element e)
            {
                jQueryObject jqElement = jQuery.FromElement(e);
                strStyleRules += jqElement.GetHtml();
                jqElement.Remove();
            });

            // proceed with non-style tags
            jqContent = jqContent.Not("style").Remove();

            // remove attribute id if any
#if DEBUG
            if (!string.IsNullOrEmpty(jqContent.GetAttribute("id")))
            {
                throw new Exception("Global ID's not permitted. Element with ID \"" + jqContent.GetAttribute("id") + "\" found.");
            }
#endif
            jqContent.RemoveAttr("id");

            // store reference
            _jqRootElement = jqContent;

            // store reference from element back to this control
            _jqRootElement.Data(DataNameControl, this);

            // identify locally-named elements. this runs before parsing children because we don't want to add children's locally-named html elements.
            {
                jqContent.Find("*[" + AttributeNameLocalId + "]").Each(
                    delegate(int i, Element e)
                    {
                        jQueryObject jqElement = jQuery.FromElement(e);
                        if (!string.IsNullOrEmpty(jqElement.GetAttribute(AttributeNameControlClass)))
                        {
                            return;
                        }

                        string strLocalId = GetLocalId(jqElement);
                        if (strLocalId == null)
                        {
                            return;
                        }

                        // store record of it
                        this._hash_oNamedChildElements[strLocalId] = jqElement;

                        // remove absolute id if any
#if DEBUG
                        if (!string.IsNullOrEmpty(jqElement.GetAttribute("id")))
                        {
                            throw new Exception("Global ID's not permitted. Element with ID \"" + jqElement.GetAttribute("id") + "\" found.");
                        }
#endif
                        jqElement.RemoveAttr("id");
                    })
                ;
            }

            // rewrite image and image button paths
            {
                string baseUrl = BaseUrlImages;
                if (baseUrl.Length > 0)
                {
                    jqContent.Find("img, input[type=image]").Each(
                        delegate(int i, Element e)
                        {
                            jQueryObject jqe = jQuery.FromElement(e);
                            string src = jqe.GetAttribute("src");
                            if (string.IsNullOrEmpty(src))
                            {
                                string nullSrc = "http://null-image";

                                if (Window.Location.Protocol == "https:")
                                {
                                    nullSrc = "https://null-image";
                                }

                                jqe.Attribute("src", nullSrc);
                                return;
                            }

                            if (src.StartsWith("http://") || src.StartsWith("https://"))
                            {
                                return;
                            }

                            jqe.Attribute("src", CombinePaths(baseUrl, src));
                        }
                    );
                }
            }

            // calculcate search namespace
            Type currentType = this.GetType();
            string currentTopLevelNamespace
                = currentType
                .FullName
                .Substr(0, currentType.FullName.IndexOf('.'))
            ;

            // add class for identifying this as a template control
            _jqRootElement.AddClass(CssClassNameControl);

            // add class for identifying this as a newly added template control
            _jqRootElement.AddClass(CssClassNameControlUnadded);

            // recurse into child controls // todo: move this to *after* processing labels and images?
            jqContent.Find("div[" + AttributeNameControlClass + "]").Each(
                delegate(int index, Element element)
                {
                    jQueryObject jqElement = jQuery.FromElement(element);
                    string strChildTypeName = jqElement.GetAttribute(AttributeNameControlClass);

                    string strChildTypeNameResolved
                        = ResolveTypeName(
                            strChildTypeName,
                            currentTopLevelNamespace
                        )
                    ;
                    Type oChildType = Type.GetType(strChildTypeNameResolved);

                    if (Script.IsNullOrUndefined(oChildType))
                    {
#if DEBUG
                        throw new Exception("Could not locate type \"" + (strChildTypeNameResolved ?? strChildTypeName) + "\"");
#else
                        return;
#endif
                    }

                    TemplateControl childControl = Type.CreateInstance(oChildType, null) as TemplateControl;

                    if (!(childControl is TemplateControl))
                    {
                        // this check is still needed because of how the 'as' operator behaves in Script#.
#if DEBUG
                        throw new Exception("Control must derive from 'TemplateControl'.");
#else
                        return;
#endif
                    }

                    // grab local id if any
                    string strLocalId = GetLocalId(jqElement) ?? GenerateNewAutoId();

                    // store named control
                    if (strLocalId != null)
                    {
                        this._hash_oNamedChildControls[strLocalId] = childControl;
                    }

                    // merge style and class attributes
                    string strClass = jqElement.GetAttribute("class");
                    string strStyle = jqElement.GetAttribute("style");
                    if (!string.IsNullOrEmpty(strClass))
                    {
                        string strClassFromTemplate = childControl.RootElement.GetAttribute("class") ?? string.Empty;
                        childControl.RootElement.Attribute("class", strClassFromTemplate + " " + strClass);
                    }
                    if (!string.IsNullOrEmpty(strStyle))
                    {
                        string strStyleFromTemplate = childControl.RootElement.GetAttribute("style") ?? string.Empty;
                        childControl.RootElement.Attribute("style", strStyleFromTemplate + " " + strStyle);
                    }

                    // preserve other attributes
                    for (int i = 0, m = jqElement[0].Attributes.Length; i < m; ++i)
                    {
                        ElementAttribute a = (ElementAttribute)Type.GetField(jqElement[0].Attributes, (string)(object)i);
                        if (jQuery.Browser.Version == "7.0" && jQuery.Browser.MSIE && !a.Specified)
                        {
                            continue;
                        }
                        string attributeName = a.Name.ToLowerCase();
                        switch (attributeName)
                        {
                            case "id":
                            case "xid":
                            case "class":
                            case "style":
                            case "control":
                                break;
                            default:
                                childControl.RootElement.Attribute(a.Name, a.Value);
                                break;
                        }
                    }

                    // replace the placeholder element with the new control.
                    jqElement.RemoveAttr("id").After(childControl.RootElement).Remove();

                    // preserve local id & control type name
                    if (strLocalId != null)
                    {
                        childControl.RootElement.Attribute("xid", strLocalId);
                    }
                    childControl.RootElement.Attribute("control", jqElement.GetAttribute(AttributeNameControlClass));

                    // any children content?
                    jQueryObject jqChildContent = jqElement.Find(">*");
                    if (jqChildContent.Length > 0)
                    {
                        childControl.ProcessChildContent(jqChildContent);
                    }
                }
            );

            // rewrite radio input groups // todo: do this before processing child controls?
            {
                jQueryObject jqRadioInputs = _jqRootElement.Find("input[type=radio]");
                Dictionary hash_rewrittenGroupNames = new Dictionary();
                jqRadioInputs.Each(delegate(int index, Element element)
                {
                    jQueryObject jqRadio = jQuery.FromElement(element);

                    // rewrite name attribute
                    {
                        string strGroupName = jqRadio.GetAttribute("name");
                        if (string.IsNullOrEmpty(strGroupName))
                        {
                            return;
                        }
                        // need a new name?
                        string strNewGroupName;
                        if (hash_rewrittenGroupNames.ContainsKey(strGroupName))
                        {
                            strNewGroupName = (string)hash_rewrittenGroupNames[strGroupName];
                        }
                        else
                        {
                            hash_rewrittenGroupNames[strGroupName] = strNewGroupName = GenerateNewAutoId();
                        }
                        jqRadio.Attribute("name", strNewGroupName);
                    }

                    // make sure the element has an id, for label elements to use
                    if (string.IsNullOrEmpty(jqRadio.GetAttribute("id")))
                    {
                        jqRadio.Attribute("id", GenerateNewAutoId());
                    }
                });
                this._hash_rewrittenGroupNames = hash_rewrittenGroupNames;
            }

            // rewrite label elements // todo: do this before processing child controls?
            {
                jQueryObject jqLabels = _jqRootElement.Find("label[for]");
                jqLabels.Each(delegate(int index, Element element)
                {
                    if (_bPresented) { } // workaround to delegate bug in Script# 0.7.0.0
                    jQueryObject jqLabelElement = jQuery.FromElement(element);
                    string strForId = jqLabelElement.GetAttribute("for");
                    // is this element rewritten?
                    jQueryObject jqTargetElement = TryGetElement(strForId);
                    if (jqTargetElement == null)
                    {
                        return;
                    }
                    string strTargetElementNewId = jqTargetElement.GetAttribute("id");
                    // make sure the "for" element has an id
                    if (string.IsNullOrEmpty(strTargetElementNewId))
                    {
                        jqTargetElement.Attribute("id", strTargetElementNewId = GenerateNewAutoId());
                    }
                    jqLabelElement.Attribute("for", strTargetElementNewId);

                    return;
                });
            }

            // fixup css rules & add to head
            if (strStyleRules.Length != 0)
            {
                ProcessCss(this, strStyleRules);
            }

            // auto fill members that point to elements/controls
            AutoFillMemberFields();

            // any elements with advanced layout enabled?
            AdvancedLayout.AutoEnable(_jqRootElement);
        }
예제 #8
0
        private static void Arrange(jQueryObject element)
        {
#if DEBUG
            if (!element.Is("." + CssClassNameAdvancedLayout))
            {
                throw new Exception("Element not marked for advanced layout.");
            }
#endif
            // does element have its al state parsed?
            AdvancedLayoutState elementState = (AdvancedLayoutState)element.GetDataValue(DataNameLayoutState);
            if (elementState == null)
            {
                element.Data(DataNameLayoutState, elementState = ParseAdvancedLayout(element));
            }

            // grab parents
            jQueryObject parent = element.Parent();
            jQueryObject offsetParent = element.OffsetParent();
            if (offsetParent.Length == 0 || parent.Length == 0)
            {
                return;
            }

            bool parentIsOffsetParent = offsetParent[0] == parent[0];
#if DEBUG
            if (!parentIsOffsetParent && element.Is(":visible"))
            {
                throw new Exception("Parent must use position:absolute|fixed|relative;.");
            }
#endif
            if (!parentIsOffsetParent)
            {
                return;
            }

            // gather parent padding and client dimensions
            DimensionsAndPadding parentDimensions = null;
            parentDimensions = GetDimensionsAndPadding(parent);

            // detect parent's coordinates in offset-parent frame.
            float contentStartInOffsetSpaceX, contentStartInOffsetSpaceY;
            {
                if (parentIsOffsetParent)
                { // parent is offset parent. we know our local frame.
                    contentStartInOffsetSpaceX = 0;
                    contentStartInOffsetSpaceY = 0;
                }
                else
                { // experimental support for staticly positioned parent.

                    parent.Prepend(_frameDetector);

                    jQueryPosition parentContentFrameInDocumentSpace = _frameDetector.GetOffset();
                    jQueryPosition offsetParentFrameInDocumentSpace = offsetParent.GetOffset();
                    if (parentContentFrameInDocumentSpace != null && offsetParentFrameInDocumentSpace != null)
                    {
                        contentStartInOffsetSpaceX = parentContentFrameInDocumentSpace.Left - offsetParentFrameInDocumentSpace.Left - parentDimensions.PaddingLeft;
                        contentStartInOffsetSpaceY = parentContentFrameInDocumentSpace.Top - offsetParentFrameInDocumentSpace.Top - parentDimensions.PaddingTop;
                    }
                    else
                    {
                        jQueryPosition contentStartInOffsetSpace = _frameDetector.Position();
                        if (contentStartInOffsetSpace != null)
                        {
                            contentStartInOffsetSpaceX = contentStartInOffsetSpace.Left - parentDimensions.PaddingLeft;
                            contentStartInOffsetSpaceY = contentStartInOffsetSpace.Top - parentDimensions.PaddingTop;
                        }
                        else
                        {
                            contentStartInOffsetSpaceX = 0;
                            contentStartInOffsetSpaceY = 0;
                        }
                    }

                    _frameDetector.Remove();
                }

            }

            double topBoundary = contentStartInOffsetSpaceY + parentDimensions.PaddingTop + elementState.Margin.Top;
            double bottomBoundary = contentStartInOffsetSpaceY + parentDimensions.ClientHeight - parentDimensions.PaddingBottom - elementState.Margin.Bottom;
            double leftBoundary = contentStartInOffsetSpaceX + parentDimensions.PaddingLeft + elementState.Margin.Left;
            double rightBoundary = contentStartInOffsetSpaceX + parentDimensions.ClientWidth - parentDimensions.PaddingRight - elementState.Margin.Right;


            // determine where to position
            int top = 0;
            int left = 0;
            int width = 0;
            int height = 0;
            switch (elementState.VerticalAlignment)
            {
                case VerticalAlignment.Top:
                    height = Math.Round(elementState.Height - elementState.Padding.Top - elementState.Padding.Bottom);
                    top = Math.Round(topBoundary);
                    break;

                case VerticalAlignment.Center:
                    height = Math.Round(elementState.Height - elementState.Padding.Top - elementState.Padding.Bottom);
                    top = Math.Round(topBoundary * 0.5 + bottomBoundary * 0.5 - height * 0.5);
                    break;

                case VerticalAlignment.Bottom:
                    height = Math.Round(elementState.Height - elementState.Padding.Top - elementState.Padding.Bottom);
                    top = Math.Round(contentStartInOffsetSpaceY + parentDimensions.ClientHeight - parentDimensions.PaddingBottom - elementState.Margin.Bottom - elementState.Height);
                    break;

                case VerticalAlignment.Stretch:
                    height = Math.Round(bottomBoundary - topBoundary - elementState.Padding.Top - elementState.Padding.Bottom);
                    top = Math.Round(topBoundary);
                    break;

            }
            switch (elementState.HorizontalAlignment)
            {
                case HorizontalAlignment.Left:
                    width = Math.Round(elementState.Width - elementState.Padding.Left - elementState.Padding.Right);
                    left = Math.Round(leftBoundary);
                    break;

                case HorizontalAlignment.Center:
                    width = Math.Round(elementState.Width - elementState.Padding.Left - elementState.Padding.Right);
                    left = Math.Round(leftBoundary * 0.5 + rightBoundary * 0.5 - width * 0.5);
                    break;

                case HorizontalAlignment.Right:
                    width = Math.Round(elementState.Width - elementState.Padding.Left - elementState.Padding.Right);
                    left = Math.Round(contentStartInOffsetSpaceX + parentDimensions.ClientWidth - parentDimensions.PaddingRight - elementState.Margin.Right - elementState.Width);
                    break;

                case HorizontalAlignment.Stretch:
                    width = Math.Round(rightBoundary - leftBoundary - elementState.Padding.Left - elementState.Padding.Right);
                    left = Math.Round(leftBoundary);
                    break;
            }

            if (width <= 0)
            {
                width = 0;
            }
            if (height <= 0)
            {
                height = 0;
            }

            element.CSS(
                new Dictionary(
                    "position", "absolute",
                    "top", top,
                    "left", left,
                    "width", width,
                    "height", height,
                    "padding-top", elementState.Padding.Top,
                    "padding-right", elementState.Padding.Right,
                    "padding-bottom", elementState.Padding.Bottom,
                    "padding-left", elementState.Padding.Left
                )
            );
        }
예제 #9
0
 private void RemoveFilterHandler(jQueryObject row)
 {
     row.Data("FilterHandler", null);
     row.Data("FilterHandlerField", null);
 }