[31601] | 1 | var wsNameCorrect = false;
|
---|
| 2 | var inputFileCorrect = false;
|
---|
| 3 |
|
---|
| 4 | var uploadHasError = function (element, iconElement) {
|
---|
| 5 | wsSubmitButtonVisibility();
|
---|
| 6 | element.addClass('has-error');
|
---|
| 7 | element.removeClass('has-success');
|
---|
| 8 | iconElement.addClass('glyphicon');
|
---|
| 9 | iconElement.addClass('glyphicon-remove');
|
---|
| 10 | iconElement.removeClass('glyphicon-ok');
|
---|
| 11 | };
|
---|
| 12 |
|
---|
| 13 | var uploadHasSuccess = function (element, iconElement) {
|
---|
| 14 | wsSubmitButtonVisibility();
|
---|
| 15 | element.addClass('has-success');
|
---|
| 16 | element.removeClass('has-error');
|
---|
| 17 | iconElement.addClass('glyphicon');
|
---|
| 18 | iconElement.addClass('glyphicon-ok');
|
---|
| 19 | iconElement.removeClass('glyphicon-remove');
|
---|
| 20 | };
|
---|
| 21 |
|
---|
| 22 | var wsSubmitButtonVisibility = function () {
|
---|
| 23 | var wsSubmitButton = $('#ws-submit');
|
---|
| 24 |
|
---|
| 25 | // disable submit button at start
|
---|
| 26 | wsSubmitButton.prop("disabled", true);
|
---|
| 27 | var inputFileValue = $('#inputCSV').val();
|
---|
| 28 | if (wsNameCorrect && inputFileCorrect) {
|
---|
| 29 | wsSubmitButton.prop("disabled", false);
|
---|
| 30 | } else {
|
---|
| 31 | wsSubmitButton.prop("disabled", true);
|
---|
| 32 | }
|
---|
| 33 | };
|
---|
| 34 |
|
---|
| 35 | var checkWsNameValidity = function (wsname, onInvalidWSName, onValidWSName) {
|
---|
| 36 | var request = $.ajax({
|
---|
| 37 | url: "/iswsnamevalid?wsName=" + wsname,
|
---|
| 38 | type: "GET",
|
---|
| 39 | success: function (result) {
|
---|
| 40 | if (!result.valid) {
|
---|
| 41 | onInvalidWSName();
|
---|
| 42 | } else {
|
---|
| 43 | onValidWSName();
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | });
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | var wsNameInputKeyUp = function () {
|
---|
| 50 | var wsName = $(this).val();
|
---|
| 51 | var wsNameControlGroup = $('#wsname-control-group');
|
---|
| 52 | var wsNameWarnBlock = $('#wsname-warn-block');
|
---|
| 53 | var wsNameFeedback = $('#wsname-feedback');
|
---|
| 54 |
|
---|
| 55 | if (wsName.indexOf(' ') >= 0 || wsName.indexOf('\'') >= 0 || wsName.match('[&?~!@#;%^*+={}|<>,"]') || wsName.match(/\\$/) || wsName.indexOf('\[') >= 0 || wsName.indexOf('\]') >= 0) {
|
---|
| 56 | wsNameCorrect = false;
|
---|
| 57 | uploadHasError(wsNameControlGroup, wsNameFeedback);
|
---|
| 58 | wsNameWarnBlock.html('Workset name contains illegal characters &?~!@#;%^*+={}|<>,\'"\\ or spaces.');
|
---|
| 59 | } else if (wsName.length == 0) {
|
---|
| 60 | wsNameCorrect = false;
|
---|
| 61 | uploadHasError(wsNameControlGroup, wsNameFeedback);
|
---|
| 62 | wsNameWarnBlock.html('Workset name cannot be empty!');
|
---|
| 63 | } else {
|
---|
| 64 | checkWsNameValidity(wsName, function () {
|
---|
| 65 | wsNameCorrect = false;
|
---|
| 66 | uploadHasError(wsNameControlGroup, wsNameFeedback);
|
---|
| 67 | wsNameWarnBlock.html('You already have a workset with this name. Please choose another name.');
|
---|
| 68 | }, function () {
|
---|
| 69 | wsNameCorrect = true;
|
---|
| 70 | uploadHasSuccess(wsNameControlGroup, wsNameFeedback);
|
---|
| 71 | wsNameWarnBlock.html('');
|
---|
| 72 | });
|
---|
| 73 | }
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | var inputFileChange = function () {
|
---|
| 77 | var fileName = $(this).val();
|
---|
| 78 | var validExtns = [".csv",".txt"];
|
---|
| 79 |
|
---|
| 80 | var inputFileControlGroup = $('#inputfile-control-group');
|
---|
| 81 | var inputFileWarnBlock = $('#inputfile-warn-block');
|
---|
| 82 | var inputFileFeedback = $('#inputfile-feedback');
|
---|
| 83 |
|
---|
| 84 | if (fileName.length != 0) {
|
---|
| 85 | if (validExtns.indexOf(fileName.substr(fileName.lastIndexOf('.'))) > -1){
|
---|
| 86 | inputFileCorrect = true;
|
---|
| 87 | uploadHasSuccess(inputFileControlGroup, inputFileFeedback);
|
---|
| 88 | inputFileWarnBlock.html('');
|
---|
| 89 | } else {
|
---|
| 90 | inputFileCorrect = false;
|
---|
| 91 | uploadHasError(inputFileControlGroup, inputFileFeedback);
|
---|
| 92 | inputFileWarnBlock.html('Workset should be uploaded as a CSV or TXT file.');
|
---|
| 93 | }
|
---|
| 94 | }else {
|
---|
| 95 | inputFileCorrect = false;
|
---|
| 96 | uploadHasError(inputFileControlGroup, inputFileFeedback);
|
---|
| 97 | inputFileWarnBlock.html('Please upload a file.');
|
---|
| 98 | }
|
---|
| 99 | };
|
---|
| 100 |
|
---|
| 101 | var worksetNameValidation = function () {
|
---|
| 102 | $('#uploadWorksetName').bind("change keyup", wsNameInputKeyUp);
|
---|
| 103 | };
|
---|
| 104 |
|
---|
| 105 | var inputFileValidation = function () {
|
---|
| 106 | $('#inputCSV').bind("change", inputFileChange);
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | $(document).ready(function () {
|
---|
| 110 | worksetNameValidation();
|
---|
| 111 | inputFileValidation();
|
---|
| 112 | wsSubmitButtonVisibility();
|
---|
| 113 | });
|
---|
| 114 |
|
---|
| 115 |
|
---|