<commit_before>define([
    'backbone',
    'underscore',
    'fuelux/wizard'
], function(Backbone, _) {

    return Backbone.View.extend({

        initialize: function(options){
            this.template = options.template;
            this.i18n = options.i18n;
            this.steps = options.steps;
            this.renderOptions = options.renderOptions;
        },

        render: function(){
            this.$el.html(this.template({
                renderOptions: this.renderOptions,
                steps: this.steps,
                i18n: this.i18n
            }));

            this.$wizard = this.$('.wizard');

            _.each(this.steps, function(step){
                step.view = new step.constructor({
                    el: this.$('.'+ step.class)
                });
            }, this);
        },

        renderActiveStep: function(){
            this.getStepByAttribute({active: 'active'}).view.render();
        },

        getStepByAttribute: function(attributeHash){
            return _.findWhere(this.steps, attributeHash);
        }<commit_msg>[site-admin][js-utils] (CCUK-1916 WIP) Refactor wizard-custom to better justify its existence and for easier reuse. [rev: luca.mandrioli]<commit_after>define([
    'backbone',
    'underscore',
    'fuelux/wizard'
], function(Backbone, _) {

    return Backbone.View.extend({

        initialize: function(options){
            _.bindAll(this, 'handleStepChange', 'handleStepChanged', 'handleStepClick', 'handleFinished');

            this.template = options.template;
            this.i18n = options.i18n;
            this.steps = options.steps;
            this.renderOptions = options.renderOptions;

            if(options.onStepChange) {
                this.handleStepChange = options.onStepChange;
            }

            if(options.onStepChanged) {
                this.handleStepChanged = options.onStepChanged;
            }

            if(options.onStepClick) {
                this.handleStepClick = options.onStepClick;
            }

            if(options.onFinished) {
                this.handleFinished = options.onFinished;
            }
        },

        render: function(){
            this.$el.html(this.template({
                renderOptions: this.renderOptions,
                steps: this.steps,
                i18n: this.i18n
            }));

            this.$wizard = this.$('.wizard');

            _.each(this.steps, function(step){
                step.view = new step.constructor({
                    el: this.$('.'+ step.class)
                });
            }, this);

            this.$wizard.on('change', this.handleStepChange);
            this.$wizard.on('changed', this.handleStepChanged);
            this.$wizard.on('stepclick', this.handleStepClick);
            this.$wizard.on('finished', this.handleFinished);
        },

        // takes 1 based arguments to match fuelux
        getStep: function(index) {
            return this.steps[index - 1];
        },

        getCurrentStep: function() {
            return this.getStep(this.$wizard.wizard('selectedItem').step);
        },

        renderActiveStep: function(){
            this.getStepByAttribute({active: true}).view.render();
        },

        getStepByAttribute: function(attributeHash){
            return _.findWhere(this.steps, attributeHash);
        },

        // if you want to override this function you should probably call this as the first line of your function
        handleStepChange: function(e, wizardObj) {
            var newStepNumber = wizardObj.step + (wizardObj.direction === 'next' ? 1 : -1);
            var newStep = this.getStep(newStepNumber);

            if(newStep.view.$el.children().length === 0){
                newStep.view.render();
            }
        },

        handleStepChanged: $.noop,

        handleStepClick: $.noop,

        handleFinished: $.noop
{'fraction_non_alphanumeric': 0.12256410256410256, 'fraction_numerical': 0.00641025641025641, 'mean_word_length': 1.7588401697312588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1884627', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1009, 'n_words': 189}