public MultiSearchViewModel2013()
        {
            OrganizationServiceProxy.WithCredentials = true;

            // Get Config
            Dictionary <string, string> dataConfig = PageEx.GetWebResourceData();

            // Query the quick search entities
            QueryQuickSearchEntities();
            Dictionary <string, Entity> views = GetViewQueries();

            _parser = new QueryParser();

            foreach (string typeName in _entityTypeNames)
            {
                Entity view      = views[typeName];
                string fetchXml  = view.GetAttributeValueString("fetchxml");
                string layoutXml = view.GetAttributeValueString("layoutxml");

                // Parse the fetch and layout to get the attributes and columns
                FetchQuerySettings config = _parser.Parse(fetchXml, layoutXml);
                config.RecordCount = Knockout.Observable <string>();

                config.DataView = new VirtualPagedEntityDataViewModel(25, typeof(Entity), true);
                config.RecordCount.SetValue(GetResultLabel(config));
                Config.Push(config);


                // Wire up record count change
                config.DataView.OnPagingInfoChanged.Subscribe(OnPagingInfoChanged(config));
            }

            _parser.QueryDisplayNames();
        }
Exemplo n.º 2
0
        private static void InitLocalisedContent()
        {
            Dictionary <string, string> parameters;
            string id;
            string logicalName;
            int    pageSize = 10;

#if DEBUG
            id          = "3D5A7E01-0B3F-E811-A952-000D3AB899D0";
            logicalName = "account";
            parameters  = new Dictionary <string, string>();
#else
            parameters  = PageEx.GetWebResourceData();
            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);
            jQuery.Window.Resize(OnResize);
            vm = new ContactsViewModel(parent, pageSize);

            GridDataViewBinder contactsDataBinder = new GridDataViewBinder();
            List <Column>      columns            = GridDataViewBinder.ParseLayout(ResourceStrings.LastName + ",lastname,200," + ResourceStrings.FirstName + ",firstname,200," + ResourceStrings.PreferredContactMethodCode + ",preferredcontactmethodcode,120," + ResourceStrings.CreditLimit + ",creditlimit,120");
            contactsGrid = contactsDataBinder.DataBindXrmGrid(vm.Contacts, columns, "container", "pager", true, false);

            foreach (Column col in columns)
            {
                switch (col.Field)
                {
                case "preferredcontactmethodcode":
                    XrmOptionSetEditor.BindColumn(col, "contact", "preferredcontactmethodcode", true);
                    break;

                case "firstname":
                case "lastname":
                    XrmTextEditor.BindColumn(col);
                    break;

                case "creditlimit":
                    XrmMoneyEditor.BindColumn(col, 0, 1000000000);
                    break;
                }
            }

            ViewBase.RegisterViewModel(vm);
            OnResize(null);
            jQuery.OnDocumentReady(delegate()
            {
                vm.Search();
            }
                                   );
        }
Exemplo n.º 3
0
        private static void InitLocalisedContent()
        {
            Dictionary <string, string> entityTypes;
            string id;
            string logicalName;

#if DEBUG
            id                         = "C489707F-B5E2-E411-80D5-080027846324";
            logicalName                = "account";
            entityTypes                = new Dictionary <string, string>();
            entityTypes["account"]     = "name";
            entityTypes["contact"]     = "fullname";
            entityTypes["opportunity"] = "name";
#else
            entityTypes = 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();
#endif
            EntityReference parent = new EntityReference(new Guid(id), logicalName, null);
            vm = new ConnectionsViewModel(parent, entityTypes);
            // Bind Connections grid
            GridDataViewBinder contactGridDataBinder = new GridDataViewBinder();
            List <Column>      columns = GridDataViewBinder.ParseLayout(String.Format("{0},record1id,250,{1},record1roleid,250", ResourceStrings.ConnectTo, ResourceStrings.Role));

            // Role2Id Column
            XrmLookupEditor.BindColumn(columns[1], vm.RoleSearchCommand, "connectionroleid", "name", "");

            connectionsGrid = contactGridDataBinder.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));
            });

            // Let's not use a hover button because it get's n 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.º 4
0
        public MultiSearchViewModel2013()
        {
            //OrganizationServiceProxy.WithCredentials = true;
            DependentObservableOptions <string> throttledSearchTermObservable = new DependentObservableOptions <string>();

            throttledSearchTermObservable.Model            = this;
            throttledSearchTermObservable.GetValueFunction = new Func <string>(delegate
            {
                return(this.SearchTerm.GetValue());
            });
            ThrottledSearchTerm = Knockout.DependentObservable <string>(throttledSearchTermObservable).Extend(new Dictionary("throttle", 400));
            ThrottledSearchTerm.Subscribe(new Action <string>(delegate(string search)
            {
                // Search whilst typing using the throttle extension
                SearchCommand();
            }));

            // Get Config
            Dictionary <string, string> dataConfig = PageEx.GetWebResourceData();

            // Query the quick search entities
            QueryQuickSearchEntities();
            Dictionary <string, Entity> views = GetViewQueries();

            _parser = new QueryParser();

            foreach (string typeName in _entityTypeNames)
            {
                Entity view      = views[typeName];
                string fetchXml  = view.GetAttributeValueString("fetchxml");
                string layoutXml = view.GetAttributeValueString("layoutxml");

                // Parse the fetch and layout to get the attributes and columns
                FetchQuerySettings config = _parser.Parse(fetchXml, layoutXml);
                config.RecordCount = Knockout.Observable <string>();

                config.DataView = new VirtualPagedEntityDataViewModel(25, typeof(Entity), true);
                config.RecordCount.SetValue(GetResultLabel(config));
                Config.Push(config);


                // Wire up record count change
                config.DataView.OnPagingInfoChanged.Subscribe(OnPagingInfoChanged(config));
            }

            _parser.QueryDisplayNames();
        }
Exemplo n.º 5
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.º 6
0
        public MultiSearchViewModel()
        {
            // Get Config
            Dictionary <string, string> dataConfig = PageEx.GetWebResourceData();

            List <string> typeCodes = new List <string>();
            List <string> typeNames = new List <string>();

            // There is an odd behaviour with the savedquery fetchxml where you query with typecodes and get back typenames
            // so we need both to preserve the display order
            if (dataConfig.ContainsKey("typeCodes"))
            {
                typeCodes = (List <string>)(object) dataConfig["typeCodes"].Split(",");
                typeNames = (List <string>)(object) dataConfig["typeNames"].Split(",");
            }
            else
            {
                typeCodes = new List <string>("1", "2", "4", "4200", "3");
                typeNames = new List <string>("account", "contact", "lead", "activitypointer", "opportunity");
            }

            // 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'>";

            foreach (string view in typeCodes)
            {
                getviewfetchXml += @"<condition attribute='returnedtypecode' operator='eq' value='" + view + @"'/>";
            }
            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();
            Dictionary <string, Entity> entityLookup = new Dictionary <string, Entity>();

            // Preseve the requested view order
            foreach (Entity view in quickFindQuery.Entities)
            {
                entityLookup[view.GetAttributeValueString("returnedtypecode")] = view;
            }
            foreach (string typeName in typeNames)
            {
                Entity view      = entityLookup[typeName];
                string fetchXml  = view.GetAttributeValueString("fetchxml");
                string layoutXml = view.GetAttributeValueString("layoutxml");

                // Parse the fetch and layout to get the attributes and columns
                FetchQuerySettings config = parser.Parse(fetchXml, layoutXml);
                config.DataView = new EntityDataViewModel(10, typeof(Entity), true);
                Config.Push(config);
            }

            // Load the display name metadata
            parser.QueryDisplayNames();
        }