Author: ymartel Date: 2014-07-04 11:47:25 +0200 (Fri, 04 Jul 2014) New Revision: 416 Url: http://forge.chorem.org/projects/chorem/repository/revisions/416 Log: bind the employee with ExpenseAccount in scope Modified: trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js 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-07-03 15:58:51 UTC (rev 415) +++ trunk/chorem-webmotion/src/main/webapp/WEB-INF/jsp/financial/expenseAccountView.jsp 2014-07-04 09:47:25 UTC (rev 416) @@ -33,7 +33,8 @@ <script> angular.module('expenseAccountPage').value('expenseAccountInit', { expenseAccount: ${expenseAccount.toJson()}, - saveURL: "<c:url value="/financial/expenseAccounts"/>" + saveURL: "<c:url value="/financial/expenseAccounts"/>", + baseURL: "<c:url value="/"/>" }); </script> </head> @@ -43,9 +44,9 @@ <dl> <dd ng-if="expenseAccount && expenseAccount.employeeId"><a href="<c:url value="/wikitty/view/{{expenseAccount.employeeId}}"/>">{{expenseAccount.employeeName}}</a></dd> <dd ng-if="!expenseAccount || !expenseAccount.employeeId"> - <input type="text" ng-model="expenseAccount.employeeName" id="text-expenseAccount-employee" /> + <input type="text" ng-model="expenseAccount.employeeName" id="text-expenseAccount-employee" auto-complete auto-complete-source=<c:url value="/wikitty-json/search?extension=Employee"/> /> <input type="hidden" ng-model="expenseAccount.employeeId" id="hidden-expenseAccount-employee"/> - <script> + <!-- script> $(function() { $( "#text-expenseAccount-employee" ).autocompleteByExtension({ source: "<c:url value="/wikitty-json/search?extension=Employee"/>", @@ -58,7 +59,7 @@ } }); }); - </script> + </script --> </dd> <dd ng-if="editPeriod == false">Period from {{expenseAccount.startDate |date}} to {{expenseAccount.endDate |date}}</dd> Modified: trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js =================================================================== --- trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js 2014-07-03 15:58:51 UTC (rev 415) +++ trunk/chorem-webmotion/src/main/webapp/js/financial/expenseAccount.js 2014-07-04 09:47:25 UTC (rev 416) @@ -6,7 +6,7 @@ $scope.expenseAccount = expenseAccountInit.expenseAccount; $scope.editPeriod = expenseAccountInit && expenseAccountInit.id ? false : true; - $scope.saveURL = expenseAccountInit.saveURL; + $scope.baseURL = expenseAccountInit.baseURL; $scope.newLine = function() { if ($scope.showNewLine === true) { @@ -27,6 +27,10 @@ } } + $scope.ac_options = { + baseURL : $scope.baseURL, + }; + $scope.addLine = function() { if(!$scope.expenseAccount.expenseAccountEntries) { @@ -44,13 +48,34 @@ console.log($scope.expenseAccount) - url = $scope.saveURL + "/" + $scope.expenseAccount.id; + url = $scope.baseURL + "financial/expenseAccounts/" + $scope.expenseAccount.id; $resource('url', $scope.expenseAccount, {'update' : {method:'PUT'}}).update(function(result) { console.log("saved!"); }); } +}); -}); +app.directive("autoComplete", function() { + return { + restrict : "A" , + require : '^ngModel', + link : function (scope, element, attrs) { + + // prevent html5/browser auto completion + attrs.$set('autocomplete','off'); + + scope.autocomplete = $(element).autocompleteByExtension({ + source: scope.baseURL + "wikitty-json/search?extension=Employee", + minLength: 2, + select: function(event, ui) { + scope.expenseAccount.employeeName = ui.item.label; + scope.expenseAccount.employeeId = ui.item.id; + return true; + } + }); + } + } +}); \ No newline at end of file