Merge pull request #446 from madawas/IOTS-296

IOTS-296: Refactoring Policy create/edit units
revert-70aa11f8
Madawa Soysa 8 years ago committed by GitHub
commit 2d0b0ed94b

@ -59,6 +59,11 @@ var disableInlineError = function (inputField, errorMsg, errorSign) {
}
};
/**
* Load all device groups.
*
* @param callback function to call on loading completion.
*/
function loadGroups(callback) {
invokerUtil.get(
"/api/device-mgt/v1.0/groups",
@ -68,6 +73,12 @@ function loadGroups(callback) {
});
}
/**
* Creates DeviceGroupWrapper object from selected groups.
*
* @param selectedGroups
* @returns {Array} DeviceGroupWrapper list.
*/
var createDeviceGroupWrapper = function (selectedGroups) {
var groupObjects = [];
loadGroups(function (deviceGroups) {
@ -136,7 +147,6 @@ stepForwardFrom["policy-platform"] = function (actionButton) {
$.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) {
var content = template();
$("#device-type-policy-operations").html(content).removeClass("hidden");
// $("#device-type-policy-operations").removeClass("hidden");
$(".policy-platform").addClass("hidden");
});

@ -63,7 +63,7 @@
<div id="policy-naming-main-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<div>
<div class="clearfix">
<label class="wr-input-label">
Set a name * to your policy<br>
( should be 1-to-30 characters long )

@ -63,6 +63,11 @@ var disableInlineError = function (inputField, errorMsg, errorSign) {
}
};
/**
* Load all device groups.
*
* @param callback function to call on loading completion.
*/
function loadGroups(callback) {
invokerUtil.get(
"/api/device-mgt/v1.0/groups",
@ -72,12 +77,18 @@ function loadGroups(callback) {
});
}
/**
* Creates DeviceGroupWrapper object from selected groups.
*
* @param selectedGroups
* @returns {Array} DeviceGroupWrapper list.
*/
var createDeviceGroupWrapper = function (selectedGroups) {
var groupObjects = [];
loadGroups(function (deviceGroups) {
var tenantId = $("#logged-in-user").data("tenant-id");
for (var index in deviceGroups) {
if(deviceGroups.hasOwnProperty(index)) {
if (deviceGroups.hasOwnProperty(index)) {
var deviceGroupWrapper = {};
if (selectedGroups.indexOf(deviceGroups[index].name) > -1) {
deviceGroupWrapper.id = deviceGroups[index].id;
@ -132,7 +143,18 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
currentlyEffected["roles"] = policyPayloadObj.roles;
currentlyEffected["users"] = policyPayloadObj.users;
currentlyEffected["groups"] = policyPayloadObj.deviceGroups;
currentlyEffected["groups"] = [];
if (policyPayloadObj.deviceGroups) {
var deviceGroups = policyPayloadObj.deviceGroups;
for (var index in deviceGroups) {
if (deviceGroups.hasOwnProperty(index)) {
currentlyEffected["groups"].push(deviceGroups[index].name);
}
}
} else {
currentlyEffected["groups"].push("NONE");
}
if (currentlyEffected["roles"].length > 0) {
$("#user-roles-radio-btn").prop("checked", true);
@ -146,7 +168,7 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
userInput.val(currentlyEffected["users"]).trigger("change");
}
if(currentlyEffected["groups"].length > 0) {
if (currentlyEffected["groups"].length > 0) {
groupsInput.val(currentlyEffected["groups"]).trigger("change");
}
@ -178,8 +200,8 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
script.type = 'text/javascript';
script.src = policyOperationsScriptSrc;
$(".wr-advance-operations").prepend(script);
var configuredOperations = operationModule.
populateProfile(policy["platform"], policyPayloadObj["profile"]["profileFeaturesList"]);
var configuredOperations = operationModule.populateProfile(policy["platform"],
policyPayloadObj["profile"]["profileFeaturesList"]);
polulateProfileOperations(configuredOperations);
}
});
@ -222,7 +244,7 @@ stepForwardFrom["policy-criteria"] = function () {
}
});
policy["selectedGroups"] = $("#groups-input").val();
if (policy["selectedGroups"].length > 1 || policy["selectedGroups"][0] !== "NONE") {
if (policy["selectedGroups"] && (policy["selectedGroups"].length > 1 || policy["selectedGroups"][0] !== "NONE")) {
policy["selectedGroups"] = createDeviceGroupWrapper(policy["selectedGroups"]);
}
@ -422,7 +444,7 @@ var updatePolicy = function (policy, state) {
payload["roles"] = [];
}
if(policy["selectedGroups"]) {
if (policy["selectedGroups"]) {
payload["deviceGroups"] = policy["selectedGroups"];
}

Loading…
Cancel
Save