This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit 91396303b4273f34348bfbfce74a715e7e2eb2d2 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Jan 21 17:50:23 2015 +0100 add edit document page --- .../src/main/webapp/js/coselmar-controllers.js | 83 +++++++- .../src/main/webapp/js/coselmar-services.js | 7 +- .../src/main/webapp/views/documents/document.html | 82 +------- .../main/webapp/views/documents/editDocument.html | 227 +++++++++++++++++++++ .../documents/{document.html => viewDocument.html} | 37 +--- 5 files changed, 320 insertions(+), 116 deletions(-) diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index e1eadae..83eba95 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -149,14 +149,14 @@ coselmarControllers.controller("NewDocumentCtrl", ['$scope', '$location', 'docum if (keyword && $scope.document.keywords.indexOf(keyword) == -1) { $scope.document.keywords.push(keyword); } - } + }; $scope.removeKeyword = function(keyword) { var position = $scope.document.keywords.indexOf(keyword); if (keyword && position != -1) { $scope.document.keywords.splice(position, 1); } - } + }; }]); @@ -167,7 +167,11 @@ coselmarControllers.controller("DocumentViewCtrl", $scope.container = {baseUrl : coselmarConfig.BASE_URL}; - documentService.getDocument($routeParams.documentId, $scope); + $scope.editSession = $routeParams.edit ? $routeParams.edit : false; + + documentService.getDocument($routeParams.documentId, function(document) { + $scope.document = document; + }); $scope.deleteDocument = function(documentId){ @@ -178,6 +182,79 @@ coselmarControllers.controller("DocumentViewCtrl", }); }; + + // edit part + + $scope.canEdit = true; + + //to enter in edit mode from view + $scope.edit = function() { + $location.search("edit"); + } + + $scope.existing = {'types' : [], 'keywords' : []}; + + if ($scope.editSession == true) { + documentService.findAllTypes(function(results) { + $scope.existing.types = results; + }); + + documentService.findAllKeywords(function(results) { + $scope.existing.keywords = results; + }); + } + + $scope.isFormValid = function() { + var isValid = $scope.document.name && $scope.document.name.length > 0; + console.log(isValid); + isValid = isValid && $scope.document.type && $scope.document.type.length > 0; + isValid = isValid && $scope.document.keywords && $scope.document.keywords.length > 0; + isValid = isValid && $scope.document.authors && $scope.document.authors.length > 0; + isValid = isValid && $scope.document.copyright && $scope.document.copyright.length > 0; + isValid = isValid && $scope.document.summary && $scope.document.summary.length > 0; + if (!$scope.document.fileName) { + isValid = isValid && $scope.document.externalUrl && $scope.document.externalUrl.length > 0; + } + return isValid; + }; + + $scope.saveDocument = function(){ + + if (angular.isDate($scope.document.publicationDate)) { + $scope.document.publicationDate = $scope.document.publicationDate.getTime(); + } + + // Call service to create a new document + if ($scope.isFormValid()) { + $scope.hasErrors = false; + + documentService.saveDocument($scope.document, function() { + $location.search(""); + }, function(error) { + console.log("error occurs"); + } + ); + + } else { + $scope.hasErrors = true; + } + + }; + + $scope.addKeyword = function(keyword) { + if (keyword && $scope.document.keywords.indexOf(keyword) == -1) { + $scope.document.keywords.push(keyword); + } + }; + + $scope.removeKeyword = function(keyword) { + var position = $scope.document.keywords.indexOf(keyword); + if (keyword && position != -1) { + $scope.document.keywords.splice(position, 1); + } + }; + + } ]); // Controller for document file download diff --git a/coselmar-ui/src/main/webapp/js/coselmar-services.js b/coselmar-ui/src/main/webapp/js/coselmar-services.js index e0cebeb..76cadac 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -91,13 +91,10 @@ function Document(resource, config){ docResource.upload(null, formData, successFunction, failFunction); }; - this.getDocument = function(id, scope){ + this.getDocument = function(id, successFunction){ // Load the document var docResource = resource(baseURL + '/:documentId', {documentId:'@documentId'}); - docResource.get({documentId:id}, function(document){ - console.log(document); - scope.document = document; - }); + docResource.get({documentId:id}, successFunction); }; this.deleteDocument = function(id, scope, successFunction){ diff --git a/coselmar-ui/src/main/webapp/views/documents/document.html b/coselmar-ui/src/main/webapp/views/documents/document.html index c6f382b..5ca277c 100644 --- a/coselmar-ui/src/main/webapp/views/documents/document.html +++ b/coselmar-ui/src/main/webapp/views/documents/document.html @@ -22,82 +22,6 @@ #L% --> <div style="padding: 0px 0px 0px 30px"> - <div class="page-header" style="margin: 0"> - <h1> - <!-- Heading goes here --> - Document's Details - </h1> - </div> - <div> - <table class="table table-striped"> - <tr> - <td>File Name</td> - <td>{{document.name}}</td> - </tr> - <tr> - <td>Depositor</td> - <td>{{document.ownerName}}</td> - </tr> - <tr> - <td>Type</td> - <td>{{document.type}}</td> - </tr> - <tr> - <td>Keywords</td> - <td>{{document.keywords}}</td> - </tr> - <tr> - <td>Privacy</td> - <td>{{document.privacy}}</td> - </tr> - <tr> - <td>Deposite Date</td> - <td>{{document.depositDate | date:'mediumDate'}}</td> - </tr> - <tr> - <td>Summary</td> - <td>{{document.summary}}</td> - </tr> - <tr> - <td>Authors</td> - <td>{{document.authors}}</td> - </tr> - <tr> - <td>Copyright</td> - <td>{{document.copyright}}</td> - </tr> - <tr> - <td>License</td> - <td>{{document.license}}</td> - </tr> - <tr> - <td>Language</td> - <td>{{document.language}}</td> - </tr> - <tr> - <td>PublicationDate</td> - <td>{{document.publicationDate | date:'mediumDate'}}</td> - </tr> - <tr> - <td>Document type</td> - <td ng-if="document.withFile">{{document.mimeType}}</td> - <td ng-if="!document.withFile">External Link</td> - </tr> - <tr ng-if="document.withFile && document.fileName"> - <td>Document File</td> - <td>{{document.fileName}}</td> - </tr> - <tr> - <td>Comment</td> - <td>{{document.comment}}</td> - </tr> - </table> - <div class="float-right"> - <a href="{{container.baseUrl}}/documents/{{document.id}}/file" class="btn btn-primary" ng-if="document.withFile">Download</a> - <a href="{{document.externalUrl}}" target="_blank" class="btn btn-primary" ng-if="document.externalUrl">Open Link</a> - <a class="btn btn-danger" - ng-confirm-message="Do you really want to delete this document ?" - ng-confirm-click="deleteDocument(document.id)">Delete</a> - </div> - </div> -</div> \ No newline at end of file + <div ng-include="src='views/documents/viewDocument.html'" ng-if="editSession != true" /> + <div ng-include="src='views/documents/editDocument.html'" ng-if="editSession == true" /> +</div> diff --git a/coselmar-ui/src/main/webapp/views/documents/editDocument.html b/coselmar-ui/src/main/webapp/views/documents/editDocument.html new file mode 100644 index 0000000..af40a5f --- /dev/null +++ b/coselmar-ui/src/main/webapp/views/documents/editDocument.html @@ -0,0 +1,227 @@ + <div class="page-header" style="margin: 0"> + <h2>{{document.name}}</h2> + </div> + + <div style="padding-bottom: 50px"> + + <div class=""> + + <form class="form-horizontal" name="documentForm" role="form" > + + <!-- Line with Title, type and privacy --> + <div class="form-group row"> + <div ng-class="{'has-error' : documentForm.name.$invalid && !documentForm.name.$pristine}"> + <label class="col-md-2 control-label">Name *</label> + + <div class="col-md-4"> + <input type="text" class="form-control" name="name" + placeholder="Document Name" + ng-model="document.name" required/> + + <p ng-show="documentForm.name.$invalid && !documentForm.name.$pristine" + class="help-block">Document name is required.</p> + </div> + </div> + + <div class="" + ng-class="{'has-error' : documentForm.type.$invalid && !documentForm.type.$pristine}"> + <label class="col-md-1 control-label">Type *</label> + + <div class="col-md-2"> + <input type="text" class="form-control" name="type" + data-ng-model="document.type" list="existingTypes" required/> + + <p ng-show="documentForm.type.$invalid && !documentForm.type.$pristine" + class="help-block">Document type is required.</p> + </div> + <datalist id="existingTypes"> + <option data-ng-repeat="type in existing.types" value="{{type}}"> + </datalist> + </div> + + <div> + + <label class="col-md-1 control-label">Privacy</label> + + <div class="col-md-2"> + <input type="text" class="form-control" name="type" + data-ng-model="document.privacy" disabled="disabled"/> + </div> + </div> + </div> + + <!-- Line with Data : file or External URL --> + <div class="form-group" + ng-class="{'has-error' : !document.externalUrl + && !documentForm.externalUrl.$pristine && !document.fileName}"> + + <div> + <label class="col-md-2 control-label">File</label> + + <div class="col-md-4"> + <input type="text" class="form-control" name="fileName" + data-ng-model="document.fileName" disabled="disabled" /> + </div> + </div> + + <div> + <label class="col-md-2 control-label">External URL</label> + + <div class="col-md-4"> + <input type="input" class="form-control" name="externalUrl" + placeholder="http://website" + ng-model="document.externalUrl" /> + + </div> + </div> + <p ng-show="!document.externalUrl && !documentForm.externalUrl.$pristine && !document.fileName" + class="help-block text-center clear">For this document, an external URL is required.</p> + </div> + + <!-- Line with Keywords --> + <div class="form-group"> + <div ng-class="{'has-error' : documentForm.keywords.$invalid + && !documentForm.keywords.$pristine}"> + + <label class="col-md-2 control-label">keywords *</label> + + <div class="col-md-2"> + <input type="text" class="form-control" name="keywords" + placeholder="Validate with add" + ng-model="toAddKeyword" list="existingKeywords" /> + + <p ng-show="document.keywords.length < 1 && !documentForm.keywords.$pristine" + class="help-block">At least one keyword is required.</p> + </div> + <datalist id="existingKeywords"> + <option data-ng-repeat="keyword in existing.keywords" value="{{keyword}}"> + </datalist> + </div> + + <div class="col-md-1"> + <button class="btn btn-primary" value="add" + ng-click="addKeyword(toAddKeyword); toAddKeyword=''">add</button> + </div> + + + <div class="col-md-7"> + <span ng-repeat="keyword in document.keywords" class="" aria-hidden="true"> + {{keyword}} + <button type="button" class="close" title="remove" ng-click="removeKeyword(keyword);"> + × + </button> + </span> + + </div> + </div> + + <!-- Line with Authors and copyright--> + <div class="form-group"> + <div ng-class="{'has-error' : documentForm.authors.$invalid + && !documentForm.authors.$pristine}"> + <label class="col-md-2 control-label">Authors *</label> + + <div class="col-md-4"> + <input type="text" class="form-control" name="authors" + placeholder="Name FirstName" + ng-model="document.authors" required/> + + <p ng-show="documentForm.authors.$invalid && !documentForm.authors.$pristine" + class="help-block">Document authors is required.</p> + </div> + </div> + + <div ng-class="{'has-error' : documentForm.copyright.$invalid + && !documentForm.copyright.$pristine}"> + + <label class="col-md-2 control-label">Copyright *</label> + + <div class="col-md-4"> + <input type="text" class="form-control" name="copyright" + placeholder="Copyright owner" + ng-model="document.copyright" required/> + + <p ng-show="documentForm.copyright.$invalid && !documentForm.copyright.$pristine" + class="help-block">Copyright is required.</p> + </div> + </div> + </div> + + <!-- Line with License, publication date and language --> + <div class="form-group"> + <div > + <label class="col-md-2 control-label">Licence</label> + + <div class="col-md-4"> + <input type="text" class="form-control" name="licence" + placeholder="License of document" + ng-model="document.licence"/> + </div> + </div> + + <div> + <label class="col-md-1 control-label">Language</label> + + <div class="col-md-1"> + <input type="text" class="form-control" name="language" + placeholder="en,fr,..." + ng-model="document.language"/> + </div> + </div> + + <div> + <label class="col-md-2 control-label">Publication date</label> + + <div class="col-md-2"> + <div class="input-group"> + <input type="text" class="form-control" name="publicationDate" + placeholder="dd/MM/yyyy" + ng-model="document.publicationDate" + datepicker-popup="dd/MM/yyyy" is-open="publicationDateOpened" + ng-click="publicationDateOpened = true"/> + <span class="input-group-addon"><span class="glyphicon glyphicon-calendar" aria-hidden="true"></span></span> + </div> + </div> + + </div> + </div> + + <!-- Summary --> + <div class="form-group" + ng-class="{'has-error' : documentForm.summary.$invalid && !documentForm.summary.$pristine}"> + <label class="col-md-2 control-label">Summary *</label> + + <div class="col-md-10"> + <textarea type="text" class="form-control" name="summary" rows="5" + placeholder="Tape the document summary, it will help to retrieve document" + ng-model="document.summary" required/> + + <p ng-show="documentForm.summary.$invalid && !documentForm.summary.$pristine" + class="help-block">A summary is required.</p> + </div> + </div> + + <!-- Comment --> + <div class="form-group" > + <label class="col-md-2 control-label">Comment</label> + + <div class="col-md-10"> + <textarea type="text" class="form-control" name="comment" rows="5" + ng-model="document.comment" /> + + </div> + </div> + + <div class="form-group"> + <div ng-if="hasErrors" class="has-error"> + <div class="text-center help-block">Some mandatory fields (*) have not been filled.</div> + </div> + <div class="float-right col-md-4"> + <input type="submit" value="Submit" class="btn btn-action btn-success" + ng-click="saveDocument()" /> + </div> + </div> + </form> + </div> + + </div> diff --git a/coselmar-ui/src/main/webapp/views/documents/document.html b/coselmar-ui/src/main/webapp/views/documents/viewDocument.html similarity index 67% copy from coselmar-ui/src/main/webapp/views/documents/document.html copy to coselmar-ui/src/main/webapp/views/documents/viewDocument.html index c6f382b..e604b4f 100644 --- a/coselmar-ui/src/main/webapp/views/documents/document.html +++ b/coselmar-ui/src/main/webapp/views/documents/viewDocument.html @@ -1,27 +1,4 @@ -<!-- - #%L - Coselmar :: UI - $Id:$ - $HeadURL:$ - %% - Copyright (C) 2014 Ifremer, Code Lutin - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program. If not, see - <http://www.gnu.org/licenses/gpl-3.0.html>. - #L% - --> -<div style="padding: 0px 0px 0px 30px"> + <div class="page-header" style="margin: 0"> <h1> <!-- Heading goes here --> @@ -93,11 +70,13 @@ </tr> </table> <div class="float-right"> - <a href="{{container.baseUrl}}/documents/{{document.id}}/file" class="btn btn-primary" ng-if="document.withFile">Download</a> - <a href="{{document.externalUrl}}" target="_blank" class="btn btn-primary" ng-if="document.externalUrl">Open Link</a> - <a class="btn btn-danger" + <a class="btn btn-action btn-edit" ng-click="edit()" ng-if="editSession != true && canEdit"> + <span class="fa fa-edit" aria-hidden="true"></span>Edit + </a> + <a href="{{container.baseUrl}}/documents/{{document.id}}/file" class="btn btn-action btn-success" ng-if="document.withFile">Download</a> + <a href="{{document.externalUrl}}" target="_blank" class="btn btn-action btn-success" ng-if="document.externalUrl">Open Link</a> + <a class="btn btn-action btn-disable" ng-confirm-message="Do you really want to delete this document ?" ng-confirm-click="deleteDocument(document.id)">Delete</a> </div> - </div> -</div> \ No newline at end of file + </div> \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.