You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by tv...@apache.org on 2013/09/22 23:21:48 UTC
svn commit: r1525449 - in /tomee/tomee/trunk/examples/moviefun-rest: ./
src/main/java/org/superbiz/moviefun/
src/main/java/org/superbiz/moviefun/rest/ src/main/webapp/
src/main/webapp/WEB-INF/ src/main/webapp/app/ src/main/webapp/app/js/
src/main/webap...
Author: tveronezi
Date: Sun Sep 22 21:21:47 2013
New Revision: 1525449
URL: http://svn.apache.org/r1525449
Log:
https://issues.apache.org/jira/browse/TOMEE-1037
Added:
tomee/tomee/trunk/examples/moviefun-rest/Makefile
tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/
tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/ApplicationConfig.java
tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/LoadRest.java
tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/MoviesRest.java
- copied, changed from r1524967, tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/MoviesBean.java
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/app.less
- copied, changed from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/app.less
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/config.js
- copied, changed from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/config.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/application.js
- copied, changed from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/application.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/i18n.js
- copied, changed from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/i18n.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/id.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/log.js
- copied unchanged from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/log.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movie.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movies.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/start.js
- copied unchanged from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/start.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates.js
- copied, changed from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/templates.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-paginator-button.handlebars
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-row.handlebars
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application.handlebars
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/container.handlebars
- copied, changed from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/templates/container.handlebars
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/load-data-link.handlebars
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/movie.handlebars
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-paginator.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-row.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/container.js
- copied, changed from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/view/container.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/movie.js
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/application.jsp
Removed:
tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/ActionServlet.java
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/WEB-INF/moviefun.jsp
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/assets/
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/default.css
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/index.jsp
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/setup.jsp
tomee/tomee/trunk/examples/moviefun-rest/src/test/java/org/superbiz/moviefun/MoviesTest.java
Modified:
tomee/tomee/trunk/examples/moviefun-rest/pom.xml
tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/Movie.java
tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/MoviesBean.java
tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/WEB-INF/web.xml
tomee/tomee/trunk/examples/moviefun-rest/src/test/java/org/superbiz/moviefun/MoviesRestTest.java
Added: tomee/tomee/trunk/examples/moviefun-rest/Makefile
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/Makefile?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/Makefile (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/Makefile Sun Sep 22 21:21:47 2013
@@ -0,0 +1,20 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+up-static:
+ rm -rf target/apache-tomee/webapps/moviefun/app
+ cp -r src/main/webapp/app target/apache-tomee/webapps/moviefun/
+
+.PHONY: up-static
+
Modified: tomee/tomee/trunk/examples/moviefun-rest/pom.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/pom.xml?rev=1525449&r1=1525448&r2=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/pom.xml (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/pom.xml Sun Sep 22 21:21:47 2013
@@ -19,7 +19,7 @@
<artifactId>moviefun-rest</artifactId>
<packaging>war</packaging>
<version>1.1-SNAPSHOT</version>
- <name>OpenEJB :: Web Examples :: Moviefun</name>
+ <name>OpenEJB :: Web Examples :: Moviefun Rest</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tomee.version>1.6.0-SNAPSHOT</tomee.version>
@@ -36,6 +36,31 @@
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
+ <groupId>com.googlecode.jslint4java</groupId>
+ <artifactId>jslint4java-maven-plugin</artifactId>
+ <version>2.0.5</version>
+ <configuration>
+ <failOnError>true</failOnError>
+ <options>
+ <vars>true</vars>
+ <unparam>true</unparam>
+ <predef>define,require,requirejs,window,Backbone,_,$,Handlebars,APP_CONFIG</predef>
+ <indent>4</indent>
+ </options>
+ <sourceFolders>
+ <sourceFolder>${basedir}/src/main/webapp/app/js</sourceFolder>
+ </sourceFolders>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>install</phase>
+ <goals>
+ <goal>lint</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
@@ -63,7 +88,6 @@
</plugin>
</plugins>
</build>
-
<dependencies>
<dependency>
<groupId>org.apache.openejb</groupId>
@@ -101,6 +125,46 @@
<version>1.6.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>webaccess-gui-backbone</artifactId>
+ <version>${tomee.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>webaccess-gui-bootstrap</artifactId>
+ <version>${tomee.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>webaccess-gui-jquery</artifactId>
+ <version>${tomee.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>webaccess-gui-handlebars</artifactId>
+ <version>${tomee.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>webaccess-gui-json2</artifactId>
+ <version>${tomee.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>webaccess-gui-lessjs</artifactId>
+ <version>${tomee.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>webaccess-gui-requirejs</artifactId>
+ <version>${tomee.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>webaccess-gui-underscorejs</artifactId>
+ <version>${tomee.version}</version>
+ </dependency>
</dependencies>
<!-- This section allows you to configure where to publish libraries for
sharing. It is not required and may be deleted. For more information see:
Modified: tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/Movie.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/Movie.java?rev=1525449&r1=1525448&r2=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/Movie.java (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/Movie.java Sun Sep 22 21:21:47 2013
@@ -21,14 +21,10 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.xml.bind.annotation.XmlRootElement;
-import java.io.Serializable;
@Entity
@XmlRootElement(name = "movie")
-public class Movie implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
+public class Movie {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
Modified: tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/MoviesBean.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/MoviesBean.java?rev=1525449&r1=1525448&r2=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/MoviesBean.java (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/MoviesBean.java Sun Sep 22 21:21:47 2013
@@ -20,122 +20,67 @@ import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Path;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
+import javax.persistence.criteria.*;
import javax.persistence.metamodel.EntityType;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
import java.util.List;
-
-@javax.ws.rs.Path("movies")
-@Produces({"application/json"})
@Stateless
public class MoviesBean {
@PersistenceContext(unitName = "movie-unit")
private EntityManager entityManager;
- @GET()
- @javax.ws.rs.Path("{id}")
- public Movie find(@PathParam("id") Long id) {
+ public Movie find(Long id) {
return entityManager.find(Movie.class, id);
}
- @POST
- @javax.ws.rs.Path("create")
public void addMovie(Movie movie) {
entityManager.persist(movie);
}
- @PUT
- @javax.ws.rs.Path("edit")
public void editMovie(Movie movie) {
entityManager.merge(movie);
}
- public void deleteMovie(Movie movie) {
- entityManager.remove(movie);
- }
-
- @DELETE
- @javax.ws.rs.Path("delete/{id}")
- public void deleteMovieId(@PathParam("id") long id) {
+ public void deleteMovie(long id) {
Movie movie = entityManager.find(Movie.class, id);
- deleteMovie(movie);
+ entityManager.remove(movie);
}
- @GET
- @javax.ws.rs.Path("list")
- public List<Movie> getMovies() {
- CriteriaQuery<Movie> cq = entityManager.getCriteriaBuilder().createQuery(Movie.class);
- cq.select(cq.from(Movie.class));
- return entityManager.createQuery(cq).getResultList();
- }
-
- @GET()
- @javax.ws.rs.Path("list/{first}/{max}")
- public List<Movie> findAll(@PathParam("first") int firstResult, @PathParam("max") int maxResults) {
- CriteriaQuery<Movie> cq = entityManager.getCriteriaBuilder().createQuery(Movie.class);
- cq.select(cq.from(Movie.class));
+ public List<Movie> getMovies(Integer firstResult, Integer maxResults, String field, String searchTerm) {
+ CriteriaBuilder qb = entityManager.getCriteriaBuilder();
+ CriteriaQuery<Movie> cq = qb.createQuery(Movie.class);
+ Root<Movie> root = cq.from(Movie.class);
+ EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
+ if (field != null && searchTerm != null && !"".equals(field.trim()) && !"".equals(searchTerm.trim())) {
+ Path<String> path = root.get(type.getDeclaredSingularAttribute(field.trim(), String.class));
+ Predicate condition = qb.like(path, "%" + searchTerm.trim() + "%");
+ cq.where(condition);
+ }
TypedQuery<Movie> q = entityManager.createQuery(cq);
- q.setMaxResults(maxResults);
- q.setFirstResult(firstResult);
+ if (maxResults != null) {
+ q.setMaxResults(maxResults);
+ }
+ if (firstResult != null) {
+ q.setFirstResult(firstResult);
+ }
return q.getResultList();
}
- @GET()
- @javax.ws.rs.Path("count")
- public int countAll() {
- CriteriaQuery<Long> cq = entityManager.getCriteriaBuilder().createQuery(Long.class);
- Root<Movie> rt = cq.from(Movie.class);
- cq.select(entityManager.getCriteriaBuilder().count(rt));
- TypedQuery<Long> q = entityManager.createQuery(cq);
- return (q.getSingleResult()).intValue();
- }
-
- @GET()
- @javax.ws.rs.Path("count/{field}/{searchTerm}")
- public int count(@PathParam("field") String field, @PathParam("searchTerm") String searchTerm) {
+ public int count(String field, String searchTerm) {
CriteriaBuilder qb = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> cq = qb.createQuery(Long.class);
Root<Movie> root = cq.from(Movie.class);
EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
-
- Path<String> path = root.get(type.getDeclaredSingularAttribute(field, String.class));
- Predicate condition = qb.like(path, "%" + searchTerm + "%");
-
cq.select(qb.count(root));
- cq.where(condition);
-
+ if (field != null && searchTerm != null && !"".equals(field.trim()) && !"".equals(searchTerm.trim())) {
+ Path<String> path = root.get(type.getDeclaredSingularAttribute(field.trim(), String.class));
+ Predicate condition = qb.like(path, "%" + searchTerm.trim() + "%");
+ cq.where(condition);
+ }
return entityManager.createQuery(cq).getSingleResult().intValue();
}
- @GET()
- @javax.ws.rs.Path("list/{field}/{searchTerm}/{first}/{max}")
- public List<Movie> findRange(String field, String searchTerm, int firstResult, int maxResults) {
- CriteriaBuilder qb = entityManager.getCriteriaBuilder();
- CriteriaQuery<Movie> cq = qb.createQuery(Movie.class);
- Root<Movie> root = cq.from(Movie.class);
- EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
-
- Path<String> path = root.get(type.getDeclaredSingularAttribute(field, String.class));
- Predicate condition = qb.like(path, "%" + searchTerm + "%");
-
- cq.where(condition);
- TypedQuery<Movie> q = entityManager.createQuery(cq);
- q.setMaxResults(maxResults);
- q.setFirstResult(firstResult);
- return q.getResultList();
- }
-
public void clean() {
entityManager.createQuery("delete from Movie").executeUpdate();
}
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/ApplicationConfig.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/ApplicationConfig.java?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/ApplicationConfig.java (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/ApplicationConfig.java Sun Sep 22 21:21:47 2013
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.moviefun.rest;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+@ApplicationPath("/rest")
+public class ApplicationConfig extends Application {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Set<Class<?>> getClasses() {
+ return new HashSet<Class<?>>(Arrays.asList(LoadRest.class, MoviesRest.class));
+ }
+}
\ No newline at end of file
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/LoadRest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/LoadRest.java?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/LoadRest.java (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/LoadRest.java Sun Sep 22 21:21:47 2013
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.moviefun.rest;
+
+import org.superbiz.moviefun.Movie;
+import org.superbiz.moviefun.MoviesBean;
+
+import javax.ejb.EJB;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+@Path("load")
+public class LoadRest {
+ @EJB
+ private MoviesBean moviesBean;
+
+ @POST
+ public void load() {
+ moviesBean.addMovie(new Movie("Wedding Crashers", "David Dobkin", "Comedy", 7, 2005));
+ moviesBean.addMovie(new Movie("Starsky & Hutch", "Todd Phillips", "Action", 6, 2004));
+ moviesBean.addMovie(new Movie("Shanghai Knights", "David Dobkin", "Action", 6, 2003));
+ moviesBean.addMovie(new Movie("I-Spy", "Betty Thomas", "Adventure", 5, 2002));
+ moviesBean.addMovie(new Movie("The Royal Tenenbaums", "Wes Anderson", "Comedy", 8, 2001));
+ moviesBean.addMovie(new Movie("Zoolander", "Ben Stiller", "Comedy", 6, 2001));
+ moviesBean.addMovie(new Movie("Shanghai Noon", "Tom Dey", "Comedy", 7, 2000));
+ }
+
+}
\ No newline at end of file
Copied: tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/MoviesRest.java (from r1524967, tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/MoviesBean.java)
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/MoviesRest.java?p2=tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/MoviesRest.java&p1=tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/MoviesBean.java&r1=1524967&r2=1525449&rev=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/MoviesBean.java (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/java/org/superbiz/moviefun/rest/MoviesRest.java Sun Sep 22 21:21:47 2013
@@ -14,129 +14,59 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.superbiz.moviefun;
+package org.superbiz.moviefun.rest;
-import javax.ejb.Stateless;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.TypedQuery;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Path;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-import javax.persistence.metamodel.EntityType;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import java.util.List;
+import org.superbiz.moviefun.Movie;
+import org.superbiz.moviefun.MoviesBean;
+import javax.ejb.EJB;
+import javax.ws.rs.*;
+import java.util.List;
-@javax.ws.rs.Path("movies")
+@Path("movies")
@Produces({"application/json"})
-@Stateless
-public class MoviesBean {
+public class MoviesRest {
- @PersistenceContext(unitName = "movie-unit")
- private EntityManager entityManager;
+ @EJB
+ private MoviesBean service;
- @GET()
- @javax.ws.rs.Path("{id}")
+ @GET
+ @Path("{id}")
public Movie find(@PathParam("id") Long id) {
- return entityManager.find(Movie.class, id);
+ return service.find(id);
}
- @POST
- @javax.ws.rs.Path("create")
- public void addMovie(Movie movie) {
- entityManager.persist(movie);
+ @GET
+ public List<Movie> getMovies(@QueryParam("first") Integer first, @QueryParam("max") Integer max,
+ @QueryParam("field") String field, @QueryParam("searchTerm") String searchTerm) {
+ return service.getMovies(first, max, field, searchTerm);
}
- @PUT
- @javax.ws.rs.Path("edit")
- public void editMovie(Movie movie) {
- entityManager.merge(movie);
+ @POST
+ @Consumes("application/json")
+ public Movie addMovie(Movie movie) {
+ service.addMovie(movie);
+ return movie;
}
- public void deleteMovie(Movie movie) {
- entityManager.remove(movie);
+ @PUT
+ @Path("{id}")
+ @Consumes("application/json")
+ public Movie editMovie(Movie movie) {
+ service.editMovie(movie);
+ return movie;
}
@DELETE
- @javax.ws.rs.Path("delete/{id}")
- public void deleteMovieId(@PathParam("id") long id) {
- Movie movie = entityManager.find(Movie.class, id);
- deleteMovie(movie);
+ @Path("{id}")
+ public void deleteMovie(@PathParam("id") long id) {
+ service.deleteMovie(id);
}
@GET
- @javax.ws.rs.Path("list")
- public List<Movie> getMovies() {
- CriteriaQuery<Movie> cq = entityManager.getCriteriaBuilder().createQuery(Movie.class);
- cq.select(cq.from(Movie.class));
- return entityManager.createQuery(cq).getResultList();
- }
-
- @GET()
- @javax.ws.rs.Path("list/{first}/{max}")
- public List<Movie> findAll(@PathParam("first") int firstResult, @PathParam("max") int maxResults) {
- CriteriaQuery<Movie> cq = entityManager.getCriteriaBuilder().createQuery(Movie.class);
- cq.select(cq.from(Movie.class));
- TypedQuery<Movie> q = entityManager.createQuery(cq);
- q.setMaxResults(maxResults);
- q.setFirstResult(firstResult);
- return q.getResultList();
- }
-
- @GET()
- @javax.ws.rs.Path("count")
- public int countAll() {
- CriteriaQuery<Long> cq = entityManager.getCriteriaBuilder().createQuery(Long.class);
- Root<Movie> rt = cq.from(Movie.class);
- cq.select(entityManager.getCriteriaBuilder().count(rt));
- TypedQuery<Long> q = entityManager.createQuery(cq);
- return (q.getSingleResult()).intValue();
- }
-
- @GET()
- @javax.ws.rs.Path("count/{field}/{searchTerm}")
- public int count(@PathParam("field") String field, @PathParam("searchTerm") String searchTerm) {
- CriteriaBuilder qb = entityManager.getCriteriaBuilder();
- CriteriaQuery<Long> cq = qb.createQuery(Long.class);
- Root<Movie> root = cq.from(Movie.class);
- EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
-
- Path<String> path = root.get(type.getDeclaredSingularAttribute(field, String.class));
- Predicate condition = qb.like(path, "%" + searchTerm + "%");
-
- cq.select(qb.count(root));
- cq.where(condition);
-
- return entityManager.createQuery(cq).getSingleResult().intValue();
- }
-
- @GET()
- @javax.ws.rs.Path("list/{field}/{searchTerm}/{first}/{max}")
- public List<Movie> findRange(String field, String searchTerm, int firstResult, int maxResults) {
- CriteriaBuilder qb = entityManager.getCriteriaBuilder();
- CriteriaQuery<Movie> cq = qb.createQuery(Movie.class);
- Root<Movie> root = cq.from(Movie.class);
- EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
-
- Path<String> path = root.get(type.getDeclaredSingularAttribute(field, String.class));
- Predicate condition = qb.like(path, "%" + searchTerm + "%");
-
- cq.where(condition);
- TypedQuery<Movie> q = entityManager.createQuery(cq);
- q.setMaxResults(maxResults);
- q.setFirstResult(firstResult);
- return q.getResultList();
+ @Path("count")
+ public int count(@QueryParam("field") String field, @QueryParam("searchTerm") String searchTerm) {
+ return service.count(field, searchTerm);
}
- public void clean() {
- entityManager.createQuery("delete from Movie").executeUpdate();
- }
}
\ No newline at end of file
Modified: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/WEB-INF/web.xml?rev=1525449&r1=1525448&r2=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/WEB-INF/web.xml (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/WEB-INF/web.xml Sun Sep 22 21:21:47 2013
@@ -18,7 +18,25 @@
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
+ <welcome-file>application.jsp</welcome-file>
</welcome-file-list>
+
+ <!-- The trick is to put all your static files under the same directory and map the "default" servlet to it -->
+ <servlet-mapping>
+ <servlet-name>default</servlet-name>
+ <url-pattern>/app/*</url-pattern>
+ </servlet-mapping>
+
+ <!-- Any other request will point to the "index.jsp" page. This way Backbone knows how to manage page transitions
+ at the client side in case the user starts the application from a permalink. -->
+ <servlet>
+ <servlet-name>application</servlet-name>
+ <jsp-file>/application.jsp</jsp-file>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>application</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
</web-app>
Copied: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/app.less (from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/app.less)
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/app.less?p2=tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/app.less&p1=tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/app.less&r1=1524967&r2=1525449&rev=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/app.less (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/app.less Sun Sep 22 21:21:47 2013
@@ -16,115 +16,33 @@
*/
body {
- .growl-container {
- position: absolute;
- bottom: 20px;
- left: 20px;
- z-index: 5000;
-
- .growl {
- display: none;
- width: 300px;
- }
- }
-}
+ @content-margin-top: 80px;
-.ux-contentarea {
- @topOffset: 55px;
- @offset: 5px;
-
- .panel-body {
- padding: 0;
+ .ux-movie-window {
+ margin-top: @content-margin-top;
}
- .ux-logfile-output {
- position: absolute;
- top: @topOffset;
- bottom: @offset;
- left: @offset;
- right: @offset;
- margin-bottom: 0;
-
- > div.panel-body {
- position: absolute;
- top: (@topOffset + @offset);
- bottom: @offset;
- left: @offset;
- right: @offset;
- overflow: auto;
-
- pre {
- padding: 0;
- border: 0;
- margin: 0;
- background-color: white;
- border: 0;
- border-radius: 0;
- overflow: auto;
- width: 2000px;
- }
- }
+ .ux-landing {
+ margin-top: @content-margin-top;
}
- .ux-scripting {
- @outputWidth: 500px;
+ .ux-setup {
+ margin-top: @content-margin-top;
+ }
- .ux-commands {
- position: absolute;
- bottom: ((@offset * 2) + 8);
- right: ((@offset * 2) + 8);
- }
+ .ux-application {
+ margin-top: @content-margin-top;
- .ux-script {
- position: absolute;
- top: @topOffset;
- bottom: @offset;
- margin-bottom: 0;
+ .pagination {
+ margin-top: 0px;
+ margin-bottom: 0px;
}
-
- .ux-script-output {
- left: @offset;
- width: @outputWidth;
-
- pre {
- padding: 0;
- border: 0;
- margin: 0;
- background-color: white;
- border: 0;
- border-radius: 0;
- overflow: auto;
- width: 2000px;
- }
-
- > div.panel-heading > button {
- position: absolute;
- top: 4px;
- right: @offset;
- }
-
- > div.panel-body {
- position: absolute;
- top: @topOffset;
- bottom: @offset;
- left: @offset;
- width: (@outputWidth - (@offset * 2));
- overflow: auto;
- }
+ th:last-child {
+ width: 5px;
}
- .ux-script-source {
- right: @offset;
- left: (@outputWidth + (@offset * 2));
-
- > div.panel-body {
- position: absolute;
- top: (@topOffset + @offset);
- left: (@offset * 2);
- right: (@offset * 2);
- overflow: auto;
- }
+ a.ux-edit-row:hover {
+ cursor: hand;
}
}
-
}
Copied: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/config.js (from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/config.js)
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/config.js?p2=tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/config.js&p1=tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/config.js&r1=1524967&r2=1525449&rev=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/config.js (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/config.js Sun Sep 22 21:21:47 2013
@@ -19,67 +19,27 @@
var APP_CONFIG = {
baseUrl: window.ux.ROOT_URL,
paths: {
- // https://github.com/requirejs/text
'text': 'app/lib/require/text',
-
- // http://lesscss.org/
'lib/less': 'app/lib/less/less.min',
-
- 'lib/codemirror': 'app/lib/codemirror/lib/codemirror',
- 'lib/show-hint': 'app/lib/codemirror/addon/hint/show-hint',
- 'lib/anyword-hint': 'app/lib/codemirror/addon/hint/anyword-hint',
- 'lib/javascript-mode': 'app/lib/codemirror/mode/javascript/javascript',
- 'lib/groovy-mode': 'app/lib/codemirror/mode/groovy/groovy',
-
- // http://jquery.com/
'lib/jquery': 'app/lib/jquery/jquery.min',
-
- // http://twitter.github.com/bootstrap/
'lib/bootstrap': 'app/lib/bootstrap/js/bootstrap.min',
-
- // http://handlebarsjs.com/
'lib/handlebars': 'app/lib/handlebars/handlebars',
-
'lib/underscore': 'app/lib/underscorejs/underscore-min',
-
'lib/json2': 'app/lib/json2/json2',
-
'lib/backbone': 'app/lib/backbone/backbone-min'
},
shim: {
- 'lib/show-hint': {
- deps: ['lib/codemirror']
- },
- 'lib/anyword-hint': {
- deps: ['lib/show-hint']
- },
- 'lib/javascript-mode': {
- deps: ['lib/anyword-hint']
- },
- 'lib/groovy-mode': {
- deps: ['lib/anyword-hint']
- },
-
- // bootstrap depends on jquery, therefore we need to load jquery first
- // http://requirejs.org/docs/api.html#config-shim
'lib/bootstrap': {
deps: ['lib/jquery']
},
-
'lib/underscore': {
exports: '_'
},
-
'lib/backbone': {
deps: ['lib/jquery', 'lib/json2', 'lib/underscore']
},
-
'app/js/templates': {
deps: ['lib/underscore', 'app/js/i18n']
- },
-
- 'app/js/models': {
- deps: ['lib/underscore']
}
}
};
\ No newline at end of file
Copied: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/application.js (from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/application.js)
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/application.js?p2=tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/application.js&p1=tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/application.js&r1=1524967&r2=1525449&rev=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/application.js (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/application.js Sun Sep 22 21:21:47 2013
@@ -21,101 +21,142 @@
var deps = [
'app/js/view/container',
- 'app/js/view/scripting', 'app/js/view/logfiles', 'app/js/view/growl',
+ 'app/js/view/application',
+ 'app/js/view/application-table-paginator',
+ 'app/js/view/movie',
'lib/underscore',
+ 'app/js/model/movies',
+ 'app/js/model/movie',
'app/js/i18n',
- 'lib/less', 'lib/backbone', 'lib/jquery', 'lib/bootstrap',
- 'app/js/keep-alive'
+ 'lib/less', 'lib/backbone', 'lib/jquery', 'lib/bootstrap'
];
- define(deps, function (containerView, scriptingView, logfilesView) {
+ define(deps, function (containerView, applicationView, paginator, MovieView, underscore, moviesList, MovieModel) {
+ var max = 5;
+ var appState = {
+ page: null,
+ fieldName: null,
+ fieldValue: null
+ };
containerView.render();
$.ajaxSetup({ cache: false });
+ function loadPage(pageNumber, fieldName, fieldValue) {
+ var data = {
+ max: max,
+ first: ((pageNumber - 1) * max)
+ };
+ if (fieldName && fieldValue) {
+ data.field = fieldName;
+ data.searchTerm = fieldValue;
+ }
+ moviesList.fetch({
+ data: data,
+ success: function (result) {
+ applicationView.addRows(result.models);
+
+ $.ajax({
+ url: window.ux.ROOT_URL + 'rest/movies/count/',
+ method: 'GET',
+ dataType: 'json',
+ data: {
+ field: appState.fieldName,
+ searchTerm: appState.fieldValue
+ },
+ success: function (total) {
+ var count = Math.ceil(total / max);
+ paginator.setCount(count);
+ }
+ });
+ }
+ });
+ }
+
function start() {
//Starting the backbone router.
var Router = Backbone.Router.extend({
routes: {
- '': 'showScripting',
- 'scripting': 'showScripting',
- 'scripting/:scriptType': 'showScripting',
- 'log-files': 'showLogFiles',
- 'log-files/:fileName': 'showLogFile'
+ '': 'showApplication',
+ 'application': 'showApplication',
+ 'application/:page': 'showApplication',
+ 'application/:page/:field/:value': 'showApplication'
},
- showScripting: function (scriptType) {
- containerView.showView(scriptingView);
- if (scriptType) {
- scriptingView.showSourceType(scriptType);
+ showApplication: function (page, fieldName, fieldValue) {
+ var me = this;
+ appState.page = page;
+ appState.fieldName = fieldName;
+ appState.fieldValue = fieldValue;
+ containerView.showView(applicationView);
+ if (!page || !underscore.isNumber(Number(page))) {
+ me.showApplication(1);
+ } else {
+ loadPage(Number(page), fieldName, fieldValue);
+ if (fieldName) {
+ me.navigate('application/' + page + '/' + fieldName + '/' + fieldValue, {
+ trigger: false
+ });
+ } else {
+ me.navigate('application/' + page, {
+ trigger: false
+ });
+ }
}
- },
-
- showLogFiles: function () {
- containerView.showView(logfilesView);
- },
-
- showLogFile: function (fileName) {
- containerView.showView(logfilesView);
- logfilesView.triggerFileLoad(fileName);
}
});
var router = new Router();
- containerView.on('navigate', function (data) {
- router.navigate(data.href, {
- trigger: true
- });
- });
-
- scriptingView.on('execute-action', function (data) {
+ applicationView.on('load-sample', function () {
$.ajax({
- url: window.ux.ROOT_URL + 'rest/scripting/',
+ url: window.ux.ROOT_URL + 'rest/load/',
method: 'POST',
dataType: 'json',
- data: {
- engine: data.engine,
- script: data.script
- },
+ data: {},
success: function (data) {
- scriptingView.appendOutput(data.scriptingResultDto.output);
+ router.showApplication();
}
});
});
- scriptingView.on('type-chosen', function (data) {
- router.navigate('scripting/' + data.name, {
- trigger: false
- });
- scriptingView.showSourceType(data.name);
- });
-
- logfilesView.on('load-file-options', function () {
- $.ajax({
- url: window.ux.ROOT_URL + 'rest/log/list-files',
- method: 'GET',
- dataType: 'json',
- data: {},
- success: function (data) {
- logfilesView.showList(data.listFilesResultDto.files);
+ applicationView.on('delete', function (data) {
+ data.model.destroy({
+ success: function () {
+ router.showApplication(appState.page, appState.fieldName, appState.fieldValue);
}
});
});
- logfilesView.on('load-file', function (data) {
- router.navigate('log-files/' + data.href, {
- trigger: false
- });
- $.ajax({
- url: window.ux.ROOT_URL + 'rest/log/load/' + data.href,
- method: 'GET',
- dataType: 'json',
- data: {
- href: data.href
- },
- success: function (data) {
- logfilesView.showFile(data.logFileResultDto.content);
- }
- });
+ function showMovieWindow(model) {
+ var view = new MovieView({
+ model: model
+ });
+ view.render();
+ view.on('save-model', function (data) {
+ data.model.save({}, {
+ success: function () {
+ view.remove();
+ loadPage(appState.page, appState.fieldName, appState.fieldValue);
+ }
+ });
+ });
+ $('body').append(view.$el);
+ view.$el.modal({});
+ }
+
+ applicationView.on('add', function () {
+ showMovieWindow(new MovieModel({}));
+ });
+
+ applicationView.on('edit', function (data) {
+ showMovieWindow(data.model);
+ });
+
+ paginator.on('go-to-page', function (data) {
+ var page = data.number;
+ if (page === 'last') {
+ page = paginator.getCount();
+ }
+ router.showApplication(page, appState.fieldName, appState.fieldValue);
});
//Starting the backbone history.
Copied: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/i18n.js (from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/i18n.js)
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/i18n.js?p2=tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/i18n.js&p1=tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/i18n.js&r1=1524967&r2=1525449&rev=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/i18n.js (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/i18n.js Sun Sep 22 21:21:47 2013
@@ -22,16 +22,20 @@ define(['lib/underscore', 'lib/handlebar
var missing = Handlebars.compile('[!{{key}}!]');
var messages = {
- 'application.name': 'Apache TomEE',
- 'visitor': 'visitor',
- 'scripting': 'Scripting',
- 'source': 'Source',
- 'output': 'Output',
- 'execute': 'Execute',
- 'groovy': 'Groovy',
- 'javascript': 'JavaScript',
- 'log.files': 'Log Files',
- 'log.file': 'Choose file'
+ 'application.name': 'Moviefun',
+ 'load.dada': 'Click here to load sample data',
+ 'movies': 'Movies',
+ 'title': 'Title',
+ 'director': 'Director',
+ 'genre': 'Genre',
+ 'rating': 'Rating',
+ 'year': 'Year',
+ 'add.movie': 'Add movie',
+ 'movie': 'Movie',
+ 'close': 'Close',
+ 'save': 'Save',
+
+ 'dummy': ''
};
underscore.each(underscore.keys(messages), function (key) {
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/id.js
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/id.js?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/id.js (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/id.js Sun Sep 22 21:21:47 2013
@@ -0,0 +1,43 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ "use strict";
+ */
+
+define(['lib/underscore', 'lib/handlebars'], function (underscore) {
+ 'use strict';
+
+ var value = underscore.uniqueId('moviefun_');
+
+ var current = function () {
+ return value;
+ };
+ var next = function () {
+ value = underscore.uniqueId('moviefun_');
+ return value;
+ };
+ Handlebars.registerHelper('id_current', function (key) {
+ return current();
+ });
+ Handlebars.registerHelper('id_next', function (key) {
+ return next();
+ });
+
+ return {
+ current: current,
+ next: next
+ };
+});
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movie.js
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movie.js?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movie.js (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movie.js Sun Sep 22 21:21:47 2013
@@ -0,0 +1,36 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function () {
+ 'use strict';
+
+ var deps = ['lib/backbone'];
+ define(deps, function () {
+ return Backbone.Model.extend({
+ urlRoot: window.ux.ROOT_URL + 'rest/movies',
+ idAttribute: 'id',
+ toJSON: function () {
+ return {
+ 'movie': this.attributes
+ };
+ }
+ });
+ });
+}());
+
+
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movies.js
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movies.js?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movies.js (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/model/movies.js Sun Sep 22 21:21:47 2013
@@ -0,0 +1,35 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function () {
+ 'use strict';
+
+ var deps = ['app/js/model/movie', 'lib/backbone'];
+ define(deps, function (Movie) {
+ var Cls = Backbone.Collection.extend({
+ model: Movie,
+ url: window.ux.ROOT_URL + 'rest/movies',
+ parse: function (response) {
+ return response.movie;
+ }
+ });
+ return new Cls();
+ });
+}());
+
+
Copied: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates.js (from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/templates.js)
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates.js?p2=tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates.js&p1=tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/templates.js&r1=1524967&r2=1525449&rev=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/templates.js (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates.js Sun Sep 22 21:21:47 2013
@@ -21,13 +21,11 @@
var files = [
'container',
- 'growl',
- 'growl-container',
- 'scripting',
- 'script-sample-javascript',
- 'script-sample-groovy',
- 'logfiles',
- 'logfile-link'
+ 'application',
+ 'application-table-row',
+ 'application-table-paginator-button',
+ 'load-data-link',
+ 'movie'
];
function loop(values, callback) {
@@ -57,7 +55,6 @@
if (!template) {
throw 'Template not registered. "' + templateName + '"';
}
-
var result;
if (cfg) {
result = template(cfg);
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-paginator-button.handlebars
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-paginator-button.handlebars?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-paginator-button.handlebars (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-paginator-button.handlebars Sun Sep 22 21:21:47 2013
@@ -0,0 +1 @@
+<li><a href="{{pageNumber}}">{{pageText}}</a></li>
\ No newline at end of file
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-row.handlebars
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-row.handlebars?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-row.handlebars (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application-table-row.handlebars Sun Sep 22 21:21:47 2013
@@ -0,0 +1,8 @@
+<td><a href="edit" class="ux-edit-row">{{title}}</a></td>
+<td>{{director}}</td>
+<td>{{genre}}</td>
+<td>{{rating}}</td>
+<td>{{year}}</td>
+<td>
+ <span class="glyphicon glyphicon-trash ux-delete-row"></span>
+</td>
\ No newline at end of file
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application.handlebars
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application.handlebars?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application.handlebars (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/application.handlebars Sun Sep 22 21:21:47 2013
@@ -0,0 +1,27 @@
+<div class="row">
+ <div class="col-md-12">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <h3 class="panel-title">{{i18n "movies"}}</h3>
+ </div>
+ <div class="panel-body">
+ <table class="table table-bordered table-striped table-hover">
+ <thead>
+ <tr>
+ <th>{{i18n "title"}}</th>
+ <th>{{i18n "director"}}</th>
+ <th>{{i18n "genre"}}</th>
+ <th>{{i18n "rating"}}</th>
+ <th>{{i18n "year"}}</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody></tbody>
+ </table>
+ <button type="button" class="btn btn-primary pull-right ux-add-btn">{{i18n "add.movie"}}</button>
+ </div>
+ </div>
+ </div>
+</div>
+
+
Copied: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/container.handlebars (from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/templates/container.handlebars)
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/container.handlebars?p2=tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/container.handlebars&p1=tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/templates/container.handlebars&r1=1524967&r2=1525449&rev=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/templates/container.handlebars (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/container.handlebars Sun Sep 22 21:21:47 2013
@@ -1,19 +1,10 @@
-<nav class="navbar navbar-inverse navbar-fixed-top">
- <div class="navbar-header">
- <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex8-collapse">
- <span class="sr-only">Toggle navigation</span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <a class="navbar-brand" href="#">{{i18n "application.name"}}</a>
+<div class="navbar navbar-inverse navbar-fixed-top">
+ <div class="container">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="#">{{i18n "application.name"}}</a>
+ </div>
</div>
- <div class="collapse navbar-collapse navbar-ex8-collapse">
- <ul class="nav navbar-nav">
- <li class="ux-app-menu-item ux-scripting"><a href="scripting">{{i18n "scripting"}}</a></li>
- <li class="ux-app-menu-item ux-log-files"><a href="log-files">{{i18n "log.files"}}</a></li>
- </ul>
- </div>
-</nav>
-<div class="ux-contentarea">
</div>
+<div class="container">
+ <div class="ux-contentarea"></div>
+</div>
\ No newline at end of file
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/load-data-link.handlebars
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/load-data-link.handlebars?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/load-data-link.handlebars (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/load-data-link.handlebars Sun Sep 22 21:21:47 2013
@@ -0,0 +1 @@
+<a href="load-data">{{i18n "load.dada"}}</a>
\ No newline at end of file
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/movie.handlebars
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/movie.handlebars?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/movie.handlebars (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/templates/movie.handlebars Sun Sep 22 21:21:47 2013
@@ -0,0 +1,56 @@
+<div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
+ <h4 class="modal-title">{{i18n "movie"}}</h4>
+ </div>
+ <div class="modal-body">
+ <form class="form-horizontal" role="form">
+ <div class="form-group">
+ <label for="{{id_next}}" class="col-lg-2 control-label">{{i18n "title"}}</label>
+
+ <div class="col-lg-10">
+ <input class="form-control ux-title" id="{{id_current}}" placeholder="{{i18n 'title'}}"
+ type="text" value="{{title}}">
+ </div>
+ </div>
+ <div class="form-group">
+ <label for="{{id_next}}" class="col-lg-2 control-label">{{i18n "director"}}</label>
+
+ <div class="col-lg-10">
+ <input class="form-control ux-director" id="{{id_current}}"
+ type="text" placeholder="{{i18n 'director'}}" value="{{director}}">
+ </div>
+ </div>
+ <div class="form-group">
+ <label for="{{id_next}}" class="col-lg-2 control-label">{{i18n "genre"}}</label>
+
+ <div class="col-lg-10">
+ <input class="form-control ux-genre" id="{{id_current}}" placeholder="{{i18n 'genre'}}"
+ type="text" value="{{genre}}">
+ </div>
+ </div>
+ <div class="form-group">
+ <label for="{{id_next}}" class="col-lg-2 control-label">{{i18n "rating"}}</label>
+
+ <div class="col-lg-10">
+ <input class="form-control ux-rating" id="{{id_current}}"
+ type="number" placeholder="{{i18n 'rating'}}" value="{{rating}}">
+ </div>
+ </div>
+ <div class="form-group">
+ <label for="{{id_next}}" class="col-lg-2 control-label">{{i18n "year"}}</label>
+
+ <div class="col-lg-10">
+ <input class="form-control ux-year" id="{{id_current}}" placeholder="{{i18n 'year'}}"
+ type="number" value="{{year}}">
+ </div>
+ </div>
+ </form>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default ux-close" data-dismiss="modal">{{i18n "close"}}</button>
+ <button type="button" class="btn btn-primary ux-save" data-dismiss="modal">{{i18n "save"}}</button>
+ </div>
+ </div>
+</div>
\ No newline at end of file
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-paginator.js
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-paginator.js?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-paginator.js (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-paginator.js Sun Sep 22 21:21:47 2013
@@ -0,0 +1,77 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function () {
+ 'use strict';
+
+ var deps = ['app/js/templates', 'lib/backbone'];
+ define(deps, function (templates) {
+
+ var View = Backbone.View.extend({
+ tagName: 'ul',
+ className: 'pagination',
+
+ count: 0,
+
+ events: {
+ 'click a': function (evt) {
+ evt.preventDefault();
+ var me = this;
+ var myLink = $(evt.target);
+ var href = myLink.attr('href');
+ me.trigger('go-to-page', {
+ number: href
+ });
+ }
+ },
+
+ render: function () {
+ var me = this;
+ me.$el.empty();
+ me.$el.append(templates.getValue('application-table-paginator-button', {
+ pageNumber: '1',
+ pageText: '<<'
+ }));
+ var i;
+ for (i = 1; i < me.count + 1; i += 1) {
+ me.$el.append(templates.getValue('application-table-paginator-button', {
+ pageNumber: i,
+ pageText: i
+ }));
+ }
+ me.$el.append(templates.getValue('application-table-paginator-button', {
+ pageNumber: 'last',
+ pageText: '>>'
+ }));
+ return this;
+ },
+
+ setCount: function (count) {
+ var me = this;
+ me.count = count;
+ me.render();
+ },
+
+ getCount: function () {
+ var me = this;
+ return me.count;
+ }
+ });
+ return new View().render();
+ });
+}());
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-row.js
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-row.js?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-row.js (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application-table-row.js Sun Sep 22 21:21:47 2013
@@ -0,0 +1,63 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function () {
+ 'use strict';
+
+ var deps = ['app/js/templates', 'lib/backbone'];
+ define(deps, function (templates) {
+
+ var View = Backbone.View.extend({
+ tagName: 'tr',
+ events: {
+ 'click .ux-delete-row': function (evt) {
+ evt.preventDefault();
+ var me = this;
+ me.trigger('delete', {
+ model: me.model
+ });
+ me.remove();
+ },
+ 'click .ux-edit-row': function (evt) {
+ evt.preventDefault();
+ var me = this;
+ me.trigger('edit', {
+ model: me.model
+ });
+ }
+ },
+
+ render: function () {
+ var me = this;
+ if (!this.options.isRendered) {
+ me.$el.empty();
+ me.$el.append(templates.getValue('application-table-row', {
+ title: me.model.get('title'),
+ director: me.model.get('director'),
+ genre: me.model.get('genre'),
+ rating: me.model.get('rating'),
+ year: me.model.get('year')
+ }));
+ me.options.isRendered = true;
+ }
+ return this;
+ }
+ });
+ return View;
+ });
+}());
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application.js
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application.js?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application.js (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/application.js Sun Sep 22 21:21:47 2013
@@ -0,0 +1,89 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function () {
+ 'use strict';
+
+ var deps = ['app/js/templates', 'app/js/view/application-table-row', 'app/js/view/application-table-paginator',
+ 'lib/underscore', 'lib/backbone'];
+ define(deps, function (templates, TableRowView, paginator, underscore) {
+
+ var View = Backbone.View.extend({
+ tagName: 'div',
+ className: 'ux-application',
+
+ loadDataLink: $(templates.getValue('load-data-link', {})),
+
+ events: {
+ 'click .ux-application': function (evt) {
+ evt.preventDefault();
+ var me = this;
+ me.trigger('navigate', {
+ path: 'application'
+ });
+ },
+ 'click .ux-add-btn': function (evt) {
+ evt.preventDefault();
+ var me = this;
+ me.trigger('add', {});
+ }
+ },
+
+ render: function () {
+ var me = this;
+ if (!this.options.isRendered) {
+ me.$el.empty();
+ me.$el.append(templates.getValue('application', {}));
+ me.loadDataLink.on('click', function (evt) {
+ evt.preventDefault();
+ me.trigger('load-sample', {});
+ });
+ me.options.isRendered = true;
+ }
+ return this;
+ },
+
+ addRows: function (rows) {
+ var me = this;
+ var tbody = $(me.$el.find('tbody').get(0));
+ tbody.empty();
+ paginator.$el.detach();
+ me.loadDataLink.detach();
+ underscore.each(rows, function (model) {
+ var row = new TableRowView({
+ model: model
+ });
+ row.on('delete', function (data) {
+ me.trigger('delete', data);
+ });
+ row.on('edit', function (data) {
+ me.trigger('edit', data);
+ });
+ tbody.append(row.render().$el);
+ });
+ var addButton = $(me.$el.find('.ux-add-btn').get(0));
+ if (underscore.isEmpty(rows)) {
+ addButton.before(me.loadDataLink);
+ } else {
+ addButton.before(paginator.$el);
+ }
+ }
+ });
+ return new View();
+ });
+}());
Copied: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/container.js (from r1524967, tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/view/container.js)
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/container.js?p2=tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/container.js&p1=tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/view/container.js&r1=1524967&r2=1525449&rev=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-webaccess/webaccess-gui/src/main/webapp/app/js/view/container.js (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/container.js Sun Sep 22 21:21:47 2013
@@ -42,23 +42,10 @@
myMenuItem.addClass('active');
},
- events: {
- 'click .ux-app-menu-item a': function (evt) {
- // TRICK to avoid full page reload.
- evt.preventDefault();
- var myLink = $(evt.target);
- var href = myLink.attr('href');
- this.trigger('navigate', {
- href: href
- });
- }
- },
-
render: function () {
if (this.options.isRendered) {
return this;
}
-
var html = templates.getValue('container', {
userName: ''
});
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/movie.js
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/movie.js?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/movie.js (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/app/js/view/movie.js Sun Sep 22 21:21:47 2013
@@ -0,0 +1,74 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function () {
+ 'use strict';
+
+ var deps = ['app/js/templates', 'lib/underscore', 'lib/backbone', 'app/js/id'];
+ define(deps, function (templates, underscore) {
+
+ var View = Backbone.View.extend({
+ tagName: 'div',
+ className: 'modal ux-movie-window',
+ events: {
+ 'click .ux-application': function (evt) {
+ evt.preventDefault();
+ var me = this;
+ me.trigger('show-application', {});
+ },
+ 'click .ux-close': function (evt) {
+ evt.preventDefault();
+ var me = this;
+ me.remove();
+ },
+ 'click .ux-save': function (evt) {
+ evt.preventDefault();
+ var me = this;
+ var model = me.model;
+
+ function set(name) {
+ var field = $(me.$el.find('.ux-' + name).get(0));
+ model.set(name, field.val());
+ }
+
+ set('title');
+ set('director');
+ set('genre');
+ set('rating');
+ set('year');
+ me.trigger('save-model', {
+ model: model
+ });
+ }
+ },
+ render: function () {
+ var me = this;
+ me.$el.empty();
+ me.$el.append(templates.getValue('movie', {
+ title: me.model.get('title'),
+ director: me.model.get('director'),
+ genre: me.model.get('genre'),
+ rating: me.model.get('rating'),
+ year: me.model.get('year')
+ }));
+ return me;
+ }
+ });
+ return View;
+ });
+}());
Added: tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/application.jsp
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/application.jsp?rev=1525449&view=auto
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/application.jsp (added)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/main/webapp/application.jsp Sun Sep 22 21:21:47 2013
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>Moviefun</title>
+ <link href="<c:url value='/app/lib/bootstrap/css/bootstrap.min.css'/>" rel="stylesheet">
+ <link href="<c:url value='/app/app.less'/>" rel="stylesheet/less" type="text/css">
+ <script src="<c:url value='/app/lib/require/require.js'/>"></script>
+ <script type="text/javascript">
+ window.ux = window.ux || {};
+ window.ux.SESSION_ID = "<%=request.getSession().getId()%>";
+ window.ux.ROOT_URL = "<c:url value='/'/>".replace(';jsessionid=' + window.ux.SESSION_ID, '');
+ </script>
+ <script src="<c:url value='/app/config.js'/>"></script>
+ <script src="<c:url value='/app/js/start.js'/>"></script>
+</head>
+<body></body>
+</html>
\ No newline at end of file
Modified: tomee/tomee/trunk/examples/moviefun-rest/src/test/java/org/superbiz/moviefun/MoviesRestTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/examples/moviefun-rest/src/test/java/org/superbiz/moviefun/MoviesRestTest.java?rev=1525449&r1=1525448&r2=1525449&view=diff
==============================================================================
--- tomee/tomee/trunk/examples/moviefun-rest/src/test/java/org/superbiz/moviefun/MoviesRestTest.java (original)
+++ tomee/tomee/trunk/examples/moviefun-rest/src/test/java/org/superbiz/moviefun/MoviesRestTest.java Sun Sep 22 21:21:47 2013
@@ -18,26 +18,9 @@ package org.superbiz.moviefun;
import org.apache.tomee.embedded.EmbeddedTomEEContainer;
import org.apache.ziplock.Archive;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
import javax.ejb.embeddable.EJBContainer;
-import javax.persistence.TypedQuery;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Path;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-import javax.persistence.metamodel.EntityType;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.PathParam;
import java.io.File;
import java.util.List;
import java.util.Properties;
@@ -66,10 +49,9 @@ public class MoviesRestTest {
}
}
-// @Before
+ @Before
@After
public void clean() throws Exception {
- Thread.sleep(100000);
MoviesBean movies = (MoviesBean) ejbContainer.getContext().lookup("java:global/moviefun-rest/MoviesBean");
movies.clean();
}
@@ -86,8 +68,8 @@ public class MoviesRestTest {
movie.setYear(1995);
movies.addMovie(movie);
- Assert.assertEquals(1, movies.countAll());
- List<Movie> moviesFound = movies.findRange("title", "Bad Boys", 0, 10);
+ Assert.assertEquals(1, movies.count(null, null));
+ List<Movie> moviesFound = movies.getMovies(0, 10, "title", "Bad Boys");
Assert.assertEquals(1, moviesFound.size());
Assert.assertEquals("Michael Bay", moviesFound.get(0).getDirector());
@@ -102,42 +84,4 @@ public class MoviesRestTest {
}
-
- public static interface MoviesClient {
- @GET()
- @javax.ws.rs.Path("{id}")
- public Movie find(@PathParam("id") Long id);
-
- @POST
- @javax.ws.rs.Path("create")
- public void addMovie(Movie movie);
-
- @PUT
- @javax.ws.rs.Path("edit")
- public void editMovie(Movie movie);
-
- @DELETE
- @javax.ws.rs.Path("delete/{id}")
- public void deleteMovieId(@PathParam("id") long id);
-
- @GET
- @javax.ws.rs.Path("list")
- public List<Movie> getMovies();
-
- @GET()
- @javax.ws.rs.Path("list/{first}/{max}")
- public List<Movie> findAll(@PathParam("first") int firstResult, @PathParam("max") int maxResults);
-
- @GET()
- @javax.ws.rs.Path("count")
- public int countAll() ;
-
- @GET()
- @javax.ws.rs.Path("count/{field}/{searchTerm}")
- public int count(@PathParam("field") String field, @PathParam("searchTerm") String searchTerm);
-
- @GET()
- @javax.ws.rs.Path("list/{field}/{searchTerm}/{first}/{max}")
- public List<Movie> findRange(String field, String searchTerm, int firstResult, int maxResults) ;
- }
}
\ No newline at end of file