From 05683ef81eaca3fdc6c8cdf1651477828b0870f3 Mon Sep 17 00:00:00 2001 From: jendib Date: Fri, 2 Aug 2013 23:59:00 +0200 Subject: [PATCH] Autocomplete on document title edition --- docs-parent/TODO | 1 - .../main/webapp/js/controller/DocumentEdit.js | 20 ++++++++++++++++++- .../main/webapp/partial/document.edit.html | 5 ++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs-parent/TODO b/docs-parent/TODO index f8c0fc2f..d299795a 100644 --- a/docs-parent/TODO +++ b/docs-parent/TODO @@ -1,4 +1,3 @@ -- Autocomplete on document title (client/server) - List opened sessions and ability to close them (client/server) - Display logs (client) - Reordering files and add new files to the end (server) diff --git a/docs-web/src/main/webapp/js/controller/DocumentEdit.js b/docs-web/src/main/webapp/js/controller/DocumentEdit.js index 6126fb70..60c0e4e9 100644 --- a/docs-web/src/main/webapp/js/controller/DocumentEdit.js +++ b/docs-web/src/main/webapp/js/controller/DocumentEdit.js @@ -14,6 +14,23 @@ App.controller('DocumentEdit', function($scope, $q, $http, $state, $stateParams, $scope.alerts.splice(index, 1); }; + /** + * Returns a promise for typeahead title. + */ + $scope.getTitleTypeahead = function($viewValue) { + var deferred = $q.defer(); + Restangular.one('document') + .getList('list', { + limit: 5, + sort_column: 1, + asc: true, + search: $viewValue + }).then(function(data) { + deferred.resolve(_.pluck(data.documents, 'title')); + }); + return deferred.promise; + }; + /** * Returns true if in edit mode (false in add mode). */ @@ -38,6 +55,8 @@ App.controller('DocumentEdit', function($scope, $q, $http, $state, $stateParams, $scope.edit = function() { var promise = null; var document = angular.copy($scope.document); + + // Transform date to timestamp if (document.create_date instanceof Date) { document.create_date = document.create_date.getTime(); } @@ -57,7 +76,6 @@ App.controller('DocumentEdit', function($scope, $q, $http, $state, $stateParams, // Upload files after edition promise.then(function(data) { - var promises = []; $scope.fileProgress = 0; // When all files upload are over, move on diff --git a/docs-web/src/main/webapp/partial/document.edit.html b/docs-web/src/main/webapp/partial/document.edit.html index 517bd211..fb8c2b57 100644 --- a/docs-web/src/main/webapp/partial/document.edit.html +++ b/docs-web/src/main/webapp/partial/document.edit.html @@ -2,7 +2,10 @@
- +