Get create permission working

This commit is contained in:
Joseph Schorr 2014-01-21 15:09:47 -05:00
parent e8d51b651f
commit ca934ac162
5 changed files with 166 additions and 14 deletions

View file

@ -1491,6 +1491,9 @@ quayApp.directive('prototypeManager', function () {
},
controller: function($scope, $element, ApiService) {
$scope.loading = false;
$scope.activatingForNew = null;
$scope.delegateForNew = null;
$scope.clearCounter = 0;
$scope.roles = [
{ 'id': 'read', 'title': 'Read', 'kind': 'success' },
@ -1525,6 +1528,50 @@ quayApp.directive('prototypeManager', function () {
});
};
$scope.setRoleForNew = function(role) {
$scope.newRole = role;
};
$scope.showAddDialog = function() {
$scope.activatingForNew = null;
$scope.delegateForNew = null;
$scope.newRole = 'read';
$scope.clearCounter++;
$('#addPermissionDialogModal').modal({});
};
$scope.createPrototype = function() {
$scope.loading = true;
var params = {
'orgname': $scope.organization.name
};
var data = {
'activating_user': $scope.activatingForNew,
'delegate': $scope.delegateForNew,
'role': $scope.newRole
};
ApiService.createOrganizationPrototypePermission(data, params).then(function(resp) {
$scope.prototypes.push(resp);
$scope.loading = false;
$('#addPermissionDialogModal').modal('hide');
}, function(resp) {
$('#addPermissionDialogModal').modal('hide');
bootbox.dialog({
"message": resp.data ? resp.data : 'The permission could not be created',
"title": "Cannot create permission",
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
});
};
$scope.deletePrototype = function(prototype) {
$scope.loading = true;
@ -1546,7 +1593,7 @@ quayApp.directive('prototypeManager', function () {
"className": "btn-primary"
}
}
});
});
});
};
@ -1841,7 +1888,10 @@ quayApp.directive('entitySearch', function () {
'inputTitle': '=inputTitle',
'entitySelected': '=entitySelected',
'includeTeams': '=includeTeams',
'isOrganization': '=isOrganization'
'isOrganization': '=isOrganization',
'isPersistent': '=isPersistent',
'currentEntity': '=currentEntity',
'clearNow': '=clearNow'
},
controller: function($scope, $element, Restangular, UserService, ApiService) {
$scope.lazyLoading = true;
@ -1915,10 +1965,27 @@ quayApp.directive('entitySearch', function () {
entity['is_org_member'] = true;
}
$scope.entitySelected(entity);
$scope.setEntityInternal(entity);
};
if (!$scope.entitySelected) { return; }
$scope.clearEntityInternal = function() {
$scope.currentEntity = null;
if ($scope.entitySelected) {
$scope.entitySelected(null);
}
};
$scope.setEntityInternal = function(entity) {
$(input).typeahead('setQuery', $scope.isPersistent ? entity.name : '');
if ($scope.isPersistent) {
$scope.currentEntity = entity;
}
if ($scope.entitySelected) {
$scope.entitySelected(entity);
}
};
number++;
@ -1969,13 +2036,25 @@ quayApp.directive('entitySearch', function () {
},
});
$(input).on('typeahead:selected', function(e, datum) {
$(input).typeahead('setQuery', '');
$(input).on('input', function(e) {
$scope.$apply(function() {
$scope.entitySelected(datum.entity);
if ($scope.isPersistent) {
$scope.clearEntityInternal();
}
});
});
$(input).on('typeahead:selected', function(e, datum) {
$scope.$apply(function() {
$scope.setEntityInternal(datum.entity);
});
});
$scope.$watch('clearNow', function() {
$(input).typeahead('setQuery', '');
$scope.clearEntityInternal();
});
$scope.$watch('inputTitle', function(title) {
input.setAttribute('placeholder', title);
});