Skip to content
Snippets Groups Projects
sgJobs.js 1.3 KiB
Newer Older
'use strict';

import $ from 'jquery';

/**
 * frontend javascript for sg_jobs
export default class SgJobs {

	/**
	 * Kicks things off
	 */
	constructor() {
		$('.remove-file').on('click', this._removeFile);
		$('#sgjobs-joblist').on('change', '.sgjobs-select', this._filterJoblist);
		$('#apply-cover-letter').on('change', this._checkFileSize);
		$('#apply-cv').on('change', this._checkFileSize);
		$('#apply-certificate').on('change', this._checkFileSize);
	}

	/**
	 * Remove file from application logic
	 *
	 * @param event
	 * @private
	 */
	_removeFile(event) {
		let currentElement = $(this);
		event.preventDefault();

		$.post(
			'?eID=sgAjax&extensionName=SgJobs&controller=Ajax%5CJoblist&action=deleteTempFile&format=json&vendorName=SGalinski',
			{
				file: currentElement.parent().children('.filename').html(),
				type: currentElement.attr('filetype')
			}
		).done(function() {
			currentElement.parent().remove();
		});
	 * Filter for the joblist, simply apply the form
	 *
	 * @private
	 */
	_filterJoblist() {
		$('#sgjobs-filter').submit();

	_checkFileSize() {
		if (this.files[0].size > document.querySelector('#maxFileSize').getAttribute('data-maxFilesize') * 1000) {
			alert(document.querySelector('#maxFileSizeMessage').getAttribute('data-maxFileSizeMessage'));
			this.value = "";
		};
	}