<commit_before>/**
 * @package		HUBzero CMS
 * @author		<NAME> <<EMAIL>>
 * @copyright	Copyright 2012-2015 HUBzero Foundation, LLC.
 * @license		http://opensource.org/licenses/MIT MIT
 *
 * Copyright 2012-2015 HUBzero Foundation, LLC.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License,
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

(function(window, document, ds, $, undefined) {
	ds.dd = {};
	ds.tab = {};
	ds.data = {};

	$(document).ready(function() {
		// back button
		$('.prj-db-back').on('click', function() {

			// last setp
			var step = $(this).data('step');

			if ($(this).data('warning')) {
				var ok = confirm("Any column customizations you have been doing will be lost if you go back.\n\nPlease click OK if you want to go back to the previous step");
				if (!ok) { return; }
			}

			if (step == 2 && ds.recreate) {
				window.location = window.location.href.split('create')[0];
				return false;
			}

			if (step != 3) {
				$('.main-content').css('margin-left', $('.main-menu').show().width());
			}

			if (step == 3) {
				$('.main-menu').hide();
				$('.main-content').css('margin-left', 0);
			}

			$('#prj-db-step-' + step).hide();
			$('#prj-db-step-' + (step - 1)).show();
		});


		// Setp 1: Select File
		$('#prj-db-select-src').chosen({
			search_contains: true
		});
		$('.chzn-single').css('border', '1px solid #AAA');


		// Setp 2: Preview data
		$('#prj-db-preview-file').on('click', function() {

			var msg = 'Processing...';
			if (HUB.Projects)
			{
				HUB.Projects.setStatusMessage(msg, 1);
			}
			else
			{
				ds.status_msg(msg);
			}

			$.get($('#prj-db-select-form').attr('action'), {
				file: $('#prj-db-select-src').val(),
				dir: $('#prj-db-select-src option:selected').data('dir')
			}, function(res) {
				if (HUB.Projects)
				{
					HUB.Projects.setStatusMessage(false, false);
				}
				else
				{
					ds.status_msg(false);
				}

				show_preview(res);

				$('#prj-db-step-1').hide();
				$('.main-menu').hide();
				$('.main-content').css('margin-left', 0);

				$('#prj-db-step-2').show();
			}, 'json');

			return false;
		});

		// Recreate database
		if ($('#prj-db-select-form input[name="db_id"]').length == 1) {
			ds.db_id = $('#prj-db-select-form input[name="db_id"]').val();
			ds.recreate = true;
			$('#prj-db-preview-file').trigger('click');
		} else {
			ds.db_id = '';
			ds.recreate = false;
		}

		function show_preview(res) {
			var table = res.data;
			ds.dd = table.dd;
			ds.data = table.data;
			ds.repo = res.data.repo;


			/* Populating the Repository Path list */
			var wd = (ds.repo.wd != '') ? '/' + ds.repo.wd + '/' : '/';
			var title = 'Files from the \'' + wd + '\' folder';
			if (wd == '/') {
				title = 'Files from the \'Repository Home\' folder';
			}
			var sub_dirs = '<option value="" title="' + title + '">Same folder as the CSV file</option>';

			$.each(ds.repo.sub_dirs, function(i, val) {
				var title = 'Files from : ' + wd + val;		
				sub_dirs += '<option value="' + val + '" title="' + title + '">' + val + '</option>';
			});
			$('#prj-db-col-linkpath').html(sub_dirs);
			
			$('#prj-db-rec-limit').html('Total number of records: ' + table.rec_total + ' | Loaded first ' + table.rec_display + ' records');
			$('#prj-db-preview-table-wrapper').empty();
			$('#prj-db-preview-table-wrapper').html('<table id="prj-db-preview-table" class="dv-spreadsheet"></table>');

			ds.tab = $('#prj-db-preview-table').dataTable({
				"bFilter": true,
				"bInfo": true,
				"bJQueryUI": true,
				"bAutoWidth": true,
				"aaData": table.data,
				"aoColumns": table.header,
				"sPaginationType": "full_numbers",
				"bProcessing": true,
				"fnInitComplete": function() {
					$('#prj-db-preview-table thead th').append('<div title="Click here to edit column properties" class="col-edit">&nbsp;&nbsp;</div>');

					var that = this;


					$('div.col-edit').bind('click', function(e) {
						var col = ds.dd[$('div.col-edit').index(this)];

						//$('#col-prop-dialog').html(function(i, h) { return h.supplant(col); });
						$('.col-prop').each(function() {

							var prop = $(this).attr('id').replace(/prj-db-col-/, '');
							var val = col[prop];


							if ($(this).is(':checkbox')) {
								if (typeof val !== 'undefined') {
									$(this).prop('checked', true);
								} else {
									$(this).prop('checked', false);
								}
							} else {
								$(this).val(val);
							}

							if ($(this).hasClass('color-picker')) {
								if (typeof val !== 'undefined') {
									$(this).spectrum('set', val);
									switch (prop) {
										case 'text-color':
											$(this).data('style-type', 'color');
											break;
										case 'bg-color':
											$(this).data('style-type', 'background');
											break;
									}
									$(this).data('style-val', val);

								} else {
									$(this).spectrum('set', $(this).data('default'));
									$(this).data('style-val', '');
								}
							}

							$(this).data('changed', false);

						});

						$('#col-prop-dialog').find('.tabs').tabs().tabs('select', 0).end()
						.dialog({
							title: 'Column Properties : ' + col.label,
							width: 650,
							buttons: {
								'Update Column': function() {
									var idx = col.idx;<commit_msg>[PURR][#1264][PLG_PROJECTS_DATABASES] Fixing incorrect method names in scripts<commit_after>/**
 * @package		HUBzero CMS
 * @author		<NAME> <<EMAIL>>
 * @copyright	Copyright 2012-2015 HUBzero Foundation, LLC.
 * @license		http://opensource.org/licenses/MIT MIT
 *
 * Copyright 2012-2015 HUBzero Foundation, LLC.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License,
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

(function(window, document, ds, $, undefined) {
	ds.dd = {};
	ds.tab = {};
	ds.data = {};

	$(document).ready(function() {
		// back button
		$('.prj-db-back').on('click', function() {

			// last setp
			var step = $(this).data('step');

			if ($(this).data('warning')) {
				var ok = confirm("Any column customizations you have been doing will be lost if you go back.\n\nPlease click OK if you want to go back to the previous step");
				if (!ok) { return; }
			}

			if (step == 2 && ds.recreate) {
				window.location = window.location.href.split('create')[0];
				return false;
			}

			if (step != 3) {
				$('.main-content').css('margin-left', $('.main-menu').show().width());
			}

			if (step == 3) {
				$('.main-menu').hide();
				$('.main-content').css('margin-left', 0);
			}

			$('#prj-db-step-' + step).hide();
			$('#prj-db-step-' + (step - 1)).show();
		});


		// Setp 1: Select File
		$('#prj-db-select-src').chosen({
			search_contains: true
		});
		$('.chzn-single').css('border', '1px solid #AAA');


		// Setp 2: Preview data
		$('#prj-db-preview-file').on('click', function() {

			var msg = 'Processing...';
			if (HUB.Projects)
			{
				HUB.Projects.setStatusMessage(msg, 1);
			}
			else
			{
				ds.status_msg(msg);
			}

			$.get($('#prj-db-select-form').attr('action'), {
				file: $('#prj-db-select-src').val(),
				dir: $('#prj-db-select-src option:selected').data('dir')
			}, function(res) {
				if (HUB.Projects)
				{
					HUB.Projects.setStatusMessage(false, false);
				}
				else
				{
					ds.status_msg(false);
				}

				show_preview(res);

				$('#prj-db-step-1').hide();
				$('.main-menu').hide();
				$('.main-content').css('margin-left', 0);

				$('#prj-db-step-2').show();
			}, 'json');

			return false;
		});

		// Recreate database
		if ($('#prj-db-select-form input[name="db_id"]').length == 1) {
			ds.db_id = $('#prj-db-select-form input[name="db_id"]').val();
			ds.recreate = true;
			$('#prj-db-preview-file').trigger('click');
		} else {
			ds.db_id = '';
			ds.recreate = false;
		}

		function show_preview(res) {
			var table = res.data;
			ds.dd = table.dd;
			ds.data = table.data;
			ds.repo = res.data.repo;


			/* Populating the Repository Path list */
			var wd = (ds.repo.wd != '') ? '/' + ds.repo.wd + '/' : '/';
			var title = 'Files from the \'' + wd + '\' folder';
			if (wd == '/') {
				title = 'Files from the \'Repository Home\' folder';
			}
			var sub_dirs = '<option value="" title="' + title + '">Same folder as the CSV file</option>';

			$.each(ds.repo.sub_dirs, function(i, val) {
				var title = 'Files from : ' + wd + val;		
				sub_dirs += '<option value="' + val + '" title="' + title + '">' + val + '</option>';
			});
			$('#prj-db-col-linkpath').html(sub_dirs);
			
			$('#prj-db-rec-limit').html('Total number of records: ' + table.rec_total + ' | Loaded first ' + table.rec_display + ' records');
			$('#prj-db-preview-table-wrapper').empty();
			$('#prj-db-preview-table-wrapper').html('<table id="prj-db-preview-table" class="dv-spreadsheet"></table>');

			ds.tab = $('#prj-db-preview-table').dataTable({
				"bFilter": true,
				"bInfo": true,
				"bJQueryUI": true,
				"bAutoWidth": true,
				"aaData": table.data,
				"aoColumns": table.header,
				"sPaginationType": "full_numbers",
				"bProcessing": true,
				"fnInitComplete": function() {
					$('#prj-db-preview-table thead th').append('<div title="Click here to edit column properties" class="col-edit">&nbsp;&nbsp;</div>');

					var that = this;

					$('div.col-edit').on('click', function(e) {
						var col = ds.dd[$('div.col-edit').index(this)];

						//$('#col-prop-dialog').html(function(i, h) { return h.supplant(col); });
						$('.col-prop').each(function() {

							var prop = $(this).attr('id').replace(/prj-db-col-/, '');
							var val = col[prop];


							if ($(this).is(':checkbox')) {
								if (typeof val !== 'undefined') {
									$(this).prop('checked', true);
								} else {
									$(this).prop('checked', false);
								}
							} else {
								$(this).val(val);
							}

							if ($(this).hasClass('color-picker')) {
								if (typeof val !== 'undefined') {
									$(this).spectrum('set', val);
									switch (prop) {
										case 'text-color':
											$(this).data('style-type', 'color');
											break;
										case 'bg-color':
											$(this).data('style-type', 'background');
											break;
									}
									$(this).data('style-val', val);

								} else {
									$(this).spectrum('set', $(this).data('default'));
									$(this).data('style-val', '');
								}
							}

							$(this).data('changed', false);

						});

						$('#col-prop-dialog').find('.tabs').tabs().tabs('option', 'active', 0).end()
						.dialog({
							title: 'Column Properties : ' + col.label,
							width: 650,
							buttons: {
								'Update Column': function() {
									var idx = col.idx;
{'fraction_non_alphanumeric': 0.20580743759551706, 'fraction_numerical': 0.00815078960774325, 'mean_word_length': 2.6637636080870917, 'pattern_counts': {'":': 18, '<': 25, '<?xml version=': 0, '>': 25, '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': '1782686', 'n_tokens_mistral': 5068, 'n_tokens_neox': 3915, 'n_words': 910}