/************************************************* // // Prepare SearchResults Page // **************************************************/ function PrepSearchresults(images, imgContainer, waitingImage, loadMap) { //bind dei link $('.srchItems .srchItemslist div span').each( function () { $(this).bind('click', function () { $(this).parent().parent().find('div > span').removeClass('B'); $(this).addClass('B'); ShowDetail($(this).attr('itctype'), $(this).attr('itcid')); }); }) // Prepare the map if (loadMap == 1) { Mapinit(); } // Deferred Image Loading DeferredImageLoading(images, imgContainer, waitingImage); } /************************************************* // // Deferred Image Loading // **************************************************/ function DeferredImageLoading(images, imgContainer, waitingImage) { if (images.length === 0) { EndDeferredLoading(waitingImage); return; } function imageLoaded(img) { var src = $(img).attr('src').replace('small_thumb', 'thumb'); var ft = $(''); ft.appendTo(imgContainer); $(img).hide().appendTo(ft).toggleClass('small_thumb').fadeIn().css('display', 'inline-block'); } function loadImage() { // Prepare the source var pad = "00000000"; var ID = images.pop(); var imgName = (pad+ID.toString()).slice(-pad.length); var src = '/Content/Images/Converted/'+imgName+'.xml_files/small_thumb.jpg'; var imgID = 'img'+ID.toString() var img = new Image(), timer; img.id = imgID; img.src = src; if (img.complete || img.readyState === 4) { imageLoaded(img); if (images.length !== 0) { loadImage(); } else { EndDeferredLoading(waitingImage); } } else { // handle 404 using setTimeout set at 10 seconds, adjust as needed timer = setTimeout(function() { if (images.length !== 0) { loadImage(); } else { EndDeferredLoading(waitingImage); } $(img).unbind("error load onreadystate"); }, 10000); $(img).bind("error load onreadystate", function(e) { clearTimeout(timer); if (e.type !== "error") { imageLoaded(img); } if (images.length !== 0) { loadImage(); } else { EndDeferredLoading(waitingImage); } }); } } $(waitingImage).show(); loadImage(); } function EndDeferredLoading(waitingImage) { $(waitingImage).hide(); $('.ImageBox').each(function () { $(this).fancybox({ 'type': 'image', 'centerOnScroll': true }); }); } /************************************************* // // SHAPEFILE UPLOAD SECTION // **************************************************/ function prepShapeUpload() { var flList = new Array(); $('#fu_InputFileSHP').fileupload({ autoUpload: false, maxNumberOfFiles: 3, dropZone: $('#fu_DropZoneSHP'), fileInput: $('#fu_InputFileSHP'), dataType: 'json', url: '/Edit/UploadShapeFile', maxFileSize: 5000000, acceptFileTypes: /(\.|\/)(shp|shx|dbf)$/i, add: function (e, data) { // Add the file item template to the container flList.push(data.files[0]); var flType = data.files[0].name.slice(-3); var ty; switch (flType) { case 'dbf': case 'shx': case 'shp': ty = flType; break; default: ty = 'err'; break; } if (data.originalFiles.length == 1) { $('#fu_filesListSHP').html(''); } var flSize = data.files[0].size.toString(); var flName = data.files[0].name; var html = '

' + flName + '

' + flSize + ' KB

' + '
' var newItem = $(html).hide().appendTo('#fu_filesListSHP').fadeIn(); $('#uploadBtnSHP').data('fileUploadData', data); $('#uploadBtnSHP').off('click').on('click', function () { $('.fu_tbl_progress .bar').css( 'width', '5%'); $('#fu_InputFileSHP').fileupload('send', { files: data.originalFiles }); }); }, send: function (e, data) { // Validate file extentions var isExtsOK = true; var baseFile = ''; //var flList = data.files; for (var i = 0; i < flList.length; i++) { if (i == 0) baseFile = flList[i].name.slice(0, flList[i].name.length - 4); if (((flList[i].name.slice(-3) != 'shp') && (flList[i].name.slice(-3) != 'shx') && (flList[i].name.slice(-3) != 'dbf')) || (baseFile != flList[i].name.slice(0, flList[i].name.length - 4)) ) { isExtsOK = false; break; } } // Validate the shapefile structure if (flList.length != 3 || !isExtsOK) { alert('Struttura dello shapefile non corretta. Selezionare la tripletta di files: SHP, SHX e DBF.'); return false; } else { // Link up the transformation of the upload button to the real upload start after validation $('#uploadBtnSHP').off('click') .html("Abort") .on('click', function () { $(this).data('fileUploadData').abort(); }); return true; } }, progress: function (e, data) { var progress = parseInt(data.loaded / data.total * 100, 10); $('.fu_tbl_progress .bar').css( 'width', progress + '%'); }, done: function (e, data) { var shapeFile; var sessionID; for (var i = 0; i < data.jqXHR.responseJSON.length; i++) { if (data.jqXHR.responseJSON[i].fileType == "shp") { shapeFile = data.jqXHR.responseJSON[i].name sessionID = data.jqXHR.responseJSON[i].sessionID; } } //invoca la procedura di normalizzazione ManageUploadShapeFile(shapeFile, sessionID); }, fail: function (e, data) { // Let the user know that the server didn't answer if (data.errorThrown != undefined) alert('A problem occured with server communication. Try later.'); } }); } //tipo = 'Sighting' or 'Track' function prepFIleUpload(tipo) { var flList = new Array(); $('#fu_InputFile' + tipo).fileupload({ autoUpload: false, maxNumberOfFiles: 3, dropZone: $('#fu_DropZone' + tipo), fileInput: $('#fu_InputFile' + tipo), dataType: 'json', url: '/Edit/UploadFile', maxFileSize: 5000000, acceptFileTypes: /(\.|\/)(wpt|txt|plt)$/i, add: function (e, data) { // Add the file item template to the container flList.push(data.files[0]); var flType = data.files[0].name.slice(-3); var ty; switch (flType) { case 'wpt': ty = flType; break; case 'txt': ty = flType; break; case 'plt': ty = flType; break; default: ty = 'err'; break; } var flSize = ''; if (data.files[0].size != undefined) { flSize = data.files[0].size.toString() + ' KB'; } var flName = data.files[0].name; var html = '

' + flName + '

' + flSize + '

' + '
' var fuFilesSelector = '#fu_filesList' + tipo; var newItem = $(html).hide().appendTo(fuFilesSelector).fadeIn(); $('#uploadBtn' + tipo).data('fileUploadData', data); $('#uploadBtn' + tipo).off('click').on('click', function () { $('#bar' + tipo).css( 'width', '5%'); $('#fu_InputFile' + tipo).fileupload('send', { files: data.originalFiles }); }); }, send: function (e, data) { // Validate file extentions var isExtsOK = true; var baseFile = ''; //var flList = data.files; for (var i = 0; i < flList.length; i++) { if (i == 0) baseFile = flList[i].name.slice(0, flList[i].name.length - 4); if (((flList[i].name.slice(-3) != 'wpt') && (flList[i].name.slice(-3) != 'txt') && (flList[i].name.slice(-3) != 'plt')) || (baseFile != flList[i].name.slice(0, flList[i].name.length - 4)) ) { isExtsOK = false; break; } } if (isExtsOK) { // Link up the transformation of the upload button to the real upload start after validation $('#uploadBtn' + tipo).off('click') .html("Abort") .on('click', function () { $(this).data('fileUploadData').abort(); }); } return isExtsOK; }, progress: function (e, data) { var progress = parseInt(data.loaded / data.total * 100, 10); $('#bar' + tipo).css( 'width', progress + '%'); }, done: function (e, data) { var dtFrom; var dtTo var timeFrom; var timeTo; var sessionID; var fileName; var hasError = false for (var i = 0; i < data.jqXHR.responseJSON.length; i++) { if (data.jqXHR.responseJSON[i].ErrorMsg == '') { sessionID = data.jqXHR.responseJSON[i].sessionID; dtFrom = data.jqXHR.responseJSON[i].dtFrom; dtTo = data.jqXHR.responseJSON[i].dtTo; timeFrom = data.jqXHR.responseJSON[i].timeFrom; timeTo = data.jqXHR.responseJSON[i].timeTo; fileName = data.jqXHR.responseJSON[i].name; } else { alert(data.jqXHR.responseJSON[i].ErrorMsg); hasError = true; } } var editForm; var fileSel; var fileNameSelector; var dateFromID; var dateTOID; var TimeFromID; var TimeTOID; switch (tipo) { case 'Sighting': //analizzo un sight editForm = 'EditSighting' fileNameSelector = $('#EditSighting #fileNameSighting'); fileSel = $('#fileSelSighting'); dateFromID = 'dateFromSigh'; dateTOID = 'dateToSigh'; TimeFromID = 'timeFromSigh'; TimeTOID = 'timeToSigh'; break; case 'Track': //analizzo una traccia editForm = 'EditTrack' fileNameSelector = $('#EditTrack #fileNameTrack'); fileSel = $('#fileSelTrack'); dateFromID = 'dateFrom'; dateTOID = 'dateTo'; TimeFromID = 'timeFrom'; TimeTOID = 'timeTo'; break; case 'UpdSighting': editForm = 'EditSighting' fileNameSelector = $('#EditSighting #fileNameUpdSighting'); fileSel = $('#fileSelSighting'); dateFromID = 'dateFromSigh'; dateTOID = 'dateToSigh'; TimeFromID = 'timeFromSigh'; TimeTOID = 'timeToSigh' break; case 'UpdTrack': //analizzo una traccia editForm = 'EditTrack' fileNameSelector = $('#EditTrack #fileNameUpdTrack'); fileSel = $('#fileSelTrack'); dateFromID = 'dateFrom'; dateTOID = 'dateTo'; TimeFromID = 'timeFrom'; TimeTOID = 'timeTo'; break; } if (!hasError) { $(fileSel).text(fileName); $(fileSel).removeClass('FileError'); $(fileSel).removeClass('FileOk'); $(fileNameSelector).val(fileName); $('#' + editForm).find('#' + dateFromID).val(dtFrom); $('#' + editForm).find('#' + dateTOID).val(dtTo); $('#' + editForm).find('#' + TimeFromID).val(timeFrom); $('#' + editForm).find('#' + TimeTOID).val(timeTo); var fileName = data.files[0].name; $('#fileNameSpan' + tipo).text('Current file uploaded: ' + fileName); if (map == null) { Mapinit(); } $('#prev' + tipo).fadeIn('slow'); $('#cancelUpload' + tipo).fadeIn('slow'); } ClearUploads(tipo); }, fail: function (e, data) { // Let the user know that the server didn't answer alert('A problem occured with server communication. Try later.'); } }); } function ClearUploads(tipo) { $('#fu_filesList'+tipo+' tbody').html(''); // Destroy fileuopload $('#fu_InputFile'+tipo).fileupload('destroy'); $('#uploadBtn' + tipo).off('click').html("Start upload"); // Re-apply fileupload if (tipo == 'SHP') prepShapeUpload(); else prepFIleUpload(tipo); }