From 8f2c5aa9e75dcea13aea9a912ff4cb02acaa2331 Mon Sep 17 00:00:00 2001 From: charithag Date: Thu, 6 Aug 2015 18:44:09 +0530 Subject: [PATCH] Improve UI --- .../public/js/device-listing.js | 65 ++++++++++--------- .../public/templates/group-listing.hbs | 4 +- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js index decc2b1c..c624ed06 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js @@ -164,39 +164,42 @@ function loadDevices() { } else { groups = data.data; } - viewModel.groups = groups; - var content = template(viewModel); - $("#ast-container-parent").html(content); - var deviceListing = $("#device-listing"); - var deviceListingSrc = deviceListing.attr("src"); - var imageResource = deviceListing.data("image-resource"); - $.template("device-listing", deviceListingSrc, function (template) { - for (var g in groups) { - if (groups[g].devices && groups[g].devices.length > 0) { - viewModel = {}; - viewModel.devices = groups[g].devices; - viewModel.imageLocation = imageResource; - content = template(viewModel); - } else { - if (groupId && groupId != "0") { - content = $("#no-grouped-devices-div-content").html(); - } else if (groups[g].id == 0 && g == 0) { - content = $("#no-devices-div-content").html(); + if (groups.length == 1 && groups[0].id == 0) { + $("#ast-container-parent").html($("#no-devices-div-content").html()); + } else { + viewModel.groups = groups; + var content = template(viewModel); + $("#ast-container-parent").html(content); + var deviceListing = $("#device-listing"); + var deviceListingSrc = deviceListing.attr("src"); + var imageResource = deviceListing.data("image-resource"); + $.template("device-listing", deviceListingSrc, function (template) { + for (var g in groups) { + if (groups[g].devices && groups[g].devices.length > 0) { + viewModel = {}; + viewModel.devices = groups[g].devices; + viewModel.imageLocation = imageResource; + content = template(viewModel); } else { - content = $("#no-devices-in-group-div-content").html(); + if (groupId && groupId != "0") { + content = $("#no-grouped-devices-div-content").html(); + } else { + content = $("#no-devices-in-group-div-content").html(); + } } + $("#ast-container-" + groups[g].id).html(content); } - $("#ast-container-" + groups[g].id).html(content); - } - /* - * On device checkbox select add parent selected style class - */ - $(deviceCheckbox).click(function () { - addDeviceSelectedClass(this); + /* + * On device checkbox select add parent selected style class + */ + $(deviceCheckbox).click(function () { + addDeviceSelectedClass(this); + }); + attachGroupEvents(); + attachDeviceEvents(); + formatDates(); }); - attachEvents(); - formatDates(); - }); + } }; invokerUtil.get(serviceURL, successCallback, function (message) { @@ -260,7 +263,7 @@ function hidePopup() { /** * Following functions should be triggered after AJAX request is made. */ -function attachEvents() { +function attachDeviceEvents() { /** * Following click function would execute * when a user clicks on "Remove" link @@ -535,7 +538,7 @@ function attachGroupAdding() { /** * Following functions should be triggered after AJAX request is made. */ -function attachEvents() { +function attachGroupEvents() { /** * Following click function would execute diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/group-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/group-listing.hbs index 167e309d..4bbd696c 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/group-listing.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/group-listing.hbs @@ -1,7 +1,7 @@ {{#each groups}} {{groupMap this}}
-
+
{{/if}}
-
+