From 76dcbadbf71febe93fb9d2ffd51b2f3ae54233a2 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Wed, 17 Jul 2019 14:56:54 +0530 Subject: added file select validation and varible for upload file api url --- static/website/js/cloud.js | 54 ++++++++++++++++++------------------- static/website/templates/index.html | 13 +++++---- website/views.py | 2 ++ 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/static/website/js/cloud.js b/static/website/js/cloud.js index 7d7d5dd..773a98a 100644 --- a/static/website/js/cloud.js +++ b/static/website/js/cloud.js @@ -1006,49 +1006,47 @@ $(document.body).ready(function() { }); -$(document).on("click", "#fileuploadsubmit", function() { - - if(confirm("Uploaded file last only till sesstion. Use direct file name for execution.")){ - var name = doSubmit(); - $("" + name + "").insertAfter("#uploaddataset"); - $("#uploaddatasetModal").modal('hide'); - $("#uploaddataset").hide(); - } - else{ - return false; + $(document).on("click", "#fileuploadsubmit", function() { + if( document.getElementById("fileSelect").files.length == 0 ){ + alert("No files selected"); + }else{ + if(confirm("Uploaded file last only till sesstion. Use direct file name for execution.")){ + var name = doSubmit(); + $("" + name + "").insertAfter("#uploaddataset"); + $("#uploaddatasetModal").modal('hide'); + $("#uploaddataset").hide(); + } + else{ + return false; + } } + }); - - -}); - -$(document).on("click", "#reset", function() { - if(confirm("Are you sure you want to reset? Reset will clear of your data/uploaded file.")){ - document.location.reload(true); - } - else{ - return false; - } -}); + $(document).on("click", "#reset", function() { + if(confirm("Are you sure you want to reset? Reset will clear of your data/uploaded file.")){ + document.location.reload(true); + } + else{ + return false; + } + }); }); //document.readOnly() function doSubmit(){ // Form Data var formData = new FormData(); - var fileSelect = document.getElementById("fileSelect"); if(fileSelect.files && fileSelect.files.length == 1){ var file = fileSelect.files[0] formData.set("file", file , file.name); - } - - var session_id = document.getElementById("session_id"); + var session_id = document.getElementById("session_id"); formData.set("session_id", session_id.value) - // Http Request + // Http Request var request = new XMLHttpRequest(); - request.open('POST', "http://10.101.201.190:8001/upload"); + request.open('POST', api_url_upload); request.send(formData); return (fileSelect.files[0].name); + } } diff --git a/static/website/templates/index.html b/static/website/templates/index.html index d34f097..57405b7 100644 --- a/static/website/templates/index.html +++ b/static/website/templates/index.html @@ -16,11 +16,14 @@ - + + diff --git a/website/views.py b/website/views.py index 8d63b28..f7864d1 100644 --- a/website/views.py +++ b/website/views.py @@ -3,11 +3,13 @@ from django.http import HttpResponse from django.template import loader import requests import uuid +from R_on_Cloud.config import (API_URL_UPLOAD) def index(request): context = {} session_id = uuid.uuid4() context['session_id'] = str(session_id) + context['api_url_upload'] = API_URL_UPLOAD request.session['session_id'] = str(session_id) template = loader.get_template('index.html') return HttpResponse(template.render(context, request)) -- cgit