<commit_before>if (Q.isEmpty(Q["isAddress"])) {
    Q.isAddress = function _Q_isAddress(address) {
        // https://github.com/ethereum/go-ethereum/blob/aa9fff3e68b1def0a9a22009c233150bf9ba481f/jsre/ethereum_js.go#L2295-L2329
        if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
            // check if it has the basic requirements of an address
            return false;
        } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) {
            // If it's all small caps or all all caps, return true
            return true;
        } else {
            // Otherwise check each case
//            address = address.replace('0x','');
//            var addressHash = Web3.utils.sha3(address.toLowerCase());
//            for (var i = 0; i < 40; i++ ) {
//                // the nth letter should be uppercase if the nth digit of casemap is 1
//                if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
//                    return false;
//                }
//            }
            return true;
        }
        
    }
}

if (Q.isEmpty(Q["validate"])) {
    Q.validate = function _Q_validate(address) {
    
    }
    Q.validate.notEmpty = function _Q_validate_notEmpty(input) {
        return !Q.isEmpty(input)
    }
    Q.validate.integer = function _Q_validate_integer(input) {
        return Q.isInteger(input)
    }
    Q.validate.address = function _Q_validate_address(input) {
        return Q.isAddress(input)
    }
}
(function (window, Q, $, undefined) {
	
/**
 * @module TokenSociety
 */
	
/**
 * YUIDoc description goes here
 * @class TokenSociety cool
 * @constructor
 * @param {Object} [options] Override various options for this tool
 *  @param {String} [options.fields] array of values by default. 
 *  @param {Q.Event} [options.onMove] Event that fires after a move
 */

Q.Tool.define("Assets/NFT/sales/factory", function (options) {
	var tool = this;
	var state = tool.state;
        
        var defaultsValidate = {
            notEmpty: "<b>%key%</b> is not be empty", 
            integer: "<b>%key%</b> is not a number", 
            address: "<b>%key%</b> invalid"
        };
        
        // fill missed attr fields
        for (var i in state.fields) {
            
            if (typeof(state.fields[i]) === "string") {
                state.fields[i] = {
                    value: state.fields[i],
                    hide: false
                }
            } else if (typeof(state.fields[i]) === "object") {
                let arr;
                if (Q.isEmpty(state.fields[i]["value"])) {
                    state.fields[i]["value"] = "";
                }
                if (Q.isEmpty(state.fields[i]["hide"])) {
                    state.fields[i]["hide"] = false;
                }
                
                if (Q.isEmpty(state.fields[i]["validate"])) {
                    state.fields[i]["validate"] = {};
                } else if (Array.isArray(state.fields[i]["validate"])) {
                    
                    arr = {};
                    for (var j in state.fields[i]["validate"]) {
                        let k = state.fields[i]["validate"][j];
                        if (Q.isEmpty(defaultsValidate[k])) {
                            console.warn(`validate expr "${k}" have not supported yet`);
                        } else {
                            arr[k] = defaultsValidate[k];
                        }
                    }
                    state.fields[i]["validate"] = Object.assign({}, arr);
                    
                } else if (typeof(state.fields[i]["validate"]) === "object") {
                    for (var j in state.fields[i]["validate"]) {
                        if (Q.isEmpty(defaultsValidate[j])) {
                            console.warn(`validate expr "${j}" have not supported yet`);
                        } else {
                            state.fields[i]["validate"][j] = state.fields[i]["validate"][j];
                        }
                    }
                }
            }
        }
        
	var p = Q.pipe(['stylesheet', 'text'], function (params, subjects) {
		tool.text = params.text[1];
		tool.refresh();
	});
        
	Q.addStylesheet("{{Assets}}/css/tools/NFT/sales/factory.css", p.fill('stylesheet'), { slotName: 'Assets' });
	Q.Text.get('Assets/content', p.fill('text'));
},

{ // default options here
    fields: {
        // key validate is optional
        // value can be :
        // - plain array
        //  validate: ["isEmpty", "isInteger", ...] and try to call Q methods: Q.isEmpty, Q.isInteger ...
        // - object  like {key => errormessage}
        //  validate: {"isEmpty": "err msg here to key %key%, "isInteger": "invalid key %key%, ...} and try to call Q methods: Q.isEmpty, Q.isInteger ...
        NFTContract: {value: "", hide: false, validate: ["notEmpty", "address"]},
        seriesId: {value: "", hide: false, validate: ["notEmpty", "integer"]},
        owner: {value: "", hide: false, validate: ["notEmpty", "address"]},
        currency: {value: "", hide: false, validate: ["notEmpty", "address"]},
        price: {value: "", hide: false, validate: ["notEmpty"]},
        beneficiary: {value: "", hide: false, validate: ["notEmpty", "address"]},
        autoindex: {value: "", hide: false, validate: ["notEmpty", "integer"]},
        duration: {value: "", hide: false, validate: ["notEmpty", "integer"]},
        rateInterval: {value: "", hide: false, validate: ["notEmpty", "integer"]},
        rateAmount: {value: "", hide: false, validate: ["notEmpty", "integer"]}
    },
    salesLinkPattern: "sales/{{address}}",
    onMove: new Q.Event() // an event that the tool might trigger
},

{ // methods go here
    whitelistByNFT: function(NFTContract, callback){
        let contract;
        Q.Users.Web3.getFactory('Assets/templates/R1/NFT/sales/factory')
        .then(function(_contract){
            contract = _contract;
            return  contract.whitelistByNFTContract(NFTContract).then(function(res){return res});
        }).then(function (instancesList) {
            Q.handle(callback, null, [null, {list: instancesList}, contract])
        }).catch(function (err) {
            Q.handle(callback, null, [err.reason || err]);
        })

    },
    _whitelistPush: function(item){
        var tool = this;
        let obj = $(tool.element).find(".Assets_NFT_sales_factory_instancesTableList");
        if (obj.find('tr.Assets_NFT_sales_factory_item').length == 0) {
            obj.find('tr').hide();    // all defaults  like "there are no data  etc"
        }
        obj.prepend(`<tr class="Assets_NFT_sales_factory_item"><td><a href="/test2/${item}">${item}</a></td></tr>`);
    },
    _whitelistRefresh: function(){
        var tool = this;
        let obj = $(tool.element).find(".Assets_NFT_sales_factory_instancesTableList");
        obj.find('tr').hide();
        obj.find('tr.Assets_NFT_sales_factory_loading').show();
        tool.whitelistByNFT(TokenSociety.NFT.contract.address, function(err, data){
            obj.find('tr.Assets_NFT_sales_factory_loading').hide();    
            obj.find('tr').not('.Assets_NFT_sales_factory_loading').remove();    
            if (!data || Q.isEmpty(data.list)) {
                obj.append(`<tr><td>There are no instances</td></tr>`);
            } else {
                for (var i in data.list) {
                    var link = $('<a />', {
                        href: Q.url(tool.state.salesLinkPattern.interpolate({
                            address: data.list[i]
                        }))
                    });
                    var tr = $('<tr class="Assets_NFT_sales_factory_item" />')
                        .append(link);
                    obj.prepend(tr);
                }<commit_msg>Updated sales factory tool<commit_after>if (Q.isEmpty(Q["isAddress"])) {
    Q.isAddress = function _Q_isAddress(address) {
        // https://github.com/ethereum/go-ethereum/blob/aa9fff3e68b1def0a9a22009c233150bf9ba481f/jsre/ethereum_js.go#L2295-L2329
        if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
            // check if it has the basic requirements of an address
            return false;
        } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) {
            // If it's all small caps or all all caps, return true
            return true;
        } else {
            // Otherwise check each case
//            address = address.replace('0x','');
//            var addressHash = Web3.utils.sha3(address.toLowerCase());
//            for (var i = 0; i < 40; i++ ) {
//                // the nth letter should be uppercase if the nth digit of casemap is 1
//                if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
//                    return false;
//                }
//            }
            return true;
        }
        
    }
}

if (Q.isEmpty(Q["validate"])) {
    Q.validate = function _Q_validate(address) {
    
    }
    Q.validate.notEmpty = function _Q_validate_notEmpty(input) {
        return !Q.isEmpty(input)
    }
    Q.validate.integer = function _Q_validate_integer(input) {
        return Q.isInteger(input)
    }
    Q.validate.address = function _Q_validate_address(input) {
        return Q.isAddress(input)
    }
}
(function (window, Q, $, undefined) {
	
/**
 * @module TokenSociety
 */
	
/**
 * YUIDoc description goes here
 * @class TokenSociety cool
 * @constructor
 * @param {Object} [options] Override various options for this tool
 *  @param {String} [options.fields] array of values by default. 
 *  @param {String} [NFTcontract.value]
 *  @param {String} [seriesId.value]
 *  @param {String} [currency.value]
 *  @param {Number} [price.value]
 *  @param {String} [beneficiary.value]
 *  @param {Integer} [autoindex.value]
 *  @param {String} [duration.value]
 *  @param {String} [rateInterval.value]
 *  @param {Integer} [rateAmount.value]
 *  @param {Function} [options.salesLinkTitle] Receives address and callacbk, and should call the callback with the title
 */

Q.Tool.define("Assets/NFT/sales/factory", function (options) {
	var tool = this;
	var state = tool.state;
        
        var defaultsValidate = {
            notEmpty: "<b>%key%</b> is not be empty", 
            integer: "<b>%key%</b> is not a number", 
            address: "<b>%key%</b> invalid"
        };
        
        // fill missed attr fields
        for (var i in state.fields) {
            
            if (typeof(state.fields[i]) === "string") {
                state.fields[i] = {
                    value: state.fields[i],
                    hide: false
                }
            } else if (typeof(state.fields[i]) === "object") {
                let arr;
                if (Q.isEmpty(state.fields[i]["value"])) {
                    state.fields[i]["value"] = "";
                }
                if (Q.isEmpty(state.fields[i]["hide"])) {
                    state.fields[i]["hide"] = false;
                }
                
                if (Q.isEmpty(state.fields[i]["validate"])) {
                    state.fields[i]["validate"] = {};
                } else if (Array.isArray(state.fields[i]["validate"])) {
                    
                    arr = {};
                    for (var j in state.fields[i]["validate"]) {
                        let k = state.fields[i]["validate"][j];
                        if (Q.isEmpty(defaultsValidate[k])) {
                            console.warn(`validate expr "${k}" have not supported yet`);
                        } else {
                            arr[k] = defaultsValidate[k];
                        }
                    }
                    state.fields[i]["validate"] = Object.assign({}, arr);
                    
                } else if (typeof(state.fields[i]["validate"]) === "object") {
                    for (var j in state.fields[i]["validate"]) {
                        if (Q.isEmpty(defaultsValidate[j])) {
                            console.warn(`validate expr "${j}" have not supported yet`);
                        } else {
                            state.fields[i]["validate"][j] = state.fields[i]["validate"][j];
                        }
                    }
                }
            }
        }
        
	var p = Q.pipe(['stylesheet', 'text'], function (params, subjects) {
		tool.text = params.text[1];
		tool.refresh();
	});
        
	Q.addStylesheet("{{Assets}}/css/tools/NFT/sales/factory.css", p.fill('stylesheet'), { slotName: 'Assets' });
	Q.Text.get('Assets/content', p.fill('text'));
},

{ // default options here
    fields: {
        // key validate is optional
        // value can be :
        // - plain array
        //  validate: ["isEmpty", "isInteger", ...] and try to call Q methods: Q.isEmpty, Q.isInteger ...
        // - object  like {key => errormessage}
        //  validate: {"isEmpty": "err msg here to key %key%, "isInteger": "invalid key %key%, ...} and try to call Q methods: Q.isEmpty, Q.isInteger ...
        NFTContract: {value: "", hide: false, validate: ["notEmpty", "address"]},
        seriesId: {value: "", hide: false, validate: ["notEmpty", "integer"]},
        owner: {value: "", hide: false, validate: ["notEmpty", "address"]},
        currency: {value: "", hide: false, validate: ["notEmpty", "address"]},
        price: {value: "", hide: false, validate: ["notEmpty"]},
        beneficiary: {value: "", hide: false, validate: ["notEmpty", "address"]},
        autoindex: {value: "", hide: false, validate: ["notEmpty", "integer"]},
        duration: {value: "", hide: false, validate: ["notEmpty", "integer"]},
        rateInterval: {value: "", hide: false, validate: ["notEmpty", "integer"]},
        rateAmount: {value: "", hide: false, validate: ["notEmpty", "integer"]}
    },
    salesLinkTitle: function (address, callback) {
        return address;
    },
    salesLinkPattern: "sales/{{address}}",
    onMove: new Q.Event() // an event that the tool might trigger
},

{ // methods go here
    whitelistByNFT: function(NFTContract, callback){
        let contract;
        Q.Users.Web3.getFactory('Assets/templates/R1/NFT/sales/factory')
        .then(function(_contract){
            contract = _contract;
            return  contract.whitelistByNFTContract(NFTContract).then(function(res){return res});
        }).then(function (instancesList) {
            Q.handle(callback, null, [null, {list: instancesList}, contract])
        }).catch(function (err) {
            Q.handle(callback, null, [err.reason || err]);
        })

    },
    _whitelistPush: function(item){
        var tool = this;
        let obj = $(tool.element).find(".Assets_NFT_sales_factory_instancesTableList");
        if (obj.find('tr.Assets_NFT_sales_factory_item').length == 0) {
            obj.find('tr').hide();    // all defaults  like "there are no data  etc"
        }
        obj.prepend(`<tr class="Assets_NFT_sales_factory_item"><td><a href="/test2/${item}">${item}</a></td></tr>`);
    },
    _whitelistRefresh: function(){
        var tool = this;
        let obj = $(tool.element).find(".Assets_NFT_sales_factory_instancesTableList");
        obj.find('tr').hide();
        obj.find('tr.Assets_NFT_sales_factory_loading').show();
        tool.whitelistByNFT(TokenSociety.NFT.contract.address, function(err, data){
            obj.find('tr.Assets_NFT_sales_factory_loading').hide();    
            obj.find('tr').not('.Assets_NFT_sales_factory_loading').remove();    
            if (!data || Q.isEmpty(data.list)) {
                obj.append(`<tr><td>There are no instances</td></tr>`);
            } else {
                for (var i in data.list) {
                    state.salesLinkTitle(data.list[i], function (title) {
                        var href = Q.url(tool.state.salesLinkPattern.interpolate({
                            address: data.list[i]
                        }));
                        var link = $('<a />', {href: href}).html(title);
                        var tr = $('<tr class="Assets_NFT_sales_factory_item" />')
                            .append(link);
                        obj.prepend(tr);
                    });
                }
{'fraction_non_alphanumeric': 0.16096996283433862, 'fraction_numerical': 0.007676841528057028, 'mean_word_length': 1.8735994397759104, 'pattern_counts': {'":': 4, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 2, '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': '977747', 'n_tokens_mistral': 4954, 'n_tokens_neox': 4775, 'n_words': 1024}