public string GetFetchXmlForQuery(FetchQuerySettings config, string searchTerm)
        {
            jQueryObject fetchElement = config.FetchXml.Find("fetch");

            fetchElement.Attribute("count", "{0}");
            fetchElement.Attribute("paging-cookie", "{1}");
            fetchElement.Attribute("page", "{2}");
            fetchElement.Attribute("returntotalrecordcount", "true");
            fetchElement.Attribute("distinct", "true");
            fetchElement.Attribute("no-lock", "true");

            jQueryObject orderByElement = fetchElement.Find("order");

            orderByElement.Remove();

            // Add the search string and adjust any lookup columns
            jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']");

            conditions.First().Children().Each(delegate(int index, Element element)
            {
                // Is this a lookup column?
                string logicalName = element.GetAttribute("attribute").ToString();
                if (LookupAttributes.ContainsKey(logicalName))
                {
                    element.SetAttribute("attribute", logicalName + "name");
                }
            });
            // Add the sort order placeholder
            string fetchXml = config.FetchXml.GetHtml().Replace("</entity>", "{3}</entity>");

            // Add the Query term
            fetchXml = fetchXml.Replace("#Query#", XmlHelper.Encode(searchTerm));
            return(fetchXml);
        }
Beispiel #2
0
        /// <summary>
        /// Updats the HTML element with new HTML
        /// Also, loads the new JS object (module) to handle the behavior
        /// </summary>
        /// <param name="content">The element to be updated</param>
        /// <param name="value">The HTML with which to update it</param>
        private static void UpdateModule(jQueryObject content, string value)
        {
            Module module = null;

            // Find elements which have data-type attribute with any value
            // The attribute is applied to elements that can be updated
            jQueryObject dataTypes = content.Children("*[data-type]");

            // If updatable elements exist,
            if (dataTypes.Length > 0)
            {
                // Get the first element found
                Element element = dataTypes.First().GetElement(0);

                // Find the corresponding module
                module = Module.GetModule(element);

                // Now we have the module which should be unloaded and then updated
            }

            // Fade the element out and update with the new HTML
            content.FadeOut(250, delegate()
            {
                // Unload the module
                // BUGBUG: when can this be NULL
                if (null != module)
                {
                    module.Unload();
                }

                // Update the content
                content.Html(value);

                content.FadeIn(250);

                // Check if it has any child modules to be loaded
                dataTypes = content.Children("*[data-type]");

                if (dataTypes.Length > 0)
                {
                    // Load only the first
                    LoadModule(dataTypes.First().GetElement(0));

                    // BUGBUG: do we care about the rest?
                }
            });
        }
Beispiel #3
0
        private void UpdateParens()
        {
            jQueryObject rows = rowsDiv.Children();

            if (rows.Length == 0)
            {
                return;
            }

            rows.RemoveClass("paren-start");
            rows.RemoveClass("paren-end");

            rows.Children("div.l").CSS("display", rows.Length == 1 ? "none" : "block");

            rows.First().Children("div.l").Children("a.rightparen, a.andor").CSS("visibility", "hidden");

            for (int i = 1; i < rows.Length; i++)
            {
                jQueryObject row = rows.Eq(i);
                row.Children("div.l").CSS("display", "block")
                .Children("a.lefparen, a.andor").CSS("visibility", "visible");
            }

            bool inParen = false;

            for (int i = 0; i < rows.Length; i++)
            {
                jQueryObject row      = rows.Eq(i);
                jQueryObject divParen = row.Children("div.l");
                jQueryObject lp       = divParen.Children("a.leftparen");
                jQueryObject rp       = divParen.Children("a.rightparen");

                if (rp.HasClass("active") && inParen)
                {
                    inParen = false;
                    if (i > 0)
                    {
                        rows.Eq(i - 1).AddClass("paren-end");
                    }
                }

                if (lp.HasClass("active"))
                {
                    inParen = true;
                    if (i > 0)
                    {
                        row.AddClass("paren-start");
                    }
                }
            }
        }
        private void QueryQuickSearchEntities()
        {
            OrganizationServiceProxy.RegisterExecuteMessageResponseType("ExecuteFetch", typeof(ExecuteFetchResponse));

            // Get the entities defined in the correct order
            string fetchxml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                  <entity name='multientitysearchentities'>
                                    <attribute name='entityname' />
                                    <order attribute='entityorder' descending='false' />
                                  </entity>
                                </fetch>";

            // We have to use the deprecated ExecuteFetchRequest because you can't access the multientitysearchentities through RetrieveMultiple
            ExecuteFetchRequest request = new ExecuteFetchRequest();

            request.FetchXml = fetchxml;
            ExecuteFetchResponse entityList    = (ExecuteFetchResponse)OrganizationServiceProxy.Execute(request);
            jQueryObject         entityListDOM = jQuery.FromHtml(entityList.FetchXmlResult);


            _entityTypeNames = new List <string>();
            jQueryObject results = entityListDOM.First().Find("result");

            results.Each(delegate(int index, Element element)
            {
                string entityName = XmlHelper.SelectSingleNodeValue((XmlNode)(object)element, "entityname");
                _entityTypeNames.Add(entityName);
            });

            MetadataQueryBuilder builder = new MetadataQueryBuilder();

            builder.AddEntities(_entityTypeNames, new List <string>("ObjectTypeCode", "DisplayCollectionName"));
            builder.SetLanguage((int)Script.Literal("USER_LANGUAGE_CODE"));

            RetrieveMetadataChangesResponse response = (RetrieveMetadataChangesResponse)OrganizationServiceProxy.Execute(builder.Request);

            _entityMetadata = new Dictionary <string, EntityMetadata>();
            foreach (EntityMetadata entity in response.EntityMetadata)
            {
                _entityMetadata[entity.LogicalName] = entity;
            }
        }
        public string GetFetchXmlForQuery(string entityLogicalName, string queryName, string searchTerm)
        {
            FetchQuerySettings config;

            if (queryName == "QuickFind")
            {
                config = EntityLookup[entityLogicalName].QuickFindQuery;
            }
            else
            {
                config = EntityLookup[entityLogicalName].Views[queryName];
            }
            jQueryObject fetchElement = config.FetchXml.Find("fetch");

            fetchElement.Attribute("distinct", "true");
            fetchElement.Attribute("no-lock", "true");

            jQueryObject orderByElement = fetchElement.Find("order");

            orderByElement.Remove();

            // Add the search string and adjust any lookup columns
            jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']");

            conditions.First().Children().Each(delegate(int index, Element element)
            {
                // Is this a lookup column?
                string logicalName = element.GetAttribute("attribute").ToString();
                if (LookupAttributes.ContainsKey(logicalName))
                {
                    element.SetAttribute("attribute", logicalName + "name");
                }
            });
            // Add the sort order placeholder
            string fetchXml = config.FetchXml.GetHtml();//.Replace("</entity>", "{3}</entity>");

            // Add the Query term
            fetchXml = fetchXml.Replace("#Query#", XmlHelper.Encode(searchTerm));
            return(fetchXml);
        }
        public string GetFetchXmlForQuery(string entityLogicalName, string queryName, string searchTerm, SearchTermOptions searchOptions)
        {
            FetchQuerySettings config;

            if (queryName == "QuickFind")
            {
                config = EntityLookup[entityLogicalName].QuickFindQuery;
            }
            else
            {
                config = EntityLookup[entityLogicalName].Views[queryName];
            }
            jQueryObject fetchElement = config.FetchXml.Clone().Find("fetch");

            fetchElement.Attribute("distinct", "true");
            fetchElement.Attribute("no-lock", "true");

            jQueryObject orderByElement = fetchElement.Find("order");

            orderByElement.Remove();

            // Add the search string and adjust any lookup columns
            jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']");

            conditions.First().Children().Each(delegate(int index, Element element)
            {
                // Is this a lookup column?
                string logicalName = element.GetAttribute("attribute").ToString();
                if (LookupAttributes.ContainsKey(logicalName))
                {
                    element.SetAttribute("attribute", logicalName + "name");
                }
            });

            //See what field types can we use for query and remove those attributes we cannot query using this search term.
            if (Number.IsNaN(Int32.Parse(searchTerm)))
            {
                fetchElement.Find("condition[value='#QueryInt#']").Remove();
            }
            if (Number.IsNaN(Decimal.Parse(searchTerm)))
            {
                fetchElement.Find("condition[value='#QueryCurrency#']").Remove();
            }
            if (Number.IsNaN(Date.Parse(searchTerm).GetDate()))
            {
                fetchElement.Find("condition[value='#QueryDateTime#']").Remove();
            }
            if (Number.IsNaN(Double.Parse(searchTerm)))
            {
                fetchElement.Find("condition[value='#QueryFloat#']").Remove();
            }
            // Add the sort order placeholder
            string fetchXml = fetchElement.Parent().GetHtml();//.Replace("</entity>", "{3}</entity>");

            //Prepare search term based on options
            string textSearchTerm = searchTerm;

            if (searchOptions != null && (searchOptions & SearchTermOptions.PrefixWildcard) == SearchTermOptions.PrefixWildcard)
            {
                //Trimming, in case there are already wildcards with user input
                while (textSearchTerm.StartsWith("*") || textSearchTerm.StartsWith("%"))
                {
                    textSearchTerm = textSearchTerm.Substring(1, textSearchTerm.Length);
                }
                textSearchTerm = "%" + textSearchTerm;
            }
            if (searchOptions != null && (searchOptions & SearchTermOptions.SuffixWildcard) == SearchTermOptions.SuffixWildcard)
            {
                //Trimming, in case there are already wildcards
                while (textSearchTerm.EndsWith("*") || textSearchTerm.EndsWith("%"))
                {
                    textSearchTerm = textSearchTerm.Substring(0, textSearchTerm.Length - 1);
                }
                textSearchTerm = textSearchTerm + "%";
            }

            // Add the Query term
            fetchXml = fetchXml.Replace("#Query#", XmlHelper.Encode(textSearchTerm))
                       .Replace("#QueryInt#", Int32.Parse(searchTerm).ToString())
                       .Replace("#QueryCurrency#", Double.Parse(searchTerm).ToString())
                       .Replace("#QueryDateTime#", XmlHelper.Encode(Date.Parse(searchTerm).Format("MM/dd/yyyy")))
                       .Replace("#QueryFloat#", Double.Parse(searchTerm).ToString());

            return(fetchXml);
        }
        private void ParseFetchXml(FetchQuerySettings querySettings)
        {
            jQueryObject fetchElement = querySettings.FetchXml;

            // Get the entities and link entities - only support 1 level deep
            jQueryObject entityElement = fetchElement.Find("entity");
            string       logicalName   = entityElement.GetAttribute("name");

            EntityQuery rootEntity;

            // Get query from cache or create new
            if (!EntityLookup.ContainsKey(logicalName))
            {
                rootEntity             = new EntityQuery();
                rootEntity.LogicalName = logicalName;
                rootEntity.Attributes  = new Dictionary <string, AttributeQuery>();
                EntityLookup[rootEntity.LogicalName] = rootEntity;
            }
            else
            {
                rootEntity = EntityLookup[logicalName];
            }

            // Get Linked Entities(1 deep)
            jQueryObject linkEntities = entityElement.Find("link-entity");

            linkEntities.Each(delegate(int index, Element element)
            {
                EntityQuery link = new EntityQuery();
                link.Attributes  = new Dictionary <string, AttributeQuery>();
                link.AliasName   = element.GetAttribute("alias").ToString();
                link.LogicalName = element.GetAttribute("name").ToString();
                link.Views       = new Dictionary <string, FetchQuerySettings>();

                if (!EntityLookup.ContainsKey(link.LogicalName))
                {
                    EntityLookup[link.LogicalName] = link;
                }
                else
                {
                    string alias   = link.AliasName;
                    link           = EntityLookup[link.LogicalName];
                    link.AliasName = alias;
                }

                if (!AliasEntityLookup.ContainsKey(link.AliasName))
                {
                    AliasEntityLookup[link.AliasName] = link;
                }
            });

            querySettings.RootEntity = rootEntity;

            // Issue #35 - Add any lookup/picklist quick find fields that are not included in results attributes will cause a format execption
            // because we don't have the metadata - this means that 'name' is not appended to the attribute

            // Add the search string and adjust any lookup columns
            jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']");

            conditions.First().Children().Each(delegate(int index, Element element)
            {
                logicalName    = element.GetAttribute("attribute").ToString();
                jQueryObject e = jQuery.FromElement(element);
                jQueryObject p = e.Parents("link-entity");
                if (!querySettings.RootEntity.Attributes.ContainsKey(logicalName))
                {
                    AttributeQuery attribute = new AttributeQuery();
                    attribute.LogicalName    = logicalName;
                    attribute.Columns        = new List <Column>();
                    querySettings.RootEntity.Attributes[logicalName] = attribute;
                }
            });
        }