JSFiddle - React, Tailwind, and code Playground

by Gonzalo

JavaScript

SourcingInsight.Controller.create('app.controller.c_newUpload', {
	options:{
		validFile: false,
		fileElementId: 'file', 
		next:false
	},
	listeners: function(){
		var me =  this;
		$('#cbMonth').change(function(){
			AppTPSDataUpload.options.onSelectRow.txtMonth =  $("#cbMonth option:selected").text();
		});
		$('#cbYear').change(function(){
			AppTPSDataUpload.options.onSelectRow.txtYear = $("#cbYear option:selected").text();
			AppTPSDataUpload.options.baseParams.year = $("#cbYear option:selected").text();
		});
		$('#file').change(function( _event ){
			if(!me.validateFile($(this).val())){
				$(this).val('');
			}
			else{
				me.options.validFile = true;
				$('#txtFile').val($(this).val());
			}
		});
		$('#btnCancelNewFile').click(function( _event ){
			_event.stopPropagation();
			$(this).val('');
			me.options.validFile = false;
			AppTPSDataUpload.options.onSelectRow = {};
			SourcingInsight.create('app.view.tpsHistory');
		});
		$('#btnUpload').click(function( _event ){
			_event.stopPropagation();
			if(	me.options.validFile){
				me.checkPeriod();
			}
			else{
				alert('Could you select some file, Please?');
			}						
		});
		$('#downloadTemplate').click(function( _event ){
			_event.stopPropagation();
			
		});
	},
	validateFile: function( _file ){
		var me = this;
		var re_text = /\.csv|\.xls/i;
		var filename = _file;
		var xaction = true;
		if (filename.search(re_text) == -1){
			xaction = false;
			alert('The extension file is not of type(.csv).');			
		}
		return xaction;
	},
	uploadFile: function(){
		var me = this;
		$('#messageUpload').loader({message:'Uploading File!!'});
		if(me.isValidData()){
			AppTPSDataUpload.options.onSelectRow.txtFileName = 'tps_data_'+ AppTPSDataUpload.options.onSelectRow.txtMonth +'_'+ AppTPSDataUpload.options.onSelectRow.txtYear +'.csv';
 			$.ajaxFileUpload({
				url:'app/model/uploader.php', 
				secureuri:false,
				fileElementId: me.options.fileElementId,
				dataType: 'json',
				data:...