public void HandleMouseEnter(EventData e, object item) { OnCellChangedEventData cell = (OnCellChangedEventData)(object)_grid.GetCellFromEvent(e); if (cell != null) { _mouseOut = false; Entity entityRow = (Entity)_grid.GetDataItem(cell.Row); if (entityRow != null) { Script.Literal("{0}.getGridPosition()", _grid); int viewPortRight = _grid.GetViewport().RightPx; int viewPortLeft = _grid.GetViewport().LeftPx; jQueryObject node = jQuery.Select((string)Script.Literal("{0}.getCellNode({1},{2})", _grid, cell.Row, cell.Cell)); int buttonsWidth = _hoverButtons.GetWidth(); int x = node.Parent().GetWidth(); if (viewPortRight < x + buttonsWidth) { x = viewPortRight - buttonsWidth; } int y = 0; node.Parent().Append(_hoverButtons); _hoverButtons.CSS("left", x.ToString() + "px"); _hoverButtons.CSS("top", y.ToString() + "px"); _hoverButtons.CSS("display", "block"); _hoverButtons.Attribute("rowId", entityRow.Id.ToString()); } } }
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(); }); }
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(); }); }
public void DataBindEvents(Grid grid, DataViewBase dataView, string gridContainerDivId) { // Data Sorting grid.OnSort.Subscribe(delegate(EventData o, Object item) { SortColData sorting = (SortColData)item; dataView.Sort(sorting); grid.Invalidate(); grid.Render(); }); // Session Grid DataBinding grid.OnAddNewRow.Subscribe(delegate(EventData o, Object item) { EditEventData data = (EditEventData)item; dataView.AddItem(data.item); Column column = data.column; grid.InvalidateRow(dataView.GetLength() - 1); grid.UpdateRowCount(); grid.Render(); }); dataView.OnRowsChanged.Subscribe(delegate(EventData e, object a) { OnRowsChangedEventArgs args = (OnRowsChangedEventArgs)a; if (args != null && args.Rows != null) { grid.InvalidateRows(args.Rows); grid.Render(); } else { // Assume that a new row has been added grid.InvalidateRow(dataView.GetLength()); grid.UpdateRowCount(); grid.Render(); } grid.ResizeCanvas(); }); jQueryObject loadingIndicator = null; // Wire up the validation error jQueryObject validationIndicator = null; Action <EventData, object> clearValidationIndicator = delegate(EventData e, object a) { if (validationIndicator != null) { validationIndicator.Hide(); validationIndicator.Remove(); } }; grid.OnCellChange.Subscribe(clearValidationIndicator); grid.OnActiveCellChanged.Subscribe(clearValidationIndicator); grid.OnBeforeCellEditorDestroy.Subscribe(clearValidationIndicator); grid.OnValidationError.Subscribe(delegate(EventData e, object a) { ValidationEventArgs args = (ValidationEventArgs)a; ValidationResult validationResult = (ValidationResult)args.ValidationResults; jQueryObject activeCellNode = (jQueryObject)args.CellNode; object editor = args.Editor; string errorMessage = ""; if (validationResult.Message != null) { errorMessage = validationResult.Message; } bool valid_result = validationResult.Valid; // Add the message to the tooltip on the cell if (!valid_result) { jQuery.FromObject(activeCellNode).Attribute("title", errorMessage); clearValidationIndicator(e, a); validationIndicator = jQuery.FromHtml("<div class='popup-box-container'><div width='16px' height='16px' class='sparkle-imagestrip-inlineedit_warning popup-box-icon' alt='Error' id='icon'/><div class='popup-box validation-text'/></div>").AppendTo(Document.Body); validationIndicator.Find(".validation-text").Text(errorMessage); string colisionPosition = ValidationPopupUseFitPosition ? "fit fit" : "none none"; Script.Literal(@"{0}.position({{ my: 'left bottom', at: 'left top', collision: '{2}', of: {1} }}) .show({{ effect: 'blind' }}) .delay( 500000 ) .hide({{ effect: 'fade', duration: 'slow', }}, function() {{ $( this ).remove(); }}); ", validationIndicator, activeCellNode, colisionPosition); } else { clearValidationIndicator(e, a); jQuery.FromObject(activeCellNode).Attribute("title", ""); } }); // Wire up the loading spinner dataView.OnDataLoading.Subscribe(delegate(EventData e, object a) { loadingIndicator = ShowLoadingIndicator(loadingIndicator, gridContainerDivId); foreach (Column col in grid.GetColumns()) { if (col.MaxWidth != null) { col.MaxWidth = 400; } } }); dataView.OnDataLoaded.Subscribe(delegate(EventData e, object a) { DataLoadedNotifyEventArgs args = (DataLoadedNotifyEventArgs)a; if (args != null) { if (args.ErrorMessage == null) { for (int i = args.From; i <= args.To; i++) { grid.InvalidateRow(i); } grid.UpdateRowCount(); grid.Render(); } else { Script.Alert("There was a problem refreshing the grid.\nPlease contact your system administrator:\n" + args.ErrorMessage); } } if (loadingIndicator != null) { loadingIndicator.Plugin <jQueryBlockUI>().Unblock(); } }); // Wire up edit complete to property changed grid.OnCellChange.Subscribe(delegate(EventData e, object data) { OnCellChangedEventData eventData = (OnCellChangedEventData)data; dataView.RaisePropertyChanged(""); }); }