<commit_before>Debug = function() {
	// set to true to print all important javascript debug messages
	// set to false to skip all debug messages (for production and browsers without Firebug)
	var debug = false;
	
	return {
		log: function(text) {
			if (debug) { console.log(text); }
		}
	};
}();


Templates = function() {
	var _order     = null;
	var _templates = null;
	var editmode  = false;
	
	/* private methods */
	var togglePrintButton = function() {
	  if (_templates.length > 0) {
			$("#print-start").hide();
	    $("#print-button").show();
			var pluralize = _templates.length == 1 ? "document" : "documents";
			$("#template-amount").html(_templates.length + " " + pluralize);
	  } else {
	    $("#print-button").hide();
			$("#print-start").show();
	  }
	};

	var toggleInlinePreview = function(template) {
		// preview div, which could be already inserted (cached in DOM)
		var templatePreview = $("#inline-preview-" + template);
		var templateLabel = $("#template-item-" + template + " label");
		// is template selected?
		if (_templates.indexOf(template) > -1) {
			templateLabel.addClass("selected");
			if (templatePreview.length > 0) { 
	      templatePreview.show();
	    } else {
				loadInlinePreview(template);
			}			
		} else {
			templateLabel.removeClass("selected");
			templatePreview.hide();
		}
	};
	
	var loadInlinePreview = function(template) {
		var checkbox = $("#template-item-" + template + " :checkbox").disable();
		// this is a dirty fix, because the link doesn't listen to moveout-events any more, so it doesn't get hidden, which looks weird
		$("#template-delete-link-" + template).hide();
		
		Status.show("Loading preview...");
		$.get("/orders/" + _order + "?template_id=" + template, null, function(data) { checkbox.enable(); Status.hide(); $("#preview-" + template).html(data); });
	};

	var templateChanged = function(template) {
		togglePrintButton();
		toggleInlinePreview(template);
		Debug.log("Template #" + template + " has changed.");
	};

	
	/* public methods */
	return {
		initialize: function(order) {
			_order = order;
			_templates = [];
		},
		
		select: function(template, selection) {
			var checkbox = $('#template-item-' + template + " :checkbox");
			checkbox.attr('checked', selection);
			this.updateSelection(checkbox);
		},
		
		updateSelection: function(checkbox) {
			var template = checkbox.val();
			Debug.log("Updating selection for template-checkbox-" + template + "...");
			if (checkbox.attr('checked')) {
				Debug.log("Checkbox selected");
				if (_templates.indexOf(template) == -1) {
					_templates.push(template);
				}
			} else {
				Debug.log("Checkbox deselected");
				_templates.splice(_templates.indexOf(template), 1);
			}

			templateChanged(template);
		},
	
		print: function() {
			$.ajax({
	      url: 	'/orders/' + _order + '/print',
				data: $("#selected-templates").serialize(),
	      type: 'post'
	    });
			window.print();
		},
		
		toggleEditMode: function() {
			editmode = !editmode;
			$(".template-options").toggle();
			$(".new-template").toggle();
			var linkImage = $(".template-editmode a img");
			
			if (editmode) {
				linkImage.data("old-image", linkImage.attr('src')); /* Remember original link image */
				linkImage.attr('src', '/images/button-done.png');
			} else {
				linkImage.attr("src", linkImage.data("old-image"));   /* Restore original link image */
			}
		}
	};
}();


// Usage: Dialog.open() and Dialog.close()
// Opens a div as a modal dialog which you need to fill yourself first
Dialog = function() {
	var dlg     = "#modal-dialog";
	var options = { modal: true	};
	
	var percent = function(amount, percentage) {
		return (amount / 100) * percentage;
	};
 
	var	resizeTextArea = function() {
		var dialogHeight = parseInt($(dlg).height());
		var elementsHeight = 0;
   	$(dlg + " .fixed").each(function(index, elem){
			var height = parseInt($(elem).height());
      elementsHeight += height;
    });

		var textAreaHeight =  dialogHeight - elementsHeight - 60; /*margin*/
		Debug.log("DialogHeight: " + dialogHeight + "\nElementsHeight: " + elementsHeight + "\nTextAreaHeight: " + textAreaHeight);
    $("#template_editor").height(textAreaHeight);   
	};

	return {                      
		open: function(title) {
		  var width  = $(window).width();
		  var height = $(window).height();
		
			// open with 80% width and height
			$(dlg).dialog(jQuery.extend(options, {width: percent(width, 80), height: percent(height, 80)}, {title: title, resize: resizeTextArea}));
			$(dlg).dialog('open').bind("resize dialogopen", resizeTextArea);
		},
		
		close: function() {
			$(dlg).empty();
			$(dlg).dialog('destroy');
		}	
	};
}();

<commit_msg>Removed resizing ability for Dialog. Todo: Fix sizing of Dialog elements in IE.<commit_after>Debug = function() {
	// set to true to print all important javascript debug messages
	// set to false to skip all debug messages (for production and browsers without Firebug)
	var debug = false;
	
	return {
		log: function(text) {
			if (debug) { console.log(text); }
		}
	};
}();


