From 95b4c5fbc76782358e9b1ef8c535ff7bf07026a9 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 31 Jul 2018 13:53:57 +0200 Subject: [PATCH] Created search page. --- assets/css/pages/search/main.css | 24 +++++ assets/js/common/functionsSchema.js | 14 +++ assets/js/pages/search/main.js | 161 ++++++++++++++++++++++++++++ assets/js/pagesList.js | 9 ++ system/config/dev.config.php | 8 +- 5 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 assets/css/pages/search/main.css create mode 100644 assets/js/pages/search/main.js diff --git a/assets/css/pages/search/main.css b/assets/css/pages/search/main.css new file mode 100644 index 00000000..a1ffcbab --- /dev/null +++ b/assets/css/pages/search/main.css @@ -0,0 +1,24 @@ +/** + * Search page main stylesheet + * + * @author Pierre HUBERT + */ + +.searchPage { + max-width: 500px; + margin: auto; + margin-top: 30px; +} + +.searchPage .results-container { + margin-top: 30px; +} + + +.searchPage .results-container li a img { + margin: auto 10px auto auto; + max-width: 40px; + height: 40px; + border-radius: 50%; + visibility: visible; +} \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 72754e08..e61cd49e 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1516,5 +1516,19 @@ var ComunicWeb = { }, }, + + /** + * Search page + */ + search: { + + /** + * Main page + */ + main: { + //TODO : implement + }, + + }, }, }; \ No newline at end of file diff --git a/assets/js/pages/search/main.js b/assets/js/pages/search/main.js new file mode 100644 index 00000000..a3695b55 --- /dev/null +++ b/assets/js/pages/search/main.js @@ -0,0 +1,161 @@ +/** + * Search main page + * + * @author Pierre HUBERT + */ + +ComunicWeb.pages.search.main = { + + /** + * Open search page + * + * @param {object} args Optionnal arguments + * @param {HTMLElement} target The target for the page + */ + open: function(args, target){ + + var query = null; + + if(args.urlArgs){ + if(args.urlArgs.q) + query = args.urlArgs.q; + } + + //Create page container + var pageContainer = createElem2({ + appendTo: target, + type: "div", + class: "searchPage" + }); + + //Add search form + var searchForm = createElem2({ + appendTo: pageContainer, + type: "form" + }); + + //Add search input + var inputGroup = createElem2({ + appendTo: searchForm, + type: "div", + class: "input-group input-group-sm" + }); + + var textInput = createElem2({ + appendTo: inputGroup, + type: "input", + class: "form-control", + elemType: "text", + placeholder: "Search a personn, a group..." + }); + + var inputGroupBtn = createElem2({ + appendTo: inputGroup, + type: "div", + class: "input-group-btn" + }); + + var submitButton = createElem2({ + appendTo: inputGroupBtn, + type: "button", + class: "btn btn-info btn-flat", + innerHTML: "Submit" + }); + + var searchResults = createElem2({ + appendTo: pageContainer, + type: "div", + class: "resultsTarget" + }); + + searchForm.onsubmit = function(){ + openPage("search?q=" + textInput.value); + return false; + } + + //Check for query + if(query){ + textInput.value = query; + ComunicWeb.pages.search.main.submit(textInput.value, searchResults); + } + }, + + /** + * Submit a new search + * + * @param {String} query The query string + * @param {HTMLElement} target The target for the results + */ + submit: function(query, target){ + + //Empty the target + emptyElem(target); + + //Perform a query on the API + ComunicWeb.components.search.interface.global(query, function(result){ + + //Check for errors + if(result.error){ + return target.appendChild(ComunicWeb.common.messages.createCalloutElem( + "Error", + "An error occurred while trying to perform search...", + "danger" + )); + } + + //Get information about related users + getMultipleUsersInfos(ComunicWeb.components.search.utils.getUsersId(result), function(usersInfo){ + + if(usersInfo.error){ + return target.appendChild(ComunicWeb.common.messages.createCalloutElem( + "Error", + "An error occurred while trying to get information about related users...", + "danger" + )); + } + + //Get information about related groups + getInfoMultipleGroups(ComunicWeb.components.search.utils.getGroupsId(result), function(groupsInfo){ + + if(groupsInfo.error){ + return target.appendChild(ComunicWeb.common.messages.createCalloutElem( + "Error", + "An error occurred while trying to get information about related groups...", + "danger" + )); + } + + + //Display results + ComunicWeb.pages.search.main._display_search_results(target, result, usersInfo, groupsInfo); + + }); + + }); + }); + + }, + + /** + * Display search results + * + * @param {HTMLElement} target The target for the page + * @param {Array} results The list of results + * @param {Object} usersInfo Information about the related users + * @param {Object} groupsInfo Information about the related groups + */ + _display_search_results: function(target, results, usersInfo, groupsInfo){ + + //Create results container + var resultsContainer = createElem2({ + appendTo: target, + type: "ul", + class: "nav nav-pills nav-stacked results-container" + }); + + results.forEach(function(result){ + ComunicWeb.components.search.ui.display(result, usersInfo, groupsInfo, null, resultsContainer); + }); + + } +} \ No newline at end of file diff --git a/assets/js/pagesList.js b/assets/js/pagesList.js index 6a8a60e1..f58ee4fc 100644 --- a/assets/js/pagesList.js +++ b/assets/js/pagesList.js @@ -133,6 +133,15 @@ ComunicWeb.pagesList = { disableMenus: false }, + /** + * Search page + */ + search: { + pageTitle: "Search", + methodHandler: "ComunicWeb.pages.search.main.open", + disableMenus: false + }, + /** * 404 Page not found */ diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 1a5dd4b9..2ccfe70b 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -255,7 +255,10 @@ class Dev { "css/pages/passwordForgotten/mailAdmin.css", //Password reset page - "css/pages/resetPassword/main.css" + "css/pages/resetPassword/main.css", + + //Search page + "css/pages/search/main.css" ); /** @@ -486,6 +489,9 @@ class Dev { //Virtual directory page "js/pages/virtualDirectory/page.js", + //Search page + "js/pages/search/main.js", + //Create shortcuts for common functions "js/common/shorcuts.js", "js/common/helpers.js",