var body = $('body'); body.on('click','#setlast',function() { SetLastActiveCheckType(); }); body.on('click','#remove_checktype',function(){DeleteCheckType();}); body.on('click','#add_new_checkbox',function(){ShowCheckBoxList();}); body.on('click','#add_cb_button',function(){AddNewCheckBox();}); body.on('click','#add_to_task',function(){AddToTask();}); body.on('click','#toggleTWX',function(){toggleTWX();}); body.on('change','#select_CheckBox_list',function(){ShowCheckBox(this);}); body.on('change','select',function() { var id = this.options[this.selectedIndex].value; var empty_contents = false; if (this.id == 'classes') { ShowCheckPointTypeList(id); } else if (this.id == 'select_DropList_list' || this.id == 'select_MultiSelect_list' ) { ShowCheckPointTypeContents(); } EmptyContents(this); if ($('#'+this.id).parent().parent()[0].id == 'checkpoint_list') DeleteCheckTypeDialogShow(1); }); $("#add_new_list").click( function() { AddNewCheckPointTypeDialog(GetActiveClassName()); } ); $("#send").click( function(){ AddNewCheckPointType(); } ); $("#close").click( function(){ CloseNewClassDialog(); } ); function toggleTWX() { var dataarr = new Object(); var cptype = $('#select_CheckBox_list').val(); dataarr["toggletwx"] = cptype; sendAjax('contents', dataarr); } function ShowCheckBox(el) { //alert ("ShowCheckBox "+el.value); var dataarr = new Object(); dataarr["showcheckbox"] = el.value; sendAjax('contents', dataarr); } function AddToTask() { var id = GetActiveCheckTypeID(); var taskType = $("#activeTaskTypeId")[0].getAttribute('data-activeid'); // alert("id "+id+" taskType "+taskType); sendAjaxForm('result_cont', 'ajax_form', 'response.php?add_to_task='+id+"&taskType="+taskType); } function EmptyContents(select) { if (select.getAttribute( 'data-contentsFlag') != 'noHideContents') { $('#contents').html(''); } } function ShowCheckPointTypeList(id) { if (id == '') $('#contents').html(''); else sendAjaxForm('result_cont', 'ajax_form', 'response.php?show='+id); } function DeleteCheckTypeDialogShow(val) { if (parseInt(val) == 0) { $("#add_to_task").hide(); $("#remove_checktype").hide(); } else { var taskType = $("#activeTaskTypeId")[0]; if (taskType != null) { $("#add_to_task").css("display", "inline-block"); } $("#remove_checktype").css("display", "inline-block"); } } function ShowCheckPointTypeContents() { var id = GetActiveCheckTypeID(); sendAjaxForm('contents', 'ajax_form', 'response.php?id='+id); // if (id == '0') // $("#remove_checktype").hide(); // else // $("#remove_checktype").css("display", "inline-block"); //CloseNewClassDialog(); } function DeleteCheckType() { var id = GetActiveCheckTypeID(); sendAjaxForm('contents', 'ajax_form', 'response.php?delete_cpt='+id); ShowCheckPointTypeList(GetActiveClassName()); } function GetActiveCheckTypeID() { var name = GetActiveCheckTypeName(); var select = $("#"+name)[0]; return select.options[select.selectedIndex].value; } function GetActiveClassName() { var select = $("#classes")[0]; return select.options[select.selectedIndex].value; } function GetActiveCheckTypeName() { return "select_"+GetActiveClassName()+"_list"; } function SetLastActiveCheckType() { var name = GetActiveCheckTypeName(); var select = $("#"+name)[0]; var len = select.options.length; select.selectedIndex = len-1; } var setlast = 0; function AddNewCheckPointType() { var name = $('#cb_name').val(); if (name == '') { alert('Заполните имя!'); return; } var activeClass = GetActiveClassName(); sendAjaxForm('result', 'ajax_form', 'response.php?addcpt='+activeClass+"&name="+name); CloseNewClassDialog(); ShowCheckPointTypeList(GetActiveClassName()); setlast = 2; } function CloseNewClassDialog() { $("#class_name").html(''); $("#cont").hide(); } function AddNewCheckPointTypeDialog(theclass) { $("#cont").show(); $("#class_name").show(); $("#class_name").html(theclass); } function ShowCheckBoxList() { $.ajax({ type: "POST", url: "response.php", data: { "show_cb_list": 1}, dataType: "html", success: function(data){ $("#new_cb_list").html(data); $("#new_cb_list").append(""); }, failure: function(errMsg) { alert(errMsg); } }); } function AddNewCheckBox() { var select = $("#select_cb_template")[0]; var parent_id = GetActiveCheckTypeID(); var cb_id = select.options[select.selectedIndex].value; $.ajax({ type: "POST", url: "response.php", data: { "add_cb": cb_id, "parent_id": parent_id}, dataType: "html", success: function(data){ sendAjaxForm('contents', 'ajax_form', 'response.php?id='+parent_id); }, failure: function(errMsg) { alert(errMsg); } }); } function GetDesc(type) { switch (type) { case "DropList": desc = type+": Выбор одного значения из списка"; break; case "CheckBox": desc = type+": Элемент, принимающий 1 из значений: Да/Нет (Например подтвердить наличие огнетушителя)"; break; case "MultiSelect": desc = type+": Выбор нескольких значений из списка"; break; case "SerialNumber": desc = type+": Ввод текстовых данных"; break; } return desc; } function sendAjax(result_form, dataarr, onsuccess = null, url = "response.php") { // var dict = new Object(); //or Map() // dict[ dataname ] = datavalue; $.ajax({ type: "POST", url: url, data: dataarr, dataType: "html", success: function (data) { //console.log(data); if (result_form != '' && result_form != null) { $('#' + result_form).html(data); } if (onsuccess != null) onsuccess(data); // LoadLocations(); }, failure: function (errMsg) { alert(errMsg); }, timeout : 10000000 }); } function sendAjaxForm(result_form, ajax_form, url) { $.ajax({ url: url, //url страницы (action_ajax_form.php) type: "POST", //метод отправки dataType: "html", //формат данных data: $("#"+ajax_form).serialize(), // Сеарилизуем объект success: function(response) { //Данные отправлены успешно result = response; $('#'+result_form).html(result); if (setlast > 0) { setlast-- ; if (setlast == 0) { SetLastActiveCheckType(); ShowCheckPointTypeContents(); } } //AppendDiv("test333"); }, error: function(response) { // Данные не отправлены $('#result_form').html('Ошибка. Данные не отправлены.'); } }); } function AppendDiv(id) { $('
', { id:id, text: 'Гугли!'}).appendTo('#result_form'); } function delCheckbox(id, parent_id) { if (!sure(id, "Удалить вариант ")) return; $.ajax({ type: "POST", url: "response.php", data: { "remove_cb": id, "parent_id": parent_id}, //data: JSON.stringify( markers ), // contentType: "application/json; charset=utf-8", dataType: "html", success: function(data){sendAjaxForm('contents', 'ajax_form', 'response.php?id='+parent_id);}, failure: function(errMsg) { alert(errMsg); } }); } function changeCheckbox(id) { alert ('change id '+id); }