Send a request to the server to create the group

This commit is contained in:
Pierre HUBERT
2018-07-02 08:42:55 +02:00
parent 7ff7bceca3
commit 28cb1e22e7
6 changed files with 197 additions and 25 deletions

View File

@ -0,0 +1,89 @@
/**
* Create a group page
*
* @author Pierre HUBERT
*/
ComunicWeb.pages.groups.pages.create = {
/**
* Open the page
*
* @param {HTMLElement} target The target of the page
*/
open: function(target){
//Update page title
document.title = "Create a group";
//Create page container
var pageContainer = createElem2({
appendTo: target,
type: "div",
class: "create-group-page"
});
//Form container
var formContainer = createElem2({
appendTo: pageContainer,
type: "form",
});
//Form title
createElem2({
appendTo: formContainer,
type: "h3",
innerHTML: "Create a group"
})
//Group name input
var nameInput = createFormGroup({
target: formContainer,
label: "Group name",
placeholder: "The name of the group",
type: "text"
});
//Add submit button
var submitContainer = createElem2({
appendTo: formContainer,
type: "div",
class: "submit-button-container"
});
createElem2({
appendTo: submitContainer,
type: "input",
elemType: "submit",
class: "btn btn-primary",
value: "Create"
});
//Handle form submit
formContainer.onsubmit = function(){
//Check user inputs
if(!ComunicWeb.common.formChecker.checkInput(nameInput, true)){
notify("Please specify the name of the group!", "danger");
return false;
}
//Perform a request on the server to create the group
ComunicWeb.components.groups.interface.create(nameInput.value, function(res){
//Check for errors
if(res.error){
return notify("An error occured while trying to create the group!", "danger");
}
//Redirect to the group page
openPage("groups/" + res.id);
});
//Prevent default behavior
return false;
}
}
};