<commit_before>define(['marionette',
        'models/protein',
        'collections/proteins',
    
        'views/validatedrow',
        'modules/shipment/collections/distinctproteins',
        'modules/samples/views/componentsview',
    
        'tpl!templates/shipment/sampletable.html',
        'tpl!templates/shipment/sampletablerow.html',
        'tpl!templates/shipment/sampletablerowedit.html',
    
        'utils/forms',
        'utils/sgs',
        'utils/anoms',
        'utils',
    
        'jquery',
        'jquery-ui',
        'jquery-ui.combobox',
    ], function(Marionette, Protein, Proteins, ValidatedRow, DistinctProteins, ComponentsView,
        sampletable, sampletablerow, sampletablerowedit, 
        forms, SG, Anom, utils, $) {

        
    // A Sample Row
    var GridRow = ValidatedRow.extend(_.extend({}, forms, {
        template: sampletablerow,
        tagName: 'tr',
        events: {
            'click a.edit': 'editSample',
            'click a.cancel': 'cancelEditSample',
            'click a.clone': 'cloneSample',
            'click a.clear': 'clearSample',
        },

        ui: {
            comp: 'input[name=COMPONENTID]',
            comps: 'td.components',
        },

        modelEvents: {
            'change:isSelected': 'setSelected',
            'cloned': 'render',
        },

        setSelected: function(e) {
            console.log('seleted', this.model.get('isSelected'))
            this.$el.parent().find('tr').removeClass('selected')
            this.$el.addClass('selected')

            $('html, body').animate({ scrollTop: this.$el.offset().top }, 500)
        },

        className: function() {
            if (this.model.get('isSelected')) return 'selected' 
        },
        
        editSample: function(e) {
            this.editing = true
            e.preventDefault()
            this.template = sampletablerowedit
            this.render()
            this.updateProteins()
        },
        
        cancelEditSample: function(e) {
            this.editing = false
            e.preventDefault()
            this.template = sampletablerow
            this.render()
        },
        
        setData: function() {
            var data = {}
            _.each(['CODE', 'PROTEINID','NAME','COMMENTS','SPACEGROUP', 'VOLUME'], function(f) {
                data[f] = this.$el.find('[name='+f+']').val()
            }, this)

            data['COMPONENTIDS'] = this.model.get('components').pluck('PROTEINID')
            data['COMPONENTAMOUNTS'] = this.model.get('components').pluck('ABUNDANCE')
            // data['COMPONENTACRONYMS'] = this.model.get('components').pluck('ACRONYM')
            this.model.set(data)
        },
            
        success: function(m,r,o) {
            var p = this.proteins.findWhere({ PROTEINID: this.model.get('PROTEINID') })
            if (p) this.model.set('ACRONYM', p.get('ACRONYM'))

            this.model.set('new', false)<commit_msg>need to set some sample properties on save<commit_after>define(['marionette',
        'models/protein',
        'collections/proteins',
    
        'views/validatedrow',
        'modules/shipment/collections/distinctproteins',
        'modules/samples/views/componentsview',
    
        'tpl!templates/shipment/sampletable.html',
        'tpl!templates/shipment/sampletablerow.html',
        'tpl!templates/shipment/sampletablerowedit.html',
    
        'utils/forms',
        'utils/sgs',
        'utils/anoms',
        'utils',
    
        'jquery',
        'jquery-ui',
        'jquery-ui.combobox',
    ], function(Marionette, Protein, Proteins, ValidatedRow, DistinctProteins, ComponentsView,
        sampletable, sampletablerow, sampletablerowedit, 
        forms, SG, Anom, utils, $) {

        
    // A Sample Row
    var GridRow = ValidatedRow.extend(_.extend({}, forms, {
        template: sampletablerow,
        tagName: 'tr',
        events: {
            'click a.edit': 'editSample',
            'click a.cancel': 'cancelEditSample',
            'click a.clone': 'cloneSample',
            'click a.clear': 'clearSample',
        },

        ui: {
            comp: 'input[name=COMPONENTID]',
            comps: 'td.components',
        },

        modelEvents: {
            'change:isSelected': 'setSelected',
            'cloned': 'render',
        },

        setSelected: function(e) {
            console.log('seleted', this.model.get('isSelected'))
            this.$el.parent().find('tr').removeClass('selected')
            this.$el.addClass('selected')

            $('html, body').animate({ scrollTop: this.$el.offset().top }, 500)
        },

        className: function() {
            if (this.model.get('isSelected')) return 'selected' 
        },
        
        editSample: function(e) {
            this.editing = true
            e.preventDefault()
            this.template = sampletablerowedit
            this.render()
            this.updateProteins()
        },
        
        cancelEditSample: function(e) {
            this.editing = false
            e.preventDefault()
            this.template = sampletablerow
            this.render()
        },
        
        setData: function() {
            var data = {}
            _.each(['CODE', 'PROTEINID','NAME','COMMENTS','SPACEGROUP', 'VOLUME'], function(f) {
                data[f] = this.$el.find('[name='+f+']').val()
            }, this)

            data['COMPONENTIDS'] = this.model.get('components').pluck('PROTEINID')
            data['COMPONENTAMOUNTS'] = this.model.get('components').pluck('ABUNDANCE')
            // data['COMPONENTACRONYMS'] = this.model.get('components').pluck('ACRONYM')
            this.model.set(data)
        },
            
        success: function(m,r,o) {
            var p = this.proteins.findWhere({ PROTEINID: this.model.get('PROTEINID') })
            if (p) {
                this.model.set('ACRONYM', p.get('ACRONYM'))
                this.model.set('ABUNDANCE', p.get('ABUNDANCE'))
                this.model.set('SYMBOL', p.get('CONCENTRATIONTYPE'))
            }

            this.model.set('new', false)
{'fraction_non_alphanumeric': 0.14949296696107295, 'fraction_numerical': 0.0009813542688910696, 'mean_word_length': 1.8628277153558053, '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': '6431536', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1801, 'n_words': 266}