Skip to content

Instantly share code, notes, and snippets.

@pomahtuk
Created March 20, 2014 15:15
Show Gist options
  • Save pomahtuk/9666071 to your computer and use it in GitHub Desktop.
Save pomahtuk/9666071 to your computer and use it in GitHub Desktop.
# Main controller
angular.module("Museum.controllers").controller('routingController', [
'$q'
'$scope'
'$route'
'$routeParams'
'$rootScope'
'backendWrapper'
( $q, $scope, $route, $routeParams, $rootScope, backendWrapper ) ->
$scope.controller = undefined
$scope.prevController = undefined
$scope.prevId = undefined
$scope.template = ''
render = ->
renderAction = $route.current.action
routeParams = $route.current.params
renderPath = if renderAction
renderAction.split( "." )
else
['museum']
templatesDict =
museum: "/assets/partials/prototype.html"
tour: "/assets/partials/original_tour.html"
newtour: "/assets/partials/prototype_tour.html"
if renderPath[0] is 'login'
$scope.prevController = $scope.controller
$scope.controller = renderPath[0]
$scope.prevId = routeParams.object_id
$scope.template = templatesDict[$scope.controller]
else
if $scope.controller is renderPath[0] and ( $scope.prevId is routeParams.object_id or not $scope.prevId?)
console.log 'we shouldnt render anything' # or not...
$rootScope.$broadcast "location_changes", routeParams
else
console.log 'we should render all'
$scope.prevController = $scope.controller
$scope.controller = renderPath[0]
$scope.prevId = routeParams.object_id
$scope.template = ''
deferred = $q.defer()
console.log 'story tab', routeParams
params =
deferred: deferred
object_id: routeParams.object_id
lang: routeParams.lang
item_id: routeParams.item_id
type: 'museum'
tab: routeParams.tab
backendWrapper.fetch_data(params)
deferred.promise.then (result) ->
$scope.template = templatesDict[$scope.controller]
, (error) ->
console.log error
, (message) ->
console.log 'message is', message
console.log renderPath
$scope.$on "$routeChangeSuccess", ( $currentRoute, $previousRoute ) ->
render()
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment