Files
commafeed/src/main/webapp/js/directives.js

128 lines
3.2 KiB
JavaScript
Raw Normal View History

2013-03-21 16:22:58 +01:00
var module = angular.module('commafeed.directives', []);
2013-03-25 12:24:00 +01:00
module.directive('subscribe', function(SubscriptionService) {
2013-03-24 13:11:05 +01:00
return {
scope : {},
restrict : 'E',
replace : true,
templateUrl : 'directives/subscribe.html',
controller : function($scope, SubscriptionService) {
$scope.opts = {
backdropFade : true,
dialogFade : true
};
2013-03-27 12:13:56 +01:00
$scope.isOpen = false;
$scope.isOpenImport = false;
$scope.sub = {};
2013-03-24 13:11:05 +01:00
$scope.SubscriptionService = SubscriptionService;
$scope.open = function() {
$scope.sub = {};
$scope.isOpen = true;
};
$scope.close = function() {
$scope.isOpen = false;
};
2013-03-27 12:13:56 +01:00
2013-03-24 13:11:05 +01:00
$scope.save = function() {
2013-03-27 12:13:56 +01:00
SubscriptionService.subscribe($scope.sub);
$scope.close();
2013-03-24 13:11:05 +01:00
};
2013-03-27 12:13:56 +01:00
2013-03-25 12:24:00 +01:00
$scope.openImport = function() {
$scope.isOpenImport = true;
};
$scope.closeImport = function() {
$scope.isOpenImport = false;
};
2013-03-27 12:13:56 +01:00
2013-03-25 12:24:00 +01:00
$scope.uploadComplete = function(contents, completed) {
SubscriptionService.init();
$scope.closeImport();
};
2013-03-24 13:11:05 +01:00
}
};
});
2013-03-21 16:22:58 +01:00
module.directive('category', function($compile) {
return {
2013-03-27 12:13:56 +01:00
scope : {
node : '=',
selectedType : '=',
selectedId : '=',
feedClick : '&',
categoryClick : '&',
formatCategoryName : '&',
formatFeedName : '&'
2013-03-21 16:22:58 +01:00
},
restrict : 'E',
2013-03-27 12:13:56 +01:00
replace : true,
templateUrl : 'directives/category.html',
link : function(scope, element) {
var ul = element.find('ul');
2013-03-22 22:11:40 +01:00
ul.prepend('<category ng-repeat="child in node.children" node="child" feed-click="feedClick({id:id})" \
category-click="categoryClick({id:id})" selected-type="selectedType" selected-id="selectedId" \
format-category-name="formatCategoryName({category:category})" format-feed-name="formatFeedName({feed:feed})">\
</category>');
2013-03-27 12:13:56 +01:00
$compile(ul.contents())(scope);
},
controller : function($scope, $dialog, SubscriptionService) {
$scope.unsubscribe = function(subscription) {
2013-03-24 16:39:45 +01:00
var title = 'Unsubscribe';
2013-03-27 12:13:56 +01:00
var msg = 'Unsubscribe from ' + subscription.name + ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
SubscriptionService
.unsubscribe(subscription.id);
}
});
}
}
2013-03-21 16:22:58 +01:00
};
2013-03-23 23:14:14 +01:00
});
2013-03-27 12:13:56 +01:00
module.directive('toolbar', function($routeParams, $route, SettingsService,
EntryService, SubscriptionService) {
2013-03-23 23:14:14 +01:00
return {
scope : {},
restrict : 'E',
replace : true,
templateUrl : 'directives/toolbar.html',
2013-03-24 17:52:43 +01:00
controller : function($scope, $route, SettingsService) {
2013-03-23 23:14:14 +01:00
$scope.settings = SettingsService.settings;
2013-03-24 17:52:43 +01:00
$scope.refresh = function() {
$route.reload();
2013-03-27 12:13:56 +01:00
};
2013-03-25 21:01:29 +01:00
$scope.markAllAsRead = function() {
EntryService.mark({
2013-03-27 12:13:56 +01:00
type : $routeParams._type,
id : $routeParams._id,
read : true,
2013-03-25 21:01:29 +01:00
}, function() {
SubscriptionService.init(function() {
$route.reload();
});
});
2013-03-24 17:52:43 +01:00
}
2013-03-23 23:14:14 +01:00
},
link : function($scope, element) {
2013-03-24 17:52:43 +01:00
element.find('.read-mode button').bind('click', function() {
2013-03-23 23:14:14 +01:00
SettingsService.save();
});
}
};
2013-03-21 16:22:58 +01:00
});