Created search page.

This commit is contained in:
Pierre HUBERT 2018-07-31 13:53:57 +02:00
parent a50cca62d3
commit 95b4c5fbc7
5 changed files with 215 additions and 1 deletions

View File

@ -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;
}

View File

@ -1516,5 +1516,19 @@ var ComunicWeb = {
}, },
}, },
/**
* Search page
*/
search: {
/**
* Main page
*/
main: {
//TODO : implement
},
},
}, },
}; };

View File

@ -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);
});
}
}

View File

@ -133,6 +133,15 @@ ComunicWeb.pagesList = {
disableMenus: false disableMenus: false
}, },
/**
* Search page
*/
search: {
pageTitle: "Search",
methodHandler: "ComunicWeb.pages.search.main.open",
disableMenus: false
},
/** /**
* 404 Page not found * 404 Page not found
*/ */

View File

@ -255,7 +255,10 @@ class Dev {
"css/pages/passwordForgotten/mailAdmin.css", "css/pages/passwordForgotten/mailAdmin.css",
//Password reset page //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 //Virtual directory page
"js/pages/virtualDirectory/page.js", "js/pages/virtualDirectory/page.js",
//Search page
"js/pages/search/main.js",
//Create shortcuts for common functions //Create shortcuts for common functions
"js/common/shorcuts.js", "js/common/shorcuts.js",
"js/common/helpers.js", "js/common/helpers.js",