//====== CREATE FORM TEMPLATE END FROM PREDEFINED JSON - END =============================================// var smartwiz = {}; smartwiz.masteroptionarray = []; //=========== CREATE CUSTOM FORM TEMPLATE WITH USER INPUT - START ========================================// smartwiz.createCustomFormTemplate = function() { if (isLogined() == true) { $.unblockUI(); var ishasWorkflow = false; var isSaveTemplate = false; // $('.workflowtab').hide(); $('.hasworkflow').hide(); $('#saveTemplateInput').hide(); $('.noworkflow').show(); var themeColor_prog = "dark-blue"; var themeColor_comm = "dark-blue"; var userObj = getLocalStorage("rtmProUserObject"); var username = userObj.firstname + " " + userObj.lastname; $('.username').text(username); var userprofile = userObj.email + " (" + userObj.userrole + ")"; $('.userprofile').text(userprofile); var editTemplatemode = getLocalStorage("editTemplatemode"); var selectedtemplateJson = JSON.parse(getLocalStorage("templateJson")); var dependentdataElementarr = []; var dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; getMenuByRole(userObj.userrole); // Program Theme // $('#selectedTheme').addClass('badge-' + themeColor_prog); // $('#selectedTheme').data('color', themeColor_prog); $(document).on('click', '.theme_pic', function() { themeColor_prog = $(this).data("color"); console.log(themeColor_prog); $('.program_theme').find('.theme_pic').removeClass('active'); $(this).addClass('active'); // $('#selectedTheme').removeClass(); // $('#selectedTheme').addClass('badge-' + themeColor_prog); // $('#selectedTheme').data('color', themeColor_prog); // $('#chooseThemeModal').modal('hide'); }); // COmmunity Theme $('#selectedTheme_comm').addClass('badge-' + themeColor_comm); $('#selectedTheme_comm').data('color', themeColor_comm); $(document).on('click', '.theme_pic_comm', function() { themeColor_comm = $(this).data("color"); $('.community_theme').find('.theme_pic_comm').removeClass('active'); $(this).addClass('active'); console.log(themeColor_comm); // $('#selectedTheme_comm').removeClass(); // $('#selectedTheme_comm').addClass('badge-' + themeColor_comm); // $('#selectedTheme_comm').data('color', themeColor_comm); // $('#chooseThemeModal_Comm').modal('hide'); }); if (editTemplatemode == "true") { /////////////////////////////////// NEW APPLICATION EDIT FLOW ///////////////////////////////////// console.log(selectedtemplateJson); var masterObject = {}; //FINAL MASTER OBJECT //===== LEVEL 1 =====// var templateObject = {}; var adminObject = {}; var applicationArray = []; var applicationObject = {}; // ////////////////////////////////////////// DEFINING CLIENT/////////////////////// //===== LEVEL 2 =====// var trackedentityattributesArray = []; var attributedependentquestions = []; if (!_.isEmpty(selectedtemplateJson.application[0].attributedependentquestions)) { attributedependentquestions = selectedtemplateJson.application[0].attributedependentquestions; } else { attributedependentquestions = []; } trackedentityattributesArray = selectedtemplateJson.application[0].trackedentityattributes; var UIC = ""; //==== add default attribute for UIC===// // var fname = { // "name": "firstname", // "type": "text", // "mandatory": "true" // }; // var lname = { // "name": "lastname", // "type": "text", // "mandatory": "true" // }; // var dob = { // "name": "dob", // "type": "date", // "mandatory": "true" // }; // uicArray = [{ // "attributename": "First Name", // "type": "text", // "format": "3", // "sequence": "1" // }, // { // "attributename": "Last Name", // "type": "text", // "format": "2", // "sequence": "2" // }, // { // "attributename": "Date of Birth", // "type": "date", // "format": "ddmm", // "sequence": "3" // } // ]; var temoUICArray = []; // trackedentityattributesArray.push(fname); // trackedentityattributesArray.push(lname); // trackedentityattributesArray.push(dob); // end add default attribute for UIC===// var programsArray = []; var programsObj = {}; var communitiesArray = []; var communitiesObj = {}; var uicObj = {}; var referencesObj = {}; var optionsArray = []; var CheckArray = []; var dependentquestionsObj = {}; var programStagesArray = []; var communitiesStagesArray = []; $("#ulAttrName").html(''); $("#ulMandatoryList").html(''); // FILLING ATTRIBITES $.each(trackedentityattributesArray, function(key, val) { $("#ulAttrName").append('
  • '); if (val.mandatory == "true") { $("#ulMandatoryList").append('
  • '); } else { $("#ulMandatoryList").append('
  • '); } }) // FILLING UIC ARRAY temoUICArray = selectedtemplateJson.application[0].uic; if (temoUICArray.length > 0) { $("#addUICoption").attr('checked', true); $('#editUIC').removeClass('hidden'); } else { $("#addUICoption").attr('checked', false); $('#editUIC').addClass('hidden'); } // IS RELATIONSHIP ENABLED if (selectedtemplateJson.application[0].programs[0].hasrelationshiptype == "true") { $("#enablerelation").attr('checked', true); } else { $("#enablerelation").attr('checked', false); } if (selectedtemplateJson.application[0].programs.length > 0) { // IS REFERRAL ENABLED if (selectedtemplateJson.application[0].programs[0].hasexternalreferral == "yes") { $("#hasextreferralEnabled_prg").attr('checked', true); } else { $("#hasextreferralEnabled_prg").attr('checked', false); } // IS CHAT ENABLED PROGRAM if (selectedtemplateJson.application[0].programs[0].haschat == "true") { $("#haschatEnabled_prg").attr('checked', true); } else { $("#haschatEnabled_prg").attr('checked', false); } } // IS CHAT ENABLED COMMUNITY if (selectedtemplateJson.application[0].communities.length > 0) { if (selectedtemplateJson.application[0].communities[0].haschat == "true") { $("#haschatEnabled_comm").attr('checked', true); } else { $("#haschatEnabled_comm").attr('checked', false); } } //==================================================================================================================== //SET PROGRAM NAME IN WIZARD FROM DATA ENTERED IN HOME PAGE var appinfo = getLocalStorage("AppInfo"); // $("#communitySection").hide(); ---commented for new flow // ENABLE DISABLE PROGRAM/COMMUNITY $("#communityAssocChk").on("click", function() { if ($('#communityAssocChk').is(":checked") == true) { $("#communitySection").show(); $(".commDataSection").find("*").prop("disabled", false); $('#programAssocChk').prop("disabled", false); $('.wrkfl').text("Define Workflow and Content"); $('.contentManagement').show(); } else { $("#communitySection").hide(); $(".commDataSection").find("*").prop("disabled", true); $(".commDataSection").find("*").removeClass("has-error"); $('#programAssocChk').prop("disabled", true); $('.wrkfl').text("Define Workflow"); $('.contentManagement').hide(); } }); $("#programAssocChk").on("click", function() { if ($('#programAssocChk').is(":checked") == true) { $("#programSection").show(); $(".progDataSection").find("*").prop("disabled", false); $(".workflowSection").show(); $('#communityAssocChk').prop("disabled", false); $('.wrkfl').text("Define Workflow and Content"); $('.contentManagement').show(); } else { $("#programSection").hide(); $(".progDataSection").find("*").prop("disabled", true); $(".progDataSection").find("*").removeClass("has-error"); $(".workflowSection").hide(); $('#communityAssocChk').prop("disabled", true); $('.wrkfl').text("Define Content"); $('.contentManagement').show(); } }); //END $("#btn_addAttribute").on("click", function() { console.log("Add Attribute"); $("#addNewAttributeModal").modal('show'); $("#add_NewAttribute")[0].reset(); $("#option_section_addatribute").addClass('hidden'); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) // ATTRIBUTE DEPENDENCY LEVEL $('.level_1_attr_dependencylist').html(''); $(".level_1_attributeDependency").addClass('hidden'); $(".level_2_attributeDependency").addClass('hidden'); $("#add_NewAttribute :input").prop("disabled", false); $('#add_NewAttribute')[0].reset(); dependentdataattrArr = []; dataattrDepenentObj = {}; dataattrDepenentObj.attributedependentquestions = []; $(".btn_Add_Dependency_attr_Level_1").off("click"); $(".btn_Add_Dependency_attr_Level_1").on("click", function() { var isDuplicateParentAttr = false; var parentattrname = $('#attrName').val(); isDuplicateParentAttr = isDuplicateAttribute(parentattrname, trackedentityattributesArray); if (!isDuplicateParentAttr) { $('#add_NewAttribute_level_1')[0].reset(); $("#option_section_addatribute_level_1").addClass('hidden'); var isvalidDepencyAttrAdd = false; var mandatoryChk = $("input[name='radioMandatory']:checked").val(); var typeOfAttr = $("#selType").val(); if (_.isEmpty(parentattrname) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfAttr)) { isvalidDepencyAttrAdd = false; } else { isvalidDepencyAttrAdd = true; } if (isvalidDepencyAttrAdd == true) { var matchval = ""; if (typeOfAttr == "optionlist") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOptionAttr option:selected").val(); $("#add_NewAttribute :input").prop("disabled", true); $(".level_1_attributeDependency").removeClass('hidden'); $("#add_NewAttribute_level_1 :input").prop("disabled", false); $("#matchval_attr_options_level_1").removeClass('hidden'); $("#matchval_attr_txt_level_1").addClass('hidden'); $('#matchval_attr_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_attr_options_level_1").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if (typeOfAttr == "number") { $("#matchval_attr_txt_level_1").removeClass('hidden'); $("#matchval_attr_options_level_1").addClass('hidden'); $("#add_NewAttribute :input").prop("disabled", true); $("#add_NewAttribute_level_1 :input").prop("disabled", false); $(".level_1_attributeDependency").removeClass('hidden'); } else if (typeOfAttr == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#matchval_attr_txt_level_1").removeClass('hidden'); $("#matchval_attr_options_level_1").addClass('hidden'); $("#add_NewAttribute :input").prop("disabled", true); $("#add_NewAttribute_level_1 :input").prop("disabled", false); $(".level_1_attributeDependency").removeClass('hidden'); } $('#parentAtribute_level_1').text(parentattrname); $("#addNewAttributeModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - ATTRIBUTE ============================// $(".btn_AddOptionListQuestionProgram_level_1").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); $('.optValueProgram').val(''); $('.newAppend').remove(); }); // ADD DEPENDENT ATTRIBUTE $(".btn_submit_AddAttribute_level_1").off("click"); $(".btn_submit_AddAttribute_level_1").on("click", function() { if (typeOfAttr == "optionlist") { matchval = $("#matchval_attr_options_level_1 option:selected").val(); var selectedOptions = $("#TypeofOptionAttr option:selected").val(); dltype = "option"; typename = selectedOptions; } else if (typeOfAttr == "number") { matchval = $('#matchval_attr_txt_level_1').val(); dltype = "number"; typename = parentattrname; } else if (typeOfAttr == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#matchval_attr_txt_level_1').val(); dltype = "text"; typename = parentattrname; } var dependentattr = $("#attrName_level_1").val(); var deptypeOfAttr = $("#selType_level_1 option:selected").val(); var dependentattrmand = $("input[name='radioMandatory_level_1']:checked").val(); var depttypeOfAttrOption = $("#TypeofOptionAttr_level_1 option:selected").val(); var isDlAvailable = false; var attributeObj = {}; attributeObj.name = dependentattr; var flag = false; if (deptypeOfAttr == "optionlist") { if (_.isEmpty(depttypeOfAttrOption)) { flag = true; } else { attributeObj.type = "text"; attributeObj.optionname = depttypeOfAttrOption; } } else { attributeObj.type = deptypeOfAttr; } attributeObj.mandatory = dependentattrmand; if (_.isEmpty(dependentattr) == false && _.isEmpty(matchval) == false && _.isEmpty(dependentattrmand) == false && flag == false) { if (isValidEntry(dependentattr) == true) { var childel = { childdataelementname: dependentattr } var pardependentattr = { dataelementname: parentattrname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } var tempquestionlist = []; tempquestionlist.push(parentattrname); isDlAvailable = isDuplicateAttrwithDependency(dependentattr, tempquestionlist, trackedentityattributesArray, dependentdataattrArr); if (!isDlAvailable) { if (dataattrDepenentObj.attributedependentquestions.length > 0) { var isavailable = _(dataattrDepenentObj.attributedependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == parentattrname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataattrDepenentObj.attributedependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == parentattrname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentattr.dependentdataelementnames.push(childel); dataattrDepenentObj.attributedependentquestions.push(pardependentattr); } } else { pardependentattr.dependentdataelementnames.push(childel); dataattrDepenentObj.attributedependentquestions.push(pardependentattr); } console.log(dataattrDepenentObj); attributeObj.level = 'Level-1'; dependentdataattrArr.push(attributeObj); console.log(dependentdataattrArr); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + dependentattr + "
    "; $('.level_1_attr_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_attributeDependency").addClass('hidden'); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Attribute Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Attribute name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); $(".btn_close_attr_level_1").on("click", function() { $(".level_1_attributeDependency").addClass('hidden'); $("#add_NewAttribute :input").prop("disabled", false); }); // type of option change $("#selType_level_1").on("change", function() { if ($(this).val() == "optionlist") { $("#option_section_addatribute_level_1").removeClass('hidden'); } else { $("#option_section_addatribute_level_1").addClass('hidden'); } }); }); // ADD RELATIONSHIP $("#enablerelation").on("click", function() { if ($('#enablerelation').is(":checked") == true) { $("#btn_addAttribute").click(); $("#attrName").val("Client Type"); $("#attrName").attr("disabled", "disabled"); } else { swal({ title: 'Are you sure?', text: "Deletion of attribute will remove all dependencies.", type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) // cleanup console.log(trackedentityattributesArray); for (let i in trackedentityattributesArray) { if (trackedentityattributesArray[i].name == "Client Type") { trackedentityattributesArray.splice(i, 1); } else {} } // REMOVE DEPENDENT QUESTIONS var allchilds = []; for (let i in attributedependentquestions) { if (attributedependentquestions[i].dataelementname == "Client Type") { attributedependentquestions.splice(i, 1); } else {} } console.log(allchilds); $("#ulAttrName").html(''); $("#ulMandatoryList").html(''); $.each(trackedentityattributesArray, function(key, val) { $("#ulAttrName").append('
  • '); if (val.mandatory == "true") { $("#ulMandatoryList").append('
  • '); } else { $("#ulMandatoryList").append('
  • '); } }) }) } }); // ADD UIC MODAL WITH DYNAMIC DATA POPULATION IN DROPDOWN $('#id_MobileNumber').attr('disabled', 'disabled'); $("#addUICoption").on("click", function() { // var uicAttrArry = []; if ($('#addUICoption').is(":checked") == true) { console.log("generate uic modal"); $("#genUICmodal").modal('show'); // $("#selAttrType").prop('selectedIndex', 0); // $("#selDateFormat").prop('selectedIndex', 0); $("#inpFormat").val(''); // $("#inpSequence").val(''); UIC = ''; console.log(trackedentityattributesArray); /* add default options to attribute select */ var attrOption = ''; $('#selAttribute').html(''); $('#selAttribute').children('option:not(:first)').remove(); for (var i = 0; i < trackedentityattributesArray.length; i++) { if (trackedentityattributesArray[i].mandatory == 'true') { attrOption += ''; UIC += trackedentityattributesArray[i].name; } } $('#selAttribute').append(attrOption); // remove options from select attribute which are already added in UIC attribute for (let j in temoUICArray) { $("#selAttribute option[value='" + temoUICArray[j].attributename + "']").remove(); } if ($("#selAttribute option:selected").data('type') == "date") { $('#selDateFormat').removeClass('hidden'); $('#inpFormat').hide(); } else { $('#inpFormat').show(); $('#selDateFormat').addClass('hidden'); } // generate UIC atribute table if there is any data already added $('#uicAttrTable > tbody').html(''); if (temoUICArray.length > 0) { for (let k in temoUICArray) { var attrRow = "" + temoUICArray[k].attributename + "" + "" + temoUICArray[k].type + "" + "" + temoUICArray[k].format + "" + "" + "" + "clear" + ""; $('#uicAttrTable > tbody').append(attrRow); } } else { } $('#editUIC').removeClass('hidden'); } else { temoUICArray = []; $('#editUIC').addClass('hidden'); } }); $("#selType").on("change", function() { if ($("#selType").val() == "optionlist") { $("#option_section_addatribute").removeClass('hidden'); } else { $("#option_section_addatribute").addClass('hidden'); } }); //=======ADD UIC ATTRIBUTE BUTTON=========================== $(".btn_addAtriforUIC").on("click", function() { var attrformat = ""; if ($("#selAttribute option:selected").data('type') == "date") { attrformat = $('#selDateFormat').val(); } else { attrformat = $('#inpFormat').val(); } if ($("#selAttribute").val() != null && attrformat != "") { $.each(trackedentityattributesArray, function(key, value) { if (value.name == $("#selAttribute").val()) { // temoUICArray.push(trackedentityattributesArray[key]); // var attrdata= _.filter(trackedentityattributesArray, function(item){ return item.name == value.name; }); var uicarr = { "attributename": value.name, "type": value.type, "format": attrformat // "uicode": temcrop }; temoUICArray.push(uicarr); console.log(temoUICArray); } }); $('#uicAttrTable > tbody').html(""); $.each(temoUICArray, function(key, value) { var attrRow = "" + value.attributename + "" + "" + value.type + "" + "" + value.format + "" + "" + "" + "clear" + ""; $('#uicAttrTable > tbody').append(attrRow); }); $("#selAttribute option[value='" + $("#selAttribute").val() + "']").remove(); $("#selAttribute").prop('selectedIndex', 0); // $("#selAttrType").prop('selectedIndex', 0); $("#selDateFormat").prop('selectedIndex', 0); $("#inpFormat").val(''); // $("#inpSequence").val(''); $('.warningmsg').addClass('hidden'); if ($("#selAttribute option:selected").data('type') == "date") { $('#selDateFormat').removeClass('hidden'); $('#inpFormat').hide(); } else { $('#inpFormat').show(); $('#selDateFormat').addClass('hidden'); } $.each(temoUICArray, function(key, val) { temoUICArray[key].sequence = '' + (key + 1) + ''; }); console.log('attribute addd'); console.log(temoUICArray); } else { // $('.warningmsg').removeClass('hidden'); bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } // $(".removeme").attr("onclick", "removeme()"); }); $("#selAttribute").change(function() { if ($("#selAttribute option:selected").data('type') == "date") { $('#selDateFormat').removeClass('hidden'); $('#inpFormat').hide(); } else { $('#selDateFormat').addClass('hidden'); $('#inpFormat').show(); } }); $('.close').on("click", function() {}); // REMOVE ROW ITEM $(document).on('click', '.removeRow', function() { $(this).parent().parent().remove(); var optionadd = $(this).closest('tr').children('td:first').text(); var optiontype = $(this).closest('tr').children('td:nth-child(2)').text(); var attrOption = ''; $('#selAttribute').append(attrOption); for (let j in temoUICArray) { if (temoUICArray[j].attributename == optionadd) { temoUICArray.splice(j, 1); } } if ($("#selAttribute option:selected").data('type') == "date") { $('#selDateFormat').removeClass('hidden'); $('#inpFormat').hide(); } else { $('#inpFormat').show(); $('#selDateFormat').addClass('hidden'); } console.log('------------------------'); console.log(temoUICArray); console.log('------------------------'); }); // EDIT UIC $("#editUIC").on("click", function() { $("#genUICmodal").modal('show'); $('#selAttribute').html(''); var attrOption = ''; for (var i = 0; i < trackedentityattributesArray.length; i++) { if (trackedentityattributesArray[i].mandatory == 'true') { attrOption += ''; UIC += trackedentityattributesArray[i].name; } } $('#selAttribute').append(attrOption); // POPULATE UIC TABLE $('#uicAttrTable > tbody').html(""); $.each(temoUICArray, function(key, value) { var attrRow = "" + value.attributename + "" + "" + value.type + "" + "" + value.format + "" + "" + "" + "clear" + ""; $('#uicAttrTable > tbody').append(attrRow); }); // remove options from select attribute which are already added in UIC attribute for (let j in temoUICArray) { $("#selAttribute option[value='" + temoUICArray[j].attributename + "']").remove(); } }); // TABLE ROW MOVE UP AND DOWN $(document).on('click', '#uicAttrTable img.move', function() { var row = $(this).closest('tr'); // var srow = $(this).parent().parent().children().index(row); // alert($(this).attr("value")); var attrnam = $(this).attr("value"); var rownum = row.index(); if ($(this).hasClass('up')) { row.prev().before(row); // temoUICArray[$(this).val()].sequence = '' + row.index() + ''; } else { row.next().after(row); // temoUICArray[$(this).val()].sequence = '' + row.index() + ''; } // sequencing the array as per table row var rows = $("#uicAttrTable>tbody>tr"); $.each(rows, function(key, val) { console.log(key); // alert($(rows[key]).find("td:nth-child(1)").html()); var tdval = $(rows[key]).find("td:nth-child(1)").html(); $.each(temoUICArray, function(key1, val) { if (temoUICArray[key1].attributename == tdval) { temoUICArray[key1].sequence = '' + (parseInt(key) + 1) + ''; } }); }); // $.each(temoUICArray, function(key, val) { // if (temoUICArray[key].attributename == attrnam) { // temoUICArray[rownum].sequence = '' + rownum + ''; // } // }); console.log(temoUICArray); }); //END $(".btn_GenUICode").on("click", function() { // $('#uicAttrTable tbody').each(function() { // alert($(this).find("tr").index()); // }); // $.each(temoUICArray, function(key, val) { // temoUICArray[key].sequence = '' + (key + 1) + ''; // }); // console.log(temoUICArray); }); //=======End ADD UIC ATTRIBUTE BUTTON======================= //=======ADD ATTRIBUTE BUTTON=========================== var deletedAttribute = []; $(document).on('click', 'input.checkAttribute', function() { var sThisVal = $(this).val(); if ($(this).is(':checked')) { for (let i in deletedAttribute) { if (deletedAttribute[i].name == sThisVal) { trackedentityattributesArray.push(deletedAttribute[i]); deletedAttribute.splice(i, 1); } else { } } } else { $("#idMand_" + sThisVal.replace(/ /g, '')).prop('checked', false); if ($("#addUICoption").is(':checked')) { $("#addUICoption").click(); temoUICArray = []; } for (let i in trackedentityattributesArray) { if (trackedentityattributesArray[i].name == sThisVal) { trackedentityattributesArray[i].mandatory = "false"; deletedAttribute.push(trackedentityattributesArray[i]); trackedentityattributesArray.splice(i, 1); // trackedentityattributesArray[i].mandatory = "false"; } else { } } } console.log('-----------------------'); console.log(trackedentityattributesArray); console.log(deletedAttribute); console.log(temoUICArray); console.log('-------------------------'); }); $(document).on('click', 'input.checkAttributemand', function() { var sThisVal = $(this).val(); if ($(this).is(':checked')) { // $("#id_"+sThisVal). for (let i in trackedentityattributesArray) { if (trackedentityattributesArray[i].name == sThisVal) { trackedentityattributesArray[i].mandatory = "true"; } else { } } } else { for (let i in trackedentityattributesArray) { if (trackedentityattributesArray[i].name == sThisVal) { trackedentityattributesArray[i].mandatory = "false"; } else { } } } console.log('-----------------------'); console.log(trackedentityattributesArray); console.log('-------------------------'); }); //SUBMIT ADDRIBUTE $(".btn_submit_AddAttribute").on("click", function() { var attrname = $("#attrName").val(); var selname = $("#selType").val(); var mandatoryVal = $("input[name='radioMandatory']:checked").val(); var attributeObj = {}; attributeObj.name = $("#attrName").val(); var flag = false; if ($("#selType").val() == "optionlist") { if (_.isEmpty($('#TypeofOptionAttr').val())) { flag = true; } else { attributeObj.type = "text"; attributeObj.optionname = $('#TypeofOptionAttr').val(); } } else { attributeObj.type = $("#selType").val(); } // alert(attributeObj.optionname); // alert(attributeObj.optionname); if (_.isEmpty(attrname) == false && _.isEmpty(selname) == false && _.isEmpty(mandatoryVal) == false && flag == false) { if (isValidEntry(attrname) == true) { attributeObj.mandatory = $("input[name='radioMandatory']:checked").val(); var isDlAvailable = false; var tempquestionlist = []; var tempdependentdataattrArr = []; isDlAvailable = isDuplicateAttrwithDependency(attrname, tempquestionlist, trackedentityattributesArray, tempdependentdataattrArr); if (!isDlAvailable) { trackedentityattributesArray.push(attributeObj); dependentdataElementarr = cleanChildObj(dependentdataattrArr); trackedentityattributesArray = trackedentityattributesArray.concat(dependentdataattrArr); if (_.isEmpty(dataattrDepenentObj.attributedependentquestions) == false) { // $.each(trackedentityattributesArray, function(i, e) { // if (dataattrDepenentObj.attributedependentquestions[0].dataelementname == e.name) { // if (_.isUndefined(e.attributedependentquestions)) { // e.attributedependentquestions = []; // e.attributedependentquestions = e.attributedependentquestions.concat(dataattrDepenentObj.attributedependentquestions); // } else { // e.attributedependentquestions = e.attributedependentquestions.concat(dataattrDepenentObj.attributedependentquestions); // } // } // }); attributedependentquestions = attributedependentquestions.concat(dataattrDepenentObj.attributedependentquestions); } console.log(trackedentityattributesArray); console.log(attributedependentquestions); $("#addNewAttributeModal").modal('hide'); // add_NewAttribute $(this).closest('form').find("input[type=text],input[type=number], textarea").val(""); $("#ulAttrName").html(''); $("#ulMandatoryList").html(''); $.each(trackedentityattributesArray, function(key, val) { $("#ulAttrName").append('
  • '); if (val.mandatory == "true") { $("#ulMandatoryList").append('
  • '); } else { $("#ulMandatoryList").append('
  • '); } }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Attribute Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Attribute name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); // END DEFINING CLIENT //////////////////////// DEFINE PROGRAM AND COMMUNITY SECTION // SET TEMPLATE DATA if (_.isEmpty(selectedtemplateJson.application[0].communities)) { $('#communityAssocChk').prop("checked", false); $('.definecomm').hide(); $("#communitySection").hide(); } else { communitiesObj = selectedtemplateJson.application[0].communities[0]; $('#communityAssocChk').prop("checked", true); $('.definecomm').show(); $("#communitySection").show(); $('#communityName').val(communitiesObj.name + "_" + randomid()); $('#communitydescr').val(communitiesObj.description); $('#iconviecom').attr("src", "" + communitiesObj.logo); $('#comIcon').val(getLocalStorage("comicon")); themeColor_comm = selectedtemplateJson.application[0].communities[0].theme; } if (_.isEmpty(selectedtemplateJson.application[0].programs)) { $('#programAssocChk').prop("checked", false); $('.defineprog').hide(); $("#programSection").hide(); $(".workflowSection").hide(); $('.wrkfl').text("Define Content"); } else { programsObj = selectedtemplateJson.application[0].programs[0]; $('#programName').val(programsObj.name + "_" + randomid()); $('#programdescr').val(programsObj.description); $('#programAssocChk').prop("checked", true); $('#iconviewpgm').attr("src", "" + programsObj.logo); $('#pgmIcon').val(getLocalStorage("pgmicon")); themeColor_prog = selectedtemplateJson.application[0].programs[0].theme; $("#programSection").show(); $(".workflowSection").show(); $('.wrkfl').text("Define Workflow and Content"); } if (_.isEmpty(themeColor_prog) && _.isEmpty(themeColor_comm)) { themeColor_prog = "dark-blue"; themeColor_comm = "dark-blue"; } $('.community_theme').find('.theme_pic_comm').removeClass('active'); $('.program_theme').find('.theme_pic').removeClass('active'); $('.program_theme').find('.badge-' + themeColor_prog).addClass('active'); $('.community_theme').find('.badge-' + themeColor_comm).addClass('active'); // $('#selectedTheme').removeClass(); // $('#selectedTheme').addClass('badge-' + themeColor_prog); // $('#selectedTheme').data('color', themeColor_prog); // $('#selectedTheme_comm').removeClass(); // $('#selectedTheme_comm').addClass('badge-' + themeColor_comm); // $('#selectedTheme_comm').data('color', themeColor_comm); // // if it has workflow // if (programsObj.hasworkflow == "yes") { // $('#hasWorkflow').click(); // // $('.workflowtab').show(); // $('.hasworkflow').show(); // $('.noworkflow').hide(); // ishasWorkflow = true; // } else { // // $('.workflowtab').hide(); // ishasWorkflow = false; // $('.hasworkflow').hide(); // $('.noworkflow').show(); // } // set program icon $("#pgmIcon").on('focus', function(evt) { $('#imgsectionPGM').html(''); $('#choosePgmIconModal').modal('show'); generateICONView("assets/img/appIcon/", "imgsectionPGM", "pgmicons"); }); // icon select click $(document).on('click', '.pgmicons', function() { //alert($(this).attr("src")); $('#pgmIcon').val($(this).attr("src")); $('#iconviewpgm').attr("src", "" + $('#pgmIcon').val()); setLocalStorage("pgmicon", $('#pgmIcon').val()); $('#choosePgmIconModal').modal('hide'); }); //// COMMUNITY ICONS SECTION // WORKFLOW $("#hasWorkflow").on("click", function() { if ($("#hasWorkflow").is(':checked')) { ishasWorkflow = true; // $('.workflowtab').show(); $('.hasworkflow').show(); $('.noworkflow').hide(); } else { ishasWorkflow = false; // $('.workflowtab').hide(); $('.hasworkflow').hide(); $('.noworkflow').show(); } }) // browse icon $("#comIcon").on('focus', function(evt) { $('#imgsectioncom').html(''); $('#chooseCommIconModal').modal('show'); generateICONView("assets/img/appIcon/", "imgsectioncom", "comicons"); }); // icon select click $(document).on('click', '.comicons', function() { //alert($(this).attr("src")); $('#comIcon').val($(this).attr("src")); $('#iconviecom').attr("src", "" + $('#comIcon').val()); setLocalStorage("comicon", $('#comIcon').val()); $('#chooseCommIconModal').modal('hide'); }); // END DEFINE PROGRAM AND COMMUNITY SECTION //////////////////////// DEFINE SERVICES SECTION /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //==========PROGRAM SERVICE================================= $(".btn_ProgramAddService").on("click", function() { $("#addNewProgramServiceModal").modal("show"); }); //=============== ADD NEW SERVICE - PROGRAM ========================// var serviceName; if (_.isEmpty(selectedtemplateJson.application[0].programs)) { programStagesArray = []; } else { programStagesArray = selectedtemplateJson.application[0].programs[0].stages; } // PRE LOAD ALL THE DATA $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); //========= BUTTON TO SHOW QUESTIONS MODAL======== $(document).on('click', '.btn_ProgramAddQuestion', function() { $("#addNewProgramQuestionModal").modal("show"); $(".btn_Add_Dependency_Level_1").show(); $('.btn_edit_AddQuestionProgram').hide(); $('.btn_submit_AddQuestionProgram').show(); $("#option_section_program").hide(); $("#check_section_program").hide(); $("#TypeofQuest").prop('selectedIndex', 0); $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); var pgservname = $(this).data('stage-name'); $("#programservice").text(pgservname); $('.level_1_dependencylist').html(''); $(".level_1_dependency").addClass('hidden'); $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); $('#add_NewProgramQuestion')[0].reset(); $('#questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) //////DEPENDENCY //##################################################DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_1").off("click"); $(".btn_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#programservice").text(); var parentqname = $('#questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, programStagesArray); if (!isDuplicateParent) { $('#add_NewProgramQuestion_level_1')[0].reset(); $("#option_section_program_level_1").addClass('hidden'); $("#check_section_program_level_1").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory']:checked").val(); var typeOfQuestion = $("#TypeofQuest").val(); if (_.isEmpty($('#questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName').val()) == true) { $(".parent_action_btns_section :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption option:selected").val(); $("#add_NewProgramQuestion :input").prop("disabled", true); $(".level_1_dependency").removeClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_1").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "checkboxoption") { var options = $('#TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "number") { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName').val(); $('#pquestion_level_1').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level1").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_1").off("click"); $(".btn_submit_AddQuestionProgram_level_1").on("click", function() { if ($("#TypeofQuest").val() == "option list") { matchval = $("#matchval_options_level_1 option:selected").val(); var selectedOptions = $("#TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest").val() == "checkboxoption") { matchval = $('#matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest").val() == "number") { matchval = $('#matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_1").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_1").val(); var depttypeOfOption = $("#TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_1 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#questName_level_1").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_dependency").addClass('hidden'); $(".parent_action_btns_section :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_1").removeClass('hidden'); } else { $("#option_section_program_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_1").removeClass('hidden'); $("#TypeofOptionCheck_level_1").html(""); } else { $("#check_section_program_level_1").addClass('hidden'); } }); $(".btn_close_level_1").off("click"); $(".btn_close_level_1").on("click", function() { $(".level_1_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_2").off("click"); $(".btn_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#questName_level_1').val(); var parentqname = $('#questName').val(); tempquestionlist.push(parentqname); var parentservname = $("#programservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $('#add_NewProgramQuestion_level_2')[0].reset(); $("#option_section_program_level_2").addClass('hidden'); $("#check_section_program_level_2").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var typeOfQuestion = $("#TypeofQuest_level_1").val(); if (_.isEmpty($('#questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName_level_1').val()) == true) { $(".parent_child_1_action_btn :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_2").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "number") { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName_level_1').val(); $('#pquestion_level_2').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level2").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_2").off("click"); $(".btn_submit_AddQuestionProgram_level_2").on("click", function() { if ($("#TypeofQuest_level_1").val() == "option list") { matchval = $("#matchval_options_level_2 option:selected").val(); var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest_level_1").val() == "number") { matchval = $('#matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_2").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_2']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_2").val(); var depttypeOfOption = $("#TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_2 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; var qnameParent = $('#questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#questName_level_2").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency").addClass('hidden'); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_2").removeClass('hidden'); } else { $("#option_section_program_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_2").removeClass('hidden'); $("#TypeofOptionCheck_level_2").html(""); } else { $("#check_section_program_level_2").addClass('hidden'); } }); $(".btn_close_level_2").off("click"); $(".btn_close_level_2").on("click", function() { $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $('#questName').val(selectQuest); $("#programservice").text(stagename); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } }); $(".btn_edit_AddQuestionProgram").on("click", function() { console.log("Modify"); var selectQuest = $("#questName").val(); console.log(programStagesArray); $.each(programStagesArray, function(key1, val1) { $.each(programStagesArray[key1].dataelements, function(key2, val2) { if (programStagesArray[key1].dataelements[key2].name == selectQuest) { programStagesArray[key1].dataelements[key2].type = $('#TypeofQuest').val(); } }); }); $("#addNewProgramQuestionModal").modal("hide"); }); $(document).on('click', '.btn_Delete', function() { console.log("Delete"); var qesname = $(this).closest('tr').children('td:nth-child(2)').text(); console.log(qesname); var stagename = $(this).closest('table').data('stage-name'); var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { return item.dataelementname.replace(/ /g, '').toLowerCase() == qesname.replace(/ /g, '').toLowerCase() }); } }); var tempmsg = ""; if (!_.isEmpty(isPartOfParent)) { tempmsg = "Deletion of this question will reset all dependencies on this question."; } swal({ title: 'Are you sure?', text: tempmsg, type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) var dataelObjCombo = deleteDataElementWithAvailableChildonStage(stagename, qesname, programStagesArray); programStagesArray = dataelObjCombo; console.log(programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); }).catch(swal.noop) }); }); // FILL OPTIONS optionsArray = selectedtemplateJson.application[0].references.options; $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) // ADD NEW SERVICE $(".btn_submit_AddProgramService").on("click", function() { if (isValidEntry($('#servNameProgram').val()) == true) { $("#programservice").empty(); console.log("AddProgramService"); var programStage = {}; var dataelementsArray = []; if ($('.selectRoleForworkflowPGM').prop("checked") == true) { $('.selectRoleForworkflowPGM').click(); } serviceName = $("#servNameProgram").val(); // var serviceShortName = $("#servShrtNameProgram").val(); var serviceShortName = $("#servNameProgram").val(); //Set Short Name same as Service Name programsObj.name = programName; // programsObj.shortname = programShortName; programsObj.shortname = programName; //Program Short Name = Program Name (New Requirement) programsObj.logo = ""; programStage.name = serviceName; programStage.dataelements = dataelementsArray if (programStagesArray.length > 0) { var duplicatecheck = isDuplicateReord(programStagesArray, programStage); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Service Already Available with this name.", callback: function() { } }); } else { programStagesArray.push(programStage); $("#addNewProgramServiceModal").modal("hide"); } } else { programStagesArray.push(programStage); $("#addNewProgramServiceModal").modal("hide"); } setLocalStorage("programStageArray", programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); //========= BUTTON TO SHOW QUESTIONS MODAL======== $(document).on('click', '.btn_ProgramAddQuestion', function() { $("#addNewProgramQuestionModal").modal("show"); $(".btn_Add_Dependency_Level_1").show(); $('.btn_edit_AddQuestionProgram').hide(); $('.btn_submit_AddQuestionProgram').show(); var pgservname = $(this).data('stage-name'); $("#programservice").text(pgservname); $('.level_1_dependencylist').html(''); $(".level_1_dependency").addClass('hidden'); $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); $('#add_NewProgramQuestion')[0].reset(); $('#questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) //////DEPENDENCY //##################################################DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_1").off("click"); $(".btn_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#programservice").text(); var parentqname = $('#questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, programStagesArray); if (!isDuplicateParent) { $('#add_NewProgramQuestion_level_1')[0].reset(); $("#option_section_program_level_1").addClass('hidden'); $("#check_section_program_level_1").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory']:checked").val(); var typeOfQuestion = $("#TypeofQuest").val(); if (_.isEmpty($('#questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName').val()) == true) { $(".parent_action_btns_section :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption option:selected").val(); $("#add_NewProgramQuestion :input").prop("disabled", true); $(".level_1_dependency").removeClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_1").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "checkboxoption") { var options = $('#TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "number") { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName').val(); $('#pquestion_level_1').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level1").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_1").off("click"); $(".btn_submit_AddQuestionProgram_level_1").on("click", function() { if ($("#TypeofQuest").val() == "option list") { matchval = $("#matchval_options_level_1 option:selected").val(); var selectedOptions = $("#TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest").val() == "checkboxoption") { matchval = $('#matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest").val() == "number") { matchval = $('#matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_1").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_1").val(); var depttypeOfOption = $("#TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_1 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#questName_level_1").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_dependency").addClass('hidden'); $(".parent_action_btns_section :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_1").removeClass('hidden'); } else { $("#option_section_program_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_1").removeClass('hidden'); $("#TypeofOptionCheck_level_1").html(""); } else { $("#check_section_program_level_1").addClass('hidden'); } }); $(".btn_close_level_1").off("click"); $(".btn_close_level_1").on("click", function() { $(".level_1_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_2").off("click"); $(".btn_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#questName_level_1').val(); var parentqname = $('#questName').val(); tempquestionlist.push(parentqname); var parentservname = $("#programservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $('#add_NewProgramQuestion_level_2')[0].reset(); $("#option_section_program_level_2").addClass('hidden'); $("#check_section_program_level_2").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var typeOfQuestion = $("#TypeofQuest_level_1").val(); if (_.isEmpty($('#questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName_level_1').val()) == true) { $(".parent_child_1_action_btn :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_2").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "number") { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName_level_1').val(); $('#pquestion_level_2').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level2").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_2").off("click"); $(".btn_submit_AddQuestionProgram_level_2").on("click", function() { if ($("#TypeofQuest_level_1").val() == "option list") { matchval = $("#matchval_options_level_2 option:selected").val(); var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest_level_1").val() == "number") { matchval = $('#matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_2").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_2']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_2").val(); var depttypeOfOption = $("#TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_2 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; var qnameParent = $('#questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#questName_level_2").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency").addClass('hidden'); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_2").removeClass('hidden'); } else { $("#option_section_program_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_2").removeClass('hidden'); $("#TypeofOptionCheck_level_2").html(""); } else { $("#check_section_program_level_2").addClass('hidden'); } }); $(".btn_close_level_2").off("click"); $(".btn_close_level_2").on("click", function() { $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); }); $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter Valid Service Name", callback: function() { } }); } }) //================TYPE OF QUESTION DEPENDENCY=============================// $("#option_section_program").hide(); $("#check_section_program").hide(); $("#TypeofQuest").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program").show(); } else { $("#option_section_program").hide(); } if ($(this).val() == "checkboxoption") { $("#check_section_program").show(); $("#TypeofOptionCheck").html(""); } else { $("#check_section_program").hide(); } }); //================== ADD NEW QUESTION - PROGRAM =========================// $(".btn_submit_AddQuestionProgram").on("click", function() { console.log("AddQuestionProgram"); var dataElementObj = {}; serviceName = $("#programservice").text(); var oldquestion = $("#questName").data('old_name'); var questionName = $("#questName").val(); var isDuplicateFound = isDuplicateDataElement(serviceName, oldquestion, programStagesArray); if (!isDuplicateFound) { // var questionShortName = $("#questShrtName").val(); - Removed Question Short Name as per new Requirement var questionShortName = $("#questName").val(); var mandatoryChk = $("input[name='prgm_radioMandatory']:checked").val(); var typeOfQuestion = $("#TypeofQuest").val(); var typeOfOption = $("#TypeofOption").val(); var typeOfcheck = $("#TypeofOptionCheck").val(); //===HARDCODED OPTION LIST VALUE AS TEXT(REQUIRED BY SERVICE) var flagOption = false; if (typeOfQuestion == "option list") { typeOfQuestion = "text" if (typeOfOption != "" && typeOfOption != null) { dataElementObj.optionname = typeOfOption } else { flagOption = true; } } if (typeOfQuestion == "checkboxoption") { typeOfQuestion = "text" if (typeOfcheck != "" && typeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } if (questionName != "" && mandatoryChk != undefined && typeOfQuestion != "" && flagOption == false) { if (isValidEntry(questionName) == true) { var optiontext = $("#TypeofQuest option:selected").text(); if (optiontext == "Facility") { dataElementObj.facility = "true"; } dataElementObj.name = questionName dataElementObj.type = typeOfQuestion dataElementObj.mandatory = mandatoryChk $.each(programStagesArray, function(i, e) { console.log(e); if (e.name == serviceName) { console.log(e.dataelements); e.dataelements.push(dataElementObj); dependentdataElementarr = cleanChildObj(dependentdataElementarr); e.dataelements = e.dataelements.concat(dependentdataElementarr); if (_.isUndefined(e.dependentquestions)) { if (_.isEmpty(dataDepenentObj.dependentquestions) == false) { e.dependentquestions = []; e.dependentquestions = e.dependentquestions.concat(dataDepenentObj.dependentquestions); } } else { if (_.isEmpty(dataDepenentObj.dependentquestions) == false) { e.dependentquestions = e.dependentquestions.concat(dataDepenentObj.dependentquestions); } } } }); dependentdataElementarr = []; dataDepenentObj = {}; console.log(programStagesArray); setLocalStorage("programStageArray", programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); //========= BUTTON TO SHOW QUESTIONS MODAL======== $(document).on('click', '.btn_ProgramAddQuestion', function() { $("#addNewProgramQuestionModal").modal("show"); var pgservname = $(this).data('stage-name'); $("#programservice").text(pgservname); $('.btn_edit_AddQuestionProgram').hide(); $(".btn_Add_Dependency_Level_1").show(); $('.btn_submit_AddQuestionProgram').show(); $("#option_section_program").hide(); $("#check_section_program").hide(); $('.level_1_dependencylist').html(''); $(".level_1_dependency").addClass('hidden'); $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); $('#add_NewProgramQuestion')[0].reset(); $('#questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) //////DEPENDENCY //##################################################DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_1").off("click"); $(".btn_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#programservice").text(); var parentqname = $('#questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, programStagesArray); if (!isDuplicateParent) { $("#option_section_program_level_1").addClass('hidden'); $("#check_section_program_level_1").addClass('hidden'); $('#add_NewProgramQuestion_level_1')[0].reset(); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory']:checked").val(); var typeOfQuestion = $("#TypeofQuest").val(); if (_.isEmpty($('#questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName').val()) == true) { $(".parent_action_btns_section :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption option:selected").val(); $("#add_NewProgramQuestion :input").prop("disabled", true); $(".level_1_dependency").removeClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_1").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "checkboxoption") { var options = $('#TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "number") { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName').val(); $('#pquestion_level_1').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level1").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_1").off("click"); $(".btn_submit_AddQuestionProgram_level_1").on("click", function() { if ($("#TypeofQuest").val() == "option list") { matchval = $("#matchval_options_level_1 option:selected").val(); var selectedOptions = $("#TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest").val() == "checkboxoption") { matchval = $('#matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest").val() == "number") { matchval = $('#matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_1").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_1").val(); var depttypeOfOption = $("#TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_1 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#questName_level_1").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_dependency").addClass('hidden'); $(".parent_action_btns_section :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_1").removeClass('hidden'); } else { $("#option_section_program_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_1").removeClass('hidden'); $("#TypeofOptionCheck_level_1").html(""); } else { $("#check_section_program_level_1").addClass('hidden'); } }); $(".btn_close_level_1").off("click"); $(".btn_close_level_1").on("click", function() { $(".level_1_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_2").off("click"); $(".btn_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#questName_level_1').val(); var parentqname = $('#questName').val(); tempquestionlist.push(parentqname); var parentservname = $("#programservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $('#add_NewProgramQuestion_level_2')[0].reset(); $("#option_section_program_level_2").addClass('hidden'); $("#check_section_program_level_2").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var typeOfQuestion = $("#TypeofQuest_level_1").val(); if (_.isEmpty($('#questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName_level_1').val()) == true) { $(".parent_child_1_action_btn :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_2").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "number") { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName_level_1').val(); $('#pquestion_level_2').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level2").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_2").off("click"); $(".btn_submit_AddQuestionProgram_level_2").on("click", function() { if ($("#TypeofQuest_level_1").val() == "option list") { matchval = $("#matchval_options_level_2 option:selected").val(); var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest_level_1").val() == "number") { matchval = $('#matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_2").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_2']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_2").val(); var depttypeOfOption = $("#TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_2 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; var qnameParent = $('#questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#questName_level_2").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency").addClass('hidden'); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_2").removeClass('hidden'); } else { $("#option_section_program_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_2").removeClass('hidden'); $("#TypeofOptionCheck_level_2").html(""); } else { $("#check_section_program_level_2").addClass('hidden'); } }); $(".btn_close_level_2").off("click"); $(".btn_close_level_2").on("click", function() { $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } // var seleType = $(this).closest('tr').children('td:nth-child(3)').text(); console.log(selectQuest); var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } }); $(".btn_edit_AddQuestionProgram").on("click", function() { console.log("Modify"); var selectQuest = $("#questName").val(); console.log(programStagesArray); $.each(programStagesArray, function(key1, val1) { for (let i in programStagesArray[key1].dataelements) { if (programStagesArray[key1].dataelements[i].name == selectQuest) { val1.dataelements.splice(i, 1); break; } } }); $("#addNewProgramQuestionModal").modal("hide"); }); $(document).on('click', '.btn_Delete', function() { console.log("Delete"); var qesname = $(this).closest('tr').children('td:nth-child(2)').text(); console.log(qesname); var stagename = $(this).closest('table').data('stage-name'); var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { return item.dataelementname.replace(/ /g, '').toLowerCase() == qesname.replace(/ /g, '').toLowerCase() }); } }); var tempmsg = ""; if (!_.isEmpty(isPartOfParent)) { tempmsg = "Deletion of this question will reset all dependencies on this question."; } swal({ title: 'Are you sure?', text: tempmsg, type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) var dataelObjCombo = deleteDataElementWithAvailableChildonStage(stagename, qesname, programStagesArray); programStagesArray = dataelObjCombo; console.log(programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } // var seleType = $(this).closest('tr').children('td:nth-child(3)').text(); console.log(selectQuest); var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } }); }); }).catch(swal.noop) }); }); $("#addNewProgramQuestionModal").modal("hide"); $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields.", callback: function() { } }); } } else { // program edit submit by sohan console.log(serviceName); console.log(questionName); var dataElementObj = {}; var mandatoryChk = $("input[name='prgm_radioMandatory']:checked").val(); var typeOfQuestion = $("#TypeofQuest").val(); var typeOfOption = $("#TypeofOption").val(); var typeOfcheck = $("#TypeofOptionCheck").val(); //===HARDCODED OPTION LIST VALUE AS TEXT(REQUIRED BY SERVICE) var flagOption = false; if (typeOfQuestion == "option list") { typeOfQuestion = "text" if (typeOfOption != "" && typeOfOption != null) { dataElementObj.optionname = typeOfOption } else { flagOption = true; } } if (typeOfQuestion == "checkboxoption") { typeOfQuestion = "text" if (typeOfcheck != "" && typeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } if (questionName != "" && mandatoryChk != undefined && typeOfQuestion != "" && flagOption == false) { if (isValidEntry(questionName) == true) { var optiontext = $("#TypeofQuest option:selected").text(); if (optiontext == "Facility") { dataElementObj.facility = "true"; } dataElementObj.name = questionName dataElementObj.type = typeOfQuestion dataElementObj.mandatory = mandatoryChk swal({ title: 'Are you sure?', // text: "Data Element is Already Available!", type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Update it!', buttonsStyling: false }).then(function() { swal({ title: 'Updated!', text: 'Updated Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) $.each(programStagesArray, function(key, val) { if (val.name == serviceName) { $.each(val.dataelements, function(key1, val1) { if (val1.name == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val.dataelements[key1] = dataElementObj; } }); $.each(val.dependentquestions, function(key2, val2) { if (val2.dataelementname == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val2.dataelementname = questionName; } $.each(val2.dependentdataelementnames, function(key3, val3) { if (val3.childdataelementname == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val3.childdataelementname = questionName; } }); }); } }); console.log(programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); console.log(optionsArray); $.each(optionsArray, function(i, e) { // $("#TypeofOption").append('');; $("#TypeofOption").append('');; }) // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } // var seleType = $(this).closest('tr').children('td:nth-child(3)').text(); console.log(selectQuest); var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } }); }); $("#addNewProgramQuestionModal").modal("hide"); }).catch(swal.noop) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } }); //=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_AddOptionListQuestionProgram").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } // $('.input_fields_container').remove('.newAppend'); // $(".input_fields_container").remove(":contains('newAppend')"); $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".add_optionValues_ProgQuest").off("click"); $(".add_optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // $('.remove_optionValues_ProgQuest').parent().parent().remove(); }); // DELETE CHILD ELEMENT $(document).on('click', '.custom-alert-list>.close', function() { var qesname = $(this).parent().find('.chdelname').text(); // WORK IN PROGRESS $(this).parent().remove(); var dataelObjCombo = deleteDataElementWithAvailableChild(qesname, dependentdataElementarr, dataDepenentObj.dependentquestions); dependentdataElementarr = dataelObjCombo.dependentdataElementarr; dataDepenentObj.dependentquestions = dataelObjCombo.dataDepenentObj; $('.level_1_dependencylist').html(""); $.each(dependentdataElementarr, function(key, val) { var temshtml = ""; temshtml += "
    [" + val.level + "]" + val.name + "
    "; $('.level_1_dependencylist').append(temshtml); }) }); // DELETE CHILD ELEMENT $(document).on('click', '.custom-alert-list_attr>.close', function() { var attrname = $(this).parent().find('.chdelname').text(); // WORK IN PROGRESS $(this).parent().remove(); var dataelObjCombo = deleteAttributeWithAvailableChild(attrname, dependentdataattrArr, dataattrDepenentObj.attributedependentquestions); dependentdataattrArr = dataelObjCombo.dependentdataattrArr; dataattrDepenentObj.attributedependentquestions = dataelObjCombo.attributedependentquestions; $('.level_1_dependencylist').html(""); $.each(dependentdataattrArr, function(key, val) { var temshtml = ""; temshtml += "
    [" + val.level + "]" + val.name + "
    "; $('.level_1_dependencylist').append(temshtml); }) }); // DELETE PROGRAM STAGE $(document).on('click', '.btn_Delete_stage', function() { var stagename = $(this).data('stage-name'); swal({ title: 'Are you sure you want to delete ?', text: 'Service delete will reset workflow.', type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Stage Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) // WORKFLOW RESET pgrolesforstage = []; stageroles = []; $('.selectRoleForworkflowPGM').prop("checked", false); $('#stageRoleAssignTBL > tbody').html(''); $('#step').html(''); $('#stageRoleAssignTBL > thead >tr').html(''); programStagesArray = _(programStagesArray).filter(function(item) { return item.name !== stagename }); console.log(programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); }).catch(swal.noop) }); // DELETE COMMUNITY STAGE $(document).on('click', '.btn_Delete_stage_comm', function() { var stagename = $(this).data('stage-name'); swal({ title: 'Are you sure you want to delete ?', text: 'Service delete will reset workflow.', type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Stage Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) // WORKFLOW RESET pgrolesforstage = []; stageroles = []; $('.selectRoleForworkflowPGM').prop("checked", false); $('#stageRoleAssignTBL > tbody').html(''); $('#step').html(''); $('#stageRoleAssignTBL > thead >tr').html(''); communitiesStagesArray = _(communitiesStagesArray).filter(function(item) { return item.name !== stagename }); console.log(communitiesStagesArray); $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); // comm edit by sohan }); }).catch(swal.noop) }); $(".btn_submit_AddProgram_OptionSet").off("click"); $(".btn_submit_AddProgram_OptionSet").on("click", function() { var countBlank = 0; if ($('.level_1_dependency').hasClass('hidden') == false && $("#add_NewProgramQuestion_level_1 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var typeOfQuestion = $("#TypeofQuest_level_1").val(); if (typeOfQuestion == "checkboxoption") { $('#optNameProgram').val("text"); } if ($('#optNameProgram').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { // $("#TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="product_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameProgram").val(); // console.log("arrya"); // console.log(optionsArray); if (typeOfQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#TypeofOptionCheck_level_1").append(''); }) $("#addNewProgramDefineOptionSetModal").modal("hide"); console.log(CheckArray); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } // $("#TypeofOption").html(''); $("#TypeofOption_level_1").html(''); $.each(optionsArray, function(i, e) { // $("#TypeofOption").append('');; $("#TypeofOption_level_1").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else if ($('.level_2_dependency').hasClass('hidden') == false && $("#add_NewProgramQuestion_level_2 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var typeOfQuestion = $("#TypeofQuest_level_2").val(); if (typeOfQuestion == "checkboxoption") { $('#optNameProgram').val("text"); } if ($('#optNameProgram').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { // $("#TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="product_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameProgram").val(); // console.log("arrya"); // console.log(optionsArray); if (typeOfQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#TypeofOptionCheck_level_2").append(''); }) $("#addNewProgramDefineOptionSetModal").modal("hide"); console.log(CheckArray); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } // $("#TypeofOption").html(''); // $("#TypeofOption_level_1").html(''); $("#TypeofOption_level_2").html(''); $.each(optionsArray, function(i, e) { // $("#TypeofOption").append('');; // $("#TypeofOption_level_1").append('');; $("#TypeofOption_level_2").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else if ($('.level_1_attributeDependency').hasClass('hidden') == false && $("#add_NewAttribute_level_1 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var typeOfAttr = $("#selType_level_1").val(); if ($('#optNameProgram').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { $("#TypeofOptionAttr_level_1").empty(); // $("#TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="product_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameProgram").val(); optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } $("#TypeofOptionAttr_level_1").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOptionAttr_level_1").append('');; }) // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var typeOfQuestion = $("#TypeofQuest").val(); if (typeOfQuestion == "checkboxoption") { $('#optNameProgram').val("text"); } if ($('#optNameProgram').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { $("#TypeofOption").empty(); // $("#TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="product_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameProgram").val(); // console.log("arrya"); // console.log(optionsArray); if (typeOfQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#TypeofOptionCheck").append(''); }) $("#addNewProgramDefineOptionSetModal").modal("hide"); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; // if (optionsArray.length > 0) { // if (_.contains(optionsArray, optionsObj.name.toLowerCase()) == true) { // bootbox.alert({ // size: "small", // title: "iMonitor +", // message: "Option Already Available with this name.", // callback: function() { // } // }); // } else { // optionsArray.push(optionsObj); // $("#addNewProgramDefineOptionSetModal").modal("hide"); // } // } else { // optionsArray.push(optionsObj); // $("#addNewProgramDefineOptionSetModal").modal("hide"); // } if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $("#TypeofOption_level_1").html(''); $("#TypeofOption_level_2").html(''); $("#comm_TypeofOption_level_1").html(''); $("#comm_TypeofOption_level_2").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; $("#TypeofOption_level_1").append('');; $("#TypeofOption_level_2").append('');; $("#comm_TypeofOption_level_1").append('');; $("#comm_TypeofOption_level_2").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } }) //############################################################################################################### //======================= COMMUNITY SECTION ==================================// $(".btn_CommunityAddService").on("click", function() { $("#addNewCommunityServiceModal").modal("show"); }); //=============== ADD NEW SERVICE - COMMUNITY ========================// var communityServiceName; if (_.isEmpty(selectedtemplateJson.application[0].communities)) { communitiesStagesArray = []; } else { communitiesStagesArray = selectedtemplateJson.application[0].communities[0].stages; } // LOAD COMMUNITY SERVICE DATA var actualStageLen = communitiesStagesArray.length; communitiesStagesArray = _(communitiesStagesArray).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.name != "mpesa"; // sohanchauhan }); if (actualStageLen != communitiesStagesArray.length) { $('#mpesaTrans').attr('checked', true); } $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); $(document).on('click', '.btn_CommunityAddQuestion', function() { $("#addNewCommunityQuestionModal").modal("show"); $("#option_section_community").hide(); $("#check_section_community").hide(); $('.btn_comm_Add_Dependency_Level_1').show(); $("#comm_TypeofQuest").prop('selectedIndex', 0); var commsername = $(this).data('stage-name'); $("#communityservice").text(commsername); $('.level_1_dependencylist_comm').html(''); $(".level_1_dependency_comm").addClass('hidden'); $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); $('#add_NewCommunityQuestion')[0].reset(); $('#comm_questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) // COMMUNITY DEPENENCY //##################################################COMMUNITY DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_1").off("click"); $(".btn_comm_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#communityservice").text(); var parentqname = $('#comm_questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, communitiesStagesArray); if (!isDuplicateParent) { $("#option_section_community_level_1").addClass('hidden'); $("#check_section_community_level_1").addClass('hidden'); $('#add_NewCommunityQuestion_level_1')[0].reset(); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest").val(); if (_.isEmpty($('#comm_questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName').val()) == true) { $(".parent_action_btns_section_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption option:selected").val(); $("#add_NewCommunityQuestion :input").prop("disabled", true); $(".level_1_dependency_comm").removeClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "number") { $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName').val(); $('#commuestion_level_1').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_1").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_1").off("click"); $(".btn_submit_AddCommunityQuestion_level_1").on("click", function() { if ($("#comm_TypeofQuest").val() == "option list") { matchval = $("#comm_matchval_options_level_1 option:selected").val(); var selectedOptions = $("#comm_TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest").val() == "number") { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_1").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#comm_questName_level_1").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_dependency_comm").addClass('hidden'); $(".parent_action_btns_section_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_1").removeClass('hidden'); } else { $("#option_section_community_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_1").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_1").html(""); } else { $("#check_section_community_level_1").addClass('hidden'); } }); $(".btn_comm_close_level_1").off("click"); $(".btn_comm_close_level_1").on("click", function() { $(".level_1_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_2").off("click"); $(".btn_comm_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#comm_questName_level_1').val(); var parentqname = $('#comm_questName').val(); tempquestionlist.push(parentqname); var parentservname = $("#communityservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $('#add_NewCommunityQuestion_level_2')[0].reset(); $("#option_section_community_level_2").addClass('hidden'); $("#check_section_community_level_2").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); if (_.isEmpty($('#comm_questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName_level_1').val()) == true) { $(".parent_child_1_action_btn_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "number") { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName_level_1').val(); $('#commuestion_level_2').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_2").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_2").off("click"); $(".btn_submit_AddCommunityQuestion_level_2").on("click", function() { if ($("#comm_TypeofQuest_level_1").val() == "option list") { matchval = $("#comm_matchval_options_level_2 option:selected").val(); var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest_level_1").val() == "number") { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_2").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_2']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_2").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; var qnameParent = $('#comm_questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#comm_questName_level_2").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency_comm").addClass('hidden'); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_2").removeClass('hidden'); } else { $("#option_section_community_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_2").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_2").html(""); } else { $("#check_section_community_level_2").addClass('hidden'); } }); $(".btn_comm_close_level_2").off("click"); $(".btn_comm_close_level_2").on("click", function() { $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); $(document).on('click', '.btn_Delete_comm', function() { console.log("Delete"); var qesname = $(this).closest('tr').children('td:nth-child(2)').text(); console.log(qesname); var stagename = $(this).closest('table').data('stage-name'); var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { return item.dataelementname.replace(/ /g, '').toLowerCase() == qesname.replace(/ /g, '').toLowerCase() }); } }); var tempmsg = ""; if (!_.isEmpty(isPartOfParent)) { tempmsg = "Deletion of this question will reset all dependencies on this question."; } swal({ title: 'Are you sure?', text: tempmsg, type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) var dataelObjCombo = deleteDataElementWithAvailableChildonStage(stagename, qesname, communitiesStagesArray); communitiesStagesArray = dataelObjCombo; $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); }).catch(swal.noop) }); }); // add service $(".btn_submit_AddCommunityService").on("click", function() { if (isValidEntry($('#comm_servName').val()) == true) { $("#communityservice").empty(); console.log("AddCommunityService"); var communitiesStage = {}; var dataelementsArray = []; communityServiceName = $("#comm_servName").val(); // var serviceShortName = $("#comm_servShrtName").val(); var serviceShortName = $("#comm_servName").val(); //Service Short Name Same as Service Name var AppInfo = getLocalStorage("AppInfo", AppInfo); programName = AppInfo.programName; programShortName = AppInfo.programShortName; console.log(programName); console.log(programShortName); communitiesObj.name = programName; communitiesObj.shortname = programShortName; communitiesObj.logo = ""; communitiesStage.name = communityServiceName; communitiesStage.dataelements = dataelementsArray if (communitiesStagesArray.length > 0) { var duplicatecheck = isDuplicateReord(communitiesStagesArray, communitiesStage); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Service Already Available with this name.", callback: function() { } }); } else { communitiesStagesArray.push(communitiesStage); $("#addNewCommunityServiceModal").modal("hide"); } } else { communitiesStagesArray.push(communitiesStage); $("#addNewCommunityServiceModal").modal("hide"); } setLocalStorage("communitiesStageArray", communitiesStagesArray); $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); $(document).on('click', '.btn_CommunityAddQuestion', function() { $("#addNewCommunityQuestionModal").modal("show"); var commsername = $(this).data('stage-name'); $("#communityservice").text(commsername); $('.level_1_dependencylist_comm').html(''); $('.btn_comm_Add_Dependency_Level_1').show(); $(".level_1_dependency_comm").addClass('hidden'); $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); $('#add_NewCommunityQuestion')[0].reset(); $('#comm_questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) // COMMUNITY DEPENENCY //##################################################COMMUNITY DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_1").off("click"); $(".btn_comm_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#communityservice").text(); var parentqname = $('#comm_questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, communitiesStagesArray); if (!isDuplicateParent) { $("#option_section_community_level_1").addClass('hidden'); $("#check_section_community_level_1").addClass('hidden'); $('#add_NewCommunityQuestion_level_1')[0].reset(); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest").val(); if (_.isEmpty($('#comm_questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName').val()) == true) { $(".parent_action_btns_section_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption option:selected").val(); $("#add_NewCommunityQuestion :input").prop("disabled", true); $(".level_1_dependency_comm").removeClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "number") { $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName').val(); $('#commuestion_level_1').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_1").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_1").off("click"); $(".btn_submit_AddCommunityQuestion_level_1").on("click", function() { if ($("#comm_TypeofQuest").val() == "option list") { matchval = $("#comm_matchval_options_level_1 option:selected").val(); var selectedOptions = $("#comm_TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest").val() == "number") { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_1").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#comm_questName_level_1").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_dependency_comm").addClass('hidden'); $(".parent_action_btns_section_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_1").removeClass('hidden'); } else { $("#option_section_community_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_1").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_1").html(""); } else { $("#check_section_community_level_1").addClass('hidden'); } }); $(".btn_comm_close_level_1").off("click"); $(".btn_comm_close_level_1").on("click", function() { $(".level_1_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_2").off("click"); $(".btn_comm_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#comm_questName_level_1').val(); var parentqname = $('#comm_questName').val(); tempquestionlist.push(parentqname); var parentservname = $("#communityservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $('#add_NewCommunityQuestion_level_2')[0].reset(); $("#option_section_community_level_2").addClass('hidden'); $("#check_section_community_level_2").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); if (_.isEmpty($('#comm_questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName_level_1').val()) == true) { $(".parent_child_1_action_btn_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "number") { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() {} }); } else { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName_level_1').val(); $('#commuestion_level_2').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_2").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_2").off("click"); $(".btn_submit_AddCommunityQuestion_level_2").on("click", function() { if ($("#comm_TypeofQuest_level_1").val() == "option list") { matchval = $("#comm_matchval_options_level_2 option:selected").val(); var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest_level_1").val() == "number") { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_2").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_2']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_2").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; var qnameParent = $('#comm_questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#comm_questName_level_2").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency_comm").addClass('hidden'); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_2").removeClass('hidden'); } else { $("#option_section_community_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_2").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_2").html(""); } else { $("#check_section_community_level_2").addClass('hidden'); } }); $(".btn_comm_close_level_2").off("click"); $(".btn_comm_close_level_2").on("click", function() { $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); }); $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter Service Name", callback: function() { } }); } }) //================TYPE OF QUESTION DEPENDENCY=============================// $("#option_section_community").hide(); $("#check_section_community").hide(); $("#comm_TypeofQuest").on("change", function() { // $("#comm_TypeofOption").empty(); if ($(this).val() == "option list") { $("#option_section_community").show(); } else { $("#option_section_community").hide(); } if ($(this).val() == "checkboxoption") { $("#check_section_community").show(); $("#comm_TypeofOptionCheck").html(""); } else { $("#check_section_community").hide(); } }); //================== ADD NEW QUESTION - COMMUNITY =========================// $(".btn_submit_AddCommunityQuestion").off("click"); $(".btn_submit_AddCommunityQuestion").on("click", function() { console.log("AddQuestionCommunity"); var dataElementObj = {}; communityServiceName = $("#communityservice").text(); var questionName = $("#comm_questName").val(); var oldquestion = $("#comm_questName").data('old_name'); var isDuplicateFound = isDuplicateDataElement(communityServiceName, oldquestion, communitiesStagesArray); if (!isDuplicateFound) { // var questionShortName = $("#comm_questShrtName").val(); - Removed Short Name from UI var questionShortName = $("#comm_questName").val(); //Short Name Set to Same as question name var mandatoryChk = $("input[name='comm_radioMandatory']:checked").val(); var typeOfQuestion = $("#comm_TypeofQuest").val(); var typeOfOption = $("#comm_TypeofOption").val(); var typeOfcheck = $("#comm_TypeofOptionCheck").val(); //===HARDCODED OPTION LIST VALUE AS TEXT(REQUIRED BY SERVICE) var flagOption = false; if (typeOfQuestion == "option list") { typeOfQuestion = "text" if (typeOfOption != "" && typeOfOption != null) { dataElementObj.optionname = typeOfOption } else { flagOption = true; } } if (typeOfQuestion == "checkboxoption") { typeOfQuestion = "text" if (typeOfcheck != "" && typeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } if (questionName != "" && mandatoryChk != undefined && typeOfQuestion != "" && flagOption == false) { if (isValidEntry(questionName) == true) { var isDlAvailable = false; isDlAvailable = isDuplicateDataElement(communityServiceName, questionName, communitiesStagesArray); if (!isDlAvailable) { dataElementObj.name = questionName dataElementObj.type = typeOfQuestion dataElementObj.mandatory = mandatoryChk $.each(communitiesStagesArray, function(i, e) { console.log(e); if (e.name == communityServiceName) { console.log(e.dataelements); e.dataelements.push(dataElementObj); dependentdataElementarr = cleanChildObj(dependentdataElementarr); e.dataelements = e.dataelements.concat(dependentdataElementarr); if (_.isUndefined(e.dependentquestions)) { if (_.isEmpty(dataDepenentObj.dependentquestions) == false) { e.dependentquestions = []; e.dependentquestions = e.dependentquestions.concat(dataDepenentObj.dependentquestions); } } else { if (_.isEmpty(dataDepenentObj.dependentquestions) == false) { e.dependentquestions = e.dependentquestions.concat(dataDepenentObj.dependentquestions); } } } }); dependentdataElementarr = []; dataDepenentObj = {}; console.log(communitiesStagesArray); setLocalStorage("communitiesStageArray", communitiesStagesArray); $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); $(document).on('click', '.btn_CommunityAddQuestion', function() { $("#addNewCommunityQuestionModal").modal("show"); $("#option_section_community").hide(); $("#check_section_community").hide(); $('.btn_comm_Add_Dependency_Level_1').show(); var commsername = $(this).data('stage-name'); $("#communityservice").text(commsername); $('.level_1_dependencylist_comm').html(''); $(".level_1_dependency_comm").addClass('hidden'); $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); $('#add_NewCommunityQuestion')[0].reset(); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); $('#comm_questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) // COMMUNITY DEPENENCY //##################################################COMMUNITY DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_1").off("click"); $(".btn_comm_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#communityservice").text(); var parentqname = $('#comm_questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, communitiesStagesArray); if (!isDuplicateParent) { $("#option_section_community_level_1").addClass('hidden'); $("#check_section_community_level_1").addClass('hidden'); $('#add_NewCommunityQuestion_level_1')[0].reset(); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest").val(); if (_.isEmpty($('#comm_questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName').val()) == true) { $(".parent_action_btns_section_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption option:selected").val(); $("#add_NewCommunityQuestion :input").prop("disabled", true); $(".level_1_dependency_comm").removeClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "number") { $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName').val(); $('#commuestion_level_1').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_1").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_1").off("click"); $(".btn_submit_AddCommunityQuestion_level_1").on("click", function() { if ($("#comm_TypeofQuest").val() == "option list") { matchval = $("#comm_matchval_options_level_1 option:selected").val(); var selectedOptions = $("#comm_TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest").val() == "number") { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_1").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#comm_questName_level_1").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_dependency_comm").addClass('hidden'); $(".parent_action_btns_section_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_1").removeClass('hidden'); } else { $("#option_section_community_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_1").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_1").html(""); } else { $("#check_section_community_level_1").addClass('hidden'); } }); $(".btn_comm_close_level_1").off("click"); $(".btn_comm_close_level_1").on("click", function() { $(".level_1_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_2").off("click"); $(".btn_comm_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#comm_questName_level_1').val(); var parentqname = $('#comm_questName').val(); tempquestionlist.push(parentqname); var parentservname = $("#communityservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $('#add_NewCommunityQuestion_level_2')[0].reset(); $("#option_section_community_level_2").addClass('hidden'); $("#check_section_community_level_2").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); if (_.isEmpty($('#comm_questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName_level_1').val()) == true) { $(".parent_child_1_action_btn_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "number") { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName_level_1').val(); $('#commuestion_level_2').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_2").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_2").off("click"); $(".btn_submit_AddCommunityQuestion_level_2").on("click", function() { if ($("#comm_TypeofQuest_level_1").val() == "option list") { matchval = $("#comm_matchval_options_level_2 option:selected").val(); var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest_level_1").val() == "number") { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_2").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_2']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_2").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; var qnameParent = $('#comm_questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#comm_questName_level_2").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency_comm").addClass('hidden'); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_2").removeClass('hidden'); } else { $("#option_section_community_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_2").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_2").html(""); } else { $("#check_section_community_level_2").addClass('hidden'); } }); $(".btn_comm_close_level_2").off("click"); $(".btn_comm_close_level_2").on("click", function() { $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); $(document).on('click', '.btn_Delete_comm', function() { console.log("Delete"); var qesname = $(this).closest('tr').children('td:nth-child(2)').text(); console.log(qesname); var stagename = $(this).closest('table').data('stage-name'); var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { return item.dataelementname.replace(/ /g, '').toLowerCase() == qesname.replace(/ /g, '').toLowerCase() }); } }); var tempmsg = ""; if (!_.isEmpty(isPartOfParent)) { tempmsg = "Deletion of this question will reset all dependencies on this question."; } swal({ title: 'Are you sure?', text: tempmsg, type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) var dataelObjCombo = deleteDataElementWithAvailableChildonStage(stagename, qesname, communitiesStagesArray); communitiesStagesArray = dataelObjCombo; $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); }).catch(swal.noop) }); }); $("#addNewCommunityQuestionModal").modal("hide"); $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else { // community submit edit by sohan console.log(communityServiceName); console.log(questionName); var dataElementObj = {}; var mandatoryChk = $("input[name='comm_radioMandatory']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest").val(); var comm_TypeofOption = $("#comm_TypeofOption").val(); var typeOfcheck = $("#comm_TypeofOptionCheck").val(); //===HARDCODED OPTION LIST VALUE AS TEXT(REQUIRED BY SERVICE) var flagOption = false; if (comm_TypeofQuestion == "option list") { comm_TypeofQuestion = "text" if (comm_TypeofOption != "" && comm_TypeofOption != null) { dataElementObj.optionname = comm_TypeofOption } else { flagOption = true; } } if (comm_TypeofQuestion == "checkboxoption") { comm_TypeofQuestion = "text" if (typeOfcheck != "" && typeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } if (questionName != "" && mandatoryChk != undefined && comm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(questionName) == true) { dataElementObj.name = questionName dataElementObj.type = comm_TypeofQuestion dataElementObj.mandatory = mandatoryChk swal({ title: 'Are you sure?', // text: "Data Element is Already Available!", type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Update it!', buttonsStyling: false }).then(function() { swal({ title: 'Updated!', text: 'Updated Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) $.each(communitiesStagesArray, function(key, val) { if (val.name == communityServiceName) { $.each(val.dataelements, function(key1, val1) { if (val1.name == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val.dataelements[key1] = dataElementObj; } }); $.each(val.dependentquestions, function(key2, val2) { if (val2.dataelementname == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val2.dataelementname = questionName; } $.each(val2.dependentdataelementnames, function(key3, val3) { if (val3.childdataelementname == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val3.childdataelementname = questionName; } }); }); } }); console.log(communitiesStagesArray); $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); console.log(optionsArray); $.each(optionsArray, function(i, e) { // $("#comm_TypeofOption").append('');; $("#comm_TypeofOption").append('');; }) // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); $("#addNewCommunityQuestionModal").modal("hide"); }).catch(swal.noop) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } }); //=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optValueProgram').val(''); $('.newAppend').remove(); if ($("#comm_TypeofQuest").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); }); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // $('.remove_optionValues_ProgQuest').parent().parent().remove(); }); $(document).on('click', '.custom-alert-list>.close', function() { var qesname = $(this).parent().find('.chdelname').text(); // WORK IN PROGRESS $(this).parent().remove(); var dataelObjCombo = deleteDataElementWithAvailableChild(qesname, dependentdataElementarr, dataDepenentObj.dependentquestions); dependentdataElementarr = dataelObjCombo.dependentdataElementarr; dataDepenentObj.dependentquestions = dataelObjCombo.dataDepenentObj; $('.level_1_dependencylist_comm').html(""); $.each(dependentdataElementarr, function(key, val) { var temshtml = ""; temshtml += "
    [" + val.level + "]" + val.name + "
    "; $('.level_1_dependencylist_comm').append(temshtml); }) }); $(".btn_submit_AddCommunity_OptionSet").off("click"); $(".btn_submit_AddCommunity_OptionSet").on("click", function() { var countBlank = 0; if ($('.level_1_dependency_comm').hasClass('hidden') == false && $("#add_NewCommunityQuestion_level_1 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var comm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); if (comm_TypeofQuestion == "checkboxoption") { $('#optNameCommunity').val("text"); } if ($('#optNameCommunity').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { // $("#comm_TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="community_option_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameCommunity").val(); // console.log("arrya"); // console.log(optionsArray); if (comm_TypeofQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#comm_TypeofOptionCheck_level_1").append(''); }) $("#addNewCommunityDefineOptionSetModal").modal("hide"); console.log(CheckArray); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } // $("#comm_TypeofOption").html(''); $("#comm_TypeofOption_level_1").html(''); $.each(optionsArray, function(i, e) { // $("#comm_TypeofOption").append('');; $("#comm_TypeofOption_level_1").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else if ($('.level_2_dependency_comm').hasClass('hidden') == false && $("#add_NewCommunityQuestion_level_2 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var comm_TypeofQuestion = $("#comm_TypeofQuest_level_2").val(); if (comm_TypeofQuestion == "checkboxoption") { $('#optNameCommunity').val("text"); } if ($('#optNameCommunity').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { // $("#comm_TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="community_option_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameCommunity").val(); // console.log("arrya"); // console.log(optionsArray); if (comm_TypeofQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#comm_TypeofOptionCheck_level_2").append(''); }) $("#addNewCommunityDefineOptionSetModal").modal("hide"); console.log(CheckArray); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } // $("#comm_TypeofOption").html(''); // $("#comm_TypeofOption_level_1").html(''); $("#comm_TypeofOption_level_2").html(''); $.each(optionsArray, function(i, e) { // $("#comm_TypeofOption").append('');; // $("#comm_TypeofOption_level_1").append('');; $("#comm_TypeofOption_level_2").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else { var typeOfQuestion = $("#comm_TypeofQuest").val(); if (typeOfQuestion == "checkboxoption") { $('#optNameCommunity').val("text"); } var countBlank = 0; $('.optValueCommunity').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); if ($('#optNameCommunity').val() != '' && $('.optValueCommunity').val() != '' && countBlank == 0) { $("#comm_TypeofOption").empty(); // $("#comm_TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="community_option_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameCommunity").val(); if (typeOfQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $("#addNewCommunityDefineOptionSetModal").modal("hide"); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $("#TypeofOption_level_1").html(''); $("#TypeofOption_level_2").html(''); $("#comm_TypeofOption_level_1").html(''); $("#comm_TypeofOption_level_2").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; $("#TypeofOption_level_1").append('');; $("#TypeofOption_level_2").append('');; $("#comm_TypeofOption_level_1").append('');; $("#comm_TypeofOption_level_2").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } }) //========SELECT LAYOUT ===============================================// if (_.isEmpty(selectedtemplateJson.application[0].programs)) { var mobileLayout = selectedtemplateJson.application[0].communities[0].mobilelayout; var WebLayout = selectedtemplateJson.application[0].communities[0].weblayout; } else { var mobileLayout = selectedtemplateJson.application[0].programs[0].mobilelayout; var WebLayout = selectedtemplateJson.application[0].programs[0].weblayout; } var mblayoutid = mobileLayout.replace(/ /g, ''); var wblayoutid = WebLayout.replace(/ /g, ''); $('#templateName').val(selectedtemplateJson.template.name); $('#templateDescr').val(selectedtemplateJson.template.description); $('#iconviewtmpl').attr("src", "assets/" + selectedtemplateJson.template.thumbnail); templateicon = selectedtemplateJson.template.thumbnail; $('#LayoutSection').find('.well').removeClass('layoutactive'); $("." + mblayoutid).addClass("layoutactive"); $("." + wblayoutid).addClass("layoutactive"); $(".dskLayout .dskimg").on("click", function() { $(".dskLayout .dskimg").removeClass("layoutactive"); $(this).addClass("layoutactive"); WebLayout = $(this).find("h5").html(); }); $(".mbllayout .well").on("click", function() { $(".mbllayout .well").removeClass("layoutactive"); $(this).addClass("layoutactive"); mobileLayout = $(this).find("h5").html(); }); $("#saveTemplateCheck").on("click", function() { if ($('#saveTemplateCheck').is(":checked") == true) { $('#saveTemplateInput').show(); isSaveTemplate = true; var appInfo = getLocalStorage("AppInfo"); $('#templateName').val(appInfo.appName); $('#templateDescr').val(appInfo.appName + ' description'); } else { $('#saveTemplateInput').hide(); isSaveTemplate = false; } }); //////////////////////// END DEFINE SERVICES SECTION /////////////////////////////////// } else { /////////////////////////////////// NEW APPLICATION NORMAL FLOW ///////////////////////////////////// var masterObject = {}; //FINAL MASTER OBJECT //===== LEVEL 1 =====// var templateObject = {}; var adminObject = {}; var applicationArray = []; var applicationObject = {}; $(".commIconSection").hide(); $('#pgmIcon').val(getLocalStorage("pgmicon")); $('#comIcon').val(getLocalStorage("comicon")); //===== LEVEL 2 =====// var trackedentityattributesArray = []; var attributedependentquestions = []; var UIC = ""; //==== add default attribute for UIC===// var fname = { "name": "First Name", "type": "text", "mandatory": "true" }; var lname = { "name": "Last Name", "type": "text", "mandatory": "true" }; var dob = { "name": "Date of Birth", "type": "date", "mandatory": "true" }; var mob = { "name": "Mobile Number", "type": "number", "mandatory": "true" }; var qrcode = { "name": "Associate QR code", "type": "text", "mandatory": "false" }; // uicArray = [{ // "attributename": "First Name", // "type": "text", // "format": "3", // "sequence": "1" // }, // { // "attributename": "Last Name", // "type": "text", // "format": "2", // "sequence": "2" // }, // { // "attributename": "Date of Birth", // "type": "date", // "format": "ddmm", // "sequence": "3" // } // ]; var temoUICArray = []; trackedentityattributesArray.push(fname); trackedentityattributesArray.push(lname); trackedentityattributesArray.push(dob); trackedentityattributesArray.push(mob); trackedentityattributesArray.push(qrcode); // end add default attribute for UIC===// var programsArray = []; var programsObj = {}; var communitiesArray = []; var communitiesObj = {}; var uicObj = {}; var referencesObj = {}; var optionsArray = []; var CheckArray = []; var dependentquestionsObj = {}; var programStagesArray = []; var communitiesStagesArray = []; //==================================================================================================================== //SET PROGRAM NAME IN WIZARD FROM DATA ENTERED IN HOME PAGE var appinfo = getLocalStorage("AppInfo"); if (appinfo != null) { var curProgramName = appinfo.programName; $("#programName").val(curProgramName); // $("#programShortName").val(curProgramName);//Hide Short Name as per new requirement } // $("#communitySection").hide();---commented for new flow // ENABLE DISABLE PROGRAM/COMMUNITY $("#communityAssocChk").on("click", function() { if ($('#communityAssocChk').is(":checked") == true) { $("#communitySection").show(); $(".commDataSection").find("*").prop("disabled", false); $('#programAssocChk').prop("disabled", false); $('.wrkfl').text("Define Workflow and Content"); $('.contentManagement').show(); } else { $("#communitySection").hide(); $(".commDataSection").find("*").prop("disabled", true); $(".commDataSection").find("*").removeClass("has-error"); $('#programAssocChk').prop("disabled", true); $('.wrkfl').text("Define Workflow"); $('.contentManagement').hide(); } }); $("#programAssocChk").on("click", function() { if ($('#programAssocChk').is(":checked") == true) { $("#programSection").show(); $(".progDataSection").find("*").prop("disabled", false); $(".workflowSection").show(); $('#communityAssocChk').prop("disabled", false); $('.wrkfl').text("Define Workflow and Content"); $('.contentManagement').show(); } else { $("#programSection").hide(); $(".progDataSection").find("*").prop("disabled", true); $(".progDataSection").find("*").removeClass("has-error"); $(".workflowSection").hide(); $('#communityAssocChk').prop("disabled", true); $('.wrkfl').text("Define Content"); $('.contentManagement').show(); } }); //END var dependentdataattrArr = []; var dataattrDepenentObj = {}; dataattrDepenentObj.attributedependentquestions = []; $("#btn_addAttribute").on("click", function() { console.log("Add Attribute"); $("#addNewAttributeModal").modal('show'); $("#add_NewAttribute")[0].reset(); $("#option_section_addatribute").addClass('hidden'); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) // ATTRIBUTE DEPENDENCY LEVEL $('.level_1_attr_dependencylist').html(''); $(".level_1_attributeDependency").addClass('hidden'); $(".level_2_attributeDependency").addClass('hidden'); $("#add_NewAttribute :input").prop("disabled", false); $('#add_NewAttribute')[0].reset(); dependentdataattrArr = []; dataattrDepenentObj = {}; dataattrDepenentObj.attributedependentquestions = []; $(".btn_Add_Dependency_attr_Level_1").off("click"); $(".btn_Add_Dependency_attr_Level_1").on("click", function() { var isDuplicateParentAttr = false; var parentattrname = $('#attrName').val(); isDuplicateParentAttr = isDuplicateAttribute(parentattrname, trackedentityattributesArray); if (!isDuplicateParentAttr) { $('#add_NewAttribute_level_1')[0].reset(); $("#option_section_addatribute_level_1").addClass('hidden'); var isvalidDepencyAttrAdd = false; var mandatoryChk = $("input[name='radioMandatory']:checked").val(); var typeOfAttr = $("#selType").val(); if (_.isEmpty(parentattrname) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfAttr)) { isvalidDepencyAttrAdd = false; } else { isvalidDepencyAttrAdd = true; } if (isvalidDepencyAttrAdd == true) { var matchval = ""; if (typeOfAttr == "optionlist") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOptionAttr option:selected").val(); $("#add_NewAttribute :input").prop("disabled", true); $(".level_1_attributeDependency").removeClass('hidden'); $("#add_NewAttribute_level_1 :input").prop("disabled", false); $("#matchval_attr_options_level_1").removeClass('hidden'); $("#matchval_attr_txt_level_1").addClass('hidden'); $('#matchval_attr_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_attr_options_level_1").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if (typeOfAttr == "number") { $("#matchval_attr_txt_level_1").removeClass('hidden'); $("#matchval_attr_options_level_1").addClass('hidden'); $("#add_NewAttribute :input").prop("disabled", true); $("#add_NewAttribute_level_1 :input").prop("disabled", false); $(".level_1_attributeDependency").removeClass('hidden'); } else if (typeOfAttr == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#matchval_attr_txt_level_1").removeClass('hidden'); $("#matchval_attr_options_level_1").addClass('hidden'); $("#add_NewAttribute :input").prop("disabled", true); $("#add_NewAttribute_level_1 :input").prop("disabled", false); $(".level_1_attributeDependency").removeClass('hidden'); } $('#parentAtribute_level_1').text(parentattrname); $("#addNewAttributeModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - ATTRIBUTE ============================// $(".btn_AddOptionListQuestionProgram_level_1").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); $('.optValueProgram').val(''); $('.newAppend').remove(); }); // ADD DEPENDENT ATTRIBUTE $(".btn_submit_AddAttribute_level_1").off("click"); $(".btn_submit_AddAttribute_level_1").on("click", function() { if (typeOfAttr == "optionlist") { matchval = $("#matchval_attr_options_level_1 option:selected").val(); var selectedOptions = $("#TypeofOptionAttr option:selected").val(); dltype = "option"; typename = selectedOptions; } else if (typeOfAttr == "number") { matchval = $('#matchval_attr_txt_level_1').val(); dltype = "number"; typename = parentattrname; } else if (typeOfAttr == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#matchval_attr_txt_level_1').val(); dltype = "text"; typename = parentattrname; } var dependentattr = $("#attrName_level_1").val(); var deptypeOfAttr = $("#selType_level_1 option:selected").val(); var dependentattrmand = $("input[name='radioMandatory_level_1']:checked").val(); var depttypeOfAttrOption = $("#TypeofOptionAttr_level_1 option:selected").val(); var isDlAvailable = false; var attributeObj = {}; attributeObj.name = dependentattr; var flag = false; if (deptypeOfAttr == "optionlist") { if (_.isEmpty(depttypeOfAttrOption)) { flag = true; } else { attributeObj.type = "text"; attributeObj.optionname = depttypeOfAttrOption; } } else { attributeObj.type = deptypeOfAttr; } attributeObj.mandatory = dependentattrmand; if (_.isEmpty(dependentattr) == false && _.isEmpty(matchval) == false && _.isEmpty(dependentattrmand) == false && flag == false) { if (isValidEntry(dependentattr) == true) { var childel = { childdataelementname: dependentattr } var pardependentattr = { dataelementname: parentattrname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } var tempquestionlist = []; tempquestionlist.push(parentattrname); isDlAvailable = isDuplicateAttrwithDependency(dependentattr, tempquestionlist, trackedentityattributesArray, dependentdataattrArr); if (!isDlAvailable) { if (dataattrDepenentObj.attributedependentquestions.length > 0) { var isavailable = _(dataattrDepenentObj.attributedependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == parentattrname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataattrDepenentObj.attributedependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == parentattrname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentattr.dependentdataelementnames.push(childel); dataattrDepenentObj.attributedependentquestions.push(pardependentattr); } } else { pardependentattr.dependentdataelementnames.push(childel); dataattrDepenentObj.attributedependentquestions.push(pardependentattr); } console.log(dataattrDepenentObj); attributeObj.level = 'Level-1'; dependentdataattrArr.push(attributeObj); console.log(dependentdataattrArr); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + dependentattr + "
    "; $('.level_1_attr_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_attributeDependency").addClass('hidden'); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Attribute Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Attribute name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); $(".btn_close_attr_level_1").on("click", function() { $(".level_1_attributeDependency").addClass('hidden'); $("#add_NewAttribute :input").prop("disabled", false); }); // type of option change $("#selType_level_1").on("change", function() { if ($(this).val() == "optionlist") { $("#option_section_addatribute_level_1").removeClass('hidden'); } else { $("#option_section_addatribute_level_1").addClass('hidden'); } }); }); // ADD RELATIONSHIP $("#enablerelation").on("click", function() { if ($('#enablerelation').is(":checked") == true) { $("#btn_addAttribute").click(); $("#attrName").val("Client Type"); $("#attrName").attr("disabled", "disabled"); } else { swal({ title: 'Are you sure?', text: "Deletion of attribute will remove all dependencies.", type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) // cleanup console.log(trackedentityattributesArray); for (let i in trackedentityattributesArray) { if (trackedentityattributesArray[i].name == "Client Type") { trackedentityattributesArray.splice(i, 1); } else {} } // REMOVE DEPENDENT QUESTIONS var allchilds = []; for (let i in attributedependentquestions) { if (attributedependentquestions[i].dataelementname == "Client Type") { attributedependentquestions.splice(i, 1); } else {} } console.log(allchilds); $("#ulAttrName").html(''); $("#ulMandatoryList").html(''); $.each(trackedentityattributesArray, function(key, val) { $("#ulAttrName").append('
  • '); if (val.mandatory == "true") { $("#ulMandatoryList").append('
  • '); } else { $("#ulMandatoryList").append('
  • '); } }) }) } }); // ADD UIC MODAL WITH DYNAMIC DATA POPULATION IN DROPDOWN $("#addUICoption").on("click", function() { // var uicAttrArry = []; if ($('#addUICoption').is(":checked") == true) { console.log("generate uic modal"); $("#genUICmodal").modal('show'); // $("#selAttrType").prop('selectedIndex', 0); // $("#selDateFormat").prop('selectedIndex', 0); $("#inpFormat").val(''); // $("#inpSequence").val(''); UIC = ''; console.log(trackedentityattributesArray); /* add default options to attribute select */ var attrOption = ''; $('#selAttribute').html(''); $('#selAttribute').children('option:not(:first)').remove(); for (var i = 0; i < trackedentityattributesArray.length; i++) { if (trackedentityattributesArray[i].mandatory == 'true') { attrOption += ''; UIC += trackedentityattributesArray[i].name; } } $('#selAttribute').append(attrOption); // remove options from select attribute which are already added in UIC attribute for (let j in temoUICArray) { $("#selAttribute option[value='" + temoUICArray[j].attributename + "']").remove(); } if ($("#selAttribute option:selected").data('type') == "date") { $('#selDateFormat').removeClass('hidden'); $('#inpFormat').hide(); } else { $('#inpFormat').show(); $('#selDateFormat').addClass('hidden'); } // generate UIC atribute table if there is any data already added $('#uicAttrTable > tbody').html(''); if (temoUICArray.length > 0) { for (let k in temoUICArray) { var attrRow = "" + temoUICArray[k].attributename + "" + "" + temoUICArray[k].type + "" + "" + temoUICArray[k].format + "" + "" + "clear"; $('#uicAttrTable > tbody').append(attrRow); } } else { } $('#editUIC').removeClass('hidden'); } else { temoUICArray = []; $('#editUIC').addClass('hidden'); } }); $("#selType").on("change", function() { if ($("#selType").val() == "optionlist") { $("#option_section_addatribute").removeClass('hidden'); } else { $("#option_section_addatribute").addClass('hidden'); } }); //=======ADD UIC ATTRIBUTE BUTTON=========================== $(".btn_addAtriforUIC").on("click", function() { var attrformat = ""; if ($("#selAttribute option:selected").data('type') == "date") { attrformat = $('#selDateFormat').val(); } else { attrformat = $('#inpFormat').val(); } if ($("#selAttribute").val() != null && attrformat != "") { $.each(trackedentityattributesArray, function(key, value) { if (value.name == $("#selAttribute").val()) { // temoUICArray.push(trackedentityattributesArray[key]); var uicarr = { "attributename": value.name, "type": value.type, "format": attrformat // "uicode": temcrop }; temoUICArray.push(uicarr); console.log(temoUICArray); } }); $('#uicAttrTable > tbody').html(""); $.each(temoUICArray, function(key, value) { var attrRow = "" + value.attributename + "" + "" + value.type + "" + "" + value.format + "" + "" + "" + "clear" + ""; $('#uicAttrTable > tbody').append(attrRow); }); $("#selAttribute option[value='" + $("#selAttribute").val() + "']").remove(); $("#selAttribute").prop('selectedIndex', 0); // $("#selAttrType").prop('selectedIndex', 0); $("#selDateFormat").prop('selectedIndex', 0); $("#inpFormat").val(''); // $("#inpSequence").val(''); $('.warningmsg').addClass('hidden'); if ($("#selAttribute option:selected").data('type') == "date") { $('#selDateFormat').removeClass('hidden'); $('#inpFormat').hide(); } else { $('#inpFormat').show(); $('#selDateFormat').addClass('hidden'); } $.each(temoUICArray, function(key, val) { temoUICArray[key].sequence = '' + (key + 1) + ''; }); console.log('attribute addd'); console.log(temoUICArray); } else { // $('.warningmsg').removeClass('hidden'); bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } // $(".removeme").attr("onclick", "removeme()"); }); $("#selAttribute").change(function() { if ($("#selAttribute option:selected").data('type') == "date") { $('#selDateFormat').removeClass('hidden'); $('#inpFormat').hide(); } else { $('#selDateFormat').addClass('hidden'); $('#inpFormat').show(); } }); $('.close').on("click", function() {}); // REMOVE ROW ITEM $(document).on('click', '.removeRow', function() { $(this).parent().parent().remove(); var optionadd = $(this).closest('tr').children('td:first').text(); var optiontype = $(this).closest('tr').children('td:nth-child(2)').text(); var attrOption = ''; $('#selAttribute').append(attrOption); for (let j in temoUICArray) { if (temoUICArray[j].attributename == optionadd) { temoUICArray.splice(j, 1); } } if ($("#selAttribute option:selected").data('type') == "date") { $('#selDateFormat').removeClass('hidden'); $('#inpFormat').hide(); } else { $('#inpFormat').show(); $('#selDateFormat').addClass('hidden'); } console.log('------------------------'); console.log(temoUICArray); console.log('------------------------'); }); // EDIT UIC $("#editUIC").on("click", function() { $("#genUICmodal").modal('show'); $('#selAttribute').html(''); var attrOption = ''; for (var i = 0; i < trackedentityattributesArray.length; i++) { if (trackedentityattributesArray[i].mandatory == 'true') { attrOption += ''; UIC += trackedentityattributesArray[i].name; } } $('#selAttribute').append(attrOption); if ($("#selAttribute option:selected").data('type') == "date") { $('#selDateFormat').removeClass('hidden'); $('#inpFormat').hide(); } else { $('#inpFormat').show(); $('#selDateFormat').addClass('hidden'); } // POPULATE UIC TABLE $('#uicAttrTable > tbody').html(""); $.each(temoUICArray, function(key, value) { var attrRow = "" + value.attributename + "" + "" + value.type + "" + "" + value.format + "" + "" + "" + "clear" + ""; $('#uicAttrTable > tbody').append(attrRow); }); // remove options from select attribute which are already added in UIC attribute for (let j in temoUICArray) { $("#selAttribute option[value='" + temoUICArray[j].attributename + "']").remove(); } }); // TABLE ROW MOVE UP AND DOWN $(document).on('click', '#uicAttrTable img.move', function() { var row = $(this).closest('tr'); // var srow = $(this).parent().parent().children().index(row); // alert($(this).attr("value")); var attrnam = $(this).attr("value"); var rownum = row.index(); if ($(this).hasClass('up')) { row.prev().before(row); // temoUICArray[$(this).val()].sequence = '' + row.index() + ''; } else { row.next().after(row); // temoUICArray[$(this).val()].sequence = '' + row.index() + ''; } // sequencing the array as per table row var rows = $("#uicAttrTable>tbody>tr"); $.each(rows, function(key, val) { console.log(key); // alert($(rows[key]).find("td:nth-child(1)").html()); var tdval = $(rows[key]).find("td:nth-child(1)").html(); $.each(temoUICArray, function(key1, val) { if (temoUICArray[key1].attributename == tdval) { temoUICArray[key1].sequence = '' + (parseInt(key) + 1) + ''; } }); }); // $.each(temoUICArray, function(key, val) { // if (temoUICArray[key].attributename == attrnam) { // temoUICArray[rownum].sequence = '' + rownum + ''; // } // }); console.log(temoUICArray); }); //END $(".btn_GenUICode").on("click", function() { // $('#uicAttrTable tbody').each(function() { // alert($(this).find("tr").index()); // }); // $.each(temoUICArray, function(key, val) { // temoUICArray[key].sequence = '' + (key + 1) + ''; // }); // console.log(temoUICArray); }); //=======End ADD UIC ATTRIBUTE BUTTON======================= //=======ADD ATTRIBUTE BUTTON=========================== var deletedAttribute = []; $(document).on('click', 'input.checkAttribute', function() { var sThisVal = $(this).val(); if ($(this).is(':checked')) { for (let i in deletedAttribute) { if (deletedAttribute[i].name == sThisVal) { trackedentityattributesArray.push(deletedAttribute[i]); deletedAttribute.splice(i, 1); } else { } } } else { $("#idMand_" + sThisVal.replace(/ /g, '')).prop('checked', false); if ($("#addUICoption").is(':checked')) { $("#addUICoption").click(); temoUICArray = []; } for (let i in trackedentityattributesArray) { if (trackedentityattributesArray[i].name == sThisVal) { trackedentityattributesArray[i].mandatory = "false"; deletedAttribute.push(trackedentityattributesArray[i]); trackedentityattributesArray.splice(i, 1); // trackedentityattributesArray[i].mandatory = "false"; } else { } } } console.log('-----------------------'); console.log(trackedentityattributesArray); console.log(deletedAttribute); console.log(temoUICArray); console.log('-------------------------'); }); $(document).on('click', 'input.checkAttributemand', function() { var sThisVal = $(this).val(); if ($(this).is(':checked')) { // $("#id_"+sThisVal). for (let i in trackedentityattributesArray) { if (trackedentityattributesArray[i].name == sThisVal) { trackedentityattributesArray[i].mandatory = "true"; } else { } } } else { for (let i in trackedentityattributesArray) { if (trackedentityattributesArray[i].name == sThisVal) { trackedentityattributesArray[i].mandatory = "false"; } else { } } } console.log('-----------------------'); console.log(trackedentityattributesArray); console.log('-------------------------'); }); //SUBMIT ADDRIBUTE $(".btn_submit_AddAttribute").on("click", function() { var attrname = $("#attrName").val(); var selname = $("#selType").val(); var mandatoryVal = $("input[name='radioMandatory']:checked").val(); var attributeObj = {}; attributeObj.name = $("#attrName").val(); var flag = false; if ($("#selType").val() == "optionlist") { if (_.isEmpty($('#TypeofOptionAttr').val())) { flag = true; } else { attributeObj.type = "text"; attributeObj.optionname = $('#TypeofOptionAttr').val(); } } else { attributeObj.type = $("#selType").val(); } // alert(attributeObj.optionname); if (_.isEmpty(attrname) == false && _.isEmpty(selname) == false && _.isEmpty(mandatoryVal) == false && flag == false) { if (isValidEntry(attrname) == true) { attributeObj.mandatory = $("input[name='radioMandatory']:checked").val(); var isDlAvailable = false; var tempquestionlist = []; var tempdependentdataattrArr = []; isDlAvailable = isDuplicateAttrwithDependency(attrname, tempquestionlist, trackedentityattributesArray, tempdependentdataattrArr); if (!isDlAvailable) { trackedentityattributesArray.push(attributeObj); dependentdataElementarr = cleanChildObj(dependentdataattrArr); trackedentityattributesArray = trackedentityattributesArray.concat(dependentdataattrArr); if (_.isEmpty(dataattrDepenentObj.attributedependentquestions) == false) { // $.each(trackedentityattributesArray, function(i, e) { // if (dataattrDepenentObj.attributedependentquestions[0].dataelementname == e.name) { // if (_.isUndefined(e.attributedependentquestions)) { // e.attributedependentquestions = []; // e.attributedependentquestions = e.attributedependentquestions.concat(dataattrDepenentObj.attributedependentquestions); // } else { // e.attributedependentquestions = e.attributedependentquestions.concat(dataattrDepenentObj.attributedependentquestions); // } // } // }); attributedependentquestions = attributedependentquestions.concat(dataattrDepenentObj.attributedependentquestions); } console.log(trackedentityattributesArray); console.log(attributedependentquestions); $("#addNewAttributeModal").modal('hide'); // add_NewAttribute $("#ulAttrName").html(''); $("#ulMandatoryList").html(''); $(this).closest('form').find("input[type=text],input[type=number], textarea").val(""); $.each(trackedentityattributesArray, function(key, val) { $("#ulAttrName").append('
  • '); if (val.mandatory == "true") { $("#ulMandatoryList").append('
  • '); } else { $("#ulMandatoryList").append('
  • '); } }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Attribute Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Attribute name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); ///////////////////////////////PROGRAM AND COMMUNITY SECTION /////////////////// //// PROGRAM ICONS SECTION $("#pgmIcon").on('focus', function(evt) { $('#imgsectionPGM').html(''); $('#choosePgmIconModal').modal('show'); generateICONView("assets/img/appIcon/", "imgsectionPGM", "pgmicons"); }); // icon select click $(document).on('click', '.pgmicons', function() { //alert($(this).attr("src")); $('#pgmIcon').val($(this).attr("src")); $('#iconviewpgm').attr("src", "" + $('#pgmIcon').val()); setLocalStorage("pgmicon", $('#pgmIcon').val()); $('#choosePgmIconModal').modal('hide'); }); //// COMMUNITY ICONS SECTION // WORKFLOW var ishasWorkflow = false; // $('.workflowtab').hide(); $('.hasworkflow').hide(); $('.noworkflow').show(); $("#hasWorkflow").on("click", function() { if ($("#hasWorkflow").is(':checked')) { ishasWorkflow = true; // $('.workflowtab').show(); $('.hasworkflow').show(); $('.noworkflow').hide(); } else { ishasWorkflow = false; // $('.workflowtab').hide(); $('.hasworkflow').hide(); $('.noworkflow').show(); } }) // browse icon $("#comIcon").on('focus', function(evt) { $('#imgsectioncom').html(''); $('#chooseCommIconModal').modal('show'); generateICONView("assets/img/appIcon/", "imgsectioncom", "comicons"); }); // icon select click $(document).on('click', '.comicons', function() { //alert($(this).attr("src")); $('#comIcon').val($(this).attr("src")); $('#iconviecom').attr("src", "" + $('#comIcon').val()); setLocalStorage("comicon", $('#comIcon').val()); $('#chooseCommIconModal').modal('hide'); }); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //==========PROGRAM SERVICE================================= $(".btn_ProgramAddService").on("click", function() { $("#addNewProgramServiceModal").modal("show"); }); //=============== ADD NEW SERVICE - PROGRAM ========================// var serviceName; $(".btn_submit_AddProgramService").on("click", function() { if (isValidEntry($('#servNameProgram').val()) == true) { $("#programservice").empty(); console.log("AddProgramService"); var programStage = {}; var dataelementsArray = []; if ($('.selectRoleForworkflowPGM').prop("checked") == true) { $('.selectRoleForworkflowPGM').click(); } serviceName = $("#servNameProgram").val(); // var serviceShortName = $("#servShrtNameProgram").val(); var serviceShortName = $("#servNameProgram").val(); //Set Short Name same as Service Name programsObj.name = programName; // programsObj.shortname = programShortName; programsObj.shortname = programName; //Program Short Name = Program Name (New Requirement) programsObj.logo = ""; programStage.name = serviceName; programStage.dataelements = dataelementsArray if (programStagesArray.length > 0) { var duplicatecheck = isDuplicateReord(programStagesArray, programStage); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Service Already Available with this name.", callback: function() { } }); } else { programStagesArray.push(programStage); $("#addNewProgramServiceModal").modal("hide"); } } else { programStagesArray.push(programStage); $("#addNewProgramServiceModal").modal("hide"); } setLocalStorage("programStageArray", programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); //========= BUTTON TO SHOW QUESTIONS MODAL======== $(document).on('click', '.btn_ProgramAddQuestion', function() { $("#addNewProgramQuestionModal").modal("show"); $('.btn_edit_AddQuestionProgram').hide(); $('.btn_submit_AddQuestionProgram').show(); $(".btn_Add_Dependency_Level_1").show(); var pgservname = $(this).data('stage-name'); $("#programservice").text(pgservname); $('.level_1_dependencylist').html(''); $(".level_1_dependency").addClass('hidden'); $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); $('#add_NewProgramQuestion')[0].reset(); $('#questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) //////DEPENDENCY //##################################################DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_1").off("click"); $(".btn_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#programservice").text(); var parentqname = $('#questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, programStagesArray); if (!isDuplicateParent) { $("#option_section_program_level_1").addClass('hidden'); $("#check_section_program_level_1").addClass('hidden'); $('#add_NewProgramQuestion_level_1')[0].reset(); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory']:checked").val(); var typeOfQuestion = $("#TypeofQuest").val(); if (_.isEmpty($('#questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName').val()) == true) { $(".parent_action_btns_section :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption option:selected").val(); $("#add_NewProgramQuestion :input").prop("disabled", true); $(".level_1_dependency").removeClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_1").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "checkboxoption") { var options = $('#TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "number") { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName').val(); $('#pquestion_level_1').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level1").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_1").off("click"); $(".btn_submit_AddQuestionProgram_level_1").on("click", function() { if ($("#TypeofQuest").val() == "option list") { matchval = $("#matchval_options_level_1 option:selected").val(); var selectedOptions = $("#TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest").val() == "checkboxoption") { matchval = $('#matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest").val() == "number") { matchval = $('#matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_1").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_1").val(); var depttypeOfOption = $("#TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_1 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#questName_level_1").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".parent_action_btns_section :input").prop("disabled", false); $(".level_1_dependency").addClass('hidden'); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_1").removeClass('hidden'); } else { $("#option_section_program_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_1").removeClass('hidden'); $("#TypeofOptionCheck_level_1").html(""); } else { $("#check_section_program_level_1").addClass('hidden'); } }); $(".btn_close_level_1").off("click"); $(".btn_close_level_1").on("click", function() { $(".level_1_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_2").off("click"); $(".btn_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#questName_level_1').val(); var parentqname = $('#questName').val(); var parentqname_level1 = $('#questName_level_1').val(); tempquestionlist.push(parentqname); var parentservname = $("#programservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $('#add_NewProgramQuestion_level_2')[0].reset(); $("#option_section_program_level_2").addClass('hidden'); $("#check_section_program_level_2").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var typeOfQuestion = $("#TypeofQuest_level_1").val(); if (_.isEmpty($('#questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName_level_1').val()) == true) { $(".parent_child_1_action_btn :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_2").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "number") { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName_level_1').val(); $('#pquestion_level_2').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level2").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_2").off("click"); $(".btn_submit_AddQuestionProgram_level_2").on("click", function() { if ($("#TypeofQuest_level_1").val() == "option list") { matchval = $("#matchval_options_level_2 option:selected").val(); var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest_level_1").val() == "number") { matchval = $('#matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_2").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_2']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_2").val(); var depttypeOfOption = $("#TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_2 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; var qnameParent = $('#questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#questName_level_2").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency").addClass('hidden'); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_2").removeClass('hidden'); } else { $("#option_section_program_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_2").removeClass('hidden'); $("#TypeofOptionCheck_level_2").html(""); } else { $("#check_section_program_level_2").addClass('hidden'); } }); $(".btn_close_level_2").off("click"); $(".btn_close_level_2").on("click", function() { $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); }); $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter Valid Service Name", callback: function() { } }); } }) //================TYPE OF QUESTION DEPENDENCY=============================// $("#option_section_program").hide(); $("#check_section_program").hide(); $("#TypeofQuest").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program").show(); } else { $("#option_section_program").hide(); } if ($(this).val() == "checkboxoption") { $("#check_section_program").show(); $("#TypeofOptionCheck").html(""); } else { $("#check_section_program").hide(); } }); //================== ADD NEW QUESTION - PROGRAM =========================// $(".btn_submit_AddQuestionProgram").on("click", function() { console.log(programStagesArray); console.log("AddQuestionProgram"); var dataElementObj = {}; serviceName = $("#programservice").text(); var oldquestion = $("#questName").data('old_name'); var questionName = $("#questName").val(); var isDuplicateFound = isDuplicateDataElement(serviceName, oldquestion, programStagesArray); if (!isDuplicateFound) { // var questionShortName = $("#questShrtName").val(); - Removed Question Short Name as per new Requirement var questionShortName = $("#questName").val(); var mandatoryChk = $("input[name='prgm_radioMandatory']:checked").val(); var typeOfQuestion = $("#TypeofQuest").val(); var typeOfOption = $("#TypeofOption").val(); var typeOfcheck = $("#TypeofOptionCheck").val(); //===HARDCODED OPTION LIST VALUE AS TEXT(REQUIRED BY SERVICE) var flagOption = false; if (typeOfQuestion == "option list") { typeOfQuestion = "text" if (typeOfOption != "" && typeOfOption != null) { dataElementObj.optionname = typeOfOption } else { flagOption = true; } } if (typeOfQuestion == "checkboxoption") { typeOfQuestion = "text" if (typeOfcheck != "" && typeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } if (questionName != "" && mandatoryChk != undefined && typeOfQuestion != "" && flagOption == false) { if (isValidEntry(questionName) == true) { var optiontext = $("#TypeofQuest option:selected").text(); if (optiontext == "Facility") { dataElementObj.facility = "true"; } dataElementObj.name = questionName dataElementObj.type = typeOfQuestion dataElementObj.mandatory = mandatoryChk $.each(programStagesArray, function(i, e) { console.log(e); if (e.name == serviceName) { console.log(e.dataelements); e.dataelements.push(dataElementObj); dependentdataElementarr = cleanChildObj(dependentdataElementarr); e.dataelements = e.dataelements.concat(dependentdataElementarr); if (_.isUndefined(e.dependentquestions)) { if (_.isEmpty(dataDepenentObj.dependentquestions) == false) { e.dependentquestions = []; e.dependentquestions = e.dependentquestions.concat(dataDepenentObj.dependentquestions); } } else { if (_.isEmpty(dataDepenentObj.dependentquestions) == false) { e.dependentquestions = e.dependentquestions.concat(dataDepenentObj.dependentquestions); } } } }); dependentdataElementarr = []; dataDepenentObj = {}; console.log(programStagesArray); setLocalStorage("programStageArray", programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); //========= BUTTON TO SHOW QUESTIONS MODAL======== $(document).on('click', '.btn_ProgramAddQuestion', function() { $("#addNewProgramQuestionModal").modal("show"); $(".btn_Add_Dependency_Level_1").show(); $('.btn_edit_AddQuestionProgram').hide(); $('.btn_submit_AddQuestionProgram').show(); $("#option_section_program").hide(); $("#check_section_program").hide(); var pgservname = $(this).data('stage-name'); $("#programservice").text(pgservname); $('.level_1_dependencylist').html(''); $(".level_1_dependency").addClass('hidden'); $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); $('#add_NewProgramQuestion')[0].reset(); $('#questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) //////DEPENDENCY //##################################################DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_1").off("click"); $(".btn_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#programservice").text(); var parentqname = $('#questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, programStagesArray); if (!isDuplicateParent) { $('#add_NewProgramQuestion_level_1')[0].reset(); $("#option_section_program_level_1").addClass('hidden'); $("#check_section_program_level_1").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory']:checked").val(); var typeOfQuestion = $("#TypeofQuest").val(); if (_.isEmpty($('#questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName').val()) == true) { $(".parent_action_btns_section :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption option:selected").val(); $("#add_NewProgramQuestion :input").prop("disabled", true); $(".level_1_dependency").removeClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_1").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "checkboxoption") { var options = $('#TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); $("#matchval_options_level_1").removeClass('hidden'); $("#matchval_txt_level_1").addClass('hidden'); $('#matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest").val() == "number") { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { $("#matchval_txt_level_1").removeClass('hidden'); $("#matchval_options_level_1").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", true); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName').val(); $('#pquestion_level_1').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level1").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_1").off("click"); $(".btn_submit_AddQuestionProgram_level_1").on("click", function() { if ($("#TypeofQuest").val() == "option list") { matchval = $("#matchval_options_level_1 option:selected").val(); var selectedOptions = $("#TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest").val() == "checkboxoption") { matchval = $('#matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest").val() == "number") { matchval = $('#matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest").val() == "date" || $("#TypeofQuest option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_action_btns_section :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_1").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_1").val(); var depttypeOfOption = $("#TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_1 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#questName_level_1").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_dependency").addClass('hidden'); $(".parent_action_btns_section :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_1").removeClass('hidden'); } else { $("#option_section_program_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_1").removeClass('hidden'); $("#TypeofOptionCheck_level_1").html(""); } else { $("#check_section_program_level_1").addClass('hidden'); } }); $(".btn_close_level_1").off("click"); $(".btn_close_level_1").on("click", function() { $(".level_1_dependency").addClass('hidden'); $("#add_NewProgramQuestion :input").prop("disabled", false); $(".parent_action_btns_section :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_Add_Dependency_Level_2").off("click"); $(".btn_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#questName_level_1').val(); var parentqname = $('#questName').val(); tempquestionlist.push(parentqname); var parentservname = $("#programservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $("#option_section_program_level_2").addClass('hidden'); $("#check_section_program_level_2").addClass('hidden'); $('#add_NewProgramQuestion_level_2')[0].reset(); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='prgm_radioMandatory_level_1']:checked").val(); var typeOfQuestion = $("#TypeofQuest_level_1").val(); if (_.isEmpty($('#questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(typeOfQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#questName_level_1').val()) == true) { $(".parent_child_1_action_btn :input").prop("disabled", true); var matchval = ""; if ($("#TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#matchval_options_level_2").append(''); }) // matchval = $('#matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); $("#matchval_options_level_2").removeClass('hidden'); $("#matchval_txt_level_2").addClass('hidden'); $('#matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#TypeofQuest_level_1").val() == "number") { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { $("#matchval_txt_level_2").removeClass('hidden'); $("#matchval_options_level_2").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency").removeClass('hidden'); } var servname = $("#programservice").text(); var qname = $('#questName_level_1').val(); $('#pquestion_level_2').text(qname); $("#addNewProgramQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_addOptionListQuestionProgram_level2").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".optionValues_ProgQuest").off("click"); $(".optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddQuestionProgram_level_2").off("click"); $(".btn_submit_AddQuestionProgram_level_2").on("click", function() { if ($("#TypeofQuest_level_1").val() == "option list") { matchval = $("#matchval_options_level_2 option:selected").val(); var selectedOptions = $("#TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#TypeofQuest_level_1").val() == "number") { matchval = $('#matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#TypeofQuest_level_1").val() == "date" || $("#TypeofQuest_level_1 option:selected").text() == "Facility") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { matchval = $('#matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#questName_level_2").val(); var depmandatoryChk = $("input[name='prgm_radioMandatory_level_2']:checked").val(); var deptypeOfQuestion = $("#TypeofQuest_level_2").val(); var depttypeOfOption = $("#TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = deptypeOfQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (deptypeOfQuestion == "option list") { dependentdataElementObj.type = "text" if (depttypeOfOption != "" && depttypeOfOption != null) { dependentdataElementObj.optionname = depttypeOfOption } else { flagOption = true; } } if (deptypeOfQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && deptypeOfQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var optiontext = $("#TypeofQuest_level_2 option:selected").text(); if (optiontext == "Facility") { dependentdataElementObj.facility = "true"; } var tempquestionlist = []; var qnameParent = $('#questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, programStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#questName_level_2").val() + "
    "; $('.level_1_dependencylist').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency").addClass('hidden'); $(".parent_child_1_action_btn :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_program_level_2").removeClass('hidden'); } else { $("#option_section_program_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_program_level_2").removeClass('hidden'); $("#TypeofOptionCheck_level_2").html(""); } else { $("#check_section_program_level_2").addClass('hidden'); } }); $(".btn_close_level_2").off("click"); $(".btn_close_level_2").on("click", function() { $(".level_2_dependency").addClass('hidden'); $("#add_NewProgramQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); $('#TypeofQuest option:selected').removeAttr('selected'); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); $(".btn_edit_AddQuestionProgram").on("click", function() { console.log("Modify"); var selectQuest = $("#questName").val(); console.log(programStagesArray); $.each(programStagesArray, function(key1, val1) { $.each(programStagesArray[key1].dataelements, function(key2, val2) { if (programStagesArray[key1].dataelements[key2].name == selectQuest) { programStagesArray[key1].dataelements[key2].type = $('#TypeofQuest').val(); } }); }); $("#addNewProgramQuestionModal").modal("hide"); }); // DELETE CHILD ELEMENT $(document).on('click', '.btn_Delete', function() { console.log("Delete"); var qesname = $(this).closest('tr').children('td:nth-child(2)').text(); console.log(qesname); var stagename = $(this).closest('table').data('stage-name'); var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { return item.dataelementname.replace(/ /g, '').toLowerCase() == qesname.replace(/ /g, '').toLowerCase() }); } }); var tempmsg = ""; if (!_.isEmpty(isPartOfParent)) { tempmsg = "Deletion of this question will reset all dependencies on this question."; } swal({ title: 'Are you sure?', text: tempmsg, type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) var dataelObjCombo = deleteDataElementWithAvailableChildonStage(stagename, qesname, programStagesArray); programStagesArray = dataelObjCombo; console.log(programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); }).catch(swal.noop) }); }); $("#addNewProgramQuestionModal").modal("hide"); $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else { // program edit submit by sohan // bootbox.alert({ // size: "small", // title: "iMonitor +", // message: "Question Already Available with this name.", // callback: function() { // } // }); console.log(serviceName); console.log(questionName); var dataElementObj = {}; var mandatoryChk = $("input[name='prgm_radioMandatory']:checked").val(); var typeOfQuestion = $("#TypeofQuest").val(); var typeOfOption = $("#TypeofOption").val(); var typeOfcheck = $("#TypeofOptionCheck").val(); //===HARDCODED OPTION LIST VALUE AS TEXT(REQUIRED BY SERVICE) var flagOption = false; if (typeOfQuestion == "option list") { typeOfQuestion = "text" if (typeOfOption != "" && typeOfOption != null) { dataElementObj.optionname = typeOfOption } else { flagOption = true; } } if (typeOfQuestion == "checkboxoption") { typeOfQuestion = "text" if (typeOfcheck != "" && typeOfcheck != null) { var checkvalues = $('#TypeofOptionCheck option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } if (questionName != "" && mandatoryChk != undefined && typeOfQuestion != "" && flagOption == false) { if (isValidEntry(questionName) == true) { var optiontext = $("#TypeofQuest option:selected").text(); if (optiontext == "Facility") { dataElementObj.facility = "true"; } dataElementObj.name = questionName dataElementObj.type = typeOfQuestion dataElementObj.mandatory = mandatoryChk swal({ title: 'Are you sure?', // text: "Data Element is Already Available!", type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Update it!', buttonsStyling: false }).then(function() { swal({ title: 'Updated!', text: 'Updated Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) $.each(programStagesArray, function(key, val) { if (val.name == serviceName) { $.each(val.dataelements, function(key1, val1) { if (val1.name == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val.dataelements[key1] = dataElementObj; } }); $.each(val.dependentquestions, function(key2, val2) { if (val2.dataelementname == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val2.dataelementname = questionName; } $.each(val2.dependentdataelementnames, function(key3, val3) { if (val3.childdataelementname == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val3.childdataelementname = questionName; } }); }); } }); console.log(programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); console.log(optionsArray); $.each(optionsArray, function(i, e) { // $("#TypeofOption").append('');; $("#TypeofOption").append('');; }) // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } // var seleType = $(this).closest('tr').children('td:nth-child(3)').text(); console.log(selectQuest); var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } }); }); $("#addNewProgramQuestionModal").modal("hide"); }).catch(swal.noop) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } }); //=============== ADD OPTION LIST - PROGRAM ============================// $(".btn_AddOptionListQuestionProgram").on("click", function() { $("#addNewProgramDefineOptionSetModal").modal("show"); $('#optNameProgram').val(''); $('.optvlas').val(''); if ($("#TypeofQuest").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } // $('.input_fields_container').remove('.newAppend'); // $(".input_fields_container").remove(":contains('newAppend')"); $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - PROGRAM =========================// $(".add_optionValues_ProgQuest").off("click"); $(".add_optionValues_ProgQuest").on("click", function() { $('.input_fields_container').append('
    '); $('.optvlas').val(''); $('.optvlas').focus(); }); $(".abc").on("click", '.remove_optionValues_ProgQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // $('.remove_optionValues_ProgQuest').parent().parent().remove(); }); // DELETE CHILD ELEMENT $(document).on('click', '.custom-alert-list>.close', function() { var qesname = $(this).parent().find('.chdelname').text(); // WORK IN PROGRESS $(this).parent().remove(); var dataelObjCombo = deleteDataElementWithAvailableChild(qesname, dependentdataElementarr, dataDepenentObj.dependentquestions); dependentdataElementarr = dataelObjCombo.dependentdataElementarr; dataDepenentObj.dependentquestions = dataelObjCombo.dataDepenentObj; $('.level_1_dependencylist').html(""); $.each(dependentdataElementarr, function(key, val) { var temshtml = ""; temshtml += "
    [" + val.level + "]" + val.name + "
    "; $('.level_1_dependencylist').append(temshtml); }) }); // DELETE CHILD ELEMENT $(document).on('click', '.custom-alert-list_attr>.close', function() { var attrname = $(this).parent().find('.chdelname').text(); // WORK IN PROGRESS $(this).parent().remove(); var dataelObjCombo = deleteAttributeWithAvailableChild(attrname, dependentdataattrArr, dataattrDepenentObj.attributedependentquestions); dependentdataattrArr = dataelObjCombo.dependentdataattrArr; dataattrDepenentObj.attributedependentquestions = dataelObjCombo.attributedependentquestions; $('.level_1_dependencylist').html(""); $.each(dependentdataattrArr, function(key, val) { var temshtml = ""; temshtml += "
    [" + val.level + "]" + val.name + "
    "; $('.level_1_dependencylist').append(temshtml); }) }); // DELETE PROGRAM STAGE $(document).on('click', '.btn_Delete_stage', function() { var stagename = $(this).data('stage-name'); swal({ title: 'Are you sure you want to delete ?', text: 'Service delete will reset workflow.', type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Stage Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) // WORKFLOW RESET pgrolesforstage = []; stageroles = []; $('.selectRoleForworkflowPGM').prop("checked", false); $('#stageRoleAssignTBL > tbody').html(''); $('#step').html(''); $('#stageRoleAssignTBL > thead >tr').html(''); programStagesArray = _(programStagesArray).filter(function(item) { return item.name !== stagename }); console.log(programStagesArray); $.get('app/templates/listProgramServiceQuestionTbl_template.html', function(data) { $("#listProgramServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(programStagesArray); $("#listProgramServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN PROGRAM $(".btn_Edit").on("click", function() { console.log("Edit"); $('.level_1_dependencylist').html(""); $("#add_NewProgramQuestion :input").prop("disabled", false); $("#addNewProgramQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#programservice").text(stagename); $('#questName').val(selectQuest); $('#questName').data("old_name", selectQuest); var dataelementArrObj; _.map(programStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=prgm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#TypeofQuest").val("option list").change(); $("#option_section_program").show(); $("#check_section_program").hide(); $("#TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#TypeofQuest").val("checkboxoption").change(); $("#check_section_program").show(); $("#option_section_program").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#TypeofOptionCheck").append(''); }) $(".btn_Add_Dependency_Level_1").hide(); } else { if (!_.isUndefined(dataelementArrObj[0].facility)) { $("#TypeofQuest option:contains(Facility)").prop('selected', 'selected'); } else { $("#TypeofQuest").val(dataelementArrObj[0].type).change(); } $("#option_section_program").hide(); $("#check_section_program").hide(); $(".btn_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(programStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewProgramQuestion select").prop("disabled", true); $("#add_NewProgramQuestion input:radio").prop("disabled", true); $("#add_NewProgramQuestion").addClass('warningfordependency'); console.log(selectQuest); } else { $("#add_NewProgramQuestion select, input:radio").prop("disabled", false); $("#add_NewProgramQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); }).catch(swal.noop) }); // DELETE COMMUNITY STAGE $(document).on('click', '.btn_Delete_stage_comm', function() { var stagename = $(this).data('stage-name'); swal({ title: 'Are you sure you want to delete ?', text: 'Service delete will reset workflow.', type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Stage Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) // WORKFLOW RESET pgrolesforstage = []; stageroles = []; $('.selectRoleForworkflowPGM').prop("checked", false); $('#stageRoleAssignTBL > tbody').html(''); $('#step').html(''); $('#stageRoleAssignTBL > thead >tr').html(''); communitiesStagesArray = _(communitiesStagesArray).filter(function(item) { return item.name !== stagename }); console.log(communitiesStagesArray); $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); }).catch(swal.noop) }); $(".btn_submit_AddProgram_OptionSet").off("click"); $(".btn_submit_AddProgram_OptionSet").on("click", function() { var countBlank = 0; if ($('.level_1_dependency').hasClass('hidden') == false && $("#add_NewProgramQuestion_level_1 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var typeOfQuestion = $("#TypeofQuest_level_1").val(); if (typeOfQuestion == "checkboxoption") { $('#optNameProgram').val("text"); } if ($('#optNameProgram').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { // $("#TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="product_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameProgram").val(); // console.log("arrya"); // console.log(optionsArray); if (typeOfQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#TypeofOptionCheck_level_1").append(''); }) $("#addNewProgramDefineOptionSetModal").modal("hide"); console.log(CheckArray); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } // $("#TypeofOption").html(''); $("#TypeofOption_level_1").html(''); $.each(optionsArray, function(i, e) { // $("#TypeofOption").append('');; $("#TypeofOption_level_1").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else if ($('.level_2_dependency').hasClass('hidden') == false && $("#add_NewProgramQuestion_level_2 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var typeOfQuestion = $("#TypeofQuest_level_2").val(); if (typeOfQuestion == "checkboxoption") { $('#optNameProgram').val("text"); } if ($('#optNameProgram').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { // $("#TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="product_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameProgram").val(); // console.log("arrya"); // console.log(optionsArray); if (typeOfQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#TypeofOptionCheck_level_2").append(''); }) $("#addNewProgramDefineOptionSetModal").modal("hide"); console.log(CheckArray); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } // $("#TypeofOption").html(''); // $("#TypeofOption_level_1").html(''); $("#TypeofOption_level_2").html(''); $.each(optionsArray, function(i, e) { // $("#TypeofOption").append('');; // $("#TypeofOption_level_1").append('');; $("#TypeofOption_level_2").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else if ($('.level_1_attributeDependency').hasClass('hidden') == false && $("#add_NewAttribute_level_1 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var typeOfAttr = $("#selType_level_1").val(); if ($('#optNameProgram').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { $("#TypeofOptionAttr_level_1").empty(); // $("#TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="product_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameProgram").val(); optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } $("#TypeofOptionAttr_level_1").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOptionAttr_level_1").append('');; }) // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var typeOfQuestion = $("#TypeofQuest").val(); if (typeOfQuestion == "checkboxoption") { $('#optNameProgram').val("text"); } if ($('#optNameProgram').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { $("#TypeofOption").empty(); // $("#TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="product_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameProgram").val(); // console.log("arrya"); // console.log(optionsArray); if (typeOfQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#TypeofOptionCheck").append(''); }) $("#addNewProgramDefineOptionSetModal").modal("hide"); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewProgramDefineOptionSetModal").modal("hide"); } $("#TypeofOptionAttr").html(''); $("#TypeofOptionAttr_level_1").html(''); $("#TypeofOption").html(''); $("#TypeofOption_level_1").html(''); $("#TypeofOption_level_2").html(''); $("#comm_TypeofOption").html(''); $("#comm_TypeofOption_level_1").html(''); $("#comm_TypeofOption_level_2").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $("#TypeofOptionAttr_level_1").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; $("#TypeofOption_level_1").append('');; $("#TypeofOption_level_2").append('');; $("#comm_TypeofOption_level_1").append('');; $("#comm_TypeofOption_level_2").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } }) //############################################################################################################### //======================= COMMUNITY SECTION ==================================// $(".btn_CommunityAddService").on("click", function() { $("#addNewCommunityServiceModal").modal("show"); }); //=============== ADD NEW SERVICE - COMMUNITY ========================// var communityServiceName; $(".btn_submit_AddCommunityService").on("click", function() { if (isValidEntry($('#comm_servName').val()) == true) { $("#communityservice").empty(); console.log("AddCommunityService"); var communitiesStage = {}; var dataelementsArray = []; communityServiceName = $("#comm_servName").val(); // var serviceShortName = $("#comm_servShrtName").val(); var serviceShortName = $("#comm_servName").val(); //Service Short Name Same as Service Name var AppInfo = getLocalStorage("AppInfo", AppInfo); programName = AppInfo.programName; programShortName = AppInfo.programShortName; console.log(programName); console.log(programShortName); communitiesObj.name = programName; communitiesObj.shortname = programShortName; communitiesObj.logo = ""; communitiesStage.name = communityServiceName; communitiesStage.dataelements = dataelementsArray if (communitiesStagesArray.length > 0) { var duplicatecheck = isDuplicateReord(communitiesStagesArray, communitiesStage); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Service Already Available with this name.", callback: function() { } }); } else { communitiesStagesArray.push(communitiesStage); $("#addNewCommunityServiceModal").modal("hide"); } } else { communitiesStagesArray.push(communitiesStage); $("#addNewCommunityServiceModal").modal("hide"); } setLocalStorage("communitiesStageArray", communitiesStagesArray); $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); $(document).on('click', '.btn_CommunityAddQuestion', function() { $("#addNewCommunityQuestionModal").modal("show"); var commsername = $(this).data('stage-name'); $("#communityservice").text(commsername); $('.level_1_dependencylist_comm').html(''); $('.btn_comm_Add_Dependency_Level_1').show(); $(".level_1_dependency_comm").addClass('hidden'); $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); $('#add_NewCommunityQuestion')[0].reset(); $('#comm_questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) // COMMUNITY DEPENENCY //##################################################COMMUNITY DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_1").off("click"); $(".btn_comm_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#communityservice").text(); var parentqname = $('#comm_questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, communitiesStagesArray); if (!isDuplicateParent) { $("#option_section_community_level_1").addClass('hidden'); $("#check_section_community_level_1").addClass('hidden'); $('#add_NewCommunityQuestion_level_1')[0].reset(); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest").val(); if (_.isEmpty($('#comm_questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName').val()) == true) { $(".parent_action_btns_section_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption option:selected").val(); $("#add_NewCommunityQuestion :input").prop("disabled", true); $(".level_1_dependency_comm").removeClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "number") { $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { add_NewCommunityQuestion $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName').val(); $('#commuestion_level_1').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_1").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_1").off("click"); $(".btn_submit_AddCommunityQuestion_level_1").on("click", function() { if ($("#comm_TypeofQuest").val() == "option list") { matchval = $("#comm_matchval_options_level_1 option:selected").val(); var selectedOptions = $("#comm_TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest").val() == "number") { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_1").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#comm_questName_level_1").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_dependency_comm").addClass('hidden'); $(".parent_action_btns_section_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_1").removeClass('hidden'); } else { $("#option_section_community_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_1").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_1").html(""); } else { $("#check_section_community_level_1").addClass('hidden'); } }); $(".btn_comm_close_level_1").off("click"); $(".btn_comm_close_level_1").on("click", function() { $(".level_1_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); // $('#add_NewCommunityQuestion')[0].reset(); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_2").off("click"); $(".btn_comm_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#comm_questName_level_1').val(); var parentqname = $('#comm_questName').val(); tempquestionlist.push(parentqname); var parentservname = $("#communityservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $('#add_NewCommunityQuestion_level_2')[0].reset(); $("#option_section_community_level_2").addClass('hidden'); $("#check_section_community_level_2").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); if (_.isEmpty($('#comm_questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName_level_1').val()) == true) { $(".parent_child_1_action_btn_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "number") { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName_level_1').val(); $('#commuestion_level_2').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_2").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_2").off("click"); $(".btn_submit_AddCommunityQuestion_level_2").on("click", function() { if ($("#comm_TypeofQuest_level_1").val() == "option list") { matchval = $("#comm_matchval_options_level_2 option:selected").val(); var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest_level_1").val() == "number") { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_2").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_2']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_2").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; var qnameParent = $('#comm_questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#comm_questName_level_2").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency_comm").addClass('hidden'); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_2").removeClass('hidden'); } else { $("#option_section_community_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_2").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_2").html(""); } else { $("#check_section_community_level_2").addClass('hidden'); } }); $(".btn_comm_close_level_2").off("click"); $(".btn_comm_close_level_2").on("click", function() { $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); }); $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter Valid Service Name", callback: function() { } }); } }) //================TYPE OF QUESTION DEPENDENCY=============================// $("#option_section_community").hide(); $("#check_section_community").hide(); $("#comm_TypeofQuest").on("change", function() { // $("#comm_TypeofOption").empty(); if ($(this).val() == "option list") { $("#option_section_community").show(); } else { $("#option_section_community").hide(); } if ($(this).val() == "checkboxoption") { $("#check_section_community").show(); $("#comm_TypeofOptionCheck").html(""); } else { $("#check_section_community").hide(); } }); //================== ADD NEW QUESTION - COMMUNITY =========================// $(".btn_submit_AddCommunityQuestion").off("click"); $(".btn_submit_AddCommunityQuestion").on("click", function() { console.log("AddQuestionCommunity"); var dataElementObj = {}; communityServiceName = $("#communityservice").text(); var questionName = $("#comm_questName").val(); var oldquestion = $("#comm_questName").data('old_name'); var isDuplicateFound = isDuplicateDataElement(communityServiceName, oldquestion, communitiesStagesArray); if (!isDuplicateFound) { // var isDlAvailable = false; //isDlAvailable = isDuplicateDataElement(communityServiceName, questionName, communitiesStagesArray); // if (!isDlAvailable) { // var questionShortName = $("#comm_questShrtName").val(); - Removed Short Name from UI var questionShortName = $("#comm_questName").val(); //Short Name Set to Same as question name var mandatoryChk = $("input[name='comm_radioMandatory']:checked").val(); var typeOfQuestion = $("#comm_TypeofQuest").val(); var typeOfOption = $("#comm_TypeofOption").val(); var typeOfcheck = $("#comm_TypeofOptionCheck").val(); //===HARDCODED OPTION LIST VALUE AS TEXT(REQUIRED BY SERVICE) var flagOption = false; if (typeOfQuestion == "option list") { typeOfQuestion = "text" if (typeOfOption != "" && typeOfOption != null) { dataElementObj.optionname = typeOfOption } else { flagOption = true; } } if (typeOfQuestion == "checkboxoption") { typeOfQuestion = "text" if (typeOfcheck != "" && typeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } if (questionName != "" && mandatoryChk != undefined && typeOfQuestion != "" && flagOption == false) { if (isValidEntry(questionName) == true) { dataElementObj.name = questionName dataElementObj.type = typeOfQuestion dataElementObj.mandatory = mandatoryChk $.each(communitiesStagesArray, function(i, e) { console.log(e); if (e.name == communityServiceName) { console.log(e.dataelements); e.dataelements.push(dataElementObj); dependentdataElementarr = cleanChildObj(dependentdataElementarr); e.dataelements = e.dataelements.concat(dependentdataElementarr); if (_.isUndefined(e.dependentquestions)) { if (_.isEmpty(dataDepenentObj.dependentquestions) == false) { e.dependentquestions = []; e.dependentquestions = e.dependentquestions.concat(dataDepenentObj.dependentquestions); } } else { if (_.isEmpty(dataDepenentObj.dependentquestions) == false) { e.dependentquestions = e.dependentquestions.concat(dataDepenentObj.dependentquestions); } } } }); dependentdataElementarr = []; dataDepenentObj = {}; console.log(communitiesStagesArray); setLocalStorage("communitiesStageArray", communitiesStagesArray); $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); $(document).on('click', '.btn_CommunityAddQuestion', function() { $("#addNewCommunityQuestionModal").modal("show"); $("#option_section_community").hide(); $("#check_section_community").hide(); $('.btn_comm_Add_Dependency_Level_1').show(); var commsername = $(this).data('stage-name'); $("#communityservice").text(commsername); $('.level_1_dependencylist_comm').html(''); $(".level_1_dependency_comm").addClass('hidden'); $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); $('#add_NewCommunityQuestion')[0].reset(); $('#comm_questName').data("old_name", ""); $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; }) // COMMUNITY DEPENENCY //##################################################COMMUNITY DEPENDECY QUESTION #######################################// // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_1").off("click"); $(".btn_comm_Add_Dependency_Level_1").on("click", function() { var isDuplicateParent = false; var parentservname = $("#communityservice").text(); var parentqname = $('#comm_questName').val(); isDuplicateParent = isDuplicateDataElement(parentservname, parentqname, communitiesStagesArray); if (!isDuplicateParent) { $("#option_section_community_level_1").addClass('hidden'); $("#check_section_community_level_1").addClass('hidden'); $('#add_NewCommunityQuestion_level_1')[0].reset(); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest").val(); if (_.isEmpty($('#comm_questName').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName').val()) == true) { $(".parent_action_btns_section_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption option:selected").val(); $("#add_NewCommunityQuestion :input").prop("disabled", true); $(".level_1_dependency_comm").removeClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_1").removeClass('hidden'); $("#comm_matchval_txt_level_1").addClass('hidden'); $('#comm_matchval_options_level_1').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_1").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest").val() == "number") { $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#comm_matchval_txt_level_1").removeClass('hidden'); $("#comm_matchval_options_level_1").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", true); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".level_1_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName').val(); $('#commuestion_level_1').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_1").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_1").off("click"); $(".btn_submit_AddCommunityQuestion_level_1").on("click", function() { if ($("#comm_TypeofQuest").val() == "option list") { matchval = $("#comm_matchval_options_level_1 option:selected").val(); var selectedOptions = $("#comm_TypeofOption option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_1 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest").val() == "number") { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_1').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_1").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_1 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_1 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_1 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; tempquestionlist.push(qname); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-1'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-1]" + $("#comm_questName_level_1").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_1_dependency_comm").addClass('hidden'); $(".parent_action_btns_section_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_1").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_1").removeClass('hidden'); } else { $("#option_section_community_level_1").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_1").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_1").html(""); } else { $("#check_section_community_level_1").addClass('hidden'); } }); $(".btn_comm_close_level_1").off("click"); $(".btn_comm_close_level_1").on("click", function() { $(".level_1_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion :input").prop("disabled", false); $(".parent_action_btns_section_comm :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// //############################################ DEPENDENCY LEVEL 2 START ############################## // ADD LEVEL 1 QUESTION dependentdataElementarr = []; dataDepenentObj = {}; dataDepenentObj.dependentquestions = []; $(".btn_comm_Add_Dependency_Level_2").off("click"); $(".btn_comm_Add_Dependency_Level_2").on("click", function() { var isDuplicateParent = false; var tempquestionlist = []; tempqs = $('#comm_questName_level_1').val(); var parentqname = $('#comm_questName').val(); tempquestionlist.push(parentqname); var parentservname = $("#communityservice").text(); isDuplicateParent = isDuplicateDataElementwithDependency(parentservname, tempqs, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDuplicateParent) { $('#add_NewCommunityQuestion_level_2')[0].reset(); $("#option_section_community_level_2").addClass('hidden'); $("#check_section_community_level_2").addClass('hidden'); var isvalidDepencyAdd = false; var mandatoryChk = $("input[name='comm_radioMandatory_level_1']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); if (_.isEmpty($('#comm_questName_level_1').val()) || _.isEmpty(mandatoryChk) || _.isEmpty(comm_TypeofQuestion)) { isvalidDepencyAdd = false; } else { isvalidDepencyAdd = true; } if (isvalidDepencyAdd == true) { if (isValidEntry($('#comm_questName_level_1').val()) == true) { $(".parent_child_1_action_btn_comm :input").prop("disabled", true); var matchval = ""; if ($("#comm_TypeofQuest_level_1").val() == "option list") { if (optionsArray.length > 0) { var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); var matchvalarray = _.filter(optionsArray, function(val) { return val.name == selectedOptions; }); $.each(matchvalarray[0].values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) // matchval = $('#comm_matchval_txt_level_1').val() } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { var options = $('#comm_TypeofOptionCheck_level_1 option'); var values = $.map(options, function(option) { return option.value; }); if (values.length > 0) { $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); $("#comm_matchval_options_level_2").removeClass('hidden'); $("#comm_matchval_txt_level_2").addClass('hidden'); $('#comm_matchval_options_level_2').html(''); $.each(values, function(k, v) { $("#comm_matchval_options_level_2").append(''); }) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Add Checkbox Options Before adding Dependent Questions.", callback: function() { } }); } } else if ($("#comm_TypeofQuest_level_1").val() == "number") { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { $("#comm_matchval_txt_level_2").removeClass('hidden'); $("#comm_matchval_options_level_2").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", true); $(".level_2_dependency_comm").removeClass('hidden'); } var servname = $("#communityservice").text(); var qname = $('#comm_questName_level_1').val(); $('#commuestion_level_2').text(qname); $("#addNewCommunityQuestionModal").animate({ scrollTop: $(document).height() - $(window).height() }); ///////////////OPTIONS ////=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity_level_2").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optvals').val(''); if ($("#comm_TypeofQuest_level_2").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } $('.optValueProgram').val(''); $('.newAppend').remove(); }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").off("click"); $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); $('.optvals').focus(); }); $(".abc").off("click"); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // console.log($(this).parent().parent().find('.mod_optValueProgram').val()); // checkArray = _.without(checkArray, _.findWhere(checkArray, { name: $(this).parent().parent().find('.mod_optValueProgram').val() })); }); ////////////////END $(".btn_submit_AddCommunityQuestion_level_2").off("click"); $(".btn_submit_AddCommunityQuestion_level_2").on("click", function() { if ($("#comm_TypeofQuest_level_1").val() == "option list") { matchval = $("#comm_matchval_options_level_2 option:selected").val(); var selectedOptions = $("#comm_TypeofOption_level_1 option:selected").val(); dltype = "option"; typename = selectedOptions; } else if ($("#comm_TypeofQuest_level_1").val() == "checkboxoption") { matchval = $('#comm_matchval_options_level_2 option:selected').val(); dltype = "checkbox"; typename = matchval; } else if ($("#comm_TypeofQuest_level_1").val() == "number") { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "number"; typename = qname; } else if ($("#comm_TypeofQuest_level_1").val() == "date") { bootbox.alert({ size: "small", title: "iMonitor +", message: "Support for dependency on above type of element is not available.", callback: function() { } }); } else { matchval = $('#comm_matchval_txt_level_2').val(); dltype = "text"; typename = qname; } var dependentQsl1 = $("#comm_questName_level_2").val(); var depmandatoryChk = $("input[name='comm_radioMandatory_level_2']:checked").val(); var depcomm_TypeofQuestion = $("#comm_TypeofQuest_level_2").val(); var deptcomm_TypeofOption = $("#comm_TypeofOption_level_2 option:selected").val(); var depttypeOfcheck = $("#comm_TypeofOptionCheck_level_2 option:selected").val(); var isDlAvailable = false; var dependentdataElementObj = {}; dependentdataElementObj.name = dependentQsl1; dependentdataElementObj.type = depcomm_TypeofQuestion; dependentdataElementObj.mandatory = depmandatoryChk; var flagOption = false; if (depcomm_TypeofQuestion == "option list") { dependentdataElementObj.type = "text" if (deptcomm_TypeofOption != "" && deptcomm_TypeofOption != null) { dependentdataElementObj.optionname = deptcomm_TypeofOption } else { flagOption = true; } } if (depcomm_TypeofQuestion == "checkboxoption") { dependentdataElementObj.type = "text" if (depttypeOfcheck != "" && depttypeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck_level_2 option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dependentdataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } console.log(dependentdataElementObj); var childel = { childdataelementname: dependentQsl1, stage: servname } var pardependentQs = { dataelementname: qname, dependentdataelementnames: [], matchingvalue: matchval, type: dltype, typename: typename, condition: "equalto", action: "show" } if (dependentQsl1 != "" && depmandatoryChk != undefined && depcomm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(dependentQsl1) == true) { var tempquestionlist = []; var qnameParent = $('#comm_questName').val(); tempquestionlist.push(qname, qnameParent); isDlAvailable = isDuplicateDataElementwithDependency(servname, dependentQsl1, tempquestionlist, communitiesStagesArray, dependentdataElementarr); if (!isDlAvailable) { if (dataDepenentObj.dependentquestions.length > 0) { var isavailable = _(dataDepenentObj.dependentquestions).filter(function(item) { // return item.programstagename.toLowerCase().replace(/ /g, '') == sericestagename.toLowerCase().replace(/ /g, ''); return item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase() }); if (_.isEmpty(isavailable) == false) { _.map(dataDepenentObj.dependentquestions, function(item) { if (item.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && item.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { return item.dependentdataelementnames.push(childel); } }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } // $.each(dataDepenentObj.dependentquestions, function(key, val) { // if (val.dataelementname.replace(/ /g, '').toLowerCase() == qname.replace(/ /g, '').toLowerCase() && val.matchingvalue.replace(/ /g, '').toLowerCase() == matchval.replace(/ /g, '').toLowerCase()) { // val.dependentdataelementnames.push(childel); // } else { // pardependentQs.dependentdataelementnames.push(childel); // dataDepenentObj.dependentquestions.push(pardependentQs); // } // }); } else { pardependentQs.dependentdataelementnames.push(childel); dataDepenentObj.dependentquestions.push(pardependentQs); } console.log(dataDepenentObj); dependentdataElementObj.level = 'Level-2'; dependentdataElementarr.push(dependentdataElementObj); // add dependendt to html var temshtml = ""; temshtml += "
    [Level-2]" + $("#comm_questName_level_2").val() + "
    "; $('.level_1_dependencylist_comm').append(temshtml); // $.each(dataDepenentObj, function(key, val) {}) $(".level_2_dependency_comm").addClass('hidden'); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } }); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } }); } }); // type of option change $("#comm_TypeofQuest_level_2").on("change", function() { if ($(this).val() == "option list") { $("#option_section_community_level_2").removeClass('hidden'); } else { $("#option_section_community_level_2").addClass('hidden'); } if ($(this).val() == "checkboxoption") { $("#check_section_community_level_2").removeClass('hidden'); $("#comm_TypeofOptionCheck_level_2").html(""); } else { $("#check_section_community_level_2").addClass('hidden'); } }); $(".btn_comm_close_level_2").off("click"); $(".btn_comm_close_level_2").on("click", function() { $(".level_2_dependency_comm").addClass('hidden'); $("#add_NewCommunityQuestion_level_1 :input").prop("disabled", false); $(".parent_child_1_action_btn_comm :input").prop("disabled", false); }); // CLOSE LEVEL 1 //#####################################################END DEPENDENCY QUESTION ################################// // LEVEL 2 ENDS }); $(document).on('click', '.btn_Delete_comm', function() { console.log("Delete"); var qesname = $(this).closest('tr').children('td:nth-child(2)').text(); console.log(qesname); var stagename = $(this).closest('table').data('stage-name'); var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { return item.dataelementname.replace(/ /g, '').toLowerCase() == qesname.replace(/ /g, '').toLowerCase() }); } }); var tempmsg = ""; if (!_.isEmpty(isPartOfParent)) { tempmsg = "Deletion of this question will reset all dependencies on this question."; } swal({ title: 'Are you sure?', text: tempmsg, type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Delete it!', buttonsStyling: false }).then(function() { swal({ title: 'Deleted!', text: 'Deleted Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) var dataelObjCombo = deleteDataElementWithAvailableChildonStage(stagename, qesname, communitiesStagesArray); communitiesStagesArray = dataelObjCombo; $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); }).catch(swal.noop) }); }); $("#addNewCommunityQuestionModal").modal("hide"); $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else { // community submit edit by sohan console.log(communityServiceName); console.log(questionName); var dataElementObj = {}; var mandatoryChk = $("input[name='comm_radioMandatory']:checked").val(); var comm_TypeofQuestion = $("#comm_TypeofQuest").val(); var comm_TypeofOption = $("#comm_TypeofOption").val(); var typeOfcheck = $("#comm_TypeofOptionCheck").val(); //===HARDCODED OPTION LIST VALUE AS TEXT(REQUIRED BY SERVICE) var flagOption = false; if (comm_TypeofQuestion == "option list") { comm_TypeofQuestion = "text" if (comm_TypeofOption != "" && comm_TypeofOption != null) { dataElementObj.optionname = comm_TypeofOption } else { flagOption = true; } } if (comm_TypeofQuestion == "checkboxoption") { comm_TypeofQuestion = "text" if (typeOfcheck != "" && typeOfcheck != null) { var checkvalues = $('#comm_TypeofOptionCheck option'); var chkarray = $.map(checkvalues, function(option) { return option.value; }); dataElementObj.checkboxoption = chkarray; } else { flagOption = true; } } if (questionName != "" && mandatoryChk != undefined && comm_TypeofQuestion != "" && flagOption == false) { if (isValidEntry(questionName) == true) { dataElementObj.name = questionName dataElementObj.type = comm_TypeofQuestion dataElementObj.mandatory = mandatoryChk swal({ title: 'Are you sure?', // text: "Data Element is Already Available!", type: 'warning', showCancelButton: true, confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', confirmButtonText: 'OK, Update it!', buttonsStyling: false }).then(function() { swal({ title: 'Updated!', text: 'Updated Successfully.', type: 'success', confirmButtonClass: "btn btn-success", buttonsStyling: false }) $.each(communitiesStagesArray, function(key, val) { if (val.name == communityServiceName) { $.each(val.dataelements, function(key1, val1) { if (val1.name == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val.dataelements[key1] = dataElementObj; } }); $.each(val.dependentquestions, function(key2, val2) { if (val2.dataelementname == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val2.dataelementname = questionName; } $.each(val2.dependentdataelementnames, function(key3, val3) { if (val3.childdataelementname == oldquestion) { // // Object.assign(val1, dataElementObj); // val1 = dataElementObj; val3.childdataelementname = questionName; } }); }); } }); console.log(communitiesStagesArray); $.get('app/templates/listCommunityServiceQuestionTbl_template.html', function(data) { $("#listCommunityServiceQuestionTbl").empty(); var compiled = Template7.compile(data); var html = compiled(communitiesStagesArray); $("#listCommunityServiceQuestionTbl").append(html); console.log(optionsArray); $.each(optionsArray, function(i, e) { // $("#comm_TypeofOption").append('');; $("#comm_TypeofOption").append('');; }) // DEFAULT EDIT BY SOHAN COMMUNITY $(".btn_Edit_comm").on("click", function() { console.log("Edit"); $('.level_1_dependencylist_comm').html(""); $("#add_NewCommunityQuestion :input").prop("disabled", false); $("#addNewCommunityQuestionModal").modal("show"); var selectQuest = $(this).closest('tr').children('td:nth-child(2)').text(); var stagename = $(this).closest('table').data('stage-name'); $("#communityservice").text(stagename); $('#comm_questName').val(selectQuest); $('#comm_questName').data("old_name", selectQuest); var dataelementArrObj; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { dataelementArrObj = _(val.dataelements).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.name.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); $("input[name=comm_radioMandatory][value=" + dataelementArrObj[0].mandatory + "]").prop('checked', true); if (!_.isUndefined(dataelementArrObj[0].optionname)) { $("#comm_TypeofQuest").val("option list").change(); $("#option_section_community").show(); $("#check_section_community").hide(); $("#comm_TypeofOption").val(dataelementArrObj[0].optionname).change(); $(".btn_comm_Add_Dependency_Level_1").hide(); } else if (!_.isUndefined(dataelementArrObj[0].checkboxoption)) { $("#comm_TypeofQuest").val("checkboxoption").change(); $("#check_section_community").show(); $("#option_section_community").hide(); $.each(dataelementArrObj[0].checkboxoption, function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $(".btn_comm_Add_Dependency_Level_1").hide(); } else { $("#comm_TypeofQuest").val(dataelementArrObj[0].type).change(); $("#option_section_community").hide(); $("#check_section_community").hide(); $(".btn_comm_Add_Dependency_Level_1").hide(); } var isPartOfParent; _.map(communitiesStagesArray, function(val) { if (val.name == stagename) { isPartOfParent = _(val.dependentquestions).filter(function(item) { // return item.dataelementname.toLowerCase().replace(/ /g, '') == qname.toLowerCase().replace(/ /g, '') return item.dataelementname.replace(/ /g, '').toLowerCase() == selectQuest.replace(/ /g, '').toLowerCase() }); } }); if (!_.isEmpty(isPartOfParent)) { $("#add_NewCommunityQuestion select").prop("disabled", true); $("#add_NewCommunityQuestion input:radio").prop("disabled", true); $("#add_NewCommunityQuestion").addClass('warningfordependency'); } else { $("#add_NewCommunityQuestion select, input:radio").prop("disabled", false); $("#add_NewCommunityQuestion").removeClass('warningfordependency'); } console.log(selectQuest); }); }); $("#addNewCommunityQuestionModal").modal("hide"); }).catch(swal.noop) } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter atleast 3 character in Question name.", callback: function() {} }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Fill All Required fields Before adding Dependent Questions.", callback: function() { } }); } } /* bootbox.alert({ size: "small", title: "iMonitor +", message: "Question Already Available with this name.", callback: function() { } });*/ }); //=============== ADD OPTION LIST - COMMUNITY ============================// $(".btn_AddOptionListQuestionCommunity").on("click", function() { $("#addNewCommunityDefineOptionSetModal").modal("show"); $('#optNameCommunity').val(''); $('.optValueProgram').val(''); $('.newAppend').remove(); if ($("#comm_TypeofQuest").val() == "checkboxoption") { $('.not-for-check').hide(); } else { $('.not-for-check').show(); } }); //=============== ADD OPTION VALUES - COMMUNITY =========================// $(".add_optionValues_CommQuest").on("click", function() { $('.input_fields_container_comm').append('
    '); $('.optvals').val(''); }); $(".abc").on("click", '.remove_optionValues_CommQuest', function() { console.log("remove"); $(this).parent().parent().remove(); // $('.remove_optionValues_ProgQuest').parent().parent().remove(); }); $(document).on('click', '.custom-alert-list>.close', function() { var qesname = $(this).parent().find('.chdelname').text(); // WORK IN PROGRESS $(this).parent().remove(); var dataelObjCombo = deleteDataElementWithAvailableChild(qesname, dependentdataElementarr, dataDepenentObj.dependentquestions); dependentdataElementarr = dataelObjCombo.dependentdataElementarr; dataDepenentObj.dependentquestions = dataelObjCombo.dataDepenentObj; $('.level_1_dependencylist_comm').html(""); $.each(dependentdataElementarr, function(key, val) { var temshtml = ""; temshtml += "
    [" + val.level + "]" + val.name + "
    "; $('.level_1_dependencylist_comm').append(temshtml); }) }); $(".btn_submit_AddCommunity_OptionSet").off("click"); $(".btn_submit_AddCommunity_OptionSet").on("click", function() { var countBlank = 0; if ($('.level_1_dependency_comm').hasClass('hidden') == false && $("#add_NewCommunityQuestion_level_1 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var comm_TypeofQuestion = $("#comm_TypeofQuest_level_1").val(); if (comm_TypeofQuestion == "checkboxoption") { $('#optNameCommunity').val("text"); } if ($('#optNameCommunity').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { // $("#comm_TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="community_option_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameCommunity").val(); // console.log("arrya"); // console.log(optionsArray); if (comm_TypeofQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#comm_TypeofOptionCheck_level_1").append(''); }) $("#addNewCommunityDefineOptionSetModal").modal("hide"); console.log(CheckArray); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } // $("#comm_TypeofOption").html(''); $("#comm_TypeofOption_level_1").html(''); $.each(optionsArray, function(i, e) { // $("#comm_TypeofOption").append('');; $("#comm_TypeofOption_level_1").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else if ($('.level_2_dependency_comm').hasClass('hidden') == false && $("#add_NewCommunityQuestion_level_2 :input").prop("disabled") == false) { $('.optValueProgram').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); var comm_TypeofQuestion = $("#comm_TypeofQuest_level_2").val(); if (comm_TypeofQuestion == "checkboxoption") { $('#optNameCommunity').val("text"); } if ($('#optNameCommunity').val() != '' && $('.optValueProgram').val() != '' && countBlank == 0) { // $("#comm_TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="community_option_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameCommunity").val(); // console.log("arrya"); // console.log(optionsArray); if (comm_TypeofQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#comm_TypeofOptionCheck_level_2").append(''); }) $("#addNewCommunityDefineOptionSetModal").modal("hide"); console.log(CheckArray); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } // $("#comm_TypeofOption").html(''); // $("#comm_TypeofOption_level_1").html(''); $("#comm_TypeofOption_level_2").html(''); $.each(optionsArray, function(i, e) { // $("#comm_TypeofOption").append('');; // $("#comm_TypeofOption_level_1").append('');; $("#comm_TypeofOption_level_2").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } else { var typeOfQuestion = $("#comm_TypeofQuest").val(); if (typeOfQuestion == "checkboxoption") { $('#optNameCommunity').val("text"); } var countBlank = 0; $('.optValueCommunity').each(function() { //iterate all listed class items if (isEmpty($(this).val()) != null) { countBlank += 1; } }); if ($('#optNameCommunity').val() != '' && $('.optValueCommunity').val() != '' && countBlank == 0) { $("#comm_TypeofOption").empty(); // $("#comm_TypeofOption").append(""); var optionsObj = {}; var arr = $('input[name="community_option_name[]"]').map(function() { return this.value; // $(this).val() }).get(); if (arr.length > 1) { console.log(arr); // var uniq = _.uniq(arr); var tempobj = {}; var isDuplicateArr = false; for (let i in arr) { tempobj[arr[i].toLowerCase().replace(/ /g, '')] = tempobj[arr[i].toLowerCase().replace(/ /g, '')] == undefined ? 1 : ++tempobj[arr[i].toLowerCase().replace(/ /g, '')]; if (tempobj[arr[i].toLowerCase()] > 1) { isDuplicateArr = true; break; } } // console.log(uniq); if (!isDuplicateArr) { var optionName_Program = $("#optNameCommunity").val(); if (typeOfQuestion == "checkboxoption") { CheckArray = []; CheckArray.push(arr); $.each(CheckArray[0], function(key, val) { $("#comm_TypeofOptionCheck").append(''); }) $("#addNewCommunityDefineOptionSetModal").modal("hide"); } else { optionsObj.name = optionName_Program; optionsObj.values = arr; if (optionsArray.length > 0) { var duplicatecheck = isDuplicateReord(optionsArray, optionsObj); if (duplicatecheck) { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Already Available with this name.", callback: function() { } }); } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } } else { optionsArray.push(optionsObj); $("#addNewCommunityDefineOptionSetModal").modal("hide"); } $("#TypeofOption").html(''); $("#TypeofOptionAttr").html(''); $("#comm_TypeofOption").html(''); $("#TypeofOption_level_1").html(''); $("#TypeofOption_level_2").html(''); $("#comm_TypeofOption_level_1").html(''); $("#comm_TypeofOption_level_2").html(''); $.each(optionsArray, function(i, e) { $("#TypeofOption").append('');; $('#TypeofOptionAttr').append(''); $("#comm_TypeofOption").append('');; $("#TypeofOption_level_1").append('');; $("#TypeofOption_level_2").append('');; $("#comm_TypeofOption_level_1").append('');; $("#comm_TypeofOption_level_2").append('');; }) } // $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val(''); //CLEAR ALL FIELDS } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Option Value Can't be Same.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please add minimum two option.", callback: function() { } }); } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please fill all the mandatory fields", callback: function() { } }); } } }) //========SELECT LAYOUT ===============================================// var mobileLayout = "Default Layout"; var WebLayout = "Desktop Layout"; $(".dskLayout .dskimg").on("click", function() { $(".dskLayout .dskimg").removeClass("layoutactive"); $(this).addClass("layoutactive"); WebLayout = $(this).find("h5").html(); }); $(".mbllayout .well").on("click", function() { $(".mbllayout .well").removeClass("layoutactive"); $(this).addClass("layoutactive"); mobileLayout = $(this).find("h5").html(); }); $("#saveTemplateCheck").on("click", function() { if ($('#saveTemplateCheck').is(":checked") == true) { $('#saveTemplateInput').show(); isSaveTemplate = true; var appInfo = getLocalStorage("AppInfo"); $('#templateName').val(appInfo.appName); $('#templateDescr').val(appInfo.appName + ' description'); } else { $('#saveTemplateInput').hide(); isSaveTemplate = false; } }); } /////////////////////SHUFFLE SERVICES // TABLE ROW MOVE UP AND DOWN $(document).on('click', '#programserviceTBL img.move', function() { var row = $(this).closest('tr'); // var srow = $(this).parent().parent().children().index(row); // alert($(this).attr("value")); var attrnam = $(this).attr("value"); var serviename = $(this).closest('table').data('stage-name');; var rownum = row.index(); // alert(attrnam); // alert(rownum); if ($(this).hasClass('up')) { row.prev().before(row); programStagesArray = arraymove(programStagesArray, serviename, Number(rownum), Number(rownum) - 1); } else { row.next().after(row); programStagesArray = arraymove(programStagesArray, serviename, Number(rownum), Number(rownum) + 1); } console.log(programStagesArray); }); $(document).on('click', '#listCommServicetable img.move', function() { var row = $(this).closest('tr'); // var srow = $(this).parent().parent().children().index(row); // alert($(this).attr("value")); var attrnam = $(this).attr("value"); var serviename = $(this).closest('table').data('stage-name'); var rownum = row.index(); // alert(attrnam); // alert(rownum); if ($(this).hasClass('up')) { row.prev().before(row); communitiesStagesArray = arraymove(communitiesStagesArray, serviename, Number(rownum), Number(rownum) - 1); } else { row.next().after(row); communitiesStagesArray = arraymove(communitiesStagesArray, serviename, Number(rownum), Number(rownum) + 1); } console.log(communitiesStagesArray); }); //========DEFINE WORKFLOW ===============================================// var pgrolesforstage = []; var allstageroles; var stageroles = []; apiservices.getAllRoles(userObj.language, ux.getAllRoleStageSuccessCallback, ux.fail); $('#stageRoleAssignTBL').hide(); $(".selectRoleForworkflowPGM").on("click", function() { // $.blockUI(); if (programStagesArray.length > 0) { if ($('.selectRoleForworkflowPGM').is(":checked") == false) { pgrolesforstage = []; stageroles = []; $('.checkSysRoles').each(function() { //iterate all listed checkbox items this.checked = status; //change ".checkbox" checked status }); allstageroles = getLocalStorage("allstageroles"); $('#stageRoleAssignTBL > tbody').html(''); $('#step').html(''); $('#stageRoleAssignTBL > thead >tr').html(''); } else { pgrolesforstage = []; stageroles = []; allstageroles = getLocalStorage("allstageroles"); $('.checkSysRoles').each(function() { //iterate all listed checkbox items this.checked = status; //change ".checkbox" checked status }); $('#roleselectModalstage').modal("show"); $('#stageRoleAssignTBL > tbody').html(''); $('#step').html(''); $('#stageRoleAssignTBL > thead >tr').html(''); } } else { $('.selectRoleForworkflowPGM').prop("checked", false); swal({ title: "Blank Service Found!", type: "info", text: "Please Fill Service with Dataelement to create workflow.", buttonsStyling: false, confirmButtonClass: "btn btn-info" }).catch(swal.noop) } }); $("#CreatecustomRole").on("click", function() { if (isEmpty($('#newrole').val()) == null) { // $.blockUI(); var roleisvalid = false; var customrole = $('#newrole').val(); if (customrole.toLowerCase() == "admin" || customrole.toLowerCase().startsWith("facility") == true) { bootbox.alert({ size: "small", title: "iMonitor +", message: "You are not permitted to create this role. Please enter any other role.", callback: function() { } }); } else { // for (let i in allstageroles) { // if (allstageroles[i].rolename.toLowerCase() != customrole.toLowerCase()) { // roleisvalid = true; // } else { // roleisvalid = false; // break; // } // } roleisvalid = _.filter(allstageroles, function(item) { return item.rolename.toLowerCase() == customrole.toLowerCase(); }); if (_.isEmpty(roleisvalid)) { var rolelist = ""; var rolelist = "
  • "; $(".rolesList").append(rolelist); var objval = { rolename: customrole, id: "0" } allstageroles.push(objval); } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Role Already Exists.", callback: function() { } }); } } } else { bootbox.alert({ size: "small", title: "iMonitor +", message: "Please Enter Role Name.", callback: function() { } }); } }); //===========================MASTER OPTION LOAD=======================// // MASTER LIST LOAD $(".btn_load_master_options").on("click", function() { $.blockUI(); apiservices.getAllMasterDataOption({}, ux.getAllMasterDataOption, ux.fail); smartwiz.masteroptionarray = []; $('#mastervaluelist').find('li').remove(); }); // SELECT MASTER OPTION VALUES $(document).on('click', 'input.checkMastervalues', function() { var sThisVal = $(this).val(); if ($(this).is(':checked')) { smartwiz.masteroptionarray.push(sThisVal); } else { for (let i in smartwiz.masteroptionarray) { if (smartwiz.masteroptionarray[i] == sThisVal) { smartwiz.masteroptionarray.splice(i, 1); } else { } } } console.log(smartwiz.masteroptionarray); }); // ADD MASTER OPTION TO OPTIONS SET $(document).on('click', '.btn_addMasterOption', function() { console.log(smartwiz.masteroptionarray); if (smartwiz.masteroptionarray.length > 0) { $('.input_fields_container').find('.newAppend').remove(); for (i = 0; i < smartwiz.masteroptionarray.length; i++) { $('.input_fields_container').append('
    '); } $('#masterlistmodal').modal('hide'); } else { bootbox.alert({ size: "small", title: "No Choice", message: "Please Choose Master Option value to proceed." }); } }); //===========================END MASTER OPTION LOAD===================// // ADDING ROLES FOR PROGRAM $(document).on('click', 'input.checkSysRoles', function() { var sThisVal = { rolename: $(this).attr("name"), id: $(this).val() } if ($(this).is(':checked')) { pgrolesforstage.push(sThisVal); } else { for (let i in pgrolesforstage) { if (pgrolesforstage[i].id == sThisVal.id) { pgrolesforstage.splice(i, 1); } else { } } } console.log(pgrolesforstage); }); console.log(programStagesArray); var wkfprogramStagesArray; $("#addRolestostage").on("click", function() { $('#stageRoleAssignTBL').show(); wkfprogramStagesArray = _.clone(programStagesArray); console.log(pgrolesforstage); var stageSystemRoles = getLocalStorage("allstageroles"); console.log(stageSystemRoles); // var defaultRole = {}; // var programName = $("#programName").val(); // var defaultstage = []; // $.each(programStagesArray, function(key, val) { // var tempstage = { // name: val.name, // sla: "1" // } // defaultstage.push(tempstage); // }); // for (let i in stageSystemRoles) { // if (stageSystemRoles[i].rolename == "DIC ADMIN") { // defaultRole = { // roleid: stageSystemRoles[i].id, // rolename: stageSystemRoles[i].rolename, // programname: programName, // stages: defaultstage // } // break; // } else { // defaultRole = { // rolename: "DIC ADMIN", // programname: programName, // stages: defaultstage // } // } // } if (pgrolesforstage.length > 0) { $('.role-warning').hide(); console.log("//////////////////////////"); console.log(wkfprogramStagesArray); console.log(pgrolesforstage); console.log(wkfprogramStagesArray); $('#roleselectModalstage').modal("hide"); //ADD DEFAULT STAGE TO FLOW // programStagesArray = tempstage; var rolesth = "#Stages"; $.each(pgrolesforstage, function(key, val) { rolesth += "" + val.rolename + ""; var programName = $("#programName").val(); if (val.id == "0") { var rolesobj = { rolename: val.rolename, programname: programName, stages: [] } } else { var rolesobj = { roleid: val.id, rolename: val.rolename, programname: programName, stages: [] } } // $.each(programStagesArray, function(key, val) { // var stagesobj = { // name: val.name, // sla: "2" // }; // rolesobj.stages.push(stagesobj); // }) stageroles.push(rolesobj); }); // stageroles.push(defaultRole); $('#stageRoleAssignTBL > thead >tr').append(rolesth); var isduplicatestage = _.find(wkfprogramStagesArray, function(item) { return item.name == "Registration"; }); if (_.isEmpty(isduplicatestage)) { var regstage = { "name": "Registration" } var tempStage = wkfprogramStagesArray.unshift(regstage); } $.each(wkfprogramStagesArray, function(key, val) { var stagesth = ""; var stageview = ""; var indx = key + 1; stagesth = "" + indx + "" + val.name + ""; $.each(pgrolesforstage, function(key1, val1) { stagesth += "
    "; stagesth += "
    "; stagesth += "
    "; }); var stagerow = "" + stagesth + ""; // stageview += "
    "; // stageview += "
    " + val.name + "

    "; stageview += "
  • "; stageview += "
    " + val.name + "

  • "; $('#stageRoleAssignTBL > tbody').append(stagerow); $('#step').append(stageview); // $('#workflow-view').append(stageview); }); var defstageview = ""; defstageview += "
  • "; defstageview += "DIC ADMIN
  • "; // $('.stepsarrow').find('.selrolesection').append(stageview); $(".selrolesection").each(function() { $(this).append(defstageview); }); console.log(stageroles); } else { bootbox.alert({ size: "small", title: "Invalid Entry", message: "Please Select roles to create Workflow." }); } }); // PROVIDE ACCESS TO STAGE var stageroles = []; var regaccessToRole = []; $(document).on('click', 'input.stageroleAccessCheck', function() { // var sThisVal = { // rolename: $(this).attr("name"), // id: $(this).val() // } // var roleid = $(this).attr('data-role-id'); // stageroles.push(rolesobj); var roleid = $(this).attr('data-role-id'); var rolename = $(this).attr('data-role-name'); var stagename = $(this).attr('data-stage-name'); var slainput = $(this).closest('td').find('.slainput').val(); var matchvalarray = _.filter(regaccessToRole, function(val) { return val.rolename == rolename; }); // if (stagename != "Registration") { if ($(this).is(':checked')) { var tempHtml = "
  • " + rolename + "
  • "; $('#section_' + stagename.replace(/ /g, '').replace(/[^a-zA-Z ]/g, "")).append(tempHtml); $.each(stageroles, function(key, val) { if (val.rolename == rolename) { // if (!_.isEmpty(matchvalarray)) { // var stagesobj = { // name: stagename, // sla: slainput, // registration: "0" // }; // } else { var stagesobj = { name: stagename, sla: slainput }; // } val.stages.push(stagesobj); } }) console.log(stageroles); } else { $('#' + rolename.replace(/ /g, '') + stagename.replace(/ /g, '')).remove(); $.each(stageroles, function(key, val) { if (val.rolename == rolename) { for (let i in val.stages) { if (val.stages[i].name == stagename) { val.stages.splice(i, 1); // var stagesobj = { // name: stagename, // sla: "2" // }; // val.stages.push(stagesobj); } } } }) console.log(stageroles); } }); // SAL INPUT $(document).on('keyup', 'input.slainput', function() { // var sThisVal = { // rolename: $(this).attr("name"), // id: $(this).val() // } // var roleid = $(this).attr('data-role-id'); // stageroles.push(rolesobj); var roleid = $(this).attr('data-role-id'); var rolename = $(this).attr('data-role-name'); var stagename = $(this).attr('data-stage-name'); var slainput = $(this).closest('td').find('.slainput').val(); $.each(stageroles, function(key, val) { if (val.stages.length > 0) { if (val.rolename == rolename) { $.each(val.stages, function(key1, val1) { if (val1.name == stagename) { val1.sla = slainput; } else { } }) } } }) console.log(stageroles); // console.log(pgrolesforstage); }); //////////////////////END ROLE ASSIGNMENT//////////////////////////// ///////////////////////CONTENT MANAGEMENT /////////////////////////// var contentID, contnentName, userID, cuserName; var contentmgmtObj = {}; $(".enableContentManagement").on("click", function() { if ($('.enableContentManagement').is(":checked") == false) {} else { $('#contentmanagementModal').modal("show"); } }); $("#addUsertoCMS").on("click", function() { var email = $('#newUserEmailforcms').val(); if (!_.isEmpty(email) && validateEmail(email)) { // alert('valid'); // var spaceObj = { name: $("#programName").val() + "_" + randomid() }; var contentObj = { "name": $("#communityName").val() + "_" + randomid(), "fields": [{ "id": "discription", "name": "Discription", "type": "Text", "localized": false, "required": true, "validations": [], "disabled": false, "omitted": false }, { "id": "attachments", "name": "attachments", "type": "Array", "localized": false, "required": false, "validations": [], "disabled": false, "omitted": false, "items": { "type": "Link", "validations": [], "linkType": "Asset" } }, { "id": "sequenceId", "name": "sequence Id", "type": "Integer", "localized": true, "required": true, "validations": [{ "unique": true }], "disabled": false, "omitted": false }, { "id": "title", "name": "title", "type": "Symbol", "localized": false, "required": true, "validations": [], "disabled": false, "omitted": false } ] }; $.blockUI(); apiservices.createContentinContentfull(contentObj, createContentinContentfullSuccessCallback, fails); function createContentinContentfullSuccessCallback(r) { console.log(r); contentID = r.sys.id; contnentName = r.name; var temouserObj = { "email": email, "admin": true }; apiservices.createUserforContentinContentfull(temouserObj, createUserforContentinContentfullSuccessCallback, fails); } function createUserforContentinContentfullSuccessCallback(r) { console.log(r); userID = r.sys.id; cuserName = email; $('#contentmanagementModal').modal("hide"); $('.contentsetup').hide(); var temtable = ""; temtable += "
    "; temtable += "
    Content NameUser Name
    " + contnentName + "" + cuserName + "
    "; temtable += "

    Note: User is assigned to content and also confirmation mail is sent to the same user.

    "; $("#contentData").html(temtable); $.unblockUI(); swal({ title: "Done!", text: "User added Successfully.", buttonsStyling: false, confirmButtonClass: "btn btn-success", type: "success" }).catch(swal.noop) contentmgmtObj = { "modelid": contentID, "spaceid": "hpvxigekpxg1", "spacetoken": "89dc262ce00ca1892e9e40cec240abb2a3875c06f125f924de729e67188b8968", "email": cuserName } console.log(contentmgmtObj); } function fails(r) { $.unblockUI(); var error = JSON.parse(r.responseText); if (error.message == "Forbidden") { swal({ title: "Failed", type: "error", text: error.details.reasons[1], buttonsStyling: false, confirmButtonClass: "btn btn-info" }).catch(swal.noop) console.log(r.responseText); } else { swal({ title: "Failed", type: "error", text: error.message, buttonsStyling: false, confirmButtonClass: "btn btn-info" }).catch(swal.noop) console.log(r.responseText); } console.log(r.responseText); } } else { swal({ title: "Invalid Email ID.", type: "info", text: "Please Enter Valid Email ID.", buttonsStyling: false, confirmButtonClass: "btn btn-info" }).catch(swal.noop) } }); //========FINAL SUBMIT CLICK===============================================// // CHOOSE TEMPLATE ICON var templateicon; $("#tmpIcon").on('click', function(evt) { $('#imgsectionTemolate').html(''); $('#chooseTemlateIconModal').modal('show'); generateICONView("assets/img/appIcon/", "imgsectionTemolate", "pgmicons"); }); // icon select click $(document).on('click', '.pgmicons', function() { //alert($(this).attr("src")); $('#iconviewtmpl').attr("src", "" + $(this).attr("src")); var str = $(this).attr("src"); templateicon = str.replace('assets/', ''); $('#chooseTemlateIconModal').modal('hide'); }); //END // SET DIGITAL PAYMENT $(document).on('click', '.digitalPaymentcomm', function() { var stagename = $(this).data('stage-name'); if ($(this).is(":checked") == true) { $.each(communitiesStagesArray, function(key, val) { if (val.name == stagename) { val.wallet = true; } }) } else { $.each(communitiesStagesArray, function(key, val) { if (val.name == stagename) { delete val.wallet; } }) } console.log(communitiesStagesArray); }); $(document).on('click', '.digitalPaymentprog', function() { var stagename = $(this).data('stage-name'); if ($(this).is(":checked") == true) { $.each(programStagesArray, function(key, val) { if (val.name == stagename) { val.wallet = true; } }) } else { $.each(programStagesArray, function(key, val) { if (val.name == stagename) { delete val.wallet; } }) } console.log(programStagesArray); }); // SET BLOCKCHAIN ENABLE $(document).on('click', '.blockchaincomm', function() { var stagename = $(this).data('stage-name'); if ($(this).is(":checked") == true) { $.each(communitiesStagesArray, function(key, val) { if (val.name == stagename) { val.blockchain = true; } }) } else { $.each(communitiesStagesArray, function(key, val) { if (val.name == stagename) { delete val.blockchain; } }) } console.log(communitiesStagesArray); }); $(document).on('click', '.blockchainprog', function() { var stagename = $(this).data('stage-name'); if ($(this).is(":checked") == true) { $.each(programStagesArray, function(key, val) { if (val.name == stagename) { val.blockchain = true; } }) } else { $.each(programStagesArray, function(key, val) { if (val.name == stagename) { delete val.blockchain; } }) } console.log(programStagesArray); }); $(".btn_FinalSubmit").off("click"); $(".btn_FinalSubmit").on("click", function() { // DIGITAL PAYMENT DATA ELEMENT APPEND // // DIGITAL PAYMENT var dataelement = { "dataelements": [{ "name": "Requestor Mobile No", "type": "number", "mandatory": "false" }, { "name": "Request Amount", "type": "number", "mandatory": "false" }, { "name": "Requestor Remarks", "type": "text", "mandatory": "false" } ] }; $.each(communitiesStagesArray, function(key, val) { var isDigitalalready = false; if (val.wallet == true) { $.each(val.dataelements, function(k, v) { if (v.name == "Requestor Mobile No" || v.name == "Request Amount" || v.name == "Requestor Remarks") { // delete v; isDigitalalready = true; } }); if (isDigitalalready == false) { val.dataelements = val.dataelements.concat(dataelement.dataelements); } } else { // for (let i in val.dataelements) { // if (val.dataelements[i].name == "Requestor Mobile No" || val.dataelements[i].name == "Request Amount" || val.dataelements[i].name == "Requestor Remarks") { // // delete v; // val.dataelements.splice(i, 1); // i--; // } // } val.dataelements = _.reject(val.dataelements, function(item) { return item.name == "Requestor Mobile No" || item.name == "Request Amount" || item.name == "Requestor Remarks" }); } }) $.each(programStagesArray, function(key, val) { var isDigitalalready = false; if (val.wallet == true) { $.each(val.dataelements, function(k, v) { if (v.name == "Requestor Mobile No" || v.name == "Request Amount" || v.name == "Requestor Remarks") { // delete v; isDigitalalready = true; } }); if (isDigitalalready == false) { val.dataelements = val.dataelements.concat(dataelement.dataelements); } } else { val.dataelements = _.reject(val.dataelements, function(item) { return item.name == "Requestor Mobile No" || item.name == "Request Amount" || item.name == "Requestor Remarks" }); // for (let i in val.dataelements) { // if (val.dataelements[i].name == "Requestor Mobile No" || val.dataelements[i].name == "Request Amount" || val.dataelements[i].name == "Requestor Remarks") { // // delete v; // val.dataelements.splice(i, 1); // i--; // } // } // $.each(val.dataelements, function(k, v) { // if (v.name == "Requestor Mobile No" || v.name == "Request Amount" || v.name == "Requestor Remarks") { // // delete v; // val.dataelements.splice(k, 1); // } // }); } }) // DATA CLEANUP FOR DEPENDENCY $.each(programStagesArray, function(key, val) { $.each(val.dependentquestions, function(key, val) { if (val.type == "checkbox") { val.matchingvalue = "true"; delete val.condition; } else if (val.type == "option") { delete val.condition; } }) }) $.each(communitiesStagesArray, function(key, val) { $.each(val.dependentquestions, function(key, val) { if (val.type == "checkbox") { val.matchingvalue = "true"; delete val.condition; } else if (val.type == "option") { delete val.condition; } }) }) console.log('Data Cleanup'); console.log(programStagesArray); console.log(communitiesStagesArray); // app info object var appInfo = getLocalStorage("AppInfo"); var programName = $("#programName").val(); var programdescr = $("#programdescr").val(); var programShortName = $("#programName").val(); //Program Short Name == Program Name var communityName = $("#communityName").val(); var communitydescr = $("#communitydescr").val(); var CommunityShortName = $("#communityName").val(); if (programName == communityName) { communityName = communityName + "_Community"; CommunityShortName = communityName; } programsObj.name = programName; programsObj.shortname = programShortName.substring(0, 30); programsObj.description = programdescr; programsObj.logo = getLocalStorage("pgmicon"); // custom icon programsObj.mobilelayout = mobileLayout; programsObj.weblayout = WebLayout; programsObj.theme = themeColor_prog; if (ishasWorkflow == true) { programsObj.hasworkflow = "yes"; if ($("#hasautoreferral").is(':checked')) { programsObj.autoreferral = "true"; } else { programsObj.autoreferral = "false"; } } else { programsObj.hasworkflow = "no"; programsObj.autoreferral = "false"; } // HAS CHAT if ($("#haschatEnabled_prg").is(':checked')) { programsObj.haschat = "true"; } else { programsObj.haschat = "false"; } // HAS RELATION ENABLED if ($("#enablerelation").is(':checked')) { programsObj.hasrelationshiptype = "true"; programsObj.relationshiptype = [{ "relationshiptypename": "ParentChild", "aistob": "Parent", "bistoa": "Child" }]; } else { programsObj.hasrelationshiptype = "false"; delete programsObj.relationshiptype; } // HAS EXTERNAL REFERRAL ENABLED if ($("#hasextreferralEnabled_prg").is(':checked')) { programsObj.hasexternalreferral = "yes"; } else { programsObj.hasexternalreferral = "no"; } // STAGE VALIDATION programStagesArray = _.filter(programStagesArray, function(item) { return item.name !== "Registration"; }) programsObj.stages = programStagesArray; // if (isDataAvailableinStage(programStagesArray) == true) { // programsObj.stages = programStagesArray; // } else { // programsObj.stages = programStagesArray; // } programsArray = []; programsArray.push(programsObj); communitiesObj.name = communityName; communitiesObj.shortname = CommunityShortName.substring(0, 30); communitiesObj.description = communitydescr; communitiesObj.logo = getLocalStorage("comicon"); // custom icon communitiesObj.mobilelayout = mobileLayout; communitiesObj.weblayout = WebLayout; communitiesObj.theme = themeColor_comm; if ($("#haschatEnabled_comm").is(':checked')) { communitiesObj.haschat = "true"; } else { communitiesObj.haschat = "false"; } if ($('#mpesaTrans').is(":checked") == true) { var mpesaObj = { "name": "mpesa", "dataelements": [{ "name": "Mobile No", "type": "number", "mandatory": "true" }, { "name": "Service", "type": "text", "mandatory": "true" }, { "name": "Amount", "type": "number", "mandatory": "true" }, { "name": "Remarks", "type": "text", "mandatory": "false" } ] }; communitiesStagesArray.push(mpesaObj); } else {} communitiesObj.stages = communitiesStagesArray; if (!_.isEmpty(contentmgmtObj)) { communitiesObj.contentmanagement = contentmgmtObj; } console.log("-------------------->" + communitiesObj.name); communitiesArray = []; communitiesArray.push(communitiesObj); if ($("#communityAssocChk").prop('checked') == true) { console.log("chk"); } //=========HARDCODED============== var referencesObj = {}; // var optionsArray = []; var dependentquestionsObj = {}; referencesObj.options = optionsArray; referencesObj.dependentquestions = dependentquestionsObj; //=====APPLICATION OBJECT=============// applicationObject.name = appInfo.appName; applicationObject.shortname = appInfo.appShortName; applicationObject.timezone = appInfo.timezone; applicationObject.selectedcountrycode = appInfo.countryCode; applicationObject.selectedlanguage = appInfo.language; applicationObject.logo = getLocalStorage("appicon"); // for app logo if ($('#communityAssocChk').is(":checked") == true) { applicationObject.communities = communitiesArray; } else { applicationObject.communities = []; } var isValidWorlflow = true; if ($('#programAssocChk').is(":checked") == true) { applicationObject.programs = programsArray; if (ishasWorkflow == true) { _.map(stageroles, function(item) { item.programname = $("#programName").val() }); // $.each(stageroles,function(key,val){ // }) masterObject.userroleprogramstageaccess = stageroles; $.each(stageroles, function(key, val) { $.each(val.stages, function(key1, val1) { val1.stageroletype = "program"; }) }) isValidWorlflow = true; // STAGE ROLES ACCESS } else { masterObject.userroleprogramstageaccess = []; } } else { applicationObject.programs = []; } applicationObject.trackedentityattributes = trackedentityattributesArray; if (_.isEmpty(attributedependentquestions)) { applicationObject.attributedependentquestions = []; } else { applicationObject.attributedependentquestions = attributedependentquestions; } // UIC TYPE CHANGE FOR OPTION SETS $.each(temoUICArray, function(key, val) { var attrname = val.attributename; var isavailable = _.filter(optionsArray, function(item) { return item.name == attrname; }); if (_.isEmpty(isavailable) == false) { val.type = "option"; } }) if (temoUICArray.length > 0) { applicationObject.uic = temoUICArray; } else { applicationObject.uic = temoUICArray; // applicationObject.uic = uicArray; } applicationObject.references = referencesObj; applicationArray = []; applicationArray.push(applicationObject); console.log(applicationArray); //=====TEMPLATE OBJECT - HARDCODED ==============// templateObject.version = "1.0"; templateObject.id = "1"; var nowdate = $.now(); templateObject.date = moment(nowdate).format("MMM Do YYYY");; templateObject.language = "en"; templateObject.category = "TB"; templateObject.type = "Program"; if (isSaveTemplate == true) { templateObject.savetemplate = "true"; templateObject.name = $('#templateName').val(); if (templateicon == undefined) { var str = $('#iconviewtmpl').attr("src"); templateObject.thumbnail = str.replace('assets/', ''); } else { templateObject.thumbnail = templateicon; } templateObject.description = $('#templateDescr').val(); // alert(isSaveTemplate); } else { // alert(isSaveTemplate); templateObject.savetemplate = "false"; templateObject.name = "RTM TB Green"; templateObject.thumbnail = "path"; templateObject.description = "RTM TB template with Green theme"; } //=====ADMIN OBJECT - HARDCODED ==============// var userObj = getLocalStorage("rtmProUserObject"); console.log(userObj); adminObject.userid = userObj.userid; adminObject.username = userObj.username; masterObject.template = templateObject; masterObject.admin = adminObject; masterObject.application = applicationArray; $.each(stageroles, function(key, val) { if (key > 0) { $.each(val.stages, function(key1, val1) { val1 = _.omit(val1, 'registration'); }) } }) masterObject = trimObj(masterObject); console.log(masterObject); apiservices.createCustomSmartSetupTemplate(masterObject, ux.createCustomSmartSetupTemplateSuccessCallback, ux.fail) $("html, body").animate({ scrollTop: 0 }, 600); $('.load1').removeClass('hidden'); $("#progressTimer").progressTimer({ timeLimit: 100, baseStyle: 'progress-bar-info', warningStyle: 'progress-bar-warning', completeStyle: 'progress-bar-info', onFinish: function() { console.log("I'm done"); $('.sm_step1').show(); } }); $("#progressTimer1").progressTimer({ timeLimit: 120, baseStyle: 'progress-bar-info', warningStyle: 'progress-bar-warning', completeStyle: 'progress-bar-info', onFinish: function() { console.log("I'm done"); $('.sm_step2').show(); } }); $("#progressTimer2").progressTimer({ timeLimit: 140, baseStyle: 'progress-bar-info', warningStyle: 'progress-bar-warning', completeStyle: 'progress-bar-info', onFinish: function() { console.log("I'm done"); $('.sm_step3').show(); } }); $("#progressTimer3").progressTimer({ timeLimit: 450, baseStyle: 'progress-bar-info', warningStyle: 'progress-bar-warning', completeStyle: 'progress-bar-info', onFinish: function() { console.log("I'm done"); $('.sm_step4').show(); } }); }); } else { location.href = "login.html"; } } //=========== CREATE CUSTOM FORM TEMPLATE WITH USER INPUT - END ========================================//