From f5d71d917e3776004ddd128b4475046ac7567a3e Mon Sep 17 00:00:00 2001 From: lakshani Date: Tue, 7 Feb 2017 10:38:12 +0530 Subject: [PATCH] Added change device status feature to mobile plugings --- .../device-view.hbs | 44 +++++++++++--- .../device-view.js | 3 + .../public/js/device-detail.js | 56 ++++++++++++++++++ .../device-view.hbs | 44 +++++++++++--- .../device-view.js | 3 + .../public/js/device-detail.js | 59 ++++++++++++++++++- 6 files changed, 191 insertions(+), 18 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs index ca9efda9d..4b2dfe84a 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.hbs @@ -1,4 +1,5 @@ {{unit "cdmf.unit.device.type.android.leaflet"}} +{{unit "cdmf.unit.lib.editable"}} {{unit "cdmf.unit.lib.qrcode"}} {{unit "cdmf.unit.device.type.qr-modal"}} @@ -51,14 +52,41 @@ Status - {{#equal device.status "ACTIVE"}}Active{{/equal}} - {{#equal device.status "INACTIVE"}}Inactive{{/equal}} - {{#equal device.status "BLOCKED"}}Blocked{{/equal}} - {{#equal device.status "REMOVED"}}Removed{{/equal}} + {{#if permissions.CHANGE_DEVICE_STATUS}} + {{#equal device.status "ACTIVE"}} + + {{/equal}} + {{#equal device.status "INACTIVE"}} + + {{/equal}} + {{#equal device.status "BLOCKED"}} + + {{/equal}} + {{#equal device.status "REMOVED"}} + + {{/equal}} + {{else}} + {{#equal device.status "ACTIVE"}} Active{{/equal}} + {{#equal device.status "INACTIVE"}} Inactive{{/equal}} + {{#equal device.status "BLOCKED"}} Blocked{{/equal}} + {{#equal device.status "REMOVED"}} Removed{{/equal}} + {{/if}} {{/if}} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js index a5816da5b..0a0bba6ba 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/device-view.js @@ -210,7 +210,10 @@ function onRequest(context) { {"name" : "deviceId", "value" : deviceId} ]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var permissions = userModule.getUIPermissions(); deviceViewData["autoCompleteParams"] = autoCompleteParams; + deviceViewData["permissions"] = permissions; deviceViewData["portalUrl"] = devicemgtProps['portalURL']; deviceViewData["anchor"] = encodeURI(JSON.stringify({ "device" : { "id" : deviceId, "type" : deviceType}})); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/public/js/device-detail.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/public/js/device-detail.js index 449dec84c..c628f1260 100755 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/public/js/device-detail.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.device-view/public/js/device-detail.js @@ -81,6 +81,62 @@ var InitiateViewOption = null; } }); + $('#status').on('save', function (e, params) { + var deviceStatus = params.submitValue.toUpperCase(); + var serviceUrl = "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceIdentifier + + "/changestatus?newStatus=" + deviceStatus; + var payload = null; + + if (serviceUrl) { + var successCallback = function (jqXHR, status, resp) { + if (resp.status == 200) { + setTimeout(function () { + if (deviceStatus == "REMOVED") { + $('#statusIcon').removeClass().addClass('fw fw-delete icon-danger'); + } else if (deviceStatus == "INACTIVE") { + $('#statusIcon').removeClass().addClass('fw fw-warning icon-warning'); + } else if (deviceStatus == "ACTIVE") { + $('#statusIcon').removeClass().addClass('fw fw-success icon-success'); + } + $("#statusIcon").show(); + + }, 1500); + } else { + console.log(resp.status); + } + }; + + invokerUtil.put(serviceUrl, payload, + successCallback, function (message) { + console.log(message); + }); + } + + }); + + $("#status").click(function () { + $("#statusIcon").hide(); + }); + + $.fn.editable.defaults.mode = 'inline'; + + $('#status').editable({ + value: $('#status').attr("selectedValue"), + source: [ + {value: 'Active', text: 'Active'}, + {value: "Inactive", text: 'Inactive'}, + {value: "Removed", text: 'Removed'} + ], + success: this.update_elements + }); + + $.fn.editableform.buttons = + '' + + ''; function positionArrow(selectedTab) { var selectedTabHeight = $(selectedTab).innerHeight(); diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.hbs b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.hbs index 3e999e40d..046a5ae15 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.hbs +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.hbs @@ -1,4 +1,5 @@ {{unit "cdmf.unit.device.type.windows.leaflet"}} +{{unit "cdmf.unit.lib.editable"}} {{unit "cdmf.unit.lib.qrcode"}} {{unit "cdmf.unit.device.type.qr-modal"}} @@ -51,14 +52,41 @@ Status - {{#equal device.status "ACTIVE"}}Active{{/equal}} - {{#equal device.status "INACTIVE"}}Inactive{{/equal}} - {{#equal device.status "BLOCKED"}}Blocked{{/equal}} - {{#equal device.status "REMOVED"}}Removed{{/equal}} + {{#if permissions.CHANGE_DEVICE_STATUS}} + {{#equal device.status "ACTIVE"}} + + {{/equal}} + {{#equal device.status "INACTIVE"}} + + {{/equal}} + {{#equal device.status "BLOCKED"}} + + {{/equal}} + {{#equal device.status "REMOVED"}} + + {{/equal}} + {{else}} + {{#equal device.status "ACTIVE"}} Active{{/equal}} + {{#equal device.status "INACTIVE"}} Inactive{{/equal}} + {{#equal device.status "BLOCKED"}} Blocked{{/equal}} + {{#equal device.status "REMOVED"}} Removed{{/equal}} + {{/if}} {{/if}} diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.js b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.js index c5e0619f7..b363aa2ec 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.js +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/device-view.js @@ -112,6 +112,9 @@ function onRequest(context) { {"name" : "deviceId", "value" : deviceId} ]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var permissions = userModule.getUIPermissions(); deviceViewData["autoCompleteParams"] = autoCompleteParams; + deviceViewData["permissions"] = permissions; return deviceViewData; } \ No newline at end of file diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/public/js/device-detail.js b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/public/js/device-detail.js index 0e2375033..ac2a06be8 100755 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/public/js/device-detail.js +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.device-view/public/js/device-detail.js @@ -69,8 +69,7 @@ var InitiateViewOption = null; activeTabPaneCaret.removeClass("fw-up").addClass("fw-down"); activeTabPaneCaretSiblings.removeClass("fw-down").addClass("fw-up"); }); - - + $('.media.tab-responsive a[data-toggle="collapse"]').on('click',function(){ var clickedPanel = $(this).attr('href'); @@ -81,6 +80,62 @@ var InitiateViewOption = null; } }); + $('#status').on('save', function (e, params) { + var deviceStatus = params.submitValue.toUpperCase(); + var serviceUrl = "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceIdentifier + + "/changestatus?newStatus=" + deviceStatus; + var payload = null; + + if (serviceUrl) { + var successCallback = function (jqXHR, status, resp) { + if (resp.status == 200) { + setTimeout(function () { + if (deviceStatus == "REMOVED") { + $('#statusIcon').removeClass().addClass('fw fw-delete icon-danger'); + } else if (deviceStatus == "INACTIVE") { + $('#statusIcon').removeClass().addClass('fw fw-warning icon-warning'); + } else if (deviceStatus == "ACTIVE") { + $('#statusIcon').removeClass().addClass('fw fw-success icon-success'); + } + $("#statusIcon").show(); + + }, 1500); + } else { + console.log(resp.status); + } + }; + + invokerUtil.put(serviceUrl, payload, + successCallback, function (message) { + console.log(message); + }); + } + + }); + + $("#status").click(function () { + $("#statusIcon").hide(); + }); + + $.fn.editable.defaults.mode = 'inline'; + + $('#status').editable({ + value: $('#status').attr("selectedValue"), + source: [ + {value: 'Active', text: 'Active'}, + {value: "Inactive", text: 'Inactive'}, + {value: "Removed", text: 'Removed'} + ], + success: this.update_elements + }); + + $.fn.editableform.buttons = + '' + + ''; function positionArrow(selectedTab) { var selectedTabHeight = $(selectedTab).innerHeight();