2016-05-12 21:59:49 +00:00
|
|
|
/**
|
|
|
|
* An element which displays a create entity dialog.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('createEntityDialog', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/create-entity-dialog.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: true,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'info': '=info',
|
|
|
|
|
|
|
|
'entityKind': '@entityKind',
|
|
|
|
'entityTitle': '@entityTitle',
|
|
|
|
'entityIcon': '@entityIcon',
|
|
|
|
'entityNameRegex': '@entityNameRegex',
|
2018-03-09 21:28:52 +00:00
|
|
|
'allowEntityDescription': '@allowEntityDescription',
|
2016-05-12 21:59:49 +00:00
|
|
|
|
|
|
|
'entityCreateRequested': '&entityCreateRequested',
|
|
|
|
'entityCreateCompleted': '&entityCreateCompleted'
|
|
|
|
},
|
|
|
|
|
2016-08-18 19:59:00 +00:00
|
|
|
controller: function($scope, $element, ApiService, UIService, UserService) {
|
|
|
|
$scope.context = {
|
2016-08-22 18:42:35 +00:00
|
|
|
'setPermissionsCounter': 0
|
2016-05-12 21:59:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
if ($scope.inBody) {
|
|
|
|
document.body.removeChild($element[0]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.hide = function() {
|
|
|
|
$element.find('.modal').modal('hide');
|
|
|
|
if ($scope.entity) {
|
|
|
|
$scope.entityCreateCompleted({'entity': $scope.entity});
|
|
|
|
$scope.entity = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.show = function() {
|
|
|
|
$scope.entityName = null;
|
2018-03-09 21:28:52 +00:00
|
|
|
$scope.entityDescription = null;
|
2016-05-12 21:59:49 +00:00
|
|
|
$scope.entity = null;
|
2016-08-18 19:59:00 +00:00
|
|
|
$scope.entityForPermissions = null;
|
2016-05-12 21:59:49 +00:00
|
|
|
$scope.creating = false;
|
|
|
|
$scope.view = 'enterName';
|
|
|
|
$scope.enterNameForm.$setPristine(true);
|
|
|
|
|
|
|
|
// Move the dialog to the body to prevent it from nesting if called
|
|
|
|
// from within another dialog.
|
|
|
|
$element.find('.modal').modal({});
|
|
|
|
$scope.inBody = true;
|
|
|
|
document.body.appendChild($element[0]);
|
|
|
|
};
|
|
|
|
|
|
|
|
var entityCreateCallback = function(entity) {
|
2016-08-18 19:59:00 +00:00
|
|
|
$scope.entity = entity;
|
|
|
|
|
2016-05-12 21:59:49 +00:00
|
|
|
if (!entity || $scope.info.skip_permissions) {
|
|
|
|
$scope.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.createEntity = function() {
|
|
|
|
$scope.view = 'creating';
|
|
|
|
$scope.entityCreateRequested({
|
|
|
|
'name': $scope.entityName,
|
2018-03-09 21:28:52 +00:00
|
|
|
'description': $scope.entityDescription,
|
2016-05-12 21:59:49 +00:00
|
|
|
'callback': entityCreateCallback
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-22 18:42:35 +00:00
|
|
|
$scope.permissionsSet = function(repositories) {
|
2016-08-18 21:44:36 +00:00
|
|
|
$scope.entity['repo_count'] = repositories.length;
|
2016-08-18 19:59:00 +00:00
|
|
|
$scope.hide();
|
2016-06-20 18:33:40 +00:00
|
|
|
};
|
|
|
|
|
2016-08-22 18:42:35 +00:00
|
|
|
$scope.settingPermissions = function() {
|
|
|
|
$scope.view = 'settingperms';
|
2016-06-20 18:33:40 +00:00
|
|
|
};
|
|
|
|
|
2016-08-22 18:42:35 +00:00
|
|
|
$scope.setPermissions = function() {
|
|
|
|
$scope.context.setPermissionsCounter++;
|
2016-06-20 18:33:40 +00:00
|
|
|
};
|
|
|
|
|
2016-08-18 19:59:00 +00:00
|
|
|
$scope.repositoriesLoaded = function(repositories) {
|
|
|
|
if (repositories && !repositories.length) {
|
|
|
|
$scope.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-22 18:42:35 +00:00
|
|
|
$scope.view = 'setperms';
|
2016-08-18 19:59:00 +00:00
|
|
|
};
|
2016-05-12 21:59:49 +00:00
|
|
|
|
|
|
|
$scope.$watch('entityNameRegex', function(r) {
|
|
|
|
if (r) {
|
|
|
|
$scope.entityNameRegexObj = new RegExp(r);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$watch('info', function(info) {
|
|
|
|
if (!info || !info.namespace) {
|
|
|
|
$scope.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.namespace = UserService.getNamespace(info.namespace);
|
|
|
|
if ($scope.namespace) {
|
|
|
|
$scope.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|