This is an automated email from the git hooks/post-receive script. New commit to branch feature/882-angular in repository chorem. See http://git.chorem.org/chorem.git commit 89ebbb7927cf0c5f74baf123ca2ebd8ab3cb97c4 Author: kootox <jean.couteau@gmail.com> Date: Thu Mar 19 10:57:09 2015 +0100 refs #882 : Add date picker on invoices --- .../webmotion/actions/crm/InvoiceAction.java | 5 +- .../org/chorem/webmotion/render/RenderJson.java | 43 +++++++++++ .../main/webapp/WEB-INF/jsp/crm/angularTest.html | 2 + .../jsp/crm/partials/invoiceCreateCard.html | 23 +++--- .../jsp/crm/partials/invoiceDetailCard.html | 8 +- .../WEB-INF/jsp/crm/partials/invoiceEditCard.html | 24 +++++- chorem-webmotion/src/main/webapp/js/crm.js | 87 +++++++++++++++++++++- 7 files changed, 173 insertions(+), 19 deletions(-) diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceAction.java index b357f34..6536fe1 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceAction.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/InvoiceAction.java @@ -3,6 +3,7 @@ package org.chorem.webmotion.actions.crm; import org.chorem.ChoremClient; import org.chorem.entities.Invoice; import org.chorem.entities.InvoiceImpl; +import org.chorem.webmotion.render.RenderJson; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; import org.nuiton.wikitty.query.WikittyQuery; @@ -48,7 +49,7 @@ public class InvoiceAction extends WebMotionController { InvoiceDTO dto = new InvoiceDTO(invoice, client); - return renderJSON(dto); + return new RenderJson(toMap(dto)); } @@ -114,7 +115,7 @@ public class InvoiceAction extends WebMotionController { dto = new InvoiceDTO(invoice, client); - return renderJSON(dto); + return new RenderJson(toMap(dto)); } diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/render/RenderJson.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/render/RenderJson.java new file mode 100644 index 0000000..f218863 --- /dev/null +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/render/RenderJson.java @@ -0,0 +1,43 @@ +package org.chorem.webmotion.render; + +import com.google.gson.Gson; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Map; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletResponse; + +import com.google.gson.GsonBuilder; +import org.debux.webmotion.server.call.Call; +import org.debux.webmotion.server.call.HttpContext; +import org.debux.webmotion.server.mapping.Mapping; +import org.debux.webmotion.server.render.Render; + +public class RenderJson extends Render { + protected Map<String, Object> model; + + public RenderJson(Map<String, Object> model) { + this.model = model; + } + + public Map<String, Object> getModel() { + return this.model; + } + + public void create(Mapping mapping, Call call) throws IOException, ServletException { + HttpContext context = call.getContext(); + HttpServletResponse response = context.getResponse(); + Object object = this.model; + if(this.model != null && this.model.size() == 1 && this.model.keySet().contains(DEFAULT_MODEL_NAME)) { + object = this.model.values().toArray()[0]; + } + + response.setContentType("application/json"); + + Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create(); + + String json = gson.toJson(object); + PrintWriter out = context.getOut(); + out.print(json); + } +} \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/angularTest.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/angularTest.html index 0b81234..6cc9f5b 100644 --- a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/angularTest.html +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/angularTest.html @@ -19,6 +19,8 @@ <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-select/0.10.0/select.js"></script> <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.css"> + <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.1/ui-bootstrap-tpls.js"></script> + </head> diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceCreateCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceCreateCard.html index 2475e54..de6f303 100644 --- a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceCreateCard.html +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceCreateCard.html @@ -52,23 +52,28 @@ </div> <div class="form-group"> - <label class="col-xs-3 control-label">Émission</label> - <div class="col-xs-9"> - <input type="text" class="form-control" ng-model="invoice.emittedDate"> - </div> - </div> - - <div class="form-group"> <label class="col-xs-3 control-label">Échéance</label> <div class="col-xs-9"> - <input type="text" class="form-control" ng-model="invoice.expectedDate"> + <p class="input-group"> + <input type="text" class="form-control" datepicker-popup="dd/MM/yyyy" ng-model="invoice.expectedDate" + is-open="openedExpected" datepicker-options="dateOptions" close-text="Close" /> + <span class="input-group-btn"> + <button type="button" class="btn btn-default" ng-click="openExpected($event)"><i class="glyphicon glyphicon-calendar"></i></button> + </span> + </p> </div> </div> <div class="form-group"> <label class="col-xs-3 control-label">Paiement</label> <div class="col-xs-9"> - <input type="text" class="form-control" ng-model="invoice.paymentDate"> + <p class="input-group"> + <input type="text" class="form-control" datepicker-popup="dd/MM/yyyy" ng-model="invoice.paymentDate" + is-open="openedPayment" datepicker-options="dateOptions" close-text="Close" /> + <span class="input-group-btn"> + <button type="button" class="btn btn-default" ng-click="openPayment($event)"><i class="glyphicon glyphicon-calendar"></i></button> + </span> + </p> </div> </div> diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceDetailCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceDetailCard.html index 68a4708..8682c06 100644 --- a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceDetailCard.html +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceDetailCard.html @@ -32,15 +32,15 @@ </div> <div class="list-group-item"> <label>Émission</label> - <h4 class="list-group-item-heading">{{invoice.emittedDate}}</h4> + <h4 class="list-group-item-heading">{{invoice.emittedDate|date:'dd/MM/yyyy'}}</h4> </div> <div class="list-group-item"> - <label>Limite de paiement</label> - <h4 class="list-group-item-heading">{{invoice.expectedDate}}</h4> + <label>Échéance</label> + <h4 class="list-group-item-heading">{{invoice.expectedDate|date:'dd/MM/yyyy'}}</h4> </div> <div class="list-group-item"> <label>Paiement</label> - <h4 class="list-group-item-heading">{{invoice.paymentDate}}</h4> + <h4 class="list-group-item-heading">{{invoice.paymentDate|date:'dd/MM/yyyy'}}</h4> </div> <div class="list-group-item"> <label>Target</label> diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceEditCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceEditCard.html index 812ee17..51181e7 100644 --- a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceEditCard.html +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/invoiceEditCard.html @@ -54,21 +54,39 @@ <div class="form-group"> <label class="col-xs-3 control-label">Émission</label> <div class="col-xs-9"> - <input type="text" class="form-control" ng-model="invoice.emittedDate"> + <p class="input-group"> + <input type="text" class="form-control" datepicker-popup="dd/MM/yyyy" ng-model="invoice.emittedDate" + is-open="opened" datepicker-options="dateOptions" close-text="Fermer" /> + <span class="input-group-btn"> + <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button> + </span> + </p> </div> </div> <div class="form-group"> <label class="col-xs-3 control-label">Échéance</label> <div class="col-xs-9"> - <input type="text" class="form-control" ng-model="invoice.expectedDate"> + <p class="input-group"> + <input type="text" class="form-control" datepicker-popup="dd/MM/yyyy" ng-model="invoice.expectedDate" + is-open="openedExpected" datepicker-options="dateOptions" close-text="Close" /> + <span class="input-group-btn"> + <button type="button" class="btn btn-default" ng-click="openExpected($event)"><i class="glyphicon glyphicon-calendar"></i></button> + </span> + </p> </div> </div> <div class="form-group"> <label class="col-xs-3 control-label">Paiement</label> <div class="col-xs-9"> - <input type="text" class="form-control" ng-model="invoice.paymentDate"> + <p class="input-group"> + <input type="text" class="form-control" datepicker-popup="dd/MM/yyyy" ng-model="invoice.paymentDate" + is-open="openedPayment" datepicker-options="dateOptions" close-text="Close" /> + <span class="input-group-btn"> + <button type="button" class="btn btn-default" ng-click="openPayment($event)"><i class="glyphicon glyphicon-calendar"></i></button> + </span> + </p> </div> </div> diff --git a/chorem-webmotion/src/main/webapp/js/crm.js b/chorem-webmotion/src/main/webapp/js/crm.js index 1298558..60cca07 100644 --- a/chorem-webmotion/src/main/webapp/js/crm.js +++ b/chorem-webmotion/src/main/webapp/js/crm.js @@ -1,4 +1,4 @@ -var crmTest = angular.module('crmTest', ['ngRoute','ui.select','ngSanitize']); +var crmTest = angular.module('crmTest', ['ngRoute','ui.select','ngSanitize', 'ui.bootstrap']); crmTest.config(['$routeProvider', function($routeProvider){ @@ -612,6 +612,20 @@ crmTest.controller('InvoiceCreateController', function ($scope, $http, $window) $scope.invoice.payer = $scope.company; + //date parsing before submitting + console.log($scope.invoice.emittedDate); + if ($scope.invoice.emittedDate instanceof Date){ + $scope.invoice.emittedDate = $scope.invoice.emittedDate.toJSON(); + } else { + $scope.invoice.emittedDate = undefined; + } + if ($scope.invoice.expectedDate instanceof Date){ + $scope.invoice.expectedDate = $scope.invoice.expectedDate.toJSON(); + } + if ($scope.invoice.paymentDate instanceof Date){ + $scope.invoice.paymentDate = $scope.invoice.paymentDate.toJSON(); + } + $http({ method : 'PUT', url : 'invoices/add', @@ -626,6 +640,32 @@ crmTest.controller('InvoiceCreateController', function ($scope, $http, $window) $scope.cancel = function(){ $window.history.back(); } + + $scope.open = function($event) { + $event.preventDefault(); + $event.stopPropagation(); + + $scope.opened = true; + }; + + $scope.openExpected = function($event) { + $event.preventDefault(); + $event.stopPropagation(); + + $scope.openedExpected = true; + }; + + $scope.openPayment = function($event) { + $event.preventDefault(); + $event.stopPropagation(); + + $scope.openedPayment = true; + }; + + $scope.dateOptions = { + formatYear: 'yy', + startingDay: 1 + }; }); crmTest.controller('InvoiceEditController', function ($scope, $http, $window, $routeParams) { @@ -636,6 +676,7 @@ crmTest.controller('InvoiceEditController', function ($scope, $http, $window, $r $http.get('invoices/'+$routeParams.invoiceId).success(function(data){ $scope.invoice = data; + //$scope.invoice.emittedDate=new Date($scope.invoice.emittedDate); }); //get all categories @@ -647,6 +688,24 @@ crmTest.controller('InvoiceEditController', function ($scope, $http, $window, $r $scope.invoice.payer = $scope.company; + //date parsing before submitting + console.log($scope.invoice.emittedDate); + if ($scope.invoice.emittedDate instanceof Date){ + $scope.invoice.emittedDate = $scope.invoice.emittedDate.toJSON(); + } else { + delete $scope.invoice.emittedDate; + } + if ($scope.invoice.expectedDate instanceof Date){ + $scope.invoice.expectedDate = $scope.invoice.expectedDate.toJSON(); + } else { + delete $scope.invoice.expectedDate; + } + if ($scope.invoice.paymentDate instanceof Date){ + $scope.invoice.paymentDate = $scope.invoice.paymentDate.toJSON(); + } else { + delete $scope.invoice.paymentDate; + } + $http({ method : 'POST', url : 'invoices/'+$scope.invoice.wikittyId, @@ -671,4 +730,30 @@ crmTest.controller('InvoiceEditController', function ($scope, $http, $window, $r }); } } + + $scope.open = function($event) { + $event.preventDefault(); + $event.stopPropagation(); + + $scope.opened = true; + }; + + $scope.openExpected = function($event) { + $event.preventDefault(); + $event.stopPropagation(); + + $scope.openedExpected = true; + }; + + $scope.openPayment = function($event) { + $event.preventDefault(); + $event.stopPropagation(); + + $scope.openedPayment = true; + }; + + $scope.dateOptions = { + formatYear: 'yy', + startingDay: 1 + }; }); \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.