Last active
November 6, 2018 15:18
-
-
Save PadreSVK/6d0ab1b5120e255ba699773432d6bac5 to your computer and use it in GitHub Desktop.
Project detail after add change manager functionality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@viewModel DotVVM.Samples.NestedViewModel.ViewModels.Projects.ProjectDetailViewModel, DotVVM.Samples.NestedViewModel | |
@masterPage Views/MasterPage.dotmaster | |
@import DotVVM.Samples.NestedViewModel.Resources | |
<dot:Content ContentPlaceHolderID="MainContent"> | |
<div DataContext="{value: Project}"> | |
<h1 InnerText="{value: Title}" /> | |
<br> | |
<dot:Literal Text="{resource: Texts.Label_Manager}" /><small InnerText="{value: Manager.FullName}" /> | |
<dot:Button Click="{command: _parent.InitModal()}" Visible="{value !_parent.IsModalVisible}" Text="{resource: Texts.Label_ChangeManager}"></dot:Button> | |
<p InnerText="{value: Description}" /> | |
</div> | |
<dot:Button Click="{command: Save()}" Text="{resource: Texts.Label_Save}"/> | |
<div Visible="{value: IsModalVisible}" CssClasses="modal"> | |
<div class="modal-content"> | |
<dot:Button Click="{command: CloseModal()}" class="close" Text="×" /> | |
<dot:GridView DataSource="{value: Users}" class="page-grid"> | |
<Columns> | |
<dot:GridViewTextColumn ValueBinding="{value: FullName}" HeaderText="{resource: Texts.Label_Name}" /> | |
<dot:GridViewTemplateColumn> | |
<dot:Button Click="{command: _parent.AssignManager(_this)}" Text="{resource: Texts.Label_AssignManager}" /> | |
</dot:GridViewTemplateColumn> | |
</Columns> | |
</dot:GridView> | |
</div> | |
</div> | |
</dot:Content> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DotVVM.Framework.Controls; | |
using DotVVM.Framework.ViewModel; | |
using DotVVM.Samples.NestedViewModel.DAL.Entities; | |
using DotVVM.Samples.NestedViewModel.Services; | |
using Task = System.Threading.Tasks.Task; | |
namespace DotVVM.Samples.NestedViewModel.ViewModels.Projects | |
{ | |
public class ProjectDetailViewModel : MasterPageViewModel | |
{ | |
private readonly ProjectService _projectService; | |
private readonly UsersService _usersService; | |
public ProjectDetailViewModel(ProjectService projectService, UsersService usersService) | |
{ | |
_projectService = projectService; | |
_usersService = usersService; | |
} | |
[FromRoute(nameof(Id))] public int Id { get; set; } | |
public Project Project { get; set; } | |
public bool IsModalVisible { get; set; } | |
public GridViewDataSet<User> Users { get; set; } | |
public void Save() | |
{ | |
_projectService.Save(Project); | |
} | |
public override Task Load() | |
{ | |
if (!Context.IsPostBack) | |
{ | |
Project = _projectService.GetById(Id); | |
} | |
return base.Load(); | |
} | |
public override Task PreRender() | |
{ | |
if (Users?.IsRefreshRequired == true) | |
{ | |
_usersService.LoadUsersDataSet(Users); | |
} | |
return base.PreRender(); | |
} | |
public void InitModal() | |
{ | |
IsModalVisible = true; | |
Users = new GridViewDataSet<User> | |
{ | |
PagingOptions = {PageSize = DefaultPageSize} | |
}; | |
Users.RequestRefresh(); | |
} | |
public void CloseModal() | |
{ | |
IsModalVisible = false; | |
Users = default; | |
} | |
public void AssignManager(User user) | |
{ | |
Project.Manager = user; | |
CloseModal(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment