$(function(){ $('.sortable').nesDrag("init"); $('.main_add_group').click(function(){ //console.log("add group"); var randNumber=generateRandomInteger(50000,120000000); addGroupPopupContent(randNumber); var new_group='
"+parent_block.html()+"
"); $('#ex1').dialog("close"); } function saveGroup(elem,id){ var parent_block=$(elem).parent(); elem_name=$(elem).parent().find(".group_title").val(); $('#group_'+id+' > .menuDiv').text(elem_name.substring(0,70)+" ..."); $('.popupData').find('.group_'+id).html(""+parent_block.html()+"
"); $('#ex1').dialog("close"); } //risponde a due domande: chi sono (gruppo o item), qualè l'ID di mio padre function getParentId(id){ var arrayS = $('ol.sortable').nestedSortable('toArray', {startDepthCount: 0}); //console.log(arrayS); //$('.hiered').html(JSON.stringify(arrayS)); var elem = arrayS.filter(function(v) { return v.item_id === id; // Filter out the appropriate one }); // Get result and access the foo property //console.log(elem); return elem[0].parent_id; } function getItemsByGroupId(id){ var items=[]; $('li#group_'+id+' > ol > li').each(function(id, elem){ if(!$(elem).hasClass("group")){ //console.log(elem); var item_id; item={}; item.id=item_id=$(elem).attr("id").replace("item_",""); item.title=$('input[name="items['+item_id+'][title]"]').val(); item.type=$('input[name="items['+item_id+'][type]"]').val(); item.labels=$('input[name="items['+item_id+'][labels]"]').val(); item.options=$('input[name="items['+item_id+'][options]"]').val(); item.values=$('input[name="items['+item_id+'][values]"]').val(); item.texts=$('input[name="items['+item_id+'][texts]"]').val(); item.placeholder=$('input[name="items['+item_id+'][placeholder]"]').val(); item.static=$('input[name="items['+item_id+'][static]"]').prop("checked"); item.required=$('input[name="items['+item_id+'][required]"]').prop("checked"); item.badge_type=$('input[name="items['+item_id+'][badge_type]"]').prop("checked"); item.image=$('input[name="items['+item_id+'][image]"]').val(); item.image_type=$('input[name="items['+item_id+'][image_type]"]').prop("checked"); item.prices=$('input[name="items['+item_id+'][prices]"]').val(); //aggiunti di recente item.is_searchable=$('input[name="items['+item_id+'][is_searchable]"]').prop("checked"); item.is_index=$('input[name="items['+item_id+'][is_index]"]').prop("checked"); item.is_searchable_fe=$('input[name="items['+item_id+'][is_searchable_fe]"]').prop("checked"); item.is_contact=$('input[name="items['+item_id+'][is_contact]"]').prop("checked"); item.is_on_frontend=$('input[name="items['+item_id+'][is_on_frontend]"]').prop("checked"); item.is_only_frontend=$('input[name="items['+item_id+'][is_only_frontend]"]').prop("checked"); item.minimum_salary_trigger=$('input[name="items['+item_id+'][minimum_salary_trigger]"]').attr("value"); item.revalidation_trigger=$('input[name="items['+item_id+'][revalidation_trigger]"]').prop("checked"); item.placeholder_fe=$('input[name="items['+item_id+'][placeholder_fe]"]').val(); item.labels_fe=$('input[name="items['+item_id+'][labels_fe]"]').val(); item.is_on_email=$('input[name="items['+item_id+'][is_on_email]"]').prop("checked"); item.is_and=$('input[name="items['+item_id+'][is_and]"]').prop("checked"); item.is_on_frontend_view=$('input[name="items['+item_id+'][is_on_frontend_view]"]').val(); item.hint_message=$('input[name="items['+item_id+'][hint_message]"]').val(); //recupero la posizione rispetto al padre item_position=$('#item_'+item_id).index(); item.order = item_position; items.push(item); } }); return items; } function saveModel(){ model_title=$('input[name="model[title]"]').val(); if(model_title==""){ alert("Il nome del modello è un campo obbligatorio."); return; } var groups=[]; //console.log($('ol.sortable').nestedSortable('toArray', {startDepthCount: 0})); $('.group p').each(function(){ var node=$(this); var group_data={}; var id=node.find(".group_code").val(); //recupero la posizione rispetto al padre group_position=$('#group_'+id).index(); group_data.code=id; father_id=getParentId(id); group_data.master_code=father_id; group_data.title=node.find(".group_title").val(); group_data.static=node.find(".group_static").prop("checked"); group_data.is_badge=node.find(".group_is_badge").prop("checked"); group_data.image=node.find(".group_image").prop("checked"); group_data.hidden=node.find(".group_hidden").prop("checked"); group_data.multiple=node.find(".group_multiple").prop("checked"); group_data.order = group_position; //prelevo gli item del gruppo //console.log("--------"); items=getItemsByGroupId(id); //console.log("--------"); group_data.items=items; groups.push(group_data); }); var modelData={ "name": $('input[name="model[title]"]').val(), "type": $('select[name="model[type]"]').val(), "groups": groups }; //console.log(modelData); //creo il modello //var user_code=null; //var create_deferred = this.request.Deferred(); $.ajax({ url: remoteAPIurl+'/api/v1/model?api_token='+token, crossDomain: true, type: "post", data: modelData, dataType: 'json', success: function(result, statusText, resObject){ location.href="./index.php"; }, error: function() { console.log('error'); } }); } function refresh() { this._router.navigate(['Home']); }