<commit_before>(function(module) {
	
	var _ID = "file-form";
	
	var _open = function(fragment, modal, onRegistered) {
		jQuery("#" + _ID).remove();
		
		var args = fragment != null ? {id: fragment.id()} : {};
		piggydb.util.blockPageDuringAjaxRequest();
		jQuery.get("partial/file-form.htm", args, function(html) {
			if (!module.FormDialog.checkOpenError(html)) {
				jQuery("body").append(html);
				var form = new _class(jQuery("#" + _ID));
				form.fragment = fragment;
				form.modal = modal;
				form.onRegistered = onRegistered;
				form.open();
			}
		});
	};
	
	var _initialHeight = 75;
	
	var _class = function(element) {
		module.FormDialog.call(this, element);
		
		window.fileForm = this;
		
		this.id = _ID;
		this.modal = false;
		this.indicator = this.element.find("span.indicator");
		this.fragment = null;		// target fragment widget to be updated
		this.onRegistered = null;
	};
	
	_class.openToAdd = function() {
		_open(null, false, null);
	};
	
	_class.openToUpdate = function(button) {
		_open(new piggydb.widget.Fragment(button), false, null);
	};
	
	_class.openToEmbed = function(onRegistered) {
		_open(null, true, onRegistered);
	};
	
	_class.prototype = jQuery.extend({
		
		open: function() {
			var outer = this;
			
			this.element.dialog({
				width: 600,
				height: _initialHeight,
				modal: outer.modal,
				close: function(event, ui) {
					piggydb.widget.imageViewer.close();
					window.fileForm = null;
				}
			});
		
			this.buttonsDiv().hide();
			
			this.element.find("input.file").change(function() {
				outer.setDialogHeight(_initialHeight + 15);
				outer.previewDiv().empty().putLoadingIcon("margin: 5px 10px;");
				outer.element.find("form.upload-file").submit();
			});
			this.element.find("button.register").click(function() {
				outer.clearErrors();
				outer.block();
				var values = outer.element.find("form.save-file").serializeArray();
				jQuery.post("partial/save-file.htm", values, function(html) {
					if (outer.checkErrors(html)) {
						piggydb.widget.imageViewer.close();
						outer.unblock();
					}
					else {
						piggydb.widget.Fragment.onAjaxSaved(html, outer.fragment);
						outer.close();
						if (jQuery.isFunction(outer.onRegistered)) 
							outer.onRegistered(html);
					}
				});
			});
			this.element.find("div.preview img").load(function() {
				outer.setDialogHeight(
					_initialHeight + 
					outer.previewDiv().height() +
					5);
			});
		},
		
		setDialogHeight: function(height) {
			this.element.dialog("option", "height", height);
		},
		
		buttonsDiv: function() {
			return this.element.find("div.buttons");
		},<commit_msg>#embed_file: fixed the problem that the fragment content display won't be updated afer embedding a file<commit_after>(function(module) {
	
	var _ID = "file-form";
	
	var _open = function(fragment, modal, onSaved) {
		jQuery("#" + _ID).remove();
		
		var args = fragment != null ? {id: fragment.id()} : {};
		piggydb.util.blockPageDuringAjaxRequest();
		jQuery.get("partial/file-form.htm", args, function(html) {
			if (!module.FormDialog.checkOpenError(html)) {
				jQuery("body").append(html);
				var form = new _class(jQuery("#" + _ID));
				form.fragment = fragment;
				form.modal = modal;
				form.onSaved = onSaved;
				form.open();
			}
		});
	};
	
	var _initialHeight = 75;
	
	var _class = function(element) {
		module.FormDialog.call(this, element);
		
		window.fileForm = this;
		
		this.id = _ID;
		this.modal = false;
		this.indicator = this.element.find("span.indicator");
		this.fragment = null;		// target fragment widget to be updated
		this.onSaved = null;
	};
	
	_class.openToAdd = function() {
		_open(null, false, null);
	};
	
	_class.openToUpdate = function(button) {
		_open(new piggydb.widget.Fragment(button), false, null);
	};
	
	_class.openToEmbed = function(onSaved) {
		_open(null, true, onSaved);
	};
	
	_class.prototype = jQuery.extend({
		
		open: function() {
			var outer = this;
			
			this.element.dialog({
				width: 600,
				height: _initialHeight,
				modal: outer.modal,
				close: function(event, ui) {
					piggydb.widget.imageViewer.close();
					window.fileForm = null;
				}
			});
		
			this.buttonsDiv().hide();
			
			this.element.find("input.file").change(function() {
				outer.setDialogHeight(_initialHeight + 15);
				outer.previewDiv().empty().putLoadingIcon("margin: 5px 10px;");
				outer.element.find("form.upload-file").submit();
			});
			this.element.find("button.register").click(function() {
				outer.clearErrors();
				outer.block();
				var values = outer.element.find("form.save-file").serializeArray();
				jQuery.post("partial/save-file.htm", values, function(html) {
					if (outer.checkErrors(html)) {
						piggydb.widget.imageViewer.close();
						outer.unblock();
					}
					else {
						if (jQuery.isFunction(outer.onSaved)) 
							outer.onSaved(html);
						else
							piggydb.widget.Fragment.onAjaxSaved(html, outer.fragment);
						
						outer.close();
					}
				});
			});
			this.element.find("div.preview img").load(function() {
				outer.setDialogHeight(
					_initialHeight + 
					outer.previewDiv().height() +
					5);
			});
		},
		
		setDialogHeight: function(height) {
			this.element.dialog("option", "height", height);
		},
		
		buttonsDiv: function() {
			return this.element.find("div.buttons");
		},
{'fraction_non_alphanumeric': 0.16218755872956211, 'fraction_numerical': 0.004134561172711896, 'mean_word_length': 3.2338902147971362, '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': '7311734', 'n_tokens_mistral': 2211, 'n_tokens_neox': 1735, 'n_words': 298}