ui-improvements

revert-dabc3590
Nirothipan 7 years ago
parent 5aea03c66f
commit d428901b22

@ -98,23 +98,23 @@
<br/>
{{/each}}
{{#each uiParams}}
{{#equal this.type "bi-radio"}}
<input type="radio" id="{{this.id}}"
name="{{this.name}}"
value="{{this.yesValue}}"
checked="checked"
class="radio"
onclick="changeLabel('yes')"
data-param-type="form"/>
{{this.yesValue}}
{{#equal this.type "select"}}
<div class="form-group">
<select class="form-control" id="{{this.id}}">
<option>{{this.valueOne}}</option>
<option>{{this.valueTwo}}</option>
<option>{{this.valueThree}}</option>
</select>
</div>
{{/equal}}
{{#equal this.type "radio"}}
<input type="radio" id="{{this.id}}"
name="{{this.name}}"
value="{{this.noValue}}"
value="{{this.value}}"
class="radio"
onclick="changeLabel('no')"
checked="checked"
data-param-type="form"/>
{{this.noValue}}
<br/> <br/>
{{this.value}}
{{/equal}}
{{#equal this.type "checkbox"}}
<input type="{{this.type}}" id="{{this.id}}"
@ -136,6 +136,13 @@
data-param-type="form" value=""/>
<br/>
{{/equal}}
{{#equal this.type "info"}}
<div class="form-group" id="{{this.id}}">
<span class="help-block">
+ {{this.value}}
</span>
</div>
{{/equal}}
{{/each}}
<button id="btnSend" type="button" onclick="submitForm('form-{{operation}}')"
class="btn btn-default">Send

@ -25,7 +25,7 @@ function operationSelect(selection) {
$(modalPopupContent).html($(" .operation[data-operation-code=" + selection + "]").html());
$(modalPopupContent).data("operation-code", selection);
if (selection === "FILE_TRANSFER") {
fillUserName();
fileTransferSelection();
}
showPopup();
}
@ -35,6 +35,63 @@ var resetLoader = function () {
$('#lbl-execution').addClass("hidden");
};
/**
* This function changes/hide/show field respective to the selection.
*/
function fileTransferSelection() {
var userName = document.getElementById('userName');
var password = document.getElementById('ftpPassword');
var infoTxt = document.getElementById('defaultFileLocation');
$(userName).hide();
$(password).hide();
$(infoTxt).hide();
fillUserName();
checkAuth();
changeLabels();
}
/**
* This changes the text box label when the operation is toggled between To device and From device
* and shows an info label for FILE UPLOAD regarding saving location.
*/
function changeLabels() {
var upload = document.getElementById('upload');
var download = document.getElementById('download');
var infoTxt = document.getElementById('defaultFileLocation');
console.log("info text " + infoTxt.value);
jQuery(upload).change(function () {
document.getElementById('fileURL').placeholder = "File URL";
document.getElementById('fileLocation').placeholder = "Location to save file in device";
$(infoTxt).show();
});
jQuery(download).change(function () {
document.getElementById('fileURL').placeholder = "URL to upload file from device";
document.getElementById('fileLocation').placeholder = "File location in the device";
$(infoTxt).hide();
});
}
/**
* This function show/hide username and password text boxes when authentication is toggled.
*/
function checkAuth() {
var auth = document.getElementById('authentication');
var userName = document.getElementById('userName');
var password = document.getElementById('ftpPassword');
jQuery(auth).click(function () {
if (this.checked) {
$(userName).show();
$(password).show();
} else {
$(userName).hide();
$(password).hide();
}
});
}
/**
* This function extracts the user name from the file url and fills it in the user name field.
*/
function fillUserName() {
var inputBox = document.getElementById('fileURL');
var regexp = ':\/\/[^\/]*@';
@ -53,26 +110,6 @@ function fillUserName() {
);
}
/**
* This changes the text box label when the operation is toggled between FILE UPLOAD and FILE DOWNLOAD
* and shows an info label for FILE UPLOAD regarding saving location.
* @param type
*/
function changeLabel(type) {
$(".modal #operation-error-msg").addClass("hidden");
if (type == "no") {
$(".modal #operation-warn-msg span").text("File will be saved in default location if not specified.");
$(".modal #operation-warn-msg").removeClass("hidden");
document.getElementById('fileURL').placeholder = "File URL";
document.getElementById('fileLocation').placeholder = "Location to save file in device";
} else {
$(".modal #operation-warn-msg").addClass("hidden");
document.getElementById('fileURL').placeholder = "URL for file upload";
document.getElementById('fileLocation').placeholder = "File location in the device";
}
fillUserName();
}
function submitForm(formId) {
$("#btnSend").addClass("hidden");
$("#lbl-execution").removeClass("hidden");
@ -223,14 +260,7 @@ function validatePayload(operationCode, payload) {
}
break;
case "FILE_TRANSFER":
if (payload.upload && !payload.fileURL) {
returnVal = "Please enter the URL of the file";
} else if (!payload.upload && !payload.fileURL) {
returnVal = "Please enter the FTP URL of the folder to upload file";
}
else if (!payload.upload && !payload.fileLocation) {
returnVal = "Please specify the file location in device";
}
returnVal = validateFileTransferParameters(payload);
break;
default:
break;
@ -239,6 +269,33 @@ function validatePayload(operationCode, payload) {
return returnVal;
}
/**
* This function validates all the parameters that are entered related to the file transfer operation.
* @param payload
* @returns {string}
*/
function validateFileTransferParameters(payload) {
var returnVal = "OK";
var auth = document.getElementById('authentication');
var protocol = $(document.getElementById('protocol')).find("option:selected").text();
if (payload.upload && !payload.fileURL) {
returnVal = "Please enter File URL";
} else if (!payload.upload && !payload.fileURL) {
returnVal = "Please enter the URL to upload file from device";
} else if (protocol === "HTTP" && !(payload.fileURL).startsWith("http:")) {
returnVal = "Please enter HTTP URL"
} else if (protocol === "FTP" && !(payload.fileURL).startsWith("ftp:")) {
returnVal = "Please enter FTP URL"
} else if (protocol === "SFTP" && !(payload.fileURL).startsWith("sftp:")) {
returnVal = "Please enter SFTP URL"
} else if (!payload.upload && !payload.fileLocation) {
returnVal = "Please specify the file location in device";
} else if (auth.checked && !payload.userName) {
returnVal = "Please enter the user name if authentication required"
}
return returnVal;
}
var generatePayload = function (operationCode, operationData, deviceList) {
var payload;
var operationType;

@ -140,36 +140,64 @@
"icon": "fw-save",
"formParams": [
{
"type": "bi-radio",
"name": "selection",
"type": "radio",
"name": "directionSelection",
"id": "upload",
"optional": false,
"yesValue": "FILE DOWNLOAD",
"noValue": "FILE UPLOAD"
"value": "To device"
},
{
"type": "radio",
"name": "directionSelection",
"id": "download",
"optional": false,
"value": "From device"
},
{
"type": "select",
"name": "protocolSelection",
"id": "protocol",
"optional": false,
"valueOne": "HTTP",
"valueTwo": "FTP",
"valueThree": "SFTP",
"label": "Protocol"
},
{
"type": "text",
"id": "fileURL",
"optional": false,
"label": "URL for file upload"
"label": "URL to upload file from device"
},
{
"type": "text",
"id": "userName",
"id": "fileLocation",
"optional": false,
"label": "User Name (Ignore if you don't need authentication.)"
"label": "File location in the device"
},
{
"type": "password",
"id": "ftpPassword",
"type": "info",
"id": "defaultFileLocation",
"optional": false,
"label": "Password (Ignore if you don't need authentication.)"
"value": "File will be saved in Default download directory if not specified."
},
{
"type": "checkbox",
"id": "authentication",
"optional": true,
"label": "Authentication required"
},
{
"type": "text",
"id": "fileLocation",
"id": "userName",
"optional": false,
"label": "File location in the device"
"label": "User Name"
},
{
"type": "password",
"id": "ftpPassword",
"optional": false,
"label": "Password (Ignore if not needed)"
}
],
"permission": "/device-mgt/devices/owning-device/operations/android/file-transfer"

Loading…
Cancel
Save