add valid-file directive for front-end

This commit is contained in:
Brian Gough 2018-02-05 16:56:52 +00:00
parent f20d36044b
commit ddf1d6e65e
5 changed files with 22 additions and 10 deletions

View file

@ -119,6 +119,7 @@ script(type='text/ng-template', id='entityListItemTemplate')
ng-blur="finishRenaming()",
select-name-when="entity.renaming",
on-enter="finishRenaming()"
valid-file
)
span.dropdown.entity-menu-toggle(
@ -207,6 +208,7 @@ script(type='text/ng-template', id='entityListItemTemplate')
ng-blur="finishRenaming()",
select-name-when="entity.renaming",
on-enter="finishRenaming()"
valid-file
)
span.dropdown.entity-menu-toggle(
@ -316,10 +318,10 @@ script(type='text/ng-template', id='newDocModalTemplate')
ng-model="inputs.name",
on-enter="create()",
select-name-on="open",
ng-pattern="validFileRegex",
valid-file,
name="name"
)
.text-danger.row-spaced-small(ng-show="newDocForm.name.$error.pattern")
.text-danger.row-spaced-small(ng-show="newDocForm.name.$error.validFile")
| #{translate('files_cannot_include_invalid_characters')}
.modal-footer
button.btn.btn-default(
@ -347,10 +349,10 @@ script(type='text/ng-template', id='newFolderModalTemplate')
ng-model="inputs.name",
on-enter="create()",
select-name-on="open",
ng-pattern="validFileRegex",
valid-file,
name="name"
)
.text-danger.row-spaced-small(ng-show="newFolderForm.name.$error.pattern")
.text-danger.row-spaced-small(ng-show="newFolderForm.name.$error.validFile")
| #{translate('files_cannot_include_invalid_characters')}
.modal-footer
button.btn.btn-default(

View file

@ -20,6 +20,7 @@ define [
"ide/hotkeys/index"
"ide/wordcount/index"
"ide/directives/layout"
"ide/directives/validFile"
"ide/services/ide"
"__IDE_CLIENTSIDE_INCLUDES__"
"analytics/AbTestingManager"

View file

@ -0,0 +1,12 @@
define [
"base"
], (App) ->
App.directive "validFile", () ->
return {
require: 'ngModel'
link: (scope, element, attrs, ngModelCtrl) ->
ngModelCtrl.$validators.validFile = (modelValue) ->
validFileRegex = /^[^\*\/]*$/ # Don't allow * and /
isValid = modelValue.match validFileRegex
return isValid
}

View file

@ -44,8 +44,6 @@ define [
App.controller "NewDocModalController", [
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
($scope, ide, $modalInstance, $timeout, parent_folder) ->
$scope.validFileRegex = ide.validFileRegex
$scope.inputs =
name: "name.tex"
$scope.state =
@ -78,8 +76,6 @@ define [
App.controller "NewFolderModalController", [
"$scope", "ide", "$modalInstance", "$timeout", "parent_folder",
($scope, ide, $modalInstance, $timeout, parent_folder) ->
$scope.validFileRegex = ide.validFileRegex
$scope.inputs =
name: "name"
$scope.state =

View file

@ -32,8 +32,9 @@ define [
return if !$scope.entity.renaming
name = $scope.inputs.name
if !name.match(new RegExp(ide.validFileRegex))
# validator will set name to undefined for invalid filenames
if !name?
# Showing the modal blurs the rename box which calls us again
# so track this with the invalidModalShowing flag
return if invalidModalShowing