/*!
 * mushin
 * https://github.com/thomasvs/mushin-hoodie
 *
 * Copyright 2014 Thomas Vander Stichele
 */

angular.module(
  'mushin', [
    'bp',
    'angular-loading-bar',
    'hoodie',
    'monospaced.elastic',
    'datePicker',
    'filter.duration'
  ]
)
  .config(function(
    $urlRouterProvider, $stateProvider, bpAppProvider,
    cfpLoadingBarProvider) {

    bpAppProvider.setConfig({
      platform: 'ios'
    });

    cfpLoadingBarProvider.includeSpinner = false;

    $urlRouterProvider.otherwise('/things');

    $stateProvider
      .state('things', {
        url: '/things?query',
        templateUrl: 'views/things.html',
        controller: 'ThingsController',
        data: {
          title: 'Things'
        }
      })
      .state('account', {
        url: '/things/account',
        templateUrl: 'views/account.html',
        controller: 'AccountController',
        data: {
          modal: true
        }
      })
      .state('lists', {
        url: '/lists',
        templateUrl: 'views/lists.html',
        controller: 'ListController',
        data: {
          title: 'Lists',
        }
      })
      .state('br', {
        url: '/br',
        templateUrl: 'views/br.html',
        controller: 'ListController',
        data: {
          title: 'Archive',
          state: 2,
        }
      })
      .state('thingsThing', {
        url: '/things/:id',
        templateUrl: 'views/thing.html',
        controller: 'ThingController',
        data: {
          title: 'Edit Thing',
        }
      })
/*
      .state('mitThing', {
        url: '/mit/:id',
        templateUrl: 'views/thing.html',
        controller: 'ThingController',
        data: {
          state: 2
        }
      })
      .state('brThing', {
        url: '/br/:id',
        templateUrl: 'views/thing.html',
        controller: 'ThingController',
        data: {
          state: 3
        }
      })
*/
  })
  .run(function($rootScope, $state, $q, $window) {
    var defer = $q.defer()
    var cache = $window.applicationCache
    cache.addEventListener('updateready', defer.resolve)

    if (cache.status === cache.UPDATEREADY) {
      defer.resolve()
    }

    defer.promise.then(function() {
      $window.location.reload()
    })
  })

@@ -525,43 +525,355 @@
     
-$stateProvider%0A      .state('things
+/* specified things and thingsquery separately so thingsThing can%0A     * find its parent automatically%0A     */%0A    $stateProvider%0A      .state('things', %7B%0A        url: '/things',%0A        templateUrl: 'views/things.html',%0A        controller: 'ThingsController',%0A        data: %7B%0A          title: 'Things'%0A        %7D%0A      %7D)%0A      .state('thingsquery
 ', %7B
@@ -1817,16 +1817,321 @@
 Thing',%0A
+          // have to specify manually because adding ?query higher up%0A          // makes autodetection of things as a parent break%0A          // but then it turns out that it complains about not passing%0A          // query as a parameter, so we now specify things twice higher up%0A          // up: 'things',%0A
         

make sure we can go back from editing a thing