/**
 * Copyright 2015 Longtail Ad Solutions Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 **/

(function () {

    /**
     * @ngdoc overview
     * @name jwShowcase.video
     *
     * @description
     * Video module
     */
    angular
        .module('jwShowcase.video', [])
        .config(config);

    config.$inject = ['$stateProvider', 'seoProvider'];
    function config ($stateProvider, seoProvider) {

        $stateProvider
            .state('root.video', {
                url:            '/video/:feedId/:mediaId',
                controller:     'VideoController as vm',
                templateUrl:    'views/video/video.html',
                resolve:        {
                    item: resolveItem,
                    feed: resolveFeed
                },
                params:         {
                    autoStart: false
                },
                cache:          false
            });

        seoProvider
            .state('root.video', ['$stateParams', 'config', 'dataStore', function ($stateParams, config, dataStore) {

                var item = dataStore.getItem($stateParams.mediaId, $stateParams.feedId);

                return {
                    title:       config.siteName + ' | ' + item.title,
                    description: item.description,
                    image:       item.image
                };
            }]);

        /////////////////

        resolveItem.$inject = ['$stateParams', '$q', 'dataStore', 'preload'];
        function resolveItem ($stateParams, $q, dataStore) {
            return dataStore.getItem($stateParams.mediaId, $stateParams.feedId) || $q.reject();
        }

        resolveFeed.$inject = ['$stateParams', '$q', 'dataStore', 'preload'];
        function resolveFeed ($stateParams, $q, dataStore) {
            return dataStore.getFeed($stateParams.feedId) || $q.reject();
        }
    }

}());

@@ -1008,19 +1008,16 @@
         
-   
 '/video/
@@ -1062,19 +1062,16 @@
 troller:
-   
   'Video
@@ -1117,19 +1117,16 @@
 lateUrl:
-   
  'views/
@@ -1169,27 +1169,24 @@
 esolve:     
- 
-  
 %7B%0A          
@@ -1195,20 +1195,20 @@
         
-item
+feed
 : resolv
@@ -1208,20 +1208,20 @@
  resolve
-Item
+Feed
 ,%0A      
@@ -1226,36 +1226,36 @@
                 
-feed
+item
 : resolveFeed%0A  
@@ -1247,20 +1247,20 @@
  resolve
-Feed
+Item
 %0A       
@@ -1294,19 +1294,16 @@
  params:
-   
       %7B%0A
@@ -1387,19 +1387,16 @@
 :       
-   
 false%0A  
@@ -1909,20 +1909,20 @@
  resolve
-Item
+Feed
 .$inject
@@ -1996,20 +1996,20 @@
  resolve
-Item
+Feed
  ($state
@@ -2025,32 +2025,33 @@
 q, dataStore) %7B%0A
+%0A
             retu
@@ -2038,38 +2038,42 @@
  %7B%0A%0A            
-return
+var feed =
  dataStore.getIt
@@ -2062,36 +2062,36 @@
  = dataStore.get
-Item
+Feed
 ($stateParams.me
@@ -2092,37 +2092,196 @@
 ams.
-mediaId, $stateParams.feedId)
+feedId);%0A%0A            // if the feed is loading wait for the promise to resolve.%0A            if (feed.loading) %7B%0A                return feed.promise;%0A            %7D%0A%0A            return feed
  %7C%7C 
@@ -2311,36 +2311,36 @@
 %0A        resolve
-Feed
+Item
 .$inject = %5B'$st
@@ -2358,35 +2358,19 @@
  '$q', '
-dataStore', 'preloa
+fee
 d'%5D;%0A   
@@ -2382,36 +2382,36 @@
 function resolve
-Feed
+Item
  ($stateParams, 
@@ -2410,33 +2410,28 @@
 Params, $q, 
-dataStore
+feed
 ) %7B%0A        
@@ -2441,33 +2441,29 @@
  return 
-dataStore.getFeed
+feed.findItem
 ($stateP
@@ -2468,20 +2468,21 @@
 eParams.
-feed
+media
 Id) %7C%7C $

Update video page resolves