From aeb521abe79d1dd791135265ede89b5ee48ec4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 30 Jun 2016 18:56:57 +0200 Subject: [PATCH] Feature #4614: Search users by password field in sunstone (cherry picked from commit 598fcc5f8fe86afbaa596ceddc66dc9e8624e1ca) --- .../public/app/tabs/users-tab/datatable.js | 66 ++++++++++++++++++- .../app/tabs/users-tab/datatable/search.hbs | 10 +++ .../public/app/utils/tab-datatable.js | 25 ++++++- .../app/utils/tab-datatable/search-input.hbs | 25 +++++++ src/sunstone/public/scss/_table.scss | 12 ++-- 5 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 src/sunstone/public/app/tabs/users-tab/datatable/search.hbs diff --git a/src/sunstone/public/app/tabs/users-tab/datatable.js b/src/sunstone/public/app/tabs/users-tab/datatable.js index c910b61627..a0f16f6110 100644 --- a/src/sunstone/public/app/tabs/users-tab/datatable.js +++ b/src/sunstone/public/app/tabs/users-tab/datatable.js @@ -26,6 +26,7 @@ define(function(require) { var QuotaWidgets = require('utils/quotas/quota-widgets'); var TemplateUtils = require('utils/template-utils'); var LabelsUtils = require('utils/labels/utils'); + var SearchDropdown = require('hbs!./datatable/search'); /* CONSTANTS @@ -86,6 +87,8 @@ define(function(require) { this.totalUsers = 0; + this.conf.searchDropdownHTML = SearchDropdown(); + TabDataTable.call(this); } @@ -94,6 +97,7 @@ define(function(require) { Table.prototype.elementArray = _elementArray; Table.prototype.preUpdateView = _preUpdateView; Table.prototype.postUpdateView = _postUpdateView; + Table.prototype.setupSearch = _setupSearch; return Table; @@ -101,6 +105,58 @@ define(function(require) { FUNCTION DEFINITIONS */ + function _setupSearch(context) { + var that = this; + + $(".pass-search", context).on('input', function(){ + var val = $(".pass-search", context).val(); + + if(val == undefined || val == ""){ + $("button.search-dropdown", context).addClass("hollow"); + } else { + $("button.search-dropdown", context).removeClass("hollow"); + } + + that.dataTable.fnDraw(true); + }).on("keyup keypress", function(e) { + var code = e.keyCode || e.which; + if (code == 13) { + $("button.advanced-search", context).click(); + } + }); + + $("a.advanced-search-clear", context).on('click', function(){ + $(".pass-search", context).val("").trigger("input"); + + $("button.advanced-search", context).click(); + }); + + $.fn.dataTable.ext.search.push( + function( settings, data, dataIndex ) { + // This is a global search function, we need to apply it only if the + // search is triggered for the current table + if(that.dataTableId != settings.nTable.id){ + return true; + } + + var val = $(".pass-search", context).val(); + + if(val == undefined || val == ""){ + return true; + } + + try { + var pass = $("input.check_item", that.dataTable.fnGetNodes(dataIndex)).attr("password64"); + pass = atob(pass); + + return pass == val; + } catch (err) {} + + return true; + } + ); + } + function _elementArray(element_json) { this.totalUsers++; @@ -134,10 +190,13 @@ define(function(require) { // Build hidden user template var hidden_template = TemplateUtils.templateToString(element); + this.passwordList += '