reverify_view.js 3.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/**
 * Reverification flow.
 *
 * This flow allows students who have a denied or expired verification
 * to re-submit face and ID photos.  It re-uses most of the same sub-views
 * as the payment/verification flow.
 *
 */

 var edx = edx || {};

12 13
 (function($, _, Backbone, gettext) {
     'use strict';
14

15
     edx.verify_student = edx.verify_student || {};
16

17 18
     edx.verify_student.ReverifyView = Backbone.View.extend({
         el: '#reverify-container',
19

20 21 22 23 24 25 26
         stepOrder: [
             'face-photo-step',
             'id-photo-step',
             'review-photos-step',
             'reverify-success-step'
         ],
         stepViews: {},
27

28 29 30 31 32
         initialize: function(obj) {
             this.errorModel = obj.errorModel || null;
             this.initializeStepViews(obj.stepInfo || {});
             this.currentStepIndex = 0;
         },
33

34 35
         initializeStepViews: function(stepInfo) {
             var verificationModel, stepViewConstructors, nextStepTitles;
36 37 38 39

            // We need to initialize this here, because
            // outside of this method the subview classes
            // might not yet have been loaded.
40 41 42 43 44 45 46 47 48 49 50 51 52
             stepViewConstructors = {
                 'face-photo-step': edx.verify_student.FacePhotoStepView,
                 'id-photo-step': edx.verify_student.IDPhotoStepView,
                 'review-photos-step': edx.verify_student.ReviewPhotosStepView,
                 'reverify-success-step': edx.verify_student.ReverifySuccessStepView
             };

             nextStepTitles = [
                 gettext('Take a photo of your ID'),
                 gettext('Review your info'),
                 gettext('Confirm'),
                 ''
             ];
53 54 55 56 57

            // Create the verification model, which is shared
            // among the different steps.  This allows
            // one step to save photos and another step
            // to submit them.
58
             verificationModel = new edx.verify_student.VerificationModel();
59

60 61 62 63 64 65 66
             _.each(this.stepOrder, function(name, index) {
                 var stepView = new stepViewConstructors[name]({
                     errorModel: this.errorModel,
                     nextStepTitle: nextStepTitles[index],
                     stepData: stepInfo[name],
                     model: verificationModel
                 });
67

68 69
                 this.listenTo(stepView, 'next-step', this.nextStep);
                 this.listenTo(stepView, 'go-to-step', this.goToStep);
70

71 72 73
                 this.stepViews[name] = stepView;
             }, this);
         },
74

75 76 77 78
         render: function() {
             this.renderCurrentStep();
             return this;
         },
79

80 81
         renderCurrentStep: function() {
             var stepView, stepEl;
82 83

            // Get or create the step container
84 85 86 87
             stepEl = $('#current-step-container');
             if (!stepEl.length) {
                 stepEl = $('<div id="current-step-container"></div>').appendTo(this.el);
             }
88 89 90

            // Render the step subview
            // When the view is rendered, it will overwrite the existing step in the DOM.
91 92 93 94
             stepView = this.stepViews[this.stepOrder[this.currentStepIndex]];
             stepView.el = stepEl;
             stepView.render();
         },
95

96 97
         nextStep: function() {
             this.currentStepIndex = Math.min(
98 99 100
                this.currentStepIndex + 1,
                this.stepOrder.length - 1
            );
101 102
             this.render();
         },
103

104 105
         goToStep: function(stepName) {
             var stepIndex = _.indexOf(this.stepOrder, stepName);
106

107 108 109
             if (stepIndex >= 0) {
                 this.currentStepIndex = stepIndex;
             }
110

111 112 113 114
             this.render();
         }
     });
 })(jQuery, _, Backbone, gettext);