Example #1
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();
            });
        }
Example #2
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();
            });
        }