mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
28 lines
852 B
CoffeeScript
28 lines
852 B
CoffeeScript
angular.module("admin.enterprises")
|
|
.controller "permalinkCtrl", ($scope, PermalinkChecker) ->
|
|
# locals
|
|
initialPermalink = $scope.Enterprise.permalink
|
|
pendingRequest = null
|
|
|
|
# variables on $scope
|
|
$scope.availablility = ""
|
|
$scope.checking = false
|
|
|
|
$scope.$watch "Enterprise.permalink", (newValue, oldValue) ->
|
|
if newValue == initialPermalink
|
|
$scope.availability = ""
|
|
return
|
|
|
|
$scope.checking = true
|
|
pendingRequest = PermalinkChecker.check(newValue)
|
|
|
|
pendingRequest.then (data) ->
|
|
if data.permalink == initialPermalink
|
|
$scope.availability = ""
|
|
else
|
|
$scope.availability = data.available
|
|
$scope.Enterprise.permalink = data.permalink
|
|
$scope.checking = false
|
|
, (data) ->
|
|
# Do nothing (this is hopefully an aborted request)
|