/* global app:true */

(function() {
    'use strict';

    app = app || {};

    app.Reset = Backbone.Model.extend({
        defaults: {
            success: false,
            errors: [],
            errfor: {},
            id: undefined,
            email: undefined,
            password: '',
            confirm: ''
        },
        url: function() {
            return baseUrl + '/login/reset/' + this.get('email') + '/' + this.id + '/';
        }
    });

    app.ResetView = Backbone.View.extend({
        el: '#reset',
        template: _.template($('#tmpl-reset').html()),
        events: {
            'submit form': 'preventSubmit',
            'keypress [name="confirm"]': 'resetOnEnter',
            'click .btn-reset': 'reset'
        },
        initialize: function() {
            this.listenTo(this.model, 'sync', this.render);
            this.render();
        },
        render: function() {
            this.$el.html(this.template(this.model.attributes));
            this.$el.find('[name="password"]').focus();
            return this;
        },
        preventSubmit: function(event) {
            event.preventDefault();
        },
        resetOnEnter: function(event) {
            if (event.keyCode !== 13) {
                return;
            }
            event.preventDefault();
            this.reset();
        },
        reset: function() {
            this.$el.find('.btn-reset').attr('disabled', true);

            this.model.save({
                password: this.$el.find('[name="password"]').val(),
                confirm: this.$el.find('[name="confirm"]').val()
            });
        }
    });

    var baseApi = baseUrl + 'login/reset/';
    var tokenApi = baseUrl + 'login/reset/:email/:token/';

    app.Router = Backbone.Router.extend({
        routes: {
            baseApi: 'start',
            tokenApi: 'start'
        },
        start: function(email, token) {
            app.resetView = new app.ResetView({ model: new app.Reset({ id: token, email: email }) });
        }
    });

    $(document).ready(function() {
        app.router = new app.Router();
        Backbone.history.start({ pushState: true });
    });
}());

@@ -1647,29 +1647,164 @@
 var 
-baseApi = baseUrl
+routeJson = %7B%7D;%0A    var baseUrlStrip = baseUrl;%0A%0A    if (baseUrl) %7B%0A        baseUrlStrip = baseUrlStrip.substring(1);%0A    %7D%0A%0A    routeJson%5BbaseUrlStrip
  + '
+/
 logi
@@ -1816,40 +1816,52 @@
 et/'
-;%0A    var tokenApi = 
+%5D = 'start';%0A    routeJson%5B
 baseUrl
+Strip
  + '
+/
 logi
@@ -1883,16 +1883,27 @@
 :token/'
+%5D = 'start'
 ;%0A%0A    a
@@ -1959,79 +1959,17 @@
 es: 
-%7B%0A            baseApi: 'start',%0A            tokenApi: 'start'%0A        %7D
+routeJson
 ,%0A  

fix baseUrl error on reset page