Merge pull request #829 from lasanthaDLPDS/master

Adding checkbox and radio options to device.operation-bar
4.x.x
Madhawa Perera 8 years ago committed by GitHub
commit 597b450cfb

@ -79,6 +79,11 @@
<input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control" data-param-type="query" value="{{value}}" /> <input type="{{type}}" id="{{name}}" placeholder="{{name}}" class="form-control" data-param-type="query" value="{{value}}" />
<br /> <br />
{{/each}} {{/each}}
{{#each uiParams}}
<input type="{{type}}" id="{{id}}" name="{{name}}" data-param-type="form" value="{{value}}" />
<label>{{label}}</label>
<br />
{{/each}}
<button id="btnSend" type="button" onclick="submitForm('form-{{operation}}')" class="btn btn-default">&nbsp;&nbsp;&nbsp;&nbsp;Send <button id="btnSend" type="button" onclick="submitForm('form-{{operation}}')" class="btn btn-default">&nbsp;&nbsp;&nbsp;&nbsp;Send
to Device&nbsp;&nbsp;&nbsp;&nbsp;</button> to Device&nbsp;&nbsp;&nbsp;&nbsp;</button>
<label id="lblSending" class="wr-input-label hidden"><i <label id="lblSending" class="wr-input-label hidden"><i

@ -33,6 +33,15 @@ function submitForm(formId) {
var uriencodedQueryStr = ""; var uriencodedQueryStr = "";
var uriencodedFormStr = ""; var uriencodedFormStr = "";
var payload = {}; var payload = {};
var isItemSelected;
//setting responses callbacks
var content = $("#operation-response-template").find(".content");
var defaultStatusClasses = "fw fw-stack-1x";
var title = content.find("#title");
var statusIcon = content.find("#status-icon");
var description = content.find("#description");
form.find("input").each(function () { form.find("input").each(function () {
var input = $(this); var input = $(this);
if (input.data("param-type") == "path") { if (input.data("param-type") == "path") {
@ -42,14 +51,31 @@ function submitForm(formId) {
uriencodedQueryStr += prefix + input.attr("id") + "=" + input.val(); uriencodedQueryStr += prefix + input.attr("id") + "=" + input.val();
} else if (input.data("param-type") == "form") { } else if (input.data("param-type") == "form") {
var prefix = (uriencodedFormStr == "") ? "" : "&"; var prefix = (uriencodedFormStr == "") ? "" : "&";
uriencodedFormStr += prefix + input.attr("id") + "=" + input.val(); if (input.attr("type") == "checkbox" || input.attr("type") == "radio"){
//payload[input.attr("id")] = input.val();
if (isItemSelected == undefined){
isItemSelected = false;
}
if (input.is(':checked')){
isItemSelected = true;
uriencodedFormStr += prefix + input.attr("name") + "=" + input.val();
}
}else{
uriencodedFormStr += prefix + input.attr("id") + "=" + input.val();
}
} }
}); });
if (isItemSelected === false){
title.html("Please Select One Option");
statusIcon.attr("class", defaultStatusClasses + " fw-error");
$(modalPopupContent).html(content.html());
return false;
}
uri += uriencodedQueryStr; uri += uriencodedQueryStr;
var httpMethod = form.attr("method").toUpperCase(); var httpMethod = form.attr("method").toUpperCase();
var contentType = form.attr("enctype"); var contentType = form.attr("enctype");
console.log(payload);
var featurePayload = form.attr("data-payload"); var featurePayload = form.attr("data-payload");
if (featurePayload) { if (featurePayload) {
contentType = "application/json"; contentType = "application/json";
@ -59,12 +85,7 @@ function submitForm(formId) {
contentType = "application/x-www-form-urlencoded"; contentType = "application/x-www-form-urlencoded";
payload = uriencodedFormStr; payload = uriencodedFormStr;
} }
//setting responses callbacks
var defaultStatusClasses = "fw fw-stack-1x";
var content = $("#operation-response-template").find(".content");
var title = content.find("#title");
var statusIcon = content.find("#status-icon");
var description = content.find("#description");
var successCallBack = function (response) { var successCallBack = function (response) {
var res = response; var res = response;
try { try {
@ -78,7 +99,6 @@ function submitForm(formId) {
$(modalPopupContent).html(content.html()); $(modalPopupContent).html(content.html());
}; };
var errorCallBack = function (response) { var errorCallBack = function (response) {
console.log(response);
title.html("An Error Occurred!"); title.html("An Error Occurred!");
statusIcon.attr("class", defaultStatusClasses + " fw-error"); statusIcon.attr("class", defaultStatusClasses + " fw-error");
var reason = (response.responseText == "null")?response.statusText:response.responseText; var reason = (response.responseText == "null")?response.statusText:response.responseText;
@ -105,9 +125,9 @@ function submitForm(formId) {
$(document).on('submit', 'form', function (e) { $(document).on('submit', 'form', function (e) {
e.preventDefault(); e.preventDefault();
var postOperationRequest = $.ajax({ var postOperationRequest = $.ajax({
url: $(this).attr("action") + '&' + $(this).serialize(), url: $(this).attr("action") + '&' + $(this).serialize(),
method: "post" method: "post"
}); });
var btnSubmit = $('#btnSend', this); var btnSubmit = $('#btnSend', this);
btnSubmit.addClass('hidden'); btnSubmit.addClass('hidden');

Loading…
Cancel
Save