<commit_before>Ext.define('AIDRFM.common.AIDRFMFunctions', {

    initMessageContainer: function (){
        msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
        msgCt.setStyle('position', 'absolute');
        msgCt.setStyle('z-index', 99999);
        msgCt.setWidth(400);
    },

    setAlert: function (status, msg) {
        var message = '<ul>';
        var delay = 3;
        if (Ext.isArray(msg)) {
            Ext.each(msg, function (ms) {
                message += '<li>' + ms + '</li>';
            });
            var arrSize  = msg.length;
            if (arrSize  < 2) {
                delay = 3;
            } else {
                delay = 9;
            }
        } else {
            message = '<li>' + msg + '</li>';

            // add some smarts to msg's duration (div by 13.3 between 3 & 9 seconds)
            var delayMeasure  = msg.length / 13.3;
            if (delayMeasure  < 3) {
                delay = 3;
            } else if (delayMeasure  > 9) {
                delay = 9;
            } else {
                delay = delayMeasure ;
            }
        }
        message += '</ul>';
        delay = delay * 1000;

        msgCt.alignTo(document, 't-t');
        Ext.DomHelper.append(msgCt, {html: this.buildMessageBox(status.toLowerCase(), message)}, true).slideIn('t').ghost("t", {delay: delay, remove: true});
    },

    buildMessageBox : function(title, msg) {
        return [
            '<span id="notify" class="server-' + title + '">',
                '<span class="title">',
                    this.capitaliseFirstLetter(title),
                '</span>',
                '<span>',
                    msg,
                '</span>',
            '</span>'
        ].join('');
    },

    capitaliseFirstLetter: function (string) {
        return string.charAt(0).toUpperCase() + string.slice(1);
    },

    maskCount: 0,

    showMask: function(mask){
        if (mask) {
            if (this.maskCount == 0) {
                mask.show();
            }
            this.maskCount++;
        }
    },

    hideMask: function(mask){
        if (mask) {
            this.maskCount--;
            if (this.maskCount == 0) {
                mask.hide();
            }
        }
    },

    getMask: function (showMessage, msg) {
        if (showMessage) {
            if (!msg) {
                msg = 'Loading ...';
            }
        }
        if (this.maskScreen == null) {
            this.maskScreen = new Ext.LoadMask(Ext.getBody(), {msg: msg});
        } else {
            this.maskScreen.msg = msg;
        }
        return this.maskScreen;
    },

    mandatoryFieldsEntered: function () {
        var me = this;

        var isValid = true;
        var form = Ext.getCmp('collectionForm').getForm();
        if (!form.findField('code').getValue()) {
            form.findField('code').markInvalid(['Collection Code is mandatory']);
            AIDRFMFunctions.setAlert('Error', 'Collection Code is mandatory');
            isValid = false;
        }
        if (form.findField('code').getValue() && form.findField('code').getValue().length > 64) {
            form.findField('code').markInvalid(['The maximum length for Collection Code field is 64']);
            AIDRFMFunctions.setAlert('Error', 'The maximum length for Collection Code field is 64');
            isValid = false;
        }
        if (!form.findField('name').getValue()) {
            form.findField('name').markInvalid(['Collection Name is mandatory']);
            AIDRFMFunctions.setAlert('Error', 'Collection Name is mandatory');
            isValid = false;
        }
        if (!form.findField('crisisType').getValue()) {
            form.findField('crisisType').markInvalid(['Collection Type is mandatory']);
            AIDRFMFunctions.setAlert('Error', 'Collection Type is mandatory');
            isValid = false;
        }
        if (form.findField('collectionType').getValue() === 'Twitter' && !(form.findField('track').getValue() || form.findField('geo').getValue() || form.findField('follow').getValue())) {
            AIDRFMFunctions.setAlert('Error', 'One of Keywords, Geo or Follow field is mandatory');
            isValid = false;
        }
        if (form.findField('track').getValue()) {
            var value = form.findField('track').getValue(),
                keywords = value.split(","),
                errors = [],
                isKeywordValid = true;
            Ext.Array.each(keywords, function(v) {
                if (v.length > 60) {
                    if (isKeywordValid){
                        errors.push('Each keywords should not exceed 60 chars.');
                    }
                    errors.push('<b>' + v + '</b> has more than 60 chars');
                    isKeywordValid = false;
                }
            });
            if (!isKeywordValid) {
                isValid = isKeywordValid;
                AIDRFMFunctions.setAlert('Error', errors);
            }
        }
        return isValid;
    },

    getQueryParam: function (name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return null;
        else
            return results[1];
    },

    getStatusWithStyle: function(raw, collectionType) {
        var statusText = '';

        if (raw == 'RUNNING') {

            var status = collectionType === 'Twitter' ? 'Collecting Live Tweets' : 'Collecting Live SMS';

            statusText = "<b class='greenInfo'> " + status + " </b>";
        } else if (raw == 'INITIALIZING') {
            statusText = "<b class='blueInfo'> INITIALIZING </b>";
        } else if (raw == 'STOPPED' || raw == 'FATAL-ERROR') {
            statusText = "<b class='redInfo'>" + raw + " </b>";
        }  else if (raw == 'NOT_RUNNING') {
            statusText = "<b class='warningFont'>" + raw + " </b>";
        } else {
            statusText = "<b class='warningFont'>" + raw + " </b>";
        }
        return statusText;
    },

    getAucNumberWithColors: function(r) {
        var style;
        if (r){
            if (r < 0.6){
                style = 'redInfo';
            } else if (r <= 0.8){
                style = 'warningFont';
            } else {
                style = 'greenInfo';
            }
        } else {
            r = 0;
            style = 'redInfo';
        }
        return '<span class="' + style + '">' + r.toFixed(2) + '</span>';
    },
    
    getAucNumberAsPercentageWithColors: function(r) {
        var style;
        if (r){
            if (r < 0.6){
                style = 'redInfo';
            } else if (r <= 0.8){
                style = 'warningFont';
            } else {
                style = 'greenInfo';
            }
        } else {
            r = 0;
            style = 'redInfo';
        }
        return '<span class="' + style + '">' + (r * 100).toFixed(2) + '%</span>';
    }
    

});

AIDRFMFunctions = new AIDRFM.common.AIDRFMFunctions();

NA_CATEGORY_NAME = 'N/A: does not apply, or cannot judge';

Number.prototype.format = function(n, x) {
    var re = '(\\d)(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\.' : '$') + ')';
    return this.toFixed(Math.max(0, ~~n)).replace(new RegExp(re, 'g'), '$1,');
};

if(!String.linkify) {
    String.prototype.linkify = function() {

        // http://, https://, ftp://
        var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim;

        // www. sans http:// or https://
        var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;

        // Email addresses
        var emailAddressPattern = /\w+@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6})+/gim;

        return this
            .replace(urlPattern, '<a href="$&" target="_blank">$&</a>')
            .replace(pseudoUrlPattern, '$1<a href="http://$2" target="_blank">$2</a>')
            .replace(emailAddressPattern, '<a href="mailto:$&">$&</a>');
    };
}

Ext.Ajax.on('requestexception', function (conn, response, options) {
    if (response.status == 901) {
        document.location.href = BASE_URL + '/index.jsp'
    } else{
        if(response.status != 0){
            AIDRFMFunctions.setAlert("Error", "System is down or under maintenance. For further inquiries please contact admin.");
        }
    }
});

Ext.Date.patterns = {
    ISO8601Long:"Y-m-d H:i:s",
    ISO8601Short:"Y-m-d",
    ShortDate: "n/j/Y",
    LongDate: "l, F d, Y",
    FullDateTime: "l, F d, Y g:i:s A",
    MedumDateTime: "F d, Y g:i:s A",
    MonthDay: "F d",
    ShortTime: "g:i A",
    LongTime: "g:i:s A",
    SortableDateTime: "Y-m-d\\TH:i:s",
    UniversalSortableDateTime: "Y-m-d H:i:sO",
    YearMonth: "F, Y"
};<commit_msg>Manager System Error turned off. As of now it does not reflect correct status.<commit_after>Ext.define('AIDRFM.common.AIDRFMFunctions', {

    initMessageContainer: function (){
        msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
        msgCt.setStyle('position', 'absolute');
        msgCt.setStyle('z-index', 99999);
        msgCt.setWidth(400);
    },

    setAlert: function (status, msg) {
        var message = '<ul>';
        var delay = 3;
        if (Ext.isArray(msg)) {
            Ext.each(msg, function (ms) {
                message += '<li>' + ms + '</li>';
            });
            var arrSize  = msg.length;
            if (arrSize  < 2) {
                delay = 3;
            } else {
                delay = 9;
            }
        } else {
            message = '<li>' + msg + '</li>';

            // add some smarts to msg's duration (div by 13.3 between 3 & 9 seconds)
            var delayMeasure  = msg.length / 13.3;
            if (delayMeasure  < 3) {
                delay = 3;
            } else if (delayMeasure  > 9) {
                delay = 9;
            } else {
                delay = delayMeasure ;
            }
        }
        message += '</ul>';
        delay = delay * 1000;

        msgCt.alignTo(document, 't-t');
        Ext.DomHelper.append(msgCt, {html: this.buildMessageBox(status.toLowerCase(), message)}, true).slideIn('t').ghost("t", {delay: delay, remove: true});
    },

    buildMessageBox : function(title, msg) {
        return [
            '<span id="notify" class="server-' + title + '">',
                '<span class="title">',
                    this.capitaliseFirstLetter(title),
                '</span>',
                '<span>',
                    msg,
                '</span>',
            '</span>'
        ].join('');
    },

    capitaliseFirstLetter: function (string) {
        return string.charAt(0).toUpperCase() + string.slice(1);
    },

    maskCount: 0,

    showMask: function(mask){
        if (mask) {
            if (this.maskCount == 0) {
                mask.show();
            }
            this.maskCount++;
        }
    },

    hideMask: function(mask){
        if (mask) {
            this.maskCount--;
            if (this.maskCount == 0) {
                mask.hide();
            }
        }
    },

    getMask: function (showMessage, msg) {
        if (showMessage) {
            if (!msg) {
                msg = 'Loading ...';
            }
        }
        if (this.maskScreen == null) {
            this.maskScreen = new Ext.LoadMask(Ext.getBody(), {msg: msg});
        } else {
            this.maskScreen.msg = msg;
        }
        return this.maskScreen;
    },

    mandatoryFieldsEntered: function () {
        var me = this;

        var isValid = true;
        var form = Ext.getCmp('collectionForm').getForm();
        if (!form.findField('code').getValue()) {
            form.findField('code').markInvalid(['Collection Code is mandatory']);
            AIDRFMFunctions.setAlert('Error', 'Collection Code is mandatory');
            isValid = false;
        }
        if (form.findField('code').getValue() && form.findField('code').getValue().length > 64) {
            form.findField('code').markInvalid(['The maximum length for Collection Code field is 64']);
            AIDRFMFunctions.setAlert('Error', 'The maximum length for Collection Code field is 64');
            isValid = false;
        }
        if (!form.findField('name').getValue()) {
            form.findField('name').markInvalid(['Collection Name is mandatory']);
            AIDRFMFunctions.setAlert('Error', 'Collection Name is mandatory');
            isValid = false;
        }
        if (!form.findField('crisisType').getValue()) {
            form.findField('crisisType').markInvalid(['Collection Type is mandatory']);
            AIDRFMFunctions.setAlert('Error', 'Collection Type is mandatory');
            isValid = false;
        }
        if (form.findField('collectionType').getValue() === 'Twitter' && !(form.findField('track').getValue() || form.findField('geo').getValue() || form.findField('follow').getValue())) {
            AIDRFMFunctions.setAlert('Error', 'One of Keywords, Geo or Follow field is mandatory');
            isValid = false;
        }
        if (form.findField('track').getValue()) {
            var value = form.findField('track').getValue(),
                keywords = value.split(","),
                errors = [],
                isKeywordValid = true;
            Ext.Array.each(keywords, function(v) {
                if (v.length > 60) {
                    if (isKeywordValid){
                        errors.push('Each keywords should not exceed 60 chars.');
                    }
                    errors.push('<b>' + v + '</b> has more than 60 chars');
                    isKeywordValid = false;
                }
            });
            if (!isKeywordValid) {
                isValid = isKeywordValid;
                AIDRFMFunctions.setAlert('Error', errors);
            }
        }
        return isValid;
    },

    getQueryParam: function (name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return null;
        else
            return results[1];
    },

    getStatusWithStyle: function(raw, collectionType) {
        var statusText = '';

        if (raw == 'RUNNING') {

            var status = collectionType === 'Twitter' ? 'Collecting Live Tweets' : 'Collecting Live SMS';

            statusText = "<b class='greenInfo'> " + status + " </b>";
        } else if (raw == 'INITIALIZING') {
            statusText = "<b class='blueInfo'> INITIALIZING </b>";
        } else if (raw == 'STOPPED' || raw == 'FATAL-ERROR') {
            statusText = "<b class='redInfo'>" + raw + " </b>";
        }  else if (raw == 'NOT_RUNNING') {
            statusText = "<b class='warningFont'>" + raw + " </b>";
        } else {
            statusText = "<b class='warningFont'>" + raw + " </b>";
        }
        return statusText;
    },

    getAucNumberWithColors: function(r) {
        var style;
        if (r){
            if (r < 0.6){
                style = 'redInfo';
            } else if (r <= 0.8){
                style = 'warningFont';
            } else {
                style = 'greenInfo';
            }
        } else {
            r = 0;
            style = 'redInfo';
        }
        return '<span class="' + style + '">' + r.toFixed(2) + '</span>';
    },
    
    getAucNumberAsPercentageWithColors: function(r) {
        var style;
        if (r){
            if (r < 0.6){
                style = 'redInfo';
            } else if (r <= 0.8){
                style = 'warningFont';
            } else {
                style = 'greenInfo';
            }
        } else {
            r = 0;
            style = 'redInfo';
        }
        return '<span class="' + style + '">' + (r * 100).toFixed(2) + '%</span>';
    }
    

});

