                             xhrFields:
                                 withCredentials: yes
                             success: (responseText, textStatus, jqXHR) ->
-                                History.pushState urlPath: '/signin', '', '/signin'
+                                stateController.navigateTo '/signin'
                             error: (jqXHR, textStatus, errorThrown) ->
                                 if jqXHR.responseJSON?
                                     $submitError.text jqXHR.responseJSON

    new SigninView()


define 'loginView', ['jquery', 'view', 'renderTemplate', 'dataStore', 'navigationBar', 'jquery.history', 'jquery.form'], ($, View, renderTemplate, dataStore, navigationBar, History) ->
    class LoginView extends View
        constructor: ->
            @urlRegex = /^\/login$/

        'bootstrap-filestyle': ['bootstrap']


define 'stateController', ['jquery', 'jquery.history'], ($, History) ->
    class StateController
        constructor: ->
            @viewController = null

        getStateData: (urlPath) ->
            # AT: maybe it's a bug: replaceState won't call statechange
            # event if you reload page at the same url (e.g. Cmd+R or Ctrl+F5).
            # To workaround the problem, you can pass a unique value to state.
            # I have chosen to pass unix timestamp.
            return urlPath: urlPath, tick: (new Date()).getTime()

        init: (viewController) ->
            @viewController = viewController
            History.Adapter.bind window, 'statechange', =>
                data = History.getState().data
                unless data.urlPath?
                    data.urlPath = window.location.pathname
                @viewController.render data.urlPath

            $(document).on 'click', 'a[data-push-history]', (e) =>
                e.preventDefault()
                e.stopPropagation()
                urlPath = $(e.target).attr 'href'
                title = @viewController.getTitle urlPath

                History.pushState @getStateData(urlPath), title, urlPath

            curLocation = window.location.pathname
            windowTitle = @viewController.getTitle curLocation
            historyData = urlPath: curLocation, tick: (new Date()).getTime()
            History.replaceState @getStateData(curLocation), windowTitle, curLocation

        navigateTo: (urlPath) ->
            title = @viewController.getTitle urlPath
            History.pushState @getStateData(urlPath), title, urlPath

    new StateController()


define 'dataStore', ['jquery', 'metadataStore'], ($, metadataStore) ->
