diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js new file mode 100644 index 0000000000..0dc9a79602 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/js/bottomJs.js @@ -0,0 +1,175 @@ +/* + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file except + in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +var removeCustomParam = function () { + $(this).parent().parent().remove(); +}; + +/** + * Following function would execute + * when a user clicks on the list item + * initial mode and with out select mode. + */ +function InitiateViewOption() { + $(location).attr('href', $(this).data("url")); +} + +$("#back-to-search").click(function () { + $('#advance-search-result').addClass('hidden'); + $("#advance-search-form").removeClass('hidden'); + $("#view-search-param").addClass('hidden'); + $("#back-to-search").addClass('hidden'); +}); + +$("#view-search-param").click(function () { + $("#advance-search-form").removeClass('hidden'); + $(".title-result").addClass('hidden'); + $("#view-search-param").addClass('hidden'); +}); + +var dynamicForm = '
'; + +$(document).ready(function () { + var isInit = true; + $("#add-custom-param").click(function () { + $("#customSearchParam").prepend(dynamicForm); + $(".close-button-div").unbind("click"); + $(".close-button-div").bind("click", removeCustomParam); + $(".txt-key").select2({tags: true}); + $(".no-tag").select2({tags: false}); + }); + + $("#device-search-btn").click(function () { + var location = $("#location").val(); + var payload_obj = {}; + var conditions = []; + if (location) { + var conditionObject = {}; + conditionObject.key = "LOCATION"; + conditionObject.value = location; + conditionObject.operator = "="; + conditionObject.state = "OR"; + conditions.push(conditionObject) + } + + $("#customSearchParam .dynamic-search-param").each(function () { + var value = $(this).find(".txt-value").val(); + var key = $(this).find(".txt-key").val() + if (value && key) { + var conditionObject = {}; + conditionObject.key = key; + conditionObject.value = value; + conditionObject.operator = $(this).find(".operator").val(); + conditionObject.state = $(this).find(".state").val(); + conditions.push(conditionObject) + } + }); + payload_obj.conditions = conditions; + var deviceSearchAPI = "/api/device-mgt/v1.0/devices/search-devices"; + $("#advance-search-form").addClass(" hidden"); + $("#loading-content").removeClass('hidden'); + var deviceListing = $("#device-listing"); + var deviceListingSrc = deviceListing.attr("src"); + $.template("device-listing", deviceListingSrc, function (template) { + + var successCallback = function (data) { + if (!data) { + $("#loading-content").addClass('hidden'); + $("#advance-search-result").addClass("hidden"); + $("#advance-search-form").removeClass(" hidden"); + $('#device-listing-status').removeClass('hidden'); + $('#device-listing-status-msg').text('No Device are available to be displayed.'); + return; + } + data = JSON.parse(data); + if (data.devices.length == 0) { + $("#loading-content").addClass('hidden'); + $("#advance-search-result").addClass("hidden"); + $("#advance-search-form").removeClass(" hidden"); + $('#device-listing-status').removeClass('hidden'); + $('#device-listing-status-msg').text('No Device are available to be displayed.'); + return; + } + var viewModel = {}; + var devices = []; + if (data.devices.length > 0) { + for (i = 0; i < data.devices.length; i++) { + var tempDevice = data.devices[i]; + var device = {}; + device.type = tempDevice.type; + device.name = tempDevice.name; + device.deviceIdentifier = tempDevice.deviceIdentifier; + var properties = {} ; + var enrolmentInfo = {}; + properties.VENDOR = tempDevice.deviceInfo.vendor; + properties.DEVICE_MODEL = tempDevice.deviceInfo.deviceModel; + enrolmentInfo.status = "ACTIVE"; + enrolmentInfo.owner = "N/A"; + enrolmentInfo.ownership = "N/A"; + device.enrolmentInfo = enrolmentInfo; + device.properties = properties; + devices.push(device); + } + viewModel.devices = devices; + $('#advance-search-result').removeClass('hidden'); + $("#view-search-param").removeClass('hidden'); + $("#back-to-search").removeClass('hidden'); + $('#device-grid').removeClass('hidden'); + $('#ast-container').removeClass('hidden'); + $('#user-listing-status-msg').text(""); + var content = template(viewModel); + $("#ast-container").html(content); + } else { + $('#device-listing-status').removeClass('hidden'); + $('#device-listing-status-msg').text('No Device are available to be displayed.'); + } + $("#loading-content").addClass('hidden'); + if (isInit) { + $('#device-grid').datatables_extended(); + isInit = false; + } + $(".icon .text").res_text(0.2); + }; + invokerUtil.post(deviceSearchAPI, + payload_obj, + successCallback, + function (message) { + $("#loading-content").addClass('hidden'); + $("#advance-search-result").addClass("hidden"); + $("#advance-search-form").removeClass(" hidden"); + $('#device-listing-status').removeClass('hidden'); + $('#device-listing-status-msg').text('Server is unable to perform the search please enroll at least one device or check the search query'); + } + ); + }); + }); +}); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/templates/device-listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/templates/device-listing.hbs new file mode 100644 index 0000000000..7bb2b3e306 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.device.search/public/templates/device-listing.hbs @@ -0,0 +1,44 @@ + + + {{#each devices}} + +Advanced Device Search
+