Exemplo n.º 1
0
        public static void Init()
        {
            ActivitySubGridViewModel vm = new ActivitySubGridViewModel();

            // Add resize height event
            jQuery.Window.Resize(delegate(jQueryEvent e)
            {
                OnChangeHeight();
            });

            // Create Grid
            FetchQuerySettings config         = vm.ViewConfig;
            GridDataViewBinder dataViewBinder = new GridDataViewBinder();

            Grid grid = dataViewBinder.DataBindXrmGrid(config.DataView, config.Columns, "gridcontainer", "gridpager", true, false);


            dataViewBinder.BindClickHandler(grid);

            // Data Bind
            ViewBase.RegisterViewModel(vm);

            Window.SetTimeout(delegate()
            {
                vm.Init();
                OnChangeHeight();
                grid.ResizeCanvas();
            }, 0);
        }
Exemplo n.º 2
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];
                        if (entityRow.FormattedValues.ContainsKey(config.Columns[i].Field + "name"))
                        {
                            entityRow.FormattedValues[aliasName + "name"] = entityRow.FormattedValues[config.Columns[i].Field + "name"];
                        }
                        else
                        {
                            entityRow.FormattedValues[aliasName] = entityRow.GetAttributeValue(config.Columns[i].Field) as string;
                        }
                    }
                }
                // 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);
            }
        }
        public ActivitySubGridViewModel()
        {
            // Get the Quick Find View for the entity
            string getviewfetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                              <entity name='savedquery'>
                                <attribute name='name' />
                                <attribute name='fetchxml' />
                                <attribute name='layoutxml' />
                                <attribute name='returnedtypecode' />
                                <filter type='and'>
                                <filter type='or'>";

            getviewfetchXml += @"<condition attribute='returnedtypecode' operator='eq' value='" + "4200" + @"'/>";

            getviewfetchXml += @"
                                    </filter>
                                 <condition attribute='isquickfindquery' operator='eq' value='1'/>
                                    <condition attribute='isdefault' operator='eq' value='1'/>
                                </filter>
                               
                              </entity>
                            </fetch>";
            // Get the Quick Find View
            EntityCollection quickFindQuery = OrganizationServiceProxy.RetrieveMultiple(getviewfetchXml);

            _parser = new QueryParser();
            Entity view      = quickFindQuery.Entities[0];
            string fetchXml  = view.GetAttributeValueString("fetchxml");
            string layoutXml = view.GetAttributeValueString("layoutxml");

            // Parse the fetch and layout to get the attributes and columns
            ViewConfig          = _parser.Parse(fetchXml, layoutXml);
            ViewConfig.DataView = new EntityDataViewModel(10, typeof(Entity), true);

            // Load the display name metadata
            _parser.QueryDisplayNames();
        }
Exemplo n.º 4
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;
                }
            }

            // 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();
            });
        }
Exemplo n.º 5
0
        public ConnectionsViewModel(EntityReference parentRecordId, string[] connectToTypes, int pageSize, FetchQuerySettings view)
        {
            Connections = new EntityDataViewModel(pageSize, typeof(Connection), true);
            if (view != null)
            {
                _viewFetchXml = QueryParser.GetFetchXmlParentFilter(view, "record1id");
                // Set initial sort
                _defaultSortCol = new SortCol(view.OrderByAttribute, !view.OrderByDesending);
            }

            ParentRecordId.SetValue(parentRecordId);

            ObservableConnection connection = new ObservableConnection(connectToTypes);

            connection.Record2Id.SetValue(parentRecordId);
            ConnectionEdit = (Observable <ObservableConnection>)ValidatedObservableFactory.ValidatedObservable(connection);

            Connections.OnDataLoaded.Subscribe(Connections_OnDataLoaded);
            ConnectionEdit.GetValue().OnSaveComplete += ConnectionsViewModel_OnSaveComplete;
            ObservableConnection.RegisterValidation(Connections.ValidationBinder);
            AllowAddNew = Knockout.DependentObservable <bool>(AllowAddNewComputed);
        }