From 80bb95a76df5ff2d4e32de525980cef7ddbe1b12 Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Sat, 12 Nov 2016 14:28:40 +0000 Subject: [PATCH] Announcements for un registered users --- public/templates/home/index.html | 4 ++ .../partials/alert-announcement.html | 4 +- .../partials/default-announcement.html | 4 +- .../scripts/app/controllers/home.coffee | 40 ++++++++++++++++++- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/public/templates/home/index.html b/public/templates/home/index.html index f0dee43a..3b0ec10c 100644 --- a/public/templates/home/index.html +++ b/public/templates/home/index.html @@ -1,4 +1,8 @@
+
+
+
+

see more diff --git a/public/templates/partials/alert-announcement.html b/public/templates/partials/alert-announcement.html index a19801f1..9575bb83 100644 --- a/public/templates/partials/alert-announcement.html +++ b/public/templates/partials/alert-announcement.html @@ -3,9 +3,7 @@

- - {{ ::link.title }} - + {{ ::link.title }} Don't show again
diff --git a/public/templates/partials/default-announcement.html b/public/templates/partials/default-announcement.html index e9934e78..b965dfd8 100644 --- a/public/templates/partials/default-announcement.html +++ b/public/templates/partials/default-announcement.html @@ -3,9 +3,7 @@

- - {{ ::link.title }} - + {{ ::link.title }} Don't show again
diff --git a/resources/assets/scripts/app/controllers/home.coffee b/resources/assets/scripts/app/controllers/home.coffee index c375384f..187df7df 100644 --- a/resources/assets/scripts/app/controllers/home.coffee +++ b/resources/assets/scripts/app/controllers/home.coffee @@ -20,14 +20,50 @@ window.pfm.preloaders['home'] = [ ] module.exports = angular.module('ponyfm').controller "home", [ - '$scope', 'meta', 'dashboard' - ($scope, meta, dashboard) -> + '$scope', 'meta', 'dashboard', '$http', 'announcements', '$compile' + ($scope, meta, dashboard, $http, announcements, $compile) -> meta.reset() $scope.recentTracks = null $scope.popularTracks = null + $scope.announcementClass = 'disabled' + $scope.announceWrapperClass = 'disabled' + + $scope.loadAnnouncementTemplate = (url) -> + $http.get('/templates/' + url).success (templateContent) -> + compiledHtml = $compile(templateContent)($scope) + $('#announcement').append(compiledHtml) dashboard.refresh().done (res) -> $scope.recentTracks = res.recent_tracks $scope.popularTracks = res.popular_tracks + + announcements.refresh().done (ann) -> + $scope.announcement = ann + if $scope.announcement != null + if parseInt($.cookie('hide-announcement')) != parseInt($scope.announcement.id) + $scope.announcement.dismiss = () -> + $scope.announceWrapperClass = 'disabled' + + $scope.announcement.dontShowAgain = () -> + $scope.announcement.dismiss() + $.cookie('hide-announcement', $scope.announcement.id) + + switch $scope.announcement.announcement_type_id + when 1 + $scope.announcementClass = "simple-announce " + $scope.announcement.css_class + $scope.announceWrapperClass = null + $scope.loadAnnouncementTemplate('partials/default-announcement.html') + when 2 + $scope.announcementClass = "alert-announce " + $scope.announcement.css_class + $scope.announceWrapperClass = null + $scope.loadAnnouncementTemplate('partials/alert-announcement.html') + when 3 + $scope.announcementClass = "serious-alert-announce " + $scope.announcement.css_class + $scope.announceWrapperClass = null + $scope.loadAnnouncementTemplate('partials/alert-announcement.html') + when 4 + $scope.announcementClass = $scope.announcement.css_class + $scope.announceWrapperClass = null + $scope.loadAnnouncementTemplate($scope.announcement.template_url) ]