Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
si1718-example-project-webapp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Daniel González Peña
si1718-example-project-webapp
Commits
a71de1e5
Commit
a71de1e5
authored
Nov 30, 2017
by
Daniel González Peña
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds Projects management
parent
e926d3ad
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
148 additions
and
0 deletions
+148
-0
ProjectsVM.java
src/main/java/dgpena/siexample/webapp/ProjectsVM.java
+95
-0
edit_projects.zul
src/main/webapp/edit_projects.zul
+53
-0
No files found.
src/main/java/dgpena/siexample/webapp/ProjectsVM.java
0 → 100644
View file @
a71de1e5
package
dgpena
.
siexample
.
webapp
;
import
java.util.List
;
import
javax.persistence.EntityManager
;
import
org.zkoss.bind.annotation.BindingParam
;
import
org.zkoss.bind.annotation.Command
;
import
org.zkoss.bind.annotation.Init
;
import
org.zkoss.bind.annotation.NotifyChange
;
import
dgpena.siexample.persistence.Employee
;
import
dgpena.siexample.persistence.Employees
;
import
dgpena.siexample.persistence.Project
;
import
dgpena.siexample.persistence.Projects
;
public
class
ProjectsVM
{
private
EntityManager
em
;
private
Projects
projects
;
private
Employees
employees
;
private
boolean
isEditing
=
false
;
// department under edition...
private
Project
currentProject
;
@Init
public
void
init
()
{
this
.
em
=
DesktopEntityManagerManager
.
getDesktopEntityManager
();
this
.
projects
=
new
Projects
(
em
);
this
.
employees
=
new
Employees
(
em
);
}
public
int
getProjectParticipants
(
@BindingParam
(
"p"
)
Project
p
)
{
return
p
.
getEmployees
().
size
();
}
public
List
<
Project
>
getProjects
()
{
return
this
.
projects
.
findAll
();
}
public
List
<
Employee
>
getEmployees
()
{
return
this
.
employees
.
findAll
();
}
public
Project
getCurrentProject
()
{
return
currentProject
;
}
public
void
setCurrentProject
(
Project
currentProject
)
{
this
.
currentProject
=
currentProject
;
}
@Command
@NotifyChange
(
"currentProject"
)
public
void
newProject
()
{
this
.
isEditing
=
false
;
this
.
currentProject
=
new
Project
();
}
@Command
@NotifyChange
(
"currentProject"
)
public
void
resetEditing
()
{
System
.
out
.
println
(
this
.
currentProject
.
getName
());
this
.
currentProject
=
null
;
}
@Command
@NotifyChange
({
"currentProject"
,
"projects"
})
public
void
saveProject
()
{
this
.
em
.
getTransaction
().
begin
();
if
(!
isEditing
)
{
this
.
projects
.
addNewProject
(
this
.
currentProject
);
}
this
.
em
.
getTransaction
().
commit
();
this
.
currentProject
=
null
;
}
@Command
@NotifyChange
(
"projects"
)
public
void
delete
(
@BindingParam
(
"p"
)
Project
department
)
{
this
.
em
.
getTransaction
().
begin
();
this
.
projects
.
deleteProject
(
department
);
this
.
em
.
getTransaction
().
commit
();
}
@Command
@NotifyChange
(
"currentProject"
)
public
void
edit
(
@BindingParam
(
"p"
)
Project
department
)
{
this
.
isEditing
=
true
;
this
.
currentProject
=
department
;
}
}
src/main/webapp/edit_projects.zul
0 → 100644
View file @
a71de1e5
<zk>
<window title="Projects" border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('dgpena.siexample.webapp.ProjectsVM')"
>
<window title="Project Editor" mode="modal" visible="@load(vm.currentProject ne null)">
Name: <textbox value="@load(vm.currentProject.name) @save(vm.currentProject.name, before='saveProject')"></textbox>
Employees:
<listbox model="@load(vm.employees)" multiple="true" checkmark="true" selectedItems="@load(vm.currentProject.employees) @save(vm.currentProject.employees, before='saveProject')">
<listhead>
<listheader label="name"></listheader>
</listhead>
<template name="model">
<listitem><listcell><label value="@load(each.name)"></label></listcell></listitem>
</template>
</listbox>
<hbox>
<button label="accept" onClick="@command('saveProject')"></button>
<button label="cancel" onClick="@command('resetEditing')"></button>
</hbox>
</window>
<groupbox mold="3d" closable="false">
<caption label="Projects list">
<button label="new" onClick="@command('newProject')"></button>
</caption>
<listbox model="@bind(vm.projects)">
<listhead>
<listheader label="name"></listheader>
<listheader label="participants"></listheader>
<listheader label="actions"></listheader>
</listhead>
<template name="model">
<listitem>
<listcell><label value="@bind(each.name)"></label></listcell>
<listcell><label value="@load(vm.getProjectParticipants(each))"></label></listcell>
<listcell>
<button label="edit" onClick="@command('edit', p=each)"></button>
<button label="delete" onClick="@command('delete', p=each)"></button>
</listcell>
</listitem>
</template>
</listbox>
</groupbox>
</window>
</zk>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment