<commit_before>/** GmailToTrello Application
 */

var GmailToTrello = GmailToTrello || {}; // Namespace initialization

GmailToTrello.App = function() {
    this.popupView = new GmailToTrello.PopupView();
    this.gmailView = new GmailToTrello.GmailView();
    this.data = new GmailToTrello.Model();
    
    this.bindEvents();
};

GmailToTrello.App.prototype.bindEvents = function() {
   var self = this;
    
    /*** Data's events binding ***/
    
    this.data.event.addListener('onBeforeAuthorize', function() {
        self.popupView.showMessage(self, 'Authorizing...');    
    });
    
    this.data.event.addListener('onAuthenticateFailed', function() {
        self.popupView.showMessage(self, 'Trello authorization failed');    
    });
    
    this.data.event.addListener('onAuthorized', function() {
        log('GmailToTrello.onAuthorized()');
        log("Status: " + Trello.authorized().toString());
    });
    
    this.data.event.addListener('onBeforeLoadTrello', function() {
        self.popupView.showMessage(self, 'Loading Trello data...');
    });
    
    this.data.event.addListener('onTrelloDataReady', function() {
        self.popupView.$popupContent.show();
        self.popupView.hideMessage();

        self.popupView.bindData(self.data);
    });
    
    this.data.event.addListener('onLoadTrelloListSuccess', function() {
        self.popupView.updateLists();
        self.popupView.validateData();
    });
    
    this.data.event.addListener('onLoadTrelloLabelsSuccess', function() {
        self.popupView.updateLabels();
        self.popupView.validateData();
    });

    this.data.event.addListener('onCardSubmitComplete', function(target, params) {
        self.data.newCard.url = params.data.url;
        self.data.newCard.id = params.data.id;
        self.data.event.fire('onSubmitAttachments', {data:self.data, attachments:params.attachments});
    });

    this.data.event.addListener('onSubmitAttachments', function(target, params) {
        var attach1;

        while (attach1 = params.attachments.shift() && attach1.checked !== true) {
            /* intentionally blank */
        }
        
        if (attach1) {
            var trello_attach = {'mimetype': attach1.mimetype, 'name': attach1.name, 'url': attach1.url};
            // self.Model.submitAttachments(params.data.newCard.id, params.attachments);
            Trello.post('cards/' + params.data.newCard.id + '/attachments', trello_attach, function(data) {
                params.data.event.fire('onSubmitAttachments', {data:params.data, attachments:params.attachments});
            });
        } else {
            self.popupView.displaySubmitCompleteForm();
        }
    });

    /*** PopupView's events binding ***/

    this.popupView.event.addListener('onPopupVisible', function() {
        var data = self.data;
        if (!data.isInitialized) {
            self.popupView.showMessage(self, 'Initializing...');
            self.popupView.$popupContent.hide();
            data.init();
        }
        else {
            self.popupView.reset();
        }
        data.gmail = self.gmailView.parseData();
        self.popupView.bindGmailData(data.gmail);
        //else log('GTT::Initializer closing:Data is already initialized');

    });

    this.popupView.event.addListener('onBoardChanged', function(target, params) {
        var boardId = params.boardId;
        if (boardId !== "_" && boardId !== "" && boardId!==null) {
            self.data.loadTrelloLists(boardId);
            self.data.loadTrelloLabels(boardId);
        }
    });
    
    this.popupView.event.addListener('onSubmit', function() {
        self.data.submit();
    });

    this.popupView.event.addListener('onRequestUpdateGmailData', function() {
        self.data.gmail = self.gmailView.parseData();
        self.popupView.bindGmailData(self.data.gmail);
    });
  
    this.gmailView.event.addListener('onDetected', function(){
        self.popupView.$toolBar = self.gmailView.$toolBar;
        self.popupView.$toolBarHolder = self.gmailView.$toolBarHolder;
        self.popupView.init();

    });

};

GmailToTrello.App.prototype.initialize = function() {
    this.data.isInitialized = false;
    this.gmailView.detect();

    service = analytics.getService('gmail_to_trello');

    // Get a Tracker using your Google Analytics app Tracking ID.
    tracker = service.getTracker('UA-8469046-1');

    // Record an "appView" each time the user launches your app or goes to a new
    // screen within the app.
    tracker.sendAppView('PopupView');

};
<commit_msg>Check to make sure attachments isn't blank<commit_after>/** GmailToTrello Application
 */

var GmailToTrello = GmailToTrello || {}; // Namespace initialization

GmailToTrello.App = function() {
    this.popupView = new GmailToTrello.PopupView();
    this.gmailView = new GmailToTrello.GmailView();
    this.data = new GmailToTrello.Model();
    
    this.bindEvents();
};

GmailToTrello.App.prototype.bindEvents = function() {
   var self = this;
    
    /*** Data's events binding ***/
    
    this.data.event.addListener('onBeforeAuthorize', function() {
        self.popupView.showMessage(self, 'Authorizing...');    
    });
    
    this.data.event.addListener('onAuthenticateFailed', function() {
        self.popupView.showMessage(self, 'Trello authorization failed');    
    });
    
    this.data.event.addListener('onAuthorized', function() {
        log('GmailToTrello.onAuthorized()');
        log("Status: " + Trello.authorized().toString());
    });
    
    this.data.event.addListener('onBeforeLoadTrello', function() {
        self.popupView.showMessage(self, 'Loading Trello data...');
    });
    
    this.data.event.addListener('onTrelloDataReady', function() {
        self.popupView.$popupContent.show();
        self.popupView.hideMessage();

        self.popupView.bindData(self.data);
    });
    
    this.data.event.addListener('onLoadTrelloListSuccess', function() {
        self.popupView.updateLists();
        self.popupView.validateData();
    });
    
    this.data.event.addListener('onLoadTrelloLabelsSuccess', function() {
        self.popupView.updateLabels();
        self.popupView.validateData();
    });

    this.data.event.addListener('onCardSubmitComplete', function(target, params) {
        self.data.newCard.url = params.data.url;
        self.data.newCard.id = params.data.id;
        self.data.event.fire('onSubmitAttachments', {data:self.data, attachments:params.attachments});
    });

    this.data.event.addListener('onSubmitAttachments', function(target, params) {
        var attach1;

        while (attach1 = params.attachments.shift() && attach1 && attach1.hasOwnProperty('checked') && attach1.checked !== true) {
            /* intentionally blank */
        }
        
        if (attach1) {
            var trello_attach = {'mimetype': attach1.mimetype, 'name': attach1.name, 'url': attach1.url};
            // self.Model.submitAttachments(params.data.newCard.id, params.attachments);
            Trello.post('cards/' + params.data.newCard.id + '/attachments', trello_attach, function(data) {
                params.data.event.fire('onSubmitAttachments', {data:params.data, attachments:params.attachments});
            });
        } else {
            self.popupView.displaySubmitCompleteForm();
        }
    });

    /*** PopupView's events binding ***/

    this.popupView.event.addListener('onPopupVisible', function() {
        var data = self.data;
        if (!data.isInitialized) {
            self.popupView.showMessage(self, 'Initializing...');
            self.popupView.$popupContent.hide();
            data.init();
        }
        else {
            self.popupView.reset();
        }
        data.gmail = self.gmailView.parseData();
        self.popupView.bindGmailData(data.gmail);
        //else log('GTT::Initializer closing:Data is already initialized');

    });

    this.popupView.event.addListener('onBoardChanged', function(target, params) {
        var boardId = params.boardId;
        if (boardId !== "_" && boardId !== "" && boardId!==null) {
            self.data.loadTrelloLists(boardId);
            self.data.loadTrelloLabels(boardId);
        }
    });
    
    this.popupView.event.addListener('onSubmit', function() {
        self.data.submit();
    });

    this.popupView.event.addListener('onRequestUpdateGmailData', function() {
        self.data.gmail = self.gmailView.parseData();
        self.popupView.bindGmailData(self.data.gmail);
    });
  
    this.gmailView.event.addListener('onDetected', function(){
        self.popupView.$toolBar = self.gmailView.$toolBar;
        self.popupView.$toolBarHolder = self.gmailView.$toolBarHolder;
        self.popupView.init();

    });

};

GmailToTrello.App.prototype.initialize = function() {
    this.data.isInitialized = false;
    this.gmailView.detect();

    service = analytics.getService('gmail_to_trello');

    // Get a Tracker using your Google Analytics app Tracking ID.
    tracker = service.getTracker('UA-8469046-1');

    // Record an "appView" each time the user launches your app or goes to a new
    // screen within the app.
    tracker.sendAppView('PopupView');

};

{'fraction_non_alphanumeric': 0.14492123845736013, 'fraction_numerical': 0.003476371537208039, 'mean_word_length': 2.7606209150326797, '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': '4687101', 'n_tokens_mistral': 2800, 'n_tokens_neox': 2738, 'n_words': 402}