<commit_before>define(['marionette',
    'collections/proposals',
    'collections/labcontacts',
    'collections/proteins',
    'modules/shipment/collections/dewarregistry',

    'views/table',
    'tpl!templates/shipment/migrate.html', 'jquery-ui'], 
    function(Marionette,
        Proposals, LabContacts, Proteins, DewarRegistry,
        TableView,
        template) {


    return Marionette.LayoutView.extend({
        template: template,
        className: 'content',

        regions: {
            rprots: '.rproteins',
            rconts: '.rcontacts',
        },

        events: {
            'change @ui.dews': 'displayDewar',
            'change @ui.lc': 'displayLabContact',
            'click button[name=dewar]': 'migrateDewar',
            'click button[name=lc]': 'migrateContact',
            'click button[name=protein]': 'migrateProtein',
        },


        ui: {
            prop: 'input[name=PROPOSAL]',
            dews: 'select[name=DEWAR]',
            lc: 'select[name=LABCONTACT]',
            olc: 'select[name=OLABCONTACT]',

            prot: 'select[name=PROTEIN]',

            ti: '.TITLE',
            st: '.START',

            cn: '.CARDNAME',
            ln: '.LABNAME',
            ad: '.ADDRESS',

            ncn: '.NCARDNAME',
            nln: '.NLABNAME',
            nad: '.NADDRESS',
        },


        migrateDewar: function(e) {
            e.preventDefault()

            if (!this.ui.prop.val()) {
                app.alert({ message: 'You must select a proposal to migrate to' })
                return
            }

            if (!this.ui.dews.val()) {
                app.alert({ message: 'You must select a dewar to migrate' })
                return   
            }

            var d = this.dewars.findWhere({ FACILITYCODE: this.ui.dews.val() })
            var p = this.proposals.findWhere({ PROPOSAL: this.ui.prop.val() })

            if (p && d && this.ui.lc.val()) {
                d.set({
                    PROPOSALID: p.get('PROPOSALID'),
                    LABCONTACTID: this.ui.lc.val()
                })

                var self = this
                d.save(d.changedAttributes(), {
                    patch: true,
                    success: function() {
                        app.alert({ message: 'Dewar successfully migrated to: '+p.get('PROPOSAL') })
                        self.reset()
                        self.dewars.fetch()
                    }, 

                    failure: function() {
                        app.alert({ message: 'Something went wrong when trying to migrate that Dewar' })
                    },
                })
            }
        },


        migrateContact: function() {
            var contacts = this.contacts.where({ isGridSelected: true })

            if (!this.ui.prop.val()) {
                app.alert({ message: 'You must select a proposal to migrate to' })
                return
            }
            if (!contacts.length) {
                app.alert({ message: 'You must select at least one contact to copy' })
                return
            }

            var ready = []
            _.each(contacts, function(c) {
                var nc = c.clone()
                nc.set({ 
                    LABCONTACTID: null,
                    prop: this.ui.prop.val(),
                })

                ready.push(nc.save())
            }, this)

            var self = this
            $.when.apply($, ready).done(function() {
                app.alert({ message: 'Lab Contact(s) copied to: '+self.ui.prop.val() })
            })
        },


        migrateProtein: function() {
            var ready = []
            var proteins = this.proteins.where({ isGridSelected: true })

            if (!this.ui.prop.val()) {
                app.alert({ message: 'You must select a proposal to migrate to' })
                return
            }
            if (!proteins.length) {
                app.alert({ message: 'You must select at least one protein to copy' })
                return
            }

            _.each(proteins, function(p) {
                var np = p.clone()
                np.set({ 
                    PROTEINID: null,
                    prop: this.ui.prop.val(),
                })

                ready.push(np.save())

            }, this)

            var self = this
            $.when.apply($, ready).done(function() {
                app.alert({ message: 'Protein(s) copied to: '+self.ui.prop.val() })
            })
        },

        reset: function() {
            this.ui.prop.val('')
            this.ui.lc.html('').val('')
            this.displayLabContact()
            this.displayProposal()
        },



        initialize: function(options) {
            this.proposals = new Proposals()
            this.ready = this.proposals.fetch()

            this.dewars = new DewarRegistry()
            this.dewars.fetch()

            this.labcontacts = new LabContacts()


            this.contacts = new LabContacts()
            this.listenTo(this.contacts, 'backgrid:selected', this.selectModel, this)
            this.contacts.fetch()

            this.proteins = new Proteins()
            this.listenTo(this.proteins, 'backgrid:selected', this.selectModel, this)
            this.proteins.queryParams.seq = 1
            this.proteins.fetch()
        },
<commit_msg>Quick fix to see more registered dewars in migrate tool drop down<commit_after>define(['marionette',
    'collections/proposals',
    'collections/labcontacts',
    'collections/proteins',
    'modules/shipment/collections/dewarregistry',

    'views/table',
    'tpl!templates/shipment/migrate.html', 'jquery-ui'], 
    function(Marionette,
        Proposals, LabContacts, Proteins, DewarRegistry,
        TableView,
        template) {


    return Marionette.LayoutView.extend({
        template: template,
        className: 'content',

        regions: {
            rprots: '.rproteins',
            rconts: '.rcontacts',
        },

        events: {
            'change @ui.dews': 'displayDewar',
            'change @ui.lc': 'displayLabContact',
            'click button[name=dewar]': 'migrateDewar',
            'click button[name=lc]': 'migrateContact',
            'click button[name=protein]': 'migrateProtein',
        },


        ui: {
            prop: 'input[name=PROPOSAL]',
            dews: 'select[name=DEWAR]',
            lc: 'select[name=LABCONTACT]',
            olc: 'select[name=OLABCONTACT]',

            prot: 'select[name=PROTEIN]',

            ti: '.TITLE',
            st: '.START',

            cn: '.CARDNAME',
            ln: '.LABNAME',
            ad: '.ADDRESS',

            ncn: '.NCARDNAME',
            nln: '.NLABNAME',
            nad: '.NADDRESS',
        },


        migrateDewar: function(e) {
            e.preventDefault()

            if (!this.ui.prop.val()) {
                app.alert({ message: 'You must select a proposal to migrate to' })
                return
            }

            if (!this.ui.dews.val()) {
                app.alert({ message: 'You must select a dewar to migrate' })
                return   
            }

            var d = this.dewars.findWhere({ FACILITYCODE: this.ui.dews.val() })
            var p = this.proposals.findWhere({ PROPOSAL: this.ui.prop.val() })

            if (p && d && this.ui.lc.val()) {
                d.set({
                    PROPOSALID: p.get('PROPOSALID'),
                    LABCONTACTID: this.ui.lc.val()
                })

                var self = this
                d.save(d.changedAttributes(), {
                    patch: true,
                    success: function() {
                        app.alert({ message: 'Dewar successfully migrated to: '+p.get('PROPOSAL') })
                        self.reset()
                        self.dewars.fetch()
                    }, 

                    failure: function() {
                        app.alert({ message: 'Something went wrong when trying to migrate that Dewar' })
                    },
                })
            }
        },


        migrateContact: function() {
            var contacts = this.contacts.where({ isGridSelected: true })

            if (!this.ui.prop.val()) {
                app.alert({ message: 'You must select a proposal to migrate to' })
                return
            }
            if (!contacts.length) {
                app.alert({ message: 'You must select at least one contact to copy' })
                return
            }

            var ready = []
            _.each(contacts, function(c) {
                var nc = c.clone()
                nc.set({ 
                    LABCONTACTID: null,
                    prop: this.ui.prop.val(),
                })

                ready.push(nc.save())
            }, this)

            var self = this
            $.when.apply($, ready).done(function() {
                app.alert({ message: 'Lab Contact(s) copied to: '+self.ui.prop.val() })
            })
        },


        migrateProtein: function() {
            var ready = []
            var proteins = this.proteins.where({ isGridSelected: true })

            if (!this.ui.prop.val()) {
                app.alert({ message: 'You must select a proposal to migrate to' })
                return
            }
            if (!proteins.length) {
                app.alert({ message: 'You must select at least one protein to copy' })
                return
            }

            _.each(proteins, function(p) {
                var np = p.clone()
                np.set({ 
                    PROTEINID: null,
                    prop: this.ui.prop.val(),
                })

                ready.push(np.save())

            }, this)

            var self = this
            $.when.apply($, ready).done(function() {
                app.alert({ message: 'Protein(s) copied to: '+self.ui.prop.val() })
            })
        },

        reset: function() {
            this.ui.prop.val('')
            this.ui.lc.html('').val('')
            this.displayLabContact()
            this.displayProposal()
        },



        initialize: function(options) {
            this.proposals = new Proposals()
            this.ready = this.proposals.fetch()

            // Increasing list of dewars available to drop down
            // As of 2019-06 most recent proposals have less than 28 registered dewars
            this.dewars = new DewarRegistry([], {state: {pageSize: 50}})
            this.dewars.fetch()

            this.labcontacts = new LabContacts()


            this.contacts = new LabContacts()
            this.listenTo(this.contacts, 'backgrid:selected', this.selectModel, this)
            this.contacts.fetch()

            this.proteins = new Proteins()
            this.listenTo(this.proteins, 'backgrid:selected', this.selectModel, this)
            this.proteins.queryParams.seq = 1
            this.proteins.fetch()
        },

{'fraction_non_alphanumeric': 0.12666788521294095, 'fraction_numerical': 0.0010966916468652897, 'mean_word_length': 1.3203986429177268, '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': '3859459', 'n_tokens_mistral': 3153, 'n_tokens_neox': 2931, 'n_words': 640}