From b7eb77b928c6045f36fac9c104b8008226aaa09f Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 5 Jun 2017 11:34:43 +0200 Subject: [PATCH] Added checkbox for following discussion --- assets/js/common/utils.js | 48 +++++++++++++++++++----- assets/js/components/discussions/list.js | 12 +++++- corePage/config/dev.config.php | 1 + 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/assets/js/common/utils.js b/assets/js/common/utils.js index bd84c695..6a20d989 100644 --- a/assets/js/common/utils.js +++ b/assets/js/common/utils.js @@ -67,7 +67,8 @@ function checkMail(emailAddress){ * * @param {HTMLElement} target The target of the field * @param {String} label The label of the field - * @param {String} placeholder The placeholder of the field + * @param {String} placeholder The placeholder of the field (for checkbox: + * defines if the box has to be checked by default) * @param {String} type The type of the field * @return {HTMLElement} The input */ @@ -78,17 +79,46 @@ function createFormGroup(target, label, placeholder, type){ //Add label var labelElem = createElem("label", formGroup); - labelElem.innerHTML = label; - //Create input group - var inputGroup = createElem("div", formGroup); - inputGroup.className = "input-group"; + //Treatement differs if it is a checkbox + if(type == "checkbox"){ - //Create input - var input = createElem("input", inputGroup); - input.type = type; - input.placeholder = placeholder; + //Create checkbox + var input = createElem("input", labelElem) ; + input.type = "checkbox"; + //Check if input has to be checked by default + if(placeholder){ + if(placeholder === "true"){ + input.checked = "true"; + } + } + + //Add label value + var labelValue = createElem("span", labelElem); + labelValue.innerHTML = " "+label; + + //Enable iCheck + $(input).iCheck({ + checkboxClass: 'icheckbox_flat-blue', + radioClass: 'iradio_flat-blue' + }); + } + else { + //Else continue the function as a normal input type + labelElem.innerHTML = label; + + //Create input group + var inputGroup = createElem("div", formGroup); + inputGroup.className = "input-group"; + inputGroup.style.width = "100%"; + + //Create input + var input = createElem("input", inputGroup); + input.className = "form-control"; + input.type = type; + input.placeholder = placeholder; + } //Return input return input; diff --git a/assets/js/components/discussions/list.js b/assets/js/components/discussions/list.js index a64a3aa7..e334a00e 100644 --- a/assets/js/components/discussions/list.js +++ b/assets/js/components/discussions/list.js @@ -69,7 +69,17 @@ ComunicWeb.components.discussions.list = { var createForm = createElem("div", listBox.boxBody); //Discussion name - var discussionNameInput = createFormGroup() + var discussionNameInput = createFormGroup(createForm, "Discussion name", "Optionnal", "text"); + + //Follow disucssion + var followDiscussionInput = createFormGroup(createForm, "Follow discussion", "true", "checkbox"); + + + //Create button + var createButton = createElem("butto", createForm); + createButton.className = "btn btn-primary"; + createButton.style.width = "100%"; + createButton.innerHTML = "Create discussion"; //Success return true; diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index 362e395a..1069b2e7 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -15,6 +15,7 @@ $config['CSSfiles'] = array( "%PATH_ASSETS%3rdparty/adminLTE/plugins/font-awesome/css/font-awesome.min.css", "%PATH_ASSETS%3rdparty/adminLTE/plugins/ionicons/css/ionicons.min.css", "%PATH_ASSETS%3rdparty/adminLTE/plugins/iCheck/square/blue.css", + "%PATH_ASSETS%3rdparty/adminLTE/plugins/iCheck/flat/blue.css", "%PATH_ASSETS%3rdparty/adminLTE/dist/css/AdminLTE.min.css", "%PATH_ASSETS%3rdparty/adminLTE/dist/css/skins/_all-skins.min.css",