<commit_before>/**
 * Copyright 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 * Please see distribution for license.
 */
$.register_module({
    name: 'og.blotter.forms.fungibletrade',
    dependencies: [],
    obj: function () {
        return function (config) {
            var constructor = this, form, request, data, security, $security_input, util = og.blotter.util,
            dropdown = '.og-blotter-security-select', securityId, details_selector = 'og-blocks-fungible-details',
            ids_selector = 'og-blocks-fungible-security-ids',
            blank_details = "<table class='" + details_selector + "'></table>",
            blank_ids = "<table class='" + ids_selector + "'></table>", validate;
            if(config.details) {data = config.details.data; data.id = config.details.data.trade.uniqueId;}
            else {data = {trade: og.blotter.util.fungible_trade};}
            if(data.trade.securityIdBundle) securityId = data.trade.securityIdBundle.split(',')[0];
            data.nodeId = config.portfolio ? config.portfolio.id : null;
            constructor.load = function () {
                constructor.title = 'Fungible Trade';
                form = new og.common.util.ui.Form({
                    module: 'og.blotter.forms.fungible_tash',
                    data: data,
                    selector: '.OG-blotter-form-block',
                    processor: function (data) {og.blotter.util.cleanup(data);}
                });
                security = new og.blotter.forms.blocks.Security({form: form, label: "Underlying ID",
                    security: securityId, index: "trade.securityIdBundle", edit: !!config.details, 
                    callback: function () {get_security();}
                });
                form.children.push(
                    new og.blotter.forms.blocks.Portfolio({form: form, counterparty: data.trade.counterparty,
                        portfolio: data.nodeId, trade: data.trade}),
                    new form.Block({module: 'og.blotter.forms.blocks.fungible_tash',
                        extras: {quantity: data.trade.quantity},
                        children: [security]
                    }),
                    new og.common.util.ui.Attributes({
                        form: form, attributes: data.trade.attributes, index: 'trade.attributes'
                    }),
                    new form.Block({content: blank_details}),
                    new form.Block({content: blank_ids})
                );
                form.dom();
                form.on('form:load', function () {
                    og.blotter.util.add_date_picker('.blotter-date');
                    og.blotter.util.add_time_picker('.blotter-time');
                    og.blotter.util.set_initial_focus();
                });
                form.on('form:submit', function (result) {
                    $.when(config.handler(result.data)).then(validate);
                });
            };
            get_security = function () {
                var id = security.name();
                if(id) request = og.api.rest.blotter.securities.get({id:id}).pipe(function(result){populate(result);});<commit_msg>only doing security lookup if promise id result matches request<commit_after>/**
 * Copyright 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 * Please see distribution for license.
 */
$.register_module({
    name: 'og.blotter.forms.fungibletrade',
    dependencies: [],
    obj: function () {
        return function (config) {
            var constructor = this, form, data, security, $security_input, util = og.blotter.util, promise,
            dropdown = '.og-blotter-security-select', securityId, details_selector = 'og-blocks-fungible-details',
            ids_selector = 'og-blocks-fungible-security-ids',
            blank_details = "<table class='" + details_selector + "'></table>",
            blank_ids = "<table class='" + ids_selector + "'></table>", validate;
            if(config.details) {data = config.details.data; data.id = config.details.data.trade.uniqueId;}
            else {data = {trade: og.blotter.util.fungible_trade};}
            if(data.trade.securityIdBundle) securityId = data.trade.securityIdBundle.split(',')[0];
            data.nodeId = config.portfolio ? config.portfolio.id : null;
            constructor.load = function () {
                constructor.title = 'Fungible Trade';
                form = new og.common.util.ui.Form({
                    module: 'og.blotter.forms.fungible_tash',
                    data: data,
                    selector: '.OG-blotter-form-block',
                    processor: function (data) {og.blotter.util.cleanup(data);}
                });
                security = new og.blotter.forms.blocks.Security({form: form, label: "Underlying ID",
                    security: securityId, index: "trade.securityIdBundle", edit: !!config.details, 
                    callback: function () {get_security();}
                });
                form.children.push(
                    new og.blotter.forms.blocks.Portfolio({form: form, counterparty: data.trade.counterparty,
                        portfolio: data.nodeId, trade: data.trade}),
                    new form.Block({module: 'og.blotter.forms.blocks.fungible_tash',
                        extras: {quantity: data.trade.quantity},
                        children: [security]
                    }),
                    new og.common.util.ui.Attributes({
                        form: form, attributes: data.trade.attributes, index: 'trade.attributes'
                    }),
                    new form.Block({content: blank_details}),
                    new form.Block({content: blank_ids})
                );
                form.dom();
                form.on('form:load', function () {
                    og.blotter.util.add_date_picker('.blotter-date');
                    og.blotter.util.add_time_picker('.blotter-time');
                    og.blotter.util.set_initial_focus();
                });
                form.on('form:submit', function (result) {
                    $.when(config.handler(result.data)).then(validate);
                });
            };
            get_security = function () {
                var id = security.name();
                if (id) {
                    promise = og.api.rest.blotter.securities.get({id:id});
                    promise.pipe(function(result){
                        if (promise.id === result.meta.promise) populate(result);
                    });
                }
{'fraction_non_alphanumeric': 0.12921348314606743, 'fraction_numerical': 0.0015183723048891589, 'mean_word_length': 1.7185307470078415, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4235394', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1694, 'n_words': 324}