<commit_before>/* global Handlebars, relative_modified_date, formatDate, humanFileSize, views */
var Mail = {
	State:{
		currentFolderId: null,
		currentAccountId: null,
		currentMessageId: null,
		messageView: null
	},
	UI:{
		initializeInterface:function () {
			Handlebars.registerHelper("colorOfDate", function(dateInt) {
				var lastModified = new Date(dateInt*1000);
				var lastModifiedTime = Math.round(lastModified.getTime() / 1000);

				// date column
				var modifiedColor = Math.round((Math.round((new Date()).getTime() / 1000)-lastModifiedTime)/60/60/24*5);
				if (modifiedColor > 200) {
					modifiedColor = 200;
				}
				return 'rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')';
			});

			Handlebars.registerHelper("relativeModifiedDate", function(dateInt) {
				var lastModified = new Date(dateInt*1000);
				var lastModifiedTime = Math.round(lastModified.getTime() / 1000);
				return relative_modified_date(lastModifiedTime);
			});

			Handlebars.registerHelper("formatDate", function(dateInt) {
				var lastModified = new Date(dateInt*1000);
				return formatDate(lastModified);
			});

			Handlebars.registerHelper("humanFileSize", function(size) {
				return humanFileSize(size);
			});


			// setup sendmail view
			Mail.State.messageView = new views.Messages({
				el: $('#mail_messages')
			});

			// And render it
			Mail.State.messageView.render();

			$.ajax(OC.generateUrl('apps/mail/accounts'), {
				data:{},
				type:'GET',
				success:function (jsondata) {
						// don't try to load accounts if there are none
						if(jsondata.length === 0) {
							return;
						}
						var source   = $("#mail-account-manager").html();
						var template = Handlebars.compile(source);
						var html = template(jsondata);
						$('#accountManager').html(html);
						Mail.UI.loadFoldersForAccount(jsondata[0].accountId);
					}
			});
		},

		loadFoldersForAccount : function(accountId) {
			var firstFolder, folderId;

			Mail.UI.clearFolders();
			Mail.UI.clearMessages();
			$('#app-navigation').addClass('icon-loading');
			$('#app-content').addClass('icon-loading');

			$.ajax(OC.generateUrl('apps/mail/accounts/{accountId}/folders', {accountId: accountId}), {
				data:{},
				type:'GET',
				success:function (jsondata) {
					var source   = $("#mail-folder-template").html();
					var template = Handlebars.compile(source);
					var html = template(jsondata);

					$('#app-navigation').removeClass('icon-loading');
					$('#folders').html(html);

					firstFolder = $('#app-navigation').find('.mail_folders li');

					if (firstFolder.length > 0) {
						$('#app-navigation').fadeIn(800);
						firstFolder = firstFolder.first();
						folderId = firstFolder.data('folder_id');
						accountId = firstFolder.parent().data('account_id');

						Mail.UI.loadMessages(accountId, folderId);

						// Save current folder
						Mail.UI.setFolderActive(accountId, folderId);
						Mail.State.currentAccountId = accountId;
						Mail.State.currentFolderId = folderId;
					} else {
						$('#app-navigation').fadeOut(800);
					}
				}
			});
		},

		clearMessages:function () {
			Mail.State.messageView.collection.reset();
			$('#messages-loading').fadeIn();
		},

		clearFolders:function () {
			var list = $('.mail_folders');

			list.empty();
		},

		hideMenu:function () {
			var menu = $('#new-message');

			menu.addClass('hidden');
		},

		addMessages:function (data) {
//			var source   = $("#mail-messages-template").html();
//			var template = Handlebars.compile(source);
//			var html = template(data);
//			$('#mail_messages').append(html);
			Mail.State.messageView.collection.add(data);

			_.each($('.avatar'), function(a) {
				$(a).imageplaceholder($(a).data('user'), $(a).data('user'));
			}
			);
		},

		loadMessages:function (accountId, folderId) {
			// Set folder active
			Mail.UI.setFolderInactive(Mail.State.currentAccountId, Mail.State.currentFolderId);
			Mail.UI.setFolderActive(accountId, folderId);
			Mail.UI.clearMessages();

			$('#mail_new_message').fadeIn();
			$('#app-content').addClass('icon-loading');

			$.ajax(
				OC.generateUrl('apps/mail/accounts/{accountId}/folders/{folderId}/messages',
					{'accountId':accountId, 'folderId':encodeURIComponent(folderId)}), {
					data: {},
					type:'GET',<commit_msg>hide 'Load more' button initially on folder change<commit_after>/* global Handlebars, relative_modified_date, formatDate, humanFileSize, views */
var Mail = {
	State:{
		currentFolderId: null,
		currentAccountId: null,
		currentMessageId: null,
		messageView: null
	},
	UI:{
		initializeInterface:function () {
			Handlebars.registerHelper("colorOfDate", function(dateInt) {
				var lastModified = new Date(dateInt*1000);
				var lastModifiedTime = Math.round(lastModified.getTime() / 1000);

				// date column
				var modifiedColor = Math.round((Math.round((new Date()).getTime() / 1000)-lastModifiedTime)/60/60/24*5);
				if (modifiedColor > 200) {
					modifiedColor = 200;
				}
				return 'rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')';
			});

			Handlebars.registerHelper("relativeModifiedDate", function(dateInt) {
				var lastModified = new Date(dateInt*1000);
				var lastModifiedTime = Math.round(lastModified.getTime() / 1000);
				return relative_modified_date(lastModifiedTime);
			});

			Handlebars.registerHelper("formatDate", function(dateInt) {
				var lastModified = new Date(dateInt*1000);
				return formatDate(lastModified);
			});

			Handlebars.registerHelper("humanFileSize", function(size) {
				return humanFileSize(size);
			});


			// setup sendmail view
			Mail.State.messageView = new views.Messages({
				el: $('#mail_messages')
			});

			// And render it
			Mail.State.messageView.render();

			$.ajax(OC.generateUrl('apps/mail/accounts'), {
				data:{},
				type:'GET',
				success:function (jsondata) {
						// don't try to load accounts if there are none
						if(jsondata.length === 0) {
							return;
						}
						var source   = $("#mail-account-manager").html();
						var template = Handlebars.compile(source);
						var html = template(jsondata);
						$('#accountManager').html(html);
						Mail.UI.loadFoldersForAccount(jsondata[0].accountId);
					}
			});
		},

		loadFoldersForAccount : function(accountId) {
			var firstFolder, folderId;

			Mail.UI.clearFolders();
			Mail.UI.clearMessages();
			$('#app-navigation').addClass('icon-loading');
			$('#app-content').addClass('icon-loading');

			$.ajax(OC.generateUrl('apps/mail/accounts/{accountId}/folders', {accountId: accountId}), {
				data:{},
				type:'GET',
				success:function (jsondata) {
					var source   = $("#mail-folder-template").html();
					var template = Handlebars.compile(source);
					var html = template(jsondata);

					$('#app-navigation').removeClass('icon-loading');
					$('#folders').html(html);

					firstFolder = $('#app-navigation').find('.mail_folders li');

					if (firstFolder.length > 0) {
						$('#app-navigation').fadeIn(800);
						firstFolder = firstFolder.first();
						folderId = firstFolder.data('folder_id');
						accountId = firstFolder.parent().data('account_id');

						Mail.UI.loadMessages(accountId, folderId);

						// Save current folder
						Mail.UI.setFolderActive(accountId, folderId);
						Mail.State.currentAccountId = accountId;
						Mail.State.currentFolderId = folderId;
					} else {
						$('#app-navigation').fadeOut(800);
					}
				}
			});
		},

		clearMessages:function () {
			Mail.State.messageView.collection.reset();
			$('#messages-loading').fadeIn();
		},

		clearFolders:function () {
			var list = $('.mail_folders');

			list.empty();
		},

		hideMenu:function () {
			var menu = $('#new-message');

			menu.addClass('hidden');
		},

		addMessages:function (data) {
//			var source   = $("#mail-messages-template").html();
//			var template = Handlebars.compile(source);
//			var html = template(data);
//			$('#mail_messages').append(html);
			Mail.State.messageView.collection.add(data);

			_.each($('.avatar'), function(a) {
				$(a).imageplaceholder($(a).data('user'), $(a).data('user'));
			}
			);
		},

		loadMessages:function (accountId, folderId) {
			// Set folder active
			Mail.UI.setFolderInactive(Mail.State.currentAccountId, Mail.State.currentFolderId);
			Mail.UI.setFolderActive(accountId, folderId);
			Mail.UI.clearMessages();

			$('#mail_new_message').fadeIn();
			$('#app-content').addClass('icon-loading');
			$('#load-more-mail-messages').hide();

			$.ajax(
				OC.generateUrl('apps/mail/accounts/{accountId}/folders/{folderId}/messages',
					{'accountId':accountId, 'folderId':encodeURIComponent(folderId)}), {
					data: {},
					type:'GET',
{'fraction_non_alphanumeric': 0.17224273188740194, 'fraction_numerical': 0.010613751730503, 'mean_word_length': 3.660752688172043, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3888519', 'n_tokens_mistral': 3383, 'n_tokens_neox': 2651, 'n_words': 427}