preselect All if no category is set, and prevent setting a parent category to itself

This commit is contained in:
Athou
2013-05-01 14:06:38 +02:00
parent 9223ad0def
commit 4111b49d5f
2 changed files with 12 additions and 1 deletions

View File

@@ -176,6 +176,9 @@ module.controller('FeedDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedS
$scope.sub = FeedService.get({
id : $stateParams._id
}, function(data) {
if (!data.categoryId)
data.categoryId = 'all';
});
$scope.back = function() {
@@ -240,6 +243,12 @@ module.controller('CategoryDetailsCtrl', ['$scope', '$state', '$stateParams', 'F
return parseInt($stateParams._id, 10) != $stateParams._id;
};
$scope.filterCurrent = function(elem) {
if (!$scope.category)
return true;
return elem.id != $scope.category.id;
};
CategoryService.get(function() {
if ($scope.isMeta()) {
$scope.category = {
@@ -259,6 +268,8 @@ module.controller('CategoryDetailsCtrl', ['$scope', '$state', '$stateParams', 'F
break;
}
}
if (!$scope.category.parentId)
$scope.category.parentId = 'all';
});
$scope.back = function() {

View File

@@ -15,7 +15,7 @@
<label class="control-label">Parent category</label>
<div class="controls">
<select name="category" class="input-block-level" ng-model="category.parentId"
ng-options="cat.id as cat.name for cat in CategoryService.flatCategories">
ng-options="cat.id as cat.name for cat in CategoryService.flatCategories | filter: filterCurrent">
</select>
<span class="help-block" ng-show="!form.category.$valid">Required</span>
</div>