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 2cc12ef17d27a63e582cf9d051e14bed98fba930 Author: kootox <jean.couteau@gmail.com> Date: Thu Mar 5 14:49:02 2015 +0100 refs #882 : Note CRUD on companies screen --- .../chorem/webmotion/actions/crm/NoteAction.java | 42 ++++++++++ chorem-webmotion/src/main/resources/mapping | 4 + .../WEB-INF/jsp/crm/partials/noteCreateCard.html | 47 +++++++++++ .../WEB-INF/jsp/crm/partials/noteDetailCard.html | 33 ++++++++ .../WEB-INF/jsp/crm/partials/noteEditCard.html | 50 ++++++++++++ .../WEB-INF/jsp/crm/partials/notesListCard.html | 20 ++--- chorem-webmotion/src/main/webapp/js/crm.js | 94 +++++++++++++++++++++- 7 files changed, 276 insertions(+), 14 deletions(-) diff --git a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/NoteAction.java b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/NoteAction.java index 5dff8c3..a2bcc70 100644 --- a/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/NoteAction.java +++ b/chorem-webmotion/src/main/java/org/chorem/webmotion/actions/crm/NoteAction.java @@ -2,6 +2,7 @@ package org.chorem.webmotion.actions.crm; import org.chorem.ChoremClient; import org.chorem.entities.Note; +import org.chorem.entities.NoteImpl; import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; import org.nuiton.wikitty.query.WikittyQuery; @@ -35,4 +36,45 @@ public class NoteAction extends WebMotionController{ return renderJSON(noteDTOs); } + + public Render getNote(ChoremClient client, String id) { + Note note = client.restore(Note.class, id); + + NoteDTO noteDTO = new NoteDTO(note); + + return renderJSON(noteDTO); + + } + + public Render createNote(ChoremClient client, NoteDTO noteDTO) { + Note note = new NoteImpl(); + note.setTarget(noteDTO.getTarget()); + note.setContent(noteDTO.getContent()); + note.setTitle(noteDTO.getTitle()); + note.setDate(noteDTO.getDate()); + note = client.store(note); + + noteDTO = new NoteDTO(note); + + return renderJSON(noteDTO); + } + + + public Render updateNote(ChoremClient client, String id, NoteDTO noteDTO) { + Note note = client.restore(Note.class, id); + note.setTitle(noteDTO.getTitle()); + note.setDate(noteDTO.getDate()); + note.setContent(noteDTO.getContent()); + note = client.store(note); + + noteDTO = new NoteDTO(note); + + return renderJSON(noteDTO); + } + + public Render deleteNote(ChoremClient client, String id) { + client.delete(id); + + return renderSuccess(); + } } diff --git a/chorem-webmotion/src/main/resources/mapping b/chorem-webmotion/src/main/resources/mapping index bc14900..774a512 100644 --- a/chorem-webmotion/src/main/resources/mapping +++ b/chorem-webmotion/src/main/resources/mapping @@ -105,6 +105,10 @@ DELETE /crm/companies/{id} action:crm.CompaniesAction.deleteCompa GET /crm/companies/{id}/contactDetails action:crm.ContactDetailsAction.listContactDetails GET /crm/companies/{id}/notes action:crm.NoteAction.listNotes +PUT /crm/notes/add action:crm.NoteAction.createNote +POST /crm/notes/{id} action:crm.NoteAction.updateNote +GET /crm/notes/{id} action:crm.NoteAction.getNote +DELETE /crm/notes/{id} action:crm.NoteAction.deleteNote GET /crm/companies/{id}/employees action:crm.EmployeeAction.listEmployees diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/noteCreateCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/noteCreateCard.html new file mode 100644 index 0000000..dc1dd95 --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/noteCreateCard.html @@ -0,0 +1,47 @@ +<div class="panel panel-default"> + + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Créer une note pour {{company.name}}</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="saveNote()"> + <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">Titre</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="note.title"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Date</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="note.date"> + </div> + </div> + + + <div class="form-group"> + <label class="col-xs-3 control-label">Contenu</label> + <div class="col-xs-9"> + <textarea class="form-control" ng-model="note.content"/> + </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/noteDetailCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/noteDetailCard.html new file mode 100644 index 0000000..538e79e --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/noteDetailCard.html @@ -0,0 +1,33 @@ +<div class="panel panel-default"> + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Détails de la note</h3> + <div class="btn-group pull-right visible-xs"> + <a class="btn btn-primary" href="#/companies/{{company.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}}/notes/{{note.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>Titre</label> + <h4 class="list-group-item-heading">{{note.title}}</h4> + </div> + <div class="list-group-item"> + <label>Date</label> + <h4 class="list-group-item-heading">{{note.date |date:'dd/MM:yyy'}}</h4> + </div> + <div class="list-group-item"> + <label>Description</label> + <h4 class="list-group-item-heading">{{note.content}}</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/noteEditCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/noteEditCard.html new file mode 100644 index 0000000..8ca1c6c --- /dev/null +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/noteEditCard.html @@ -0,0 +1,50 @@ +<div class="panel panel-default"> + + <div class="panel-heading clearfix"> + <h3 class="panel-title pull-left">Éditer une note</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="saveNote()"> + <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">Titre</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="note.title"> + </div> + </div> + + <div class="form-group"> + <label class="col-xs-3 control-label">Date</label> + <div class="col-xs-9"> + <input type="text" class="form-control" ng-model="note.date"> + </div> + </div> + + + <div class="form-group"> + <label class="col-xs-3 control-label">Contenu</label> + <div class="col-xs-9"> + <textarea class="form-control" ng-model="note.content"></textarea> + </div> + </div> + + </form> + </div> + + <div class="panel-footer"> + <button class="btn btn-danger btn-block" ng-click="deleteNote()"> + <i class="fa fa-trash-o"></i> + Supprimer la note + </button> + </div> +</div> \ No newline at end of file diff --git a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/notesListCard.html b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/notesListCard.html index 13069bd..a89bd60 100644 --- a/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/notesListCard.html +++ b/chorem-webmotion/src/main/webapp/WEB-INF/jsp/crm/partials/notesListCard.html @@ -2,25 +2,21 @@ <div class="panel-heading clearfix"> <h3 class="panel-title pull-left">Notes</h3> <div class="btn-group pull-right visible-xs"> - <a class="btn btn-primary" href="#" - data-toggle="modal" - data-target="#editModal"> + <a class="btn btn-primary" href="#/companies/{{company.wikittyId}}/notes/add"> <i class="fa fa-pencil"></i> - <span>Edit</span> + <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}}/notes/add"> + <i class="fa fa-plus"></i> + <span>Ajouter</span> </a> </div> <div class="list-group"> - <div class="list-group-item" ng-repeat="note in notes"> - <label>{{note.date}}</label> + <a class="list-group-item" ng-repeat="note in notes" href="#/companies/{{company.wikittyId}}/notes/{{note.wikittyId}}"/> <h4 class="list-group-item-heading">{{note.title}}</h4> - </div> + <label>{{note.date | date : dd/MM/yyy}}</label> + </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 001603c..ea67517 100644 --- a/chorem-webmotion/src/main/webapp/js/crm.js +++ b/chorem-webmotion/src/main/webapp/js/crm.js @@ -18,7 +18,19 @@ crmTest.config(['$routeProvider', when('/companies/:companyId/edit', { templateUrl:'partials/companyEditCard.html', - controller:'CompanyEditController'}); + controller:'CompanyEditController'}). + + when('/companies/:companyId/notes/add', { + templateUrl:'partials/noteCreateCard.html', + controller:'NoteCreateController'}). + + when('/companies/:companyId/notes/:noteId', { + templateUrl:'partials/noteDetailCard.html', + controller:'NoteDetailController'}). + + when('/companies/:companyId/notes/:noteId/edit', { + templateUrl:'partials/noteEditCard.html', + controller:'NoteEditController'}); }]); //Should use heritage for next main list controllers @@ -214,4 +226,82 @@ crmTest.controller('CompanyCreateController', function ($scope, $http, $location $route.reload(); } -}); \ No newline at end of file +}); + +crmTest.controller('NoteCreateController', function ($scope, $http, $location, $route) { + + $scope.company = $scope.selectedItem; + + //$scope.note.target = $scope.company.wikittyId; + + $scope.saveNote = function(){ + $scope.note.target=$scope.company.wikittyId; + $http({ + method : 'PUT', + url : 'notes/add', + data : $.param($scope.note), // 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('NoteDetailController', function ($scope, $http, $routeParams){ + + $scope.company=$scope.selectedItem; + + $http.get('notes/'+$routeParams.noteId).success(function(data){ + $scope.note = data; + }); + +}); + +crmTest.controller('NoteEditController', function ($scope, $http, $routeParams, $location, $route) { + + //copy selectedItem to not modify the parent one + $scope.company=$scope.selectedItem; + + $http.get('notes/'+$routeParams.noteId).success(function(data){ + $scope.note = data; + }); + + $scope.saveNote = function(){ + + $http({ + method : 'POST', + url : 'notes/'+$scope.note.wikittyId, + data : $.param($scope.note), // 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.deleteNote = function(){ + if(confirm('Are you sure you want to delete?')){ + $http.delete('notes/'+$scope.note.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>.