AIDRFMFunctions = new AIDRFM.common.AIDRFMFunctions();

NA_CATEGORY_NAME = 'N/A: does not apply, or cannot judge';

Number.prototype.format = function(n, x) {
    var re = '(\\d)(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\.' : '$') + ')';
    return this.toFixed(Math.max(0, ~~n)).replace(new RegExp(re, 'g'), '$1,');
};

if(!String.linkify) {
    String.prototype.linkify = function() {

        // http://, https://, ftp://
        var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim;

        // www. sans http:// or https://
        var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;

        // Email addresses
        var emailAddressPattern = /\w+@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6})+/gim;

        return this
            .replace(urlPattern, '<a href="$&" target="_blank">$&</a>')
            .replace(pseudoUrlPattern, '$1<a href="http://$2" target="_blank">$2</a>')
            .replace(emailAddressPattern, '<a href="mailto:$&">$&</a>');
    };
}

Ext.Ajax.on('requestexception', function (conn, response, options) {
    if (response.status == 901) {
        document.location.href = BASE_URL + '/index.jsp'
    } else{
        if(response.status != 0){
            //AIDRFMFunctions.setAlert("Error", "System is down or under maintenance. For further inquiries please contact admin.");
        }
    }
});

Ext.Date.patterns = {
    ISO8601Long:"Y-m-d H:i:s",
    ISO8601Short:"Y-m-d",
    ShortDate: "n/j/Y",
    LongDate: "l, F d, Y",
    FullDateTime: "l, F d, Y g:i:s A",
    MedumDateTime: "F d, Y g:i:s A",
    MonthDay: "F d",
    ShortTime: "g:i A",
    LongTime: "g:i:s A",
    SortableDateTime: "Y-m-d\\TH:i:s",
    UniversalSortableDateTime: "Y-m-d H:i:sO",
    YearMonth: "F, Y"
};
{'fraction_non_alphanumeric': 0.172524682651622, 'fraction_numerical': 0.009703808180535966, 'mean_word_length': 1.6890169902912622, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 79, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '984376', 'n_tokens_mistral': 5558, 'n_tokens_neox': 5311, 'n_words': 1159}