r298 - in trunk: magalie-services/src/main/java/com/franciaflex/magalie/services/service magalie-web/src/main/java/com/franciaflex/magalie/web/action magalie-web/src/main/webapp/WEB-INF/content magalie-web/src/main/webapp/js
Author: bleny Date: 2013-07-09 17:59:44 +0200 (Tue, 09 Jul 2013) New Revision: 298 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: use ajax request in receive-article-input to prevent loading of thousands locations Added: trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/LocationJsonAction.java Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java trunk/magalie-web/src/main/webapp/WEB-INF/content/receive-article-input.jsp trunk/magalie-web/src/main/webapp/js/receive-article-input.js Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-07-09 13:03:54 UTC (rev 297) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/ReceptionService.java 2013-07-09 15:59:44 UTC (rev 298) @@ -244,8 +244,7 @@ locations.addAll(locationDao.findAllWithoutReception(warehouse)); // add all locations in the same building, other warehouses - // FIXME brendan 04/07/13 re-enable - if (true) { + if (false) { // disabled, for a warehouse with 1000+ locations, can lead to a page of 1Mo+, now the locations are loaded on demand locations.addAll(locationDao.findAllWithoutReception(warehouse.getBuilding())); } Added: trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/LocationJsonAction.java =================================================================== --- trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/LocationJsonAction.java (rev 0) +++ trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/LocationJsonAction.java 2013-07-09 15:59:44 UTC (rev 298) @@ -0,0 +1,59 @@ +package com.franciaflex.magalie.web.action; + +import com.franciaflex.magalie.MagalieTechnicalException; +import com.franciaflex.magalie.persistence.entity.Building; +import com.franciaflex.magalie.persistence.entity.Location; +import com.franciaflex.magalie.services.exception.InvalidMagalieBarcodeException; +import com.franciaflex.magalie.services.service.MagalieBarcodeService; +import com.franciaflex.magalie.web.MagalieActionSupport; +import com.franciaflex.magalie.web.MagalieSession; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +@Results({ + @Result(name="success", type="json") +}) +public class LocationJsonAction extends MagalieActionSupport{ + + protected MagalieBarcodeService service; + + protected Location location; + + protected String locationBarcode; + + protected MagalieSession session; + + public void setSession(MagalieSession session) { + this.session = session; + } + + public void setService(MagalieBarcodeService service) { + this.service = service; + } + + public void setLocationBarcode(String locationBarcode) { + this.locationBarcode = locationBarcode; + } + + @Override + public String execute() throws InvalidMagalieBarcodeException { + + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + throw new MagalieTechnicalException(e); + } + + Building building = session.getBuilding(); + + location = service.getLocation(locationBarcode, building); + + return SUCCESS; + + } + + public Location getLocation() { + return location; + } + +} Modified: trunk/magalie-web/src/main/webapp/WEB-INF/content/receive-article-input.jsp =================================================================== --- trunk/magalie-web/src/main/webapp/WEB-INF/content/receive-article-input.jsp 2013-07-09 13:03:54 UTC (rev 297) +++ trunk/magalie-web/src/main/webapp/WEB-INF/content/receive-article-input.jsp 2013-07-09 15:59:44 UTC (rev 298) @@ -25,6 +25,8 @@ <head> <script> + <s:url action="location-json" id="locationJsonUrl" /> + var locationJsonUrl = '<s:property value="%{locationJsonUrl}" />'; var model = <s:property value="modelAsJson" escapeHtml="false" />; </script> <script src="<s:url value='/js/receive-article-input.js' />"></script> Modified: trunk/magalie-web/src/main/webapp/js/receive-article-input.js =================================================================== --- trunk/magalie-web/src/main/webapp/js/receive-article-input.js 2013-07-09 13:03:54 UTC (rev 297) +++ trunk/magalie-web/src/main/webapp/js/receive-article-input.js 2013-07-09 15:59:44 UTC (rev 298) @@ -43,14 +43,25 @@ }; model.getLocation = function(barcode) { + var locations = this.locations; var location; - for (var i = 0; i < this.locations.length; i++) { - if (barcode == this.locations[i].barcode) { - location = this.locations[i]; + for (var i = 0; i < locations.length; i++) { + if (barcode == locations[i].barcode) { + location = locations[i]; } } if (location == null) { // try to load it form JSON request ? + $.ajax({ + dataType: "json", + url: locationJsonUrl, + data: { locationBarcode: barcode }, + async: false, + success: function(data) { + location = data.location; + locations.push(location); + } + }); } if (location == null) { throw new ValidationError(barcode + " n'est pas le code barre d'un emplacement valide");
participants (1)
-
bleny@users.forge.codelutin.com