Implements a validation for empty titles input at the side bar

Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
This commit is contained in:
Michael Weimann
2018-09-06 20:48:41 +02:00
committed by Julius Härtl
parent d17cd78605
commit df43e07057
2 changed files with 31 additions and 11 deletions

View File

@@ -4,20 +4,20 @@
* @author Julius Härtl <jus@bitgrid.net> * @author Julius Härtl <jus@bitgrid.net>
* *
* @license GNU AGPL version 3 or any later version * @license GNU AGPL version 3 or any later version
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
/* global app moment angular OC */ /* global app moment angular OC */
@@ -26,6 +26,7 @@ import app from '../app/App.js';
app.controller('CardController', function ($scope, $rootScope, $sce, $location, $stateParams, $state, $interval, $timeout, $filter, BoardService, CardService, StackService, StatusService, markdownItConverter, FileService) { app.controller('CardController', function ($scope, $rootScope, $sce, $location, $stateParams, $state, $interval, $timeout, $filter, BoardService, CardService, StackService, StatusService, markdownItConverter, FileService) {
$scope.sidebar = $rootScope.sidebar; $scope.sidebar = $rootScope.sidebar;
$scope.status = { $scope.status = {
renameTitle: '',
lastEdit: 0, lastEdit: 0,
lastSave: Date.now() lastSave: Date.now()
}; };
@@ -89,9 +90,10 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
}); });
$scope.cardRenameShow = function () { $scope.cardRenameShow = function () {
if ($scope.archived || !BoardService.canEdit()) if ($scope.archived || !BoardService.canEdit()) {
{return false;} return false;
else { } else {
$scope.status.renameTitle = CardService.getCurrent().title;
$scope.status.cardRename = true; $scope.status.cardRename = true;
} }
}; };
@@ -167,9 +169,27 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
// handle rename to update information on the board as well // handle rename to update information on the board as well
$scope.cardRename = function (card) { $scope.cardRename = function (card) {
CardService.rename(card).then(function (data) { var newTitle;
if (!$scope.status.renameTitle || !$scope.status.renameTitle.trim()) {
newTitle = '';
} else {
newTitle = $scope.status.renameTitle.trim();
}
if (newTitle === card.title) {
// title unchanged
$scope.status.renameCard = false; $scope.status.renameCard = false;
}); } else if (newTitle !== '') {
// title changed
card.title = newTitle;
CardService.rename(card).then(function (data) {
$scope.status.renameCard = false;
});
} else {
// empty title
$scope.status.renameTitle = card.title;
$scope.status.renameCard = false;
}
}; };
$scope.cardUpdate = function (card) { $scope.cardUpdate = function (card) {
CardService.update(card).then(function (data) { CardService.update(card).then(function (data) {
@@ -220,7 +240,7 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
element.duedate = null; element.duedate = null;
CardService.update(element); CardService.update(element);
}; };
/** /**
* Show ui-select field when clicking the add button * Show ui-select field when clicking the add button
*/ */

View File

@@ -15,7 +15,7 @@
<!-- TODO: change to textarea elastic //--> <!-- TODO: change to textarea elastic //-->
<form ng-submit="cardRename(cardservice.getCurrent())"> <form ng-submit="cardRename(cardservice.getCurrent())">
<input class="input-inline" type="text" ng-if="status.cardRename" <input class="input-inline" type="text" ng-if="status.cardRename"
ng-model="cardservice.getCurrent().title" ng-model="status.renameTitle"
ng-blur="cardRename(cardservice.getCurrent())" ng-blur="cardRename(cardservice.getCurrent())"
autofocus-on-insert required maxlength="100"> autofocus-on-insert required maxlength="100">
</form> </form>