<commit_before>﻿///<reference path="../hdkn.d.ts"/>

module Hadouken.Plugins.Torrents.UI {
    export class AddTorrentsDialog extends Hadouken.UI.Dialog {
        constructor() {
            super("/plugins/core.torrents/dialogs/add.html");
        }

        onShow(): void {
            this.setupEvents();
        }

        setupEvents(): void {
            var c = this.getContent();

            c.find('#btn-add-torrents').on('click', (e) => {
                e.preventDefault();
                this.addTorrents();
            });
        }

        addTorrents(): void {
            console.log('adding torrents');
        }
    }
}<commit_msg>Adding torrents now works.<commit_after>﻿///<reference path="../hdkn.d.ts"/>

module Hadouken.Plugins.Torrents.UI {
    export class AddTorrentsDialog extends Hadouken.UI.Dialog {
        constructor() {
            super("/plugins/core.torrents/dialogs/add.html");
        }

        onShow(): void {
            this.setupEvents();
        }

        setupEvents(): void {
            var c = this.getContent();

            c.find('#btn-add-torrents').on('click', (e) => {
                e.preventDefault();
                this.addTorrents();
            });
        }

        addTorrents(): void {
            this.disableAddButton();

            var c = this.getContent();
            var fileInput = c.find('#torrent-files')[0];
            var reader = new FileReader();

            reader.onload = (e) => {
                var data = [
                    e.target.result.split(',')[1],
                    '',
                    ''
                ];

                var rpcClient = new Hadouken.Http.JsonRpcClient('/jsonrpc');
                rpcClient.callParams('torrents.addFile', data, (result) => {
                    this.enableAddButton();
                });
            };

            for (var i = 0; i < fileInput.files.length; i++) {
                reader.readAsDataURL(fileInput.files[i]);
            }
        }

        disableAddButton(): void {
            this.getContent().find('#btn-add-torrents').attr('disabled', true);
        }

        enableAddButton(): void {
            this.getContent().find('#btn-add-torrents').attr('disabled', false);
        }
    }
}
{'fraction_non_alphanumeric': 0.15190434012400356, 'fraction_numerical': 0.001328609388839681, 'mean_word_length': 1.4554347826086957, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 9, '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': '6206147', 'n_tokens_mistral': 655, 'n_tokens_neox': 623, 'n_words': 95}