diff --git a/config/karma.conf.js b/config/karma.conf.js index e8fc492de..bf9f80305 100644 --- a/config/karma.conf.js +++ b/config/karma.conf.js @@ -63,6 +63,7 @@ module.exports = function(config){ 'public/js/app/home/home-index.js', 'public/js/app/home/controllers/home-ctrl.js', + 'public/js/app/home/services/home-svc.js', 'public/js/app/search/search-index.js', 'public/js/app/search/controllers/search-list-ctrl.js', diff --git a/public/index.html b/public/index.html index 0effbb366..de716108f 100644 --- a/public/index.html +++ b/public/index.html @@ -96,6 +96,8 @@ + + diff --git a/public/js/app/home/controllers/home-ctrl.js b/public/js/app/home/controllers/home-ctrl.js index be1cad42f..e82a58808 100644 --- a/public/js/app/home/controllers/home-ctrl.js +++ b/public/js/app/home/controllers/home-ctrl.js @@ -10,28 +10,36 @@ * license agreement you entered into with hybris. */ -'use strict'; +(function () { + 'use strict'; -angular.module('ds.home') + angular.module('ds.home') + .controller('HomeCtrl', ['$scope', 'HomeSvc', + function ($scope, HomeSvc) { - .controller('HomeCtrl', ['$scope', - function ($scope) { + $scope.carouselInterval = 5000; + $scope.slidesLarge = []; + $scope.slidesSmall = []; + $scope.banner1 = {}; + $scope.banner2 = {}; - $scope.carouselInterval = 5000; + //Get site content data from service + $scope.getSiteContent = function getSiteContent() { + var siteContent = HomeSvc.init(); - $scope.slides = [ - { - id: 'audioBanner', - image: './img/homePg-hero-audio.jpg', - state: 'base.category' - }, - { - id: 'officeBanner', - image: './img/homePg-hero-office.jpg', - state: 'base.category' - } - ]; + $scope.slidesLarge = siteContent.slidesLarge; + $scope.slidesSmall = siteContent.slidesSmall; + $scope.banner1 = siteContent.banner1; + $scope.banner2 = siteContent.banner2; + }; + //Init site content data + $scope.getSiteContent(); - }] -); + //Listen for site change event + $scope.$on('site:updated', function siteUpdated() { + $scope.getSiteContent(); + }); + + }]); +})(); \ No newline at end of file diff --git a/public/js/app/home/directives/site-content-image-directive.js b/public/js/app/home/directives/site-content-image-directive.js new file mode 100644 index 000000000..ec5b35300 --- /dev/null +++ b/public/js/app/home/directives/site-content-image-directive.js @@ -0,0 +1,27 @@ +/** + * [y] hybris Platform + * + * Copyright (c) 2000-2015 hybris AG + * All rights reserved. + * + * This software is the confidential and proprietary information of hybris + * ("Confidential Information"). You shall not disclose such Confidential + * Information and shall use it only in accordance with the terms of the + * license agreement you entered into with hybris. + */ + +(function () { + 'use strict'; + + angular.module('ds.home') + .directive('siteContentImage', function () { + return { + restrict: 'E', + scope: { + image: '=', + id: '@imageId' + }, + templateUrl: 'js/app/home/templates/site-content-image.html' + }; + }); +})(); \ No newline at end of file diff --git a/public/js/app/home/services/home-svc.js b/public/js/app/home/services/home-svc.js new file mode 100644 index 000000000..30b63cf51 --- /dev/null +++ b/public/js/app/home/services/home-svc.js @@ -0,0 +1,108 @@ +/** + * [y] hybris Platform + * + * Copyright (c) 2000-2015 hybris AG + * All rights reserved. + * + * This software is the confidential and proprietary information of hybris + * ("Confidential Information"). You shall not disclose such Confidential + * Information and shall use it only in accordance with the terms of the + * license agreement you entered into with hybris. + */ + +(function () { + 'use strict'; + + angular.module('ds.home') + .service('HomeSvc', ['GlobalData', 'settings', '$state', + function (GlobalData, settings, $state) { + + var homeBannerId = 'homeBanner'; + + /** + * Initializes all site content in objects that can be used in UI + * @return object that contains carousel images and banners + */ + var init = function init() { + var self = this; + var slidesLarge = []; + var slidesSmall = []; + var banner1 = {}; + var banner2 = {}; + var siteContent = GlobalData.getSiteBanners(); + + if (self.siteContentExists(siteContent)) { + if (!!siteContent.topImages && siteContent.topImages.length > 0) { + + for (var i = 0; i < siteContent.topImages.length; i++) { + if (!!siteContent.topImages[i].large && siteContent.topImages[i].large.imageUrl !== '') { + slidesLarge.push({ id: homeBannerId, image: siteContent.topImages[i].large }); + } + + if (!!siteContent.topImages[i].small && siteContent.topImages[i].small.imageUrl !== '') { + slidesSmall.push({ id: homeBannerId, image: siteContent.topImages[i].small }); + } + } + } + banner1 = siteContent.banner1; + banner2 = siteContent.banner2; + } + else { + //Redirect to all products page + $state.go(settings.allProductsState); + } + + return { + slidesLarge: slidesLarge, + slidesSmall: slidesSmall, + banner1: banner1, + banner2: banner2 + }; + }; + + /** + * Checks if there is any site content defined for selected site + * @param siteContent - current site content + * @return true/false value that shows if there is site content for provided site + */ + var siteContentExists = function siteContentExists(siteContent) { + if (!siteContent) { + return false; + } + + if (!!siteContent.topImages) { + for (var i = 0; i < siteContent.topImages.length; i++) { + if (!!siteContent.topImages[i] && + !!siteContent.topImages[i].large && + (siteContent.topImages[i].large.imageUrl !== '' || + siteContent.topImages[i].small.imageUrl !== '')) { + return true; + } + } + } + + if (!!siteContent.banner1 && + !!siteContent.banner1.large && + (siteContent.banner1.large.imageUrl !== '' || + siteContent.banner1.small.imageUrl !== '')) { + return true; + } + + if (!!siteContent.banner2 && !! + !!siteContent.banner2.large && + (siteContent.banner2.large.imageUrl !== '' || + siteContent.banner2.small.imageUrl !== '')) { + return true; + } + + return false; + }; + + return { + init: init, + siteContentExists: siteContentExists + }; + + }]); + +})(); \ No newline at end of file diff --git a/public/js/app/home/templates/home.html b/public/js/app/home/templates/home.html index 0000db001..dfe84f587 100644 --- a/public/js/app/home/templates/home.html +++ b/public/js/app/home/templates/home.html @@ -1,20 +1,37 @@