Templates = function() {
	var _order     = null;
	var _templates = null;
	var editmode  = false;
	
	/* private methods */
	var togglePrintButton = function() {
	  if (_templates.length > 0) {
			$("#print-start").hide();
	    $("#print-button").show();
			var pluralize = _templates.length == 1 ? "document" : "documents";
			$("#template-amount").html(_templates.length + " " + pluralize);
	  } else {
	    $("#print-button").hide();
			$("#print-start").show();
	  }
	};

	var toggleInlinePreview = function(template) {
		// preview div, which could be already inserted (cached in DOM)
		var templatePreview = $("#inline-preview-" + template);
		var templateLabel = $("#template-item-" + template + " label");
		// is template selected?
		if (_templates.indexOf(template) > -1) {
			templateLabel.addClass("selected");
			if (templatePreview.length > 0) { 
	      templatePreview.show();
	    } else {
				loadInlinePreview(template);
			}			
		} else {
			templateLabel.removeClass("selected");
			templatePreview.hide();
		}
	};
	
	var loadInlinePreview = function(template) {
		var checkbox = $("#template-item-" + template + " :checkbox").disable();
		// this is a dirty fix, because the link doesn't listen to moveout-events any more, so it doesn't get hidden, which looks weird
		$("#template-delete-link-" + template).hide();
		
		Status.show("Loading preview...");
		$.get("/orders/" + _order + "?template_id=" + template, null, function(data) { checkbox.enable(); Status.hide(); $("#preview-" + template).html(data); });
	};

	var templateChanged = function(template) {
		togglePrintButton();
		toggleInlinePreview(template);
		Debug.log("Template #" + template + " has changed.");
	};

	
	/* public methods */
	return {
		initialize: function(order) {
			_order = order;
			_templates = [];
		},
		
		select: function(template, selection) {
			var checkbox = $('#template-item-' + template + " :checkbox");
			checkbox.attr('checked', selection);
			this.updateSelection(checkbox);
		},
		
		updateSelection: function(checkbox) {
			var template = checkbox.val();
			Debug.log("Updating selection for template-checkbox-" + template + "...");
			if (checkbox.attr('checked')) {
				Debug.log("Checkbox selected");
				if (_templates.indexOf(template) == -1) {
					_templates.push(template);
				}
			} else {
				Debug.log("Checkbox deselected");
				_templates.splice(_templates.indexOf(template), 1);
			}

			templateChanged(template);
		},
	
		print: function() {
			$.ajax({
	      url: 	'/orders/' + _order + '/print',
				data: $("#selected-templates").serialize(),
	      type: 'post'
	    });
			window.print();
		},
		
		toggleEditMode: function() {
			editmode = !editmode;
			$(".template-options").toggle();
			$(".new-template").toggle();
			var linkImage = $(".template-editmode a img");
			
			if (editmode) {
				linkImage.data("old-image", linkImage.attr('src')); /* Remember original link image */
				linkImage.attr('src', '/images/button-done.png');
			} else {
				linkImage.attr("src", linkImage.data("old-image"));   /* Restore original link image */
			}
		}
	};
}();


// Usage: Dialog.open() and Dialog.close()
// Opens a div as a modal dialog which you need to fill yourself first
Dialog = function() {
	var dlg     = "#modal-dialog";
	var options = { modal: true, resizable: false	};
	
	var percent = function(amount, percentage) {
		return (amount / 100) * percentage;
	};
 
	var	resizeTextArea = function() {
		var dialogHeight = parseInt($(dlg).height());
		var elementsHeight = 0;
   	$(dlg + " .fixed").each(function(index, elem){
			var height = parseInt($(elem).height());
      elementsHeight += height;
    });

		var heightModifier = 100;
		
		var textAreaHeight = dialogHeight - elementsHeight - heightModifier; /*margin*/
		
		Debug.log("DialogHeight: " + dialogHeight + "\nElementsHeight: " + elementsHeight + "\nTextAreaHeight: " + textAreaHeight);
    $("#template_editor").height(textAreaHeight);   
	};

	return {                      
		open: function(title) {
		  var width  = $(window).width();
		  var height = $(window).height();
		
			// open with 80% width and height
			$(dlg).dialog(jQuery.extend(options, {width: percent(width, 80), height: percent(height, 80)}, {title: title}));
			$(dlg).dialog('open').bind("dialogopen", resizeTextArea);
		},
		
		close: function() {
			$(dlg).empty();
			$(dlg).dialog('destroy');
		}	
	};
}();


{'fraction_non_alphanumeric': 0.17385330796871698, 'fraction_numerical': 0.003910378355527372, 'mean_word_length': 3.387111729253593, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5158753', 'n_tokens_mistral': 3259, 'n_tokens_neox': 2801, 'n_words': 692}