Author: ymartel Date: 2014-04-11 18:19:46 +0200 (Fri, 11 Apr 2014) New Revision: 414 Url: http://forge.chorem.org/projects/chorem/repository/revisions/414 Log: prepare save of expenseAccount \! Added: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html trunk/chorem-webmotion/src/main/webapp/js/financial/ trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java trunk/chorem-webmotion/src/main/resources/mapping trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java 2014-04-11 14:16:53 UTC (rev 413) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/financial/ExpenseAccountAction.java 2014-04-11 16:19:46 UTC (rev 414) @@ -36,6 +36,7 @@ import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; +import com.google.gson.Gson; import org.chorem.ChoremClient; import org.chorem.entities.CategoryImpl; import org.chorem.entities.Employee; @@ -120,14 +121,14 @@ return paginatedResult; } - public void saveExpenseAccount(ChoremClient client, String expenseAccountId, Call call) { - ExpenseAccount expenseAccount = client.restore(ExpenseAccount.class, expenseAccountId); - if (expenseAccount == null) { - expenseAccount = new ExpenseAccountImpl(); + public void saveExpenseAccount(ChoremClient client, String expenseAccountId, ExpenseAccountBean expenseAccount) { + ExpenseAccount expenseAccountWikitty = client.restore(ExpenseAccount.class, expenseAccountId); + if (expenseAccountWikitty == null) { + expenseAccountWikitty = new ExpenseAccountImpl(); } - Map<String,Object> extractParameters = call.getExtractParameters(); - String contextPath = call.getContext().getServletContext().getContextPath(); - contextPath.length(); + String json = expenseAccount.toJson(); + expenseAccount.toString(); + //TODO ymartel 2014/04/11 just do it } public Render findExpenseAccount(ChoremClient client, String expenseAccountId) { @@ -140,6 +141,7 @@ if (expenseAccount == null) { expenseAccountBean = new ExpenseAccountBean(); + expenseAccountBean.setId("new"); //XXX ymartel 2014/04/08 Some Fake datas, just for test Employee employee = client.findAllByExample(new EmployeeImpl(), 0, 1).get(0); Modified: trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java =================================================================== --- trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java 2014-04-11 14:16:53 UTC (rev 413) +++ trunk/chorem-webmotion/src/main/java/org/chorem/webmotion/bean/financial/ExpenseAccountBean.java 2014-04-11 16:19:46 UTC (rev 414) @@ -26,6 +26,8 @@ import java.io.Serializable; import java.util.Set; +import com.google.gson.Gson; + /** * @author ymartel <martel@codelutin.com> */ @@ -86,4 +88,8 @@ this.expenseAccountEntries = expenseAccountEntries; } + public String toJson() { + Gson gson = new Gson(); + return gson.toJson(this); + } } Modified: trunk/chorem-webmotion/src/main/resources/mapping =================================================================== --- trunk/chorem-webmotion/src/main/resources/mapping 2014-04-11 14:16:53 UTC (rev 413) +++ trunk/chorem-webmotion/src/main/resources/mapping 2014-04-11 16:19:46 UTC (rev 414) @@ -14,6 +14,7 @@ * /sales/funnel/partial/* DecoratorFilter.decorate wmDecoratorNo=true * /crm/export DecoratorFilter.decorate wmDecoratorNo=true * /project/editProject.html DecoratorFilter.decorate wmDecoratorNo=true +* /financial/expenseAccounts/expenseAccountEntryEdit.html DecoratorFilter.decorate wmDecoratorNo=true * /hr/employeeEdit/json/* DecoratorFilter.decorate wmDecoratorNo=true * /ascii/* DecoratorFilter.decorate wmDecoratorNo=true * /rest/* DecoratorFilter.decorate wmDecoratorNo=true @@ -102,6 +103,7 @@ GET /rest/financial/expenseAccounts?page={page}&count={count} action:financial.ExpenseAccountAction.findAllExpenseAccounts page=1,count=20 GET /rest/financial/expenseAccounts/{expenseAccountId} action:financial.ExpenseAccountAction.findExpenseAccount GET /financial/expenseAccounts view:financial/expenseAccounts.jsp +GET /financial/expenseAccounts/expenseAccountEntryEdit.html view:financial/expenseAccountEntryEdit.html GET /financial/expenseAccounts/{expenseAccountId} action:financial.ExpenseAccountAction.findExpenseAccount PUT /financial/expenseAccounts/{expenseAccountId} action:financial.ExpenseAccountAction.saveExpenseAccount Added: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html (rev 0) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountEntryEdit.html 2014-04-11 16:19:46 UTC (rev 414) @@ -0,0 +1,9 @@ + <td><input type="text" ng-model="newExpenseAccountEntry.justificationNumber" name="newExpenseAccountEntry.justificationNumber" size="10"></td> + <td><input type="date" ng-model="newExpenseAccountEntry.emittedDate" name="newExpenseAccountEntry.emittedDate" size="10" maxlength="10"></td> + <td><input type="text" ng-model="newExpenseAccountEntry.project" name="newExpenseAccountEntry.project" size="4"></td> + <td><input type="text" ng-model="newExpenseAccountEntry.description" name="newExpenseAccountEntry.description" class="w100"></td> + <td><input type="text" ng-model="newExpenseAccountEntry.category" name="newExpenseAccountEntry.category" class="w100"></td> + <td><input type="number" ng-model="newExpenseAccountEntry.amount" name="newExpenseAccountEntry.amount" class="w100"></td> + <td><input type="number" ng-model="newExpenseAccountEntry.VAT" name="newExpenseAccountEntry.VAT" class="w100"></td> + <td><input type="number" ng-model="newExpenseAccountEntry.total" name="newExpenseAccountEntry.total"></td> + <td><a class="btn btn-success" ng-click="addLine()"><i class="icon-pencil icon-white"></i>Validate</a></td> Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp =================================================================== --- trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp 2014-04-11 14:16:53 UTC (rev 413) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp 2014-04-11 16:19:46 UTC (rev 414) @@ -27,13 +27,20 @@ <head> <script data-require="angular-resource@1.2.0-rc.3" data-semver="1.2.0-rc.3" src="<c:url value='http://code.angularjs.org/1.2.0-rc.3/angular-resource.js'/>"></script> <link data-require="bootstrap-css@*" data-semver="3.0.0" rel="stylesheet" href="<c:url value='http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css'/>" /> + <script type="text/javascript" src="<c:url value='/js/financial/expenseAccount.js'/>"></script> + <script> + angular.module('expenseAccountPage').value('expenseAccountInit', { + expenseAccount: ${expenseAccount.toJson()}, + saveURL: "<c:url value="/financial/expenseAccounts"/>" + }); + </script> </head> -<div ng-app> +<div ng-app='expenseAccountPage' ng-controller="expenseAccountView"> <div > <dl> - <dd><a href="<c:url value="/wikitty/view/${expenseAccount.employeeId}"/>">${expenseAccount.employeeName}</a></dd> - <dd>Period : {{expenseAccount.month}} / ${expenseAccount.year}</dd> + <dd><a href="<c:url value="/wikitty/view/{{expenseAccount.employeeId}}"/>">{{expenseAccount.employeeName}}</a></dd> + <dd>Period : {{expenseAccount.month}} / {{expenseAccount.year}}</dd> </dl> </div> @@ -50,23 +57,24 @@ <th>total</th> <th>Payment Date</th> </tr> - <c:forEach var="expenseEntry" items="${expenseAccount.expenseAccountEntries}"> - <tr> - <td>${expenseEntry.justificationNumber}</td> - <td>{{${expenseEntry.emittedDate}| date:'shortDate'}}</td> - <td><a href="<c:url value="/wikitty/view/${expenseEntry.projectId}"/>">${expenseEntry.projectName}</a></td> - <td>${expenseEntry.description}</td> - <td>${expenseEntry.categoryName}</td> - <td>{{${expenseEntry.amount}|number:2}}</td> - <td>{{${expenseEntry.VAT}|number:2}}</td> - <td>{{${expenseEntry.total}|number:2}}</td> - <td><span ng-if = "${expenseEntry.paymentDate} != 0"> {{${expenseEntry.paymentDate}|date:'shortDate'}}</span></td> + <tr ng-repeat="expenseEntry in expenseAccount.expenseAccountEntries"> + <td>{{expenseEntry.justificationNumber}}</td> + <td>{{expenseEntry.emittedDate| date:'shortDate'}}</td> + <td><a href="<c:url value="/wikitty/view/{{expenseEntry.projectId}}"/>">{{expenseEntry.projectName}}</a></td> + <td>{{expenseEntry.description}}</td> + <td>{{expenseEntry.categoryName}}</td> + <td>{{expenseEntry.amount|number:2}}</td> + <td>{{expenseEntry.VAT|number:2}}</td> + <td>{{expenseEntry.total|number:2}}</td> + <td><span ng-if = "expenseEntry.paymentDate"> {{expenseEntry.paymentDate|date:'shortDate'}}</span></td> </tr> - </c:forEach> + <tr ng-if="showNewLine == true" ng-include src="'expenseAccountEntryEdit.html'"></tr> </table> </div> + <a class="btn btn-success" ng-click="newLine()"><i class="icon-list icon-white"></i> New entry</a> + <div ng-if="hasChanged == true"> + <a class="btn btn-success" ng-click="saveExpenseAccount()"><i class="icon-od icon-white"></i>Save</a> + </div> </div> -<div> - <a class="btn btn-success" href="<c:url value="/financial/expenseAccounts/new"/>"><i class="icon-list icon-white"></i> New one</a> </div> Added: trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js =================================================================== --- trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js (rev 0) +++ trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js 2014-04-11 16:19:46 UTC (rev 414) @@ -0,0 +1,50 @@ +var app = angular.module('expenseAccountPage', ['ngResource']); + +app.controller("expenseAccountView", function($scope, $resource, expenseAccountInit) { + + $scope.showNewLine = false; + $scope.expenseAccount = expenseAccountInit.expenseAccount; + $scope.saveURL = expenseAccountInit.saveURL; + + $scope.newLine = function() { + if ($scope.showNewLine === true) { + $scope.showNewLine = false; + delete $scope.newExpenseAccountEntry; + } else { + $scope.showNewLine = true; + $scope.newExpenseAccountEntry = { + justificationNumber: '', + emittedDate : '', + project: '', + description: '', + category: '', + amount: '', + VAT: '', + total: '' + }; + } + } + + $scope.addLine = function() { + + $scope.expenseAccount.expenseAccountEntries.push($scope.newExpenseAccountEntry); + + $scope.hasChanged = true; + $scope.showNewLine = false; + delete $scope.newExpenseAccountEntry; + } + + $scope.saveExpenseAccount = function() { + + console.log($scope.expenseAccount) + + url = $scope.saveURL + "/" + $scope.expenseAccount.id; + + $resource('url', $scope.expenseAccount, {'update' : {method:'PUT'}}).update(function(result) { + console.log("saved!"); + }); + } + + + +});