Esempio n. 1
0
        public void RecordSearchCommand(string term, Action<EntityCollection> callback)
        {
            if (_queryParser==null)
            {
                // Get the quick find metadata on first search
                _queryParser = new QueryParser(connectToTypes);
                _queryParser.GetQuickFinds();
                _queryParser.QueryMetadata();
            }

            // Get the option set values
            int resultsBack = 0;
            List<Entity> mergedEntities = new List<Entity>();
            Action<EntityCollection> result = delegate(EntityCollection fetchResult)
            {
                resultsBack++;
                FetchQuerySettings config = _queryParser.EntityLookup[fetchResult.EntityName].QuickFindQuery;
                // Add in the display Columns
                foreach (Dictionary<string,object> row in fetchResult.Entities)
                {
                    Entity entityRow = (Entity)(object)row;
                    int columnCount = config.Columns.Count<3 ? config.Columns.Count :3;
                    // Only get up to 3 columns
                    for (int i = 0; i < columnCount; i++)
                    {
                        // We use col<n> as the alias name so that we can show the correct values irrespective of the entity type
                        string aliasName = "col" + i.ToString();
                        row[aliasName] = row[config.Columns[i].Field];
                        entityRow.FormattedValues[aliasName + "name"] = entityRow.FormattedValues[config.Columns[i].Field + "name"];
                    }

                }
                // Merge in the results
                mergedEntities.AddRange((Entity[])(object)fetchResult.Entities.Items());
                
                mergedEntities.Sort(delegate (Entity x, Entity y){
                    return string.Compare(x.GetAttributeValueString("name"), y.GetAttributeValueString("name"));
                });
                if (resultsBack == connectToTypes.Length)
                {
                    EntityCollection results = new EntityCollection(mergedEntities);
                    callback(results);
                }
            };

            foreach (string entity in connectToTypes)
            {
                SearchRecords(term, result, entity);
            }
        }
Esempio n. 2
0
        private static void InitLocalisedContent()
        {
            
            Dictionary<string, string> parameters;
            string id;
            string logicalName;
            int pageSize = 10;
            string defaultView=null;            

#if DEBUG
            id = "C489707F-B5E2-E411-80D5-080027846324";
            logicalName = "account";
            parameters = new Dictionary<string, string>();         
           
#else
            parameters = PageEx.GetWebResourceData(); // The allowed lookup types for the connections - e.g. account, contact, opportunity. This must be passed as a data parameter to the webresource 'account=name&contact=fullname&opportunity=name
            id = ParentPage.Data.Entity.GetId();  
            logicalName =  ParentPage.Data.Entity.GetEntityName();
            ParentPage.Data.Entity.AddOnSave(CheckForSaved);
#endif
            EntityReference parent = new EntityReference(new Guid(id), logicalName, null);
            string entities = "account,contact,opportunity,systemuser";
            foreach (string key in parameters.Keys)
            {
                switch (key.ToLowerCase())
                {
                    case "entities":
                        entities = parameters[key];
                        break;
                    case "pageSize":
                        pageSize = int.Parse(parameters[key]);
                        break;
                    case "view":
                        defaultView = parameters[key];
                        break;
                    case "category":
                        category = int.Parse(parameters[key]);
                        break;
                }
            }
           
            // Get the view
            QueryParser queryParser = new QueryParser(new string[] {"connection"});
            queryParser.GetView("connection", defaultView);
            queryParser.QueryMetadata();
            EntityQuery connectionViews = queryParser.EntityLookup["connection"];
            string viewName = connectionViews.Views.Keys[0];
            FetchQuerySettings view = connectionViews.Views[viewName];

            vm = new ConnectionsViewModel(parent, entities.Split(","), pageSize, view);
            
            // Bind Connections grid
            GridDataViewBinder connectionsGridDataBinder = new GridDataViewBinder();
            List<Column> columns = view.Columns;

            // Role2Id Column - provided it is in the view!
            foreach (Column col in columns)
            {
                switch (col.Field)
                {
                    case "record2roleid":
                        XrmLookupEditor.BindColumn(col, vm.RoleSearchCommand, "connectionroleid", "name,category", "");
                        break;
                    case "description":
                        XrmTextEditor.BindColumn(col);
                        break;
                    case "effectivestart":
                    case "effectiveend":
                        XrmDateEditor.BindColumn(col, true);
                        break;
                }
            }
           

            connectionsGrid = connectionsGridDataBinder.DataBindXrmGrid(vm.Connections, columns, "container", "pager", true, false);

            connectionsGrid.OnActiveCellChanged.Subscribe(delegate(EventData e, object data)
            {
                OnCellChangedEventData eventData = (OnCellChangedEventData)data;
                vm.SelectedConnection.SetValue((Connection)connectionsGrid.GetDataItem(eventData.Row));
            });

            connectionsGridDataBinder.BindClickHandler(connectionsGrid);
            // Let's not use a hover button because it get's in the way of the editable grid!
            //RowHoverPlugin rowButtons = new RowHoverPlugin("gridButtons");
            //connectionsGrid.RegisterPlugin(rowButtons);

            ViewBase.RegisterViewModel(vm);

            OverrideMetadata();

            jQuery.Window.Resize(OnResize);
            jQuery.OnDocumentReady(delegate()
            {
                OnResize(null);
                vm.Search();
            });
        }