From a839cb22977a351a1c14e889ec43973b47f4bfc2 Mon Sep 17 00:00:00 2001 From: Athou Date: Fri, 5 Apr 2013 07:51:53 +0200 Subject: [PATCH] moved some directives to controller/partial --- src/main/webapp/js/controllers.js | 130 +++++++++++++++- src/main/webapp/js/directives.js | 146 ------------------ .../_subscribe.html} | 2 +- .../toolbar.html => templates/_toolbar.html} | 2 +- src/main/webapp/templates/feeds.html | 5 +- 5 files changed, 133 insertions(+), 152 deletions(-) rename src/main/webapp/{directives/subscribe.html => templates/_subscribe.html} (96%) rename src/main/webapp/{directives/toolbar.html => templates/_toolbar.html} (95%) diff --git a/src/main/webapp/js/controllers.js b/src/main/webapp/js/controllers.js index 69009dd5..bdf25844 100644 --- a/src/main/webapp/js/controllers.js +++ b/src/main/webapp/js/controllers.js @@ -10,6 +10,74 @@ module.run(function($rootScope) { }); }); +module.controller('SubscribeCtrl', function($scope, SubscriptionService) { + + $scope.opts = { + backdropFade : true, + dialogFade : true + }; + + $scope.isOpen = false; + $scope.isOpenImport = false; + $scope.sub = {}; + + $scope.SubscriptionService = SubscriptionService; + + $scope.open = function() { + $scope.sub = {}; + $scope.isOpen = true; + }; + + $scope.close = function() { + $scope.isOpen = false; + }; + + $scope.urlChanged = function() { + if ($scope.sub.url && !$scope.sub.title) { + $scope.sub.title = 'Loading...'; + SubscriptionService.fetch({ + url : $scope.sub.url + }, function(data) { + $scope.sub.title = data.title; + }); + } + }; + + $scope.save = function() { + SubscriptionService.subscribe($scope.sub); + $scope.close(); + }; + + $scope.openImport = function() { + $scope.isOpenImport = true; + }; + + $scope.closeImport = function() { + $scope.isOpenImport = false; + }; + + $scope.uploadComplete = function(contents, completed) { + SubscriptionService.init(); + $scope.closeImport(); + }; + + $scope.cat = {}; + + $scope.openCategory = function() { + $scope.isOpenCategory = true; + $scope.cat = {}; + }; + + $scope.closeCategory = function() { + $scope.isOpenCategory = false; + }; + + $scope.saveCategory = function() { + SubscriptionService.addCategory($scope.cat); + $scope.closeCategory(); + }; +}); + module.controller('CategoryTreeCtrl', function($scope, $timeout, $stateParams, $location, $state, $route, SubscriptionService) { @@ -105,6 +173,65 @@ module.controller('CategoryTreeCtrl', function($scope, $timeout, $stateParams, }); }); +module.controller('ToolbarCtrl', function($scope, $http, $state, $stateParams, + $route, $location, SettingsService, EntryService, SubscriptionService, + SessionService) { + + function totalActiveAjaxRequests() { + return ($http.pendingRequests.length + $.active); + } + + $scope.session = SessionService.get(); + + $scope.loading = true; + $scope.$watch(totalActiveAjaxRequests, function() { + $scope.loading = (totalActiveAjaxRequests() !== 0); + }); + + $scope.settingsService = SettingsService; + $scope.$watch('settingsService.settings.readingMode', function(newValue, + oldValue) { + if (newValue && oldValue && newValue != oldValue) { + SettingsService.save(); + } + }); + $scope.refresh = function() { + $scope.$emit('emitReload'); + }; + $scope.markAllAsRead = function() { + EntryService.mark({ + type : $stateParams._type, + id : $stateParams._id, + read : true + }, function() { + SubscriptionService.init(function() { + $scope.$emit('emitReload'); + }); + }); + }; + + $scope.keywords = $stateParams._keywords; + $scope.search = function() { + if ($scope.keywords == $stateParams._keywords) { + $scope.refresh(); + } else { + $state.transitionTo('feeds.search', { + _keywords : $scope.keywords + }); + } + }; + $scope.showButtons = function() { + return !$stateParams._keywords; + }; + + $scope.toAdmin = function() { + $location.path('admin'); + }; + $scope.toSettings = function() { + $location.path('settings'); + }; +}); + module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route, $window, EntryService, SettingsService) { @@ -361,7 +488,8 @@ module.controller('SettingsCtrl', function($scope, $location, SettingsService) { $scope.save = function() { SettingsService.settings = $scope.settings; SettingsService.save(function() { - window.location.href = window.location.href.substring(0, window.location.href.lastIndexOf('#')); + window.location.href = window.location.href.substring(0, + window.location.href.lastIndexOf('#')); }); }; }); \ No newline at end of file diff --git a/src/main/webapp/js/directives.js b/src/main/webapp/js/directives.js index 5dcc9e3d..a031d587 100644 --- a/src/main/webapp/js/directives.js +++ b/src/main/webapp/js/directives.js @@ -31,81 +31,6 @@ module.directive('scrollTo', function() { }; }); -module.directive('subscribe', function(SubscriptionService) { - return { - scope : {}, - restrict : 'E', - replace : true, - templateUrl : 'directives/subscribe.html', - controller : function($scope, SubscriptionService) { - $scope.opts = { - backdropFade : true, - dialogFade : true - }; - - $scope.isOpen = false; - $scope.isOpenImport = false; - $scope.sub = {}; - - $scope.SubscriptionService = SubscriptionService; - - $scope.open = function() { - $scope.sub = {}; - $scope.isOpen = true; - }; - - $scope.close = function() { - $scope.isOpen = false; - }; - - $scope.urlChanged = function() { - if ($scope.sub.url && !$scope.sub.title) { - $scope.sub.title = 'Loading...'; - SubscriptionService.fetch({ - url : $scope.sub.url - }, function(data) { - $scope.sub.title = data.title; - }); - } - }; - - $scope.save = function() { - SubscriptionService.subscribe($scope.sub); - $scope.close(); - }; - - $scope.openImport = function() { - $scope.isOpenImport = true; - }; - - $scope.closeImport = function() { - $scope.isOpenImport = false; - }; - - $scope.uploadComplete = function(contents, completed) { - SubscriptionService.init(); - $scope.closeImport(); - }; - - $scope.cat = {}; - - $scope.openCategory = function() { - $scope.isOpenCategory = true; - $scope.cat = {}; - }; - - $scope.closeCategory = function() { - $scope.isOpenCategory = false; - }; - - $scope.saveCategory = function() { - SubscriptionService.addCategory($scope.cat); - $scope.closeCategory(); - }; - } - }; -}); - module.directive('category', function($compile) { return { scope : { @@ -173,77 +98,6 @@ module.directive('category', function($compile) { }; }); -module.directive('toolbar', function($state, $stateParams, $route, $location, - SettingsService, EntryService, SubscriptionService, SessionService) { - return { - scope : {}, - restrict : 'E', - replace : true, - templateUrl : 'directives/toolbar.html', - controller : function($scope, $route, $http, SettingsService) { - - function totalActiveAjaxRequests() { - return ($http.pendingRequests.length + $.active); - } - - $scope.session = SessionService.get(); - - $scope.loading = true; - $scope.$watch(totalActiveAjaxRequests, function() { - $scope.loading = (totalActiveAjaxRequests() !== 0); - }); - - $scope.settingsService = SettingsService; - $scope.$watch('settingsService.settings.readingMode', function(newValue, - oldValue) { - if (newValue && oldValue && newValue != oldValue) { - SettingsService.save(); - } - }); - $scope.refresh = function() { - $scope.$emit('emitReload'); - }; - $scope.markAllAsRead = function() { - EntryService.mark({ - type : $stateParams._type, - id : $stateParams._id, - read : true - }, function() { - SubscriptionService.init(function() { - $scope.$emit('emitReload'); - }); - }); - }; - - $scope.keywords = $stateParams._keywords; - $scope.search = function() { - if ($scope.keywords == $stateParams._keywords) { - $scope.refresh(); - } else { - $state.transitionTo('feeds.search', { - _keywords : $scope.keywords - }); - } - }; - $scope.showButtons = function() { - return !$stateParams._keywords; - }; - - $scope.toAdmin = function() { - $location.path('admin'); - }; - $scope.toSettings = function() { - $location.path('settings'); - }; - }, - link : function($scope, element) { - element.find('.read-mode button').bind('click', function() { - SettingsService.save(); - }); - } - }; -}); - module.directive('spinner', function() { return { scope : { diff --git a/src/main/webapp/directives/subscribe.html b/src/main/webapp/templates/_subscribe.html similarity index 96% rename from src/main/webapp/directives/subscribe.html rename to src/main/webapp/templates/_subscribe.html index f9b1b100..7804aeb6 100644 --- a/src/main/webapp/directives/subscribe.html +++ b/src/main/webapp/templates/_subscribe.html @@ -1,4 +1,4 @@ -
+