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 b74fe5c6af1644cbd227abb4871bc5419e86923e Author: kootox <jean.couteau@gmail.com> Date: Thu Mar 5 15:51:04 2015 +0100 refs #882 : ContactDetails CRUD from company info --- .../actions/crm/ContactDetailsAction.java | 43 +++++++++++ .../webmotion/actions/crm/ContactDetailsDTO.java | 2 + chorem-webmotion/src/main/resources/mapping | 4 + .../jsp/crm/partials/contactDetailsCreateCard.html | 47 +++++++++++ .../jsp/crm/partials/contactDetailsEditCard.html | 50 ++++++++++++ .../jsp/crm/partials/contactDetailsInfoCard.html | 33 ++++++++ .../jsp/crm/partials/contactDetailsListCard.html | 20 +++-- chorem-webmotion/src/main/webapp/js/crm.js | 90 +++++++++++++++++++++- 8 files changed, 277 insertions(+), 12 deletions(-) diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/ContactDetailsAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/ContactDetailsAction.java index ae52c43..4f212ad 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/ContactDetailsAction.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/ContactDetailsAction.java @@ -2,6 +2,8 @@ package org.chorem.webmotion.actions.crm; import org.chorem.ChoremClient; import org.chorem.entities.ContactDetails; +import org.chorem.entities.ContactDetailsImpl; +import org.chorem.entities.Note; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; import org.nuiton.wikitty.query.WikittyQuery; @@ -35,4 +37,45 @@ public class ContactDetailsAction extends WebMotionController { return renderJSON(contactDTOs); } + + public Render getContactDetails(ChoremClient client, String id){ + ContactDetails cd = client.restore(ContactDetails.class, id); + + ContactDetailsDTO cdDTO = new ContactDetailsDTO(cd); + + return renderJSON(cdDTO); + } + + public Render createContactDetails(ChoremClient client, ContactDetailsDTO cdDTO){ + ContactDetails cd = new ContactDetailsImpl(); + cd.setTarget(cdDTO.getTarget()); + cd.setValue(cdDTO.getValue()); + cd.setType(cdDTO.getType()); + cd.setName(cdDTO.getName()); + cd = client.store(cd); + + cdDTO = new ContactDetailsDTO(cd); + + return renderJSON(cdDTO); + + } + + public Render updateContactDetails(ChoremClient client, String id, ContactDetailsDTO cdDTO){ + ContactDetails cd = client.restore(ContactDetails.class, id); + cd.setTarget(cdDTO.getTarget()); + cd.setValue(cdDTO.getValue()); + cd.setType(cdDTO.getType()); + cd.setName(cdDTO.getName()); + cd = client.store(cd); + + cdDTO = new ContactDetailsDTO(cd); + + return renderJSON(cdDTO); + } + + public Render deleteContactDetails(ChoremClient client, String id){ + client.delete(id); + + return renderSuccess(); + } } diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/ContactDetailsDTO.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/ContactDetailsDTO.java index 1ad09eb..45889a3 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/ContactDetailsDTO.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/ContactDetailsDTO.java @@ -12,6 +12,8 @@ public class ContactDetailsDTO { protected String target; protected String wikittyId; + public ContactDetailsDTO(){} + public ContactDetailsDTO(ContactDetails contact) { this.name = contact.getName(); this.value = contact.getValue(); diff --git a/chorem-webmotion/src/main/resources/mapping b/chorem-webmotion/src/main/resources/mapping index 774a512..00f0bd7 100644 --- a/chorem-webmotion/src/main/resources/mapping +++ b/chorem-webmotion/src/main/resources/mapping @@ -103,6 +103,10 @@ PUT /crm/companies/add action:crm.CompaniesAction.createCompa DELETE /crm/companies/{id} action:crm.CompaniesAction.deleteCompany GET /crm/companies/{id}/contactDetails action:crm.ContactDetailsAction.listContactDetails +PUT /crm/contactDetails/add action:crm.ContactDetailsAction.createContactDetails +POST /crm/contactDetails/{id} action:crm.ContactDetailsAction.updateContactDetails +GET /crm/contactDetails/{id} action:crm.ContactDetailsAction.getContactDetails +DELETE /crm/contactDetails/{id} action:crm.ContactDetailsAction.deleteContactDetails GET /crm/companies/{id}/notes action:crm.NoteAction.listNotes PUT /crm/notes/add action:crm.NoteAction.createNote diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsCreateCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsCreateCard.html new file mode 100644 index 0000000..76cf883 --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsCreateCard.html @@ -0,0 +1,47 @@ +<div class="panel panel-default"> + + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Créer un moyen de contact</h3> + <div class="btn-group pull-right"> + <button class="btn btn-danger" ng-click="cancel()"> + <i class="fa fa-times"></i> + Annuler + </button> + <button class="btn btn-success" ng-click="saveContactDetails()"> + <i class="fa fa-check"></i> + Sauver + </button> + </div> + </div> + + <div class="modal-body"> + <form class="form-horizontal"> + <div class="form-group"> + <label class="col-xs-3 control-label">Nom</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="contactDetails.name"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Type</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="contactDetails.type"> + </div> + </div> + + + <div class="form-group"> + <label class="col-xs-3 control-label">Valeur</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="contactDetails.value"> + </div> + </div> + + </form> + </div> + + <div class="panel-footer"> + + </div> +</div> \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsEditCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsEditCard.html new file mode 100644 index 0000000..5d116d1 --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsEditCard.html @@ -0,0 +1,50 @@ +<div class="panel panel-default"> + + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Éditer un moyen de contact</h3> + <div class="btn-group pull-right"> + <button class="btn btn-danger" ng-click="cancel()"> + <i class="fa fa-times"></i> + Annuler + </button> + <button class="btn btn-success" ng-click="saveContactDetails()"> + <i class="fa fa-check"></i> + Sauver + </button> + </div> + </div> + + <div class="modal-body"> + <form class="form-horizontal"> + <div class="form-group"> + <label class="col-xs-3 control-label">Nom</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="contactDetails.name"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Type</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="contactDetails.type"> + </div> + </div> + + + <div class="form-group"> + <label class="col-xs-3 control-label">Valeur</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="contactDetails.value"> + </div> + </div> + + </form> + </div> + + <div class="panel-footer"> + <button class="btn btn-danger btn-block" ng-click="deleteContactDetails()"> + <i class="fa fa-trash-o"></i> + Supprimer le moyen de contact + </button> + </div> +</div> \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsInfoCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsInfoCard.html new file mode 100644 index 0000000..6ff4a1d --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsInfoCard.html @@ -0,0 +1,33 @@ +<div class="panel panel-default"> + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Détails du moyen de contact</h3> + <div class="btn-group pull-right visible-xs"> + <a class="btn btn-primary" href="#/companies/{{company.wikittyId}}/contactDetails/{{contactDetails.wikittyId}}/edit"> + <i class="fa fa-pencil"></i> + <span>Edit</span> + </a> + </div> + <a class="btn btn-primary pull-right hidden-xs" href="#/companies/{{company.wikittyId}}/contactDetails/{{contactDetails.wikittyId}}/edit"> + <i class="fa fa-pencil"></i> + <span>Edit</span> + </a> + </div> + <div class="list-group"> + <div class="list-group-item"> + <i class="fa fa-2x fa-file-text-o pull-left"></i> + <label>Nom</label> + <h4 class="list-group-item-heading">{{contactDetails.name}}</h4> + </div> + <div class="list-group-item"> + <label>Type</label> + <h4 class="list-group-item-heading">{{contactDetails.type}}</h4> + </div> + <div class="list-group-item"> + <label>Valeur</label> + <h4 class="list-group-item-heading">{{contactDetails.value}}</h4> + </div> + </div> + <div class="panel-footer"> + <small class="pull-left"> </small> + </div> +</div> \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsListCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsListCard.html index 39b54b9..0263473 100644 --- a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsListCard.html +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/contactDetailsListCard.html @@ -2,26 +2,24 @@ <div class="panel-heading clearfix"> <h3 class="panel-title pull-left">Moyens de contact</h3> <div class="btn-group pull-right visible-xs"> - <a class="btn btn-primary" href="#" + <a class="btn btn-primary" href="#/companies/{{company.wikittyId}}/contactDetails/add" data-toggle="modal" data-target="#editModal"> - <i class="fa fa-pencil"></i> - <span>Edit</span> + <i class="fa fa-plus"></i> + <span>Ajouter</span> </a> </div> - <a class="btn btn-primary pull-right hidden-xs" href="#" - data-toggle="modal" - data-target="#editModal"> - <i class="fa fa-pencil"></i> - <span>Edit</span> + <a class="btn btn-primary pull-right hidden-xs" href="#/companies/{{company.wikittyId}}/contactDetails/add"> + <i class="fa fa-plus"></i> + <span>Ajouter</span> </a> </div> <div class="list-group"> - <div class="list-group-item" - ng-repeat="contact in contactDetails"> + <a class="list-group-item" ng-repeat="contact in contactDetails" + href="#/companies/{{company.wikittyId}}/contactDetails/{{contact.wikittyId}}"> <label>{{contact.type}} - {{contact.name}}</label> <h4 class="list-group-item-heading">{{contact.value}}</h4> - </div> + </a> </div> <div class="panel-footer"> <small class="pull-left"> </small> diff --git a/chorem-webmotion/src/main/webapp/js/crm.js b/chorem-webmotion/src/main/webapp/js/crm.js index ea67517..5d415b1 100644 --- a/chorem-webmotion/src/main/webapp/js/crm.js +++ b/chorem-webmotion/src/main/webapp/js/crm.js @@ -30,7 +30,19 @@ crmTest.config(['$routeProvider', when('/companies/:companyId/notes/:noteId/edit', { templateUrl:'partials/noteEditCard.html', - controller:'NoteEditController'}); + controller:'NoteEditController'}). + + when('/companies/:companyId/contactDetails/add', { + templateUrl:'partials/contactDetailsCreateCard.html', + controller:'ContactDetailsCreateController'}). + + when('/companies/:companyId/contactDetails/:contactDetailsId', { + templateUrl:'partials/contactDetailsInfoCard.html', + controller:'ContactDetailsDetailController'}). + + when('/companies/:companyId/contactDetails/:contactDetailsId/edit', { + templateUrl:'partials/contactDetailsEditCard.html', + controller:'ContactDetailsEditController'}); }]); //Should use heritage for next main list controllers @@ -305,3 +317,79 @@ crmTest.controller('NoteEditController', function ($scope, $http, $routeParams, } }); + +crmTest.controller('ContactDetailsCreateController', function ($scope, $http, $location, $route) { + + $scope.company = $scope.selectedItem; + + $scope.saveContactDetails = function(){ + $scope.contactDetails.target=$scope.company.wikittyId; + $http({ + method : 'PUT', + url : 'contactDetails/add', + data : $.param($scope.contactDetails), // pass in data as strings + headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload) + }) + .success(function(data) { + $location.path('companies/'+data); + $route.reload(); + }); + }; + + $scope.cancel = function(){ + $location.path('companies/'); + $route.reload(); + } + +}); + +crmTest.controller('ContactDetailsDetailController', function ($scope, $http, $routeParams){ + + $scope.company=$scope.selectedItem; + + $http.get('contactDetails/'+$routeParams.contactDetailsId).success(function(data){ + $scope.contactDetails = data; + }); + +}); + +crmTest.controller('ContactDetailsEditController', function ($scope, $http, $routeParams, $location, $route) { + + //copy selectedItem to not modify the parent one + $scope.company=$scope.selectedItem; + + $http.get('contactDetails/'+$routeParams.contactDetailsId).success(function(data){ + $scope.contactDetails = data; + }); + + $scope.saveContactDetails = function(){ + + $http({ + method : 'POST', + url : 'contactDetails/'+$scope.contactDetails.wikittyId, + data : $.param($scope.contactDetails), // pass in data as strings + headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload) + }) + .success(function(data) { + //then reload + $location.path('companies/'+$scope.selectedItem.wikittyId); + $route.reload(); + }); + }; + + $scope.cancel = function(){ + $location.path('companies/'+$scope.selectedItem.wikittyId); + $route.reload(); + } + + $scope.deleteContactDetails = function(){ + if(confirm('Are you sure you want to delete?')){ + $http.delete('contactDetails/'+$scope.contactDetails.wikittyId).success(function(data){ + + $location.path('companies'); + $route.reload(); + }); + } + } + +}); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.