<commit_before>var tc = tc || {};
tc.gam = tc.gam || {};
tc.gam.project_widgets = tc.gam.project_widgets || {};

tc.gam.project_widgets.add_link = function(options) {
    tc.util.log('project.add_link');
    var dom = options.dom,
        elements = {
            window: tc.jQ(window)
        },
        components = {
            merlin:null
        };
    
    var build_merlin = function(){
        if(components.merlin){
            return;
        }
        components.merlin = new tc.merlin(options.app,{
            name:'add-link',
            dom:dom.find('.merlin.add-link'),
            next_button:dom.find('a.submit'),
            first_step:'link-info',
            use_hashchange:false,
            data:{
                project_id:null,
                title:null,
                url:null,
                main_text:''
            },
            steps:{
                'link-info':{
                    selector:'.step.add-link-step',
                    next_step:'link-submit',
                    inputs:{
                        title:{
                            selector:'input.link-title',
                            validators:['min-3','max-50','required'],
                            hint:'Title',
                            counter:{
                                selector:'.charlimit.title',
                                limit:50
                            }
                        },
                        url:{
                            selector:'input.link-href',
                            validators:['min-3','max-300','required','url'],
                            hint:'URL'
                        },
                        main_text:{
                            selector:'input.main_text',
                            validators:['max-0']
                        }
                    },
                    init:function(merlin,dom){
                        merlin.current_step.inputs.title.dom.removeClass('has-been-focused').removeClass('has-attempted-submit').val('').triggerHandler('keyup');
                        merlin.current_step.inputs.url.dom.removeClass('has-been-focused').removeClass('has-attempted-submit').val('').triggerHandler('keyup');
                        
                        merlin.current_step.inputs.title.dom.val('Title');
                        merlin.current_step.inputs.url.dom.val('URL');
                        
                    },
                    finish:function(merlin,dom){
                        merlin.options.data = tc.jQ.extend(merlin.options.data,{
                            project_id:merlin.app.app_page.data.project.project_id,
                            title:merlin.current_step.inputs.title.dom.val(),
                            url:merlin.current_step.inputs.url.dom.val(),
                            main_text:merlin.current_step.inputs.main_text.dom.val()
                        });
                    }
                },
                'link-submit':{
                    selector:'.step.submit-link-step',
                    init:function(merlin,dom){
                        tc.jQ.ajax({
                            type:'POST',
                            url:'/project/link/add',
                            data:merlin.options.data,
                            context:merlin,
                            dataType:'text',
                            success:function(data,ts,xhr){
                                if(data == 'False'){
                                    return false;
                                }
                                project.dom.trigger('resources-refresh',{type:'link'});
                                window.location.hash = 'project-home';
                            }
                        });
                    }
                }
            }
        });
    };
    
    build_merlin();

    tc.jQ(tc).bind('show-project-widget', function(event, widgetName) {
        if (options.name === widgetName) {
            tc.util.log('&&& showing ' + options.name);<commit_msg>bug fix: using undefined var<commit_after>var tc = tc || {};
tc.gam = tc.gam || {};
tc.gam.project_widgets = tc.gam.project_widgets || {};

tc.gam.project_widgets.add_link = function(options) {
    tc.util.log('project.add_link');
    var dom = options.dom,
        elements = {
            window: tc.jQ(window)
        },
        components = {
            merlin:null
        };
    
    var build_merlin = function(){
        if(components.merlin){
            return;
        }
        components.merlin = new tc.merlin(options.app,{
            name:'add-link',
            dom:dom.find('.merlin.add-link'),
            next_button:dom.find('a.submit'),
            first_step:'link-info',
            use_hashchange:false,
            data:{
                project_id:null,
                title:null,
                url:null,
                main_text:''
            },
            steps:{
                'link-info':{
                    selector:'.step.add-link-step',
                    next_step:'link-submit',
                    inputs:{
                        title:{
                            selector:'input.link-title',
                            validators:['min-3','max-50','required'],
                            hint:'Title',
                            counter:{
                                selector:'.charlimit.title',
                                limit:50
                            }
                        },
                        url:{
                            selector:'input.link-href',
                            validators:['min-3','max-300','required','url'],
                            hint:'URL'
                        },
                        main_text:{
                            selector:'input.main_text',
                            validators:['max-0']
                        }
                    },
                    init:function(merlin,dom){
                        merlin.current_step.inputs.title.dom.removeClass('has-been-focused').removeClass('has-attempted-submit').val('').triggerHandler('keyup');
                        merlin.current_step.inputs.url.dom.removeClass('has-been-focused').removeClass('has-attempted-submit').val('').triggerHandler('keyup');
                        
                        merlin.current_step.inputs.title.dom.val('Title');
                        merlin.current_step.inputs.url.dom.val('URL');
                        
                    },
                    finish:function(merlin,dom){
                        merlin.options.data = tc.jQ.extend(merlin.options.data,{
                            project_id:merlin.app.app_page.data.project.project_id,
                            title:merlin.current_step.inputs.title.dom.val(),
                            url:merlin.current_step.inputs.url.dom.val(),
                            main_text:merlin.current_step.inputs.main_text.dom.val()
                        });
                    }
                },
                'link-submit':{
                    selector:'.step.submit-link-step',
                    init:function(merlin,dom){
                        tc.jQ.ajax({
                            type:'POST',
                            url:'/project/link/add',
                            data:merlin.options.data,
                            context:merlin,
                            dataType:'text',
                            success:function(data,ts,xhr){
                                if(data == 'False'){
                                    return false;
                                }
                                tc.jQ(tc).trigger('resources-refresh',{type:'link'});
                                window.location.hash = 'project-home';
                            }
                        });
                    }
                }
            }
        });
    };
    
    build_merlin();

    tc.jQ(tc).bind('show-project-widget', function(event, widgetName) {
        if (options.name === widgetName) {
            tc.util.log('&&& showing ' + options.name);
{'fraction_non_alphanumeric': 0.12098461538461538, 'fraction_numerical': 0.0024615384615384616, 'mean_word_length': 0.9472801341960221, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4608269', 'n_tokens_mistral': 2031, 'n_tokens_neox': 1934, 'n_words': 191}