smarter subscription dialog

This commit is contained in:
Athou
2013-05-01 15:14:43 +02:00
parent 547e1dd7ab
commit 6f9e00339f
2 changed files with 17 additions and 6 deletions

View File

@@ -41,20 +41,29 @@ function($scope, FeedService, CategoryService) {
$scope.isOpen = false;
};
// 'ok', 'loading' or 'failed'
$scope.state = 'ok';
$scope.urlChanged = function() {
var msg = 'Loading...';
if ($scope.sub.url && (!$scope.sub.title || $scope.sub.title == msg)) {
$scope.sub.title = msg;
if ($scope.sub.url) {
$scope.state = 'loading';
$scope.sub.title = 'Loading...';
FeedService.fetch({
url : $scope.sub.url
}, function(data) {
$scope.state = 'ok';
$scope.sub.title = data.title;
$scope.sub.url = data.url;
}, function(data) {
$scope.state = 'failed';
$scope.sub.title = 'Loading failed. Invalid feed?';
});
}
};
$scope.save = function() {
if ($scope.state != 'ok') {
return;
}
if (!$scope.sub.categoryId) {
return;
}

View File

@@ -19,14 +19,16 @@
<div class="control-group" ng-class="{error : !subscribeForm.url.$valid}">
<label class="control-label">Feed URL</label>
<div class="controls">
<input type="text" name="url" ng-model="sub.url" ng-blur="urlChanged()" placeholder="http://example.com/feed" class="input-block-level" required></input>
<input type="text" name="url" ng-model="sub.url" ng-blur="urlChanged()" placeholder="http://example.com/feed"
class="input-block-level" required ng-disabled="state=='loading'"></input>
<span class="help-block" ng-show="!subscribeForm.url.$valid">Required</span>
</div>
</div>
<div class="control-group" ng-class="{error : !subscribeForm.title.$valid}">
<label class="control-label">Feed Name</label>
<div class="controls">
<input type="text" name="title" ng-model="sub.title" class="input-block-level" required></input>
<input type="text" name="title" ng-model="sub.title"
class="input-block-level" required ng-disabled="state=='loading'"></input>
<span class="help-block" ng-show="!subscribeForm.title.$valid">Required</span>
</div>
</div>
@@ -42,7 +44,7 @@
</div>
<div class="modal-footer">
<button class="btn cancel" ng-click="close()" type="button">Cancel</button>
<button class="btn btn-primary ok" type="submit">Save</button>
<button class="btn btn-primary ok" type="submit" ng-disabled="state!='ok'">Save</button>
</div>
</form>
</div>