jQuery(document).ready(function() { jQuery('#submit_ticket').click(function() { jQuery('#submit_ticket').attr('disabled','disabled'); if(almaware_checkCampi()) { var view = 1; wats_loading(document.getElementById("resultticketsubmitform"),watsmsg[1]); var name = jQuery('#name').val(); var email = jQuery('#email').val(); var url = jQuery('#url').val(); var ticket_title = jQuery('#ticket_title').val(); var ticket_content = jQuery('#ticket_content').val(); var idtype = jQuery('#wats_select_ticket_type option:selected').val(); var idpriority = jQuery('#wats_select_ticket_priority option:selected').val(); var idstatus = jQuery('#wats_select_ticket_status option:selected').val(); if (jQuery('#wats_select_ticket_product')) var idproduct = jQuery('#wats_select_ticket_product option:selected').val(); else var idproduct = 0; if (jQuery('#wats_select_ticket_owner option:selected').val()) var idowner = jQuery('#wats_select_ticket_owner option:selected').val(); else var idowner = jQuery('#wats_select_ticket_owner').val(); var category = jQuery('#wats_cat_list option:selected').val(); var customfieldlist = new Array(); var j = 0; jQuery("input[name*='wats_cf']").each(function() { customfieldlist[j] = {}; customfieldlist[j][jQuery(this).attr("id")] = jQuery(this).val(); j++; }); jQuery("textarea[name*='wats_textarea_cf']").each(function() { customfieldlist[j] = {}; customfieldlist[j][jQuery(this).attr("id")] = jQuery(this).val(); j++; }); jQuery("select[name*='wats_select_cf']").each(function() { customfieldlist[j] = {}; customfieldlist[j][jQuery(this).attr("id")] = jQuery(this).children(':selected').val(); j++; }); var currentRadioGroup = ''; jQuery("input[name*='wats_checkbox_cf']").each(function() { if(currentRadioGroup != jQuery(this).attr("id")) { // presumo che tutti gli wats_checkbox_cf_[nomedelcampo] siano ordinati currentRadioGroup = jQuery(this).attr("id"); customfieldlist[j] = {}; customfieldlist[j][currentRadioGroup] = almaware_getAll_checkbox_checked_values(currentRadioGroup).toString(); j++; } }); liste = JSON.stringify(customfieldlist); var author = 0; if (jQuery('#wats_select_ticket_originator option:selected').val()) var author = jQuery('#wats_select_ticket_originator option:selected').val(); else var author = jQuery('#wats_select_ticket_originator').val(); jQuery.post(ajaxurl, {action:"wats_ticket_submit_form_ajax_processing", _ajax_nonce:jQuery("#_wpnonce_ticket_submit_form").val(), view:view, name:name, email:email, url:url, ticket_title:ticket_title, ticket_content:ticket_content, idtype:idtype, idpriority:idpriority, idstatus:idstatus, idproduct:idproduct, idowner:idowner, category:category, liste:liste, author:author}, function(res) { var message_result = eval('(' + res + ')'); wats_stop_loading(document.getElementById("resultticketsubmitform"),message_result.message); //jQuery('#submit_ticket').removeAttr('disabled'); jQuery('#submit_ticket').trigger('wats_frontend_submission_form_submitted',message_result.result); }); } else { jQuery('#submit_ticket').removeAttr('disabled');; } return false; }); var selected_wats_select_ticket_owner_ac = 0; if (jQuery("#wats_select_ticket_owner_ac").is("input")) { jQuery('#wats_select_ticket_owner_ac').autocomplete({ source: function(request,response) { jQuery.ajax({ url: ajaxurl+"?action=wats_ajax_frontend_get_user_list", dataType: "json", data: { value:jQuery('#wats_select_ticket_owner_ac').val(), _ajax_nonce:jQuery("#_wpnonce_ticket_submit_form").val(), type:'fsfownerlist', 'cookie': encodeURIComponent(document.cookie) }, success: function(data) { if (jQuery.isEmptyObject(data) == true) jQuery('#wats_select_ticket_owner').val("0"); response( jQuery.map(data, function(item) { return{value:item.label,label:item.label,hidden:item.value} })); } }); }, select: function(event,ui) { selected_wats_select_ticket_owner_ac = 1; jQuery('#wats_select_ticket_owner').val(ui.item.hidden); }, close : function(event,ui) { if (selected_wats_select_ticket_owner_ac == 0) jQuery('#wats_select_ticket_owner').val("0"); selected_wats_select_ticket_owner_ac = 0; }, minLength:3, delay:300 }); } var selected_wats_select_ticket_originator_ac = 0; if (jQuery("#wats_select_ticket_originator_ac").is("input")) { jQuery('#wats_select_ticket_originator_ac').autocomplete({ source: function(request,response) { jQuery.ajax({ url: ajaxurl+"?action=wats_ajax_frontend_get_user_list", dataType: "json", data: { value:jQuery('#wats_select_ticket_originator_ac').val(), _ajax_nonce:jQuery("#_wpnonce_ticket_submit_form").val(), type:'fsfauthorlist', 'cookie': encodeURIComponent(document.cookie) }, success: function(data) { if (jQuery.isEmptyObject(data) == true) jQuery('#wats_select_ticket_originator').val("0"); response( jQuery.map(data, function(item) { return{value:item.label,label:item.label,hidden:item.value} })); } }); }, select: function(event,ui) { selected_wats_select_ticket_originator_ac = 1; jQuery('#wats_select_ticket_originator').val(ui.item.hidden); }, close : function(event,ui) { if (selected_wats_select_ticket_originator_ac == 0) jQuery('#wats_select_ticket_originator').val("0"); selected_wats_select_ticket_originator_ac = 0; }, minLength:3, delay:300 }); } /* inizializzo il file upload */ if(jQuery('#fu').lenght > 0){ console.log('test'); jQuery('#fu').uploadify({ 'swf' : '/wp-content/plugins/almaware-ticketing-remote-file/ulpoad/uploadify.swf', 'uploader' : '/wp-content/plugins/almaware-ticketing-remote-file/ulpoad/uploadify.php', 'formData' : { 'current_user_id' : jQuery('#cui').text() }, 'onUploadSuccess' : function(file, data, response) { /*file The file object that was successfully uploaded data The data that was returned by the server-side script (anything that was echoed by the file) response The response returned by the server—true on success or false if no response. If false is returned, after the successTimeout option expires, a response of true is assumed.*/ //console.log(data); var filename = file.name; filename = filename.replace(/[^\w\.-]/gi, "-"); if(data != "Invalid file type") { jQuery('#fu_uploaded').append('
  • ' + filename + '
  • '); } else { alert(filename + " - Estensione file non consentita"); } } // Put your options here }); } return false; }); function almaware_getAll_checkbox_checked_values(id) { var allVals = []; jQuery("#"+id+":checked").each(function() { allVals.push(jQuery(this).val()); }); return allVals; } /* controllo campi obbligatori */ // non posso farlo lato server perchè WP non mi da a disposizione un hook prima del salvataggio del commento function almaware_checkCampi() { var ok = true; /*jQuery('input#wats_cf_dati_cantiere').next('span.avviso').remove(); if(jQuery('input#wats_cf_dati_cantiere').val() == '') { ok = false; jQuery('input#wats_cf_dati_cantiere').after('*'); }*/ jQuery('input#wats_cf_comune').next('span.avviso').remove(); if(jQuery('input#wats_cf_comune').val() == '') { ok = false; jQuery('input#wats_cf_comune').after('*'); } jQuery('input#wats_cf_provincia').next('span.avviso').remove(); if(jQuery('input#wats_cf_provincia').val() == '') { ok = false; jQuery('input#wats_cf_provincia').after('*'); } jQuery('input#wats_cf_via').next('span.avviso').remove(); if(jQuery('input#wats_cf_via').val() == '') { ok = false; jQuery('input#wats_cf_via').after('*'); } jQuery('input#wats_cf_numero').next('span.avviso').remove(); if(jQuery('input#wats_cf_numero').val() == '') { ok = false; jQuery('input#wats_cf_numero').after('*'); } jQuery(".wats_checkbox_cf_dati_progetto_offerta").prev('span.avviso').remove(); var dati_progetto_offerta_checked = new Array(); jQuery("#wats_checkbox_cf_dati_progetto_offerta:checked").each(function() { dati_progetto_offerta_checked.push(jQuery(this).val()); }); if(jQuery.inArray("1", dati_progetto_offerta_checked) == -1 || jQuery.inArray("2", dati_progetto_offerta_checked) == -1 || jQuery.inArray("3", dati_progetto_offerta_checked) == -1) { ok = false; jQuery(".wats_checkbox_cf_dati_progetto_offerta").each(function(index){ if(index < 3) jQuery(this).before('*') }); } jQuery('input#wats_cf_importo_listino_offerta').next('span.avviso').remove(); if(jQuery('input#wats_cf_importo_listino_offerta').val() == '') { ok = false; jQuery('input#wats_cf_importo_listino_offerta').after('*'); } jQuery('input#ticket_title').next('span.avviso').remove(); if(jQuery('input#ticket_title').val() == '') { ok = false; jQuery('input#ticket_title').after('*'); } jQuery('textarea#ticket_content').prev('span.avviso').remove(); if(jQuery('textarea#ticket_content').val() == '') { ok = false; jQuery('textarea#ticket_content').before('*'); } if (ok) { return true; } else { //Prevent the submit event and remain on the screen alert("E' necessario compilare tutti i campi per poter inviare il commento"); return false; } }