');
// if($("[id^=controller_type_parameter_"+value+"]").closest('.form-group').find('.translatable-field').length)
// $("[id^=controller_type_parameter_"+value+"]").closest('.form-group').parents('.element-tmp').after(button_tmp);
// else
// $("[id^=controller_type_parameter_"+value+"]").closest('.element-tmp').after(button_tmp);
$('.element-'+value).wrapAll('
');
$('.link_group.new').prepend('
');
$('.link_group.new').append(button_tmp);
$('.link_group.new').data('index',value);
$('.link_group.new .element-tmp').removeClass('element-tmp hidden');
$('.link_group.new').removeClass('new');
_updateLinkType(value);
$("#link_type_"+value).on('change',function(){
_updateLinkType(value);
});
}
});
$(".link_group:odd").css("background-color", "#DAE4F0");
$(".link_group:even").css("background-color", "#FFFFFF");
}
//add new link
// console.log(array_id_lang[0]);
// console.log(array_id_lang[1]);
$('.add-new-link').on('click',function(e){
e.preventDefault();
// var total_link = parseInt($("#total_link").val()) + 1;
var total_link = getMaxIndex();
var i=0;
var new_link_tmp = '';
$('.parent-tmp.hidden').each(function(){
if (i == 0)
{
//$('.add-new-link').closest('.form-group').parent().append('
');
new_link_tmp += '
';
}
new_link_tmp += '
'+$(this).html()+'
';
// $('.add-new-link').closest('.form-group').parent().append('
'+$(this).html()+'
');
i++;
if (i == $('.parent-tmp.hidden').length)
{
// console.log('test');
// $('.add-new-link').closest('.form-group').parent().append('
');
new_link_tmp += "
';
new_link_tmp += '
';
}
});
$('.add-new-link').closest('.form-group').parent().append(new_link_tmp);
$('.link_group.new').data('index',total_link);
updateNewLink(total_link, true , 0);
});
//duplicate link - block link
$('.duplicate_link').live('click',function(e){
e.preventDefault();
//var html_duplicate = $(this).closest('.link_group').html();
var html_duplicate = $(this).closest('.link_group').clone().prop('class', 'link_group new');
// console.log(html_duplicate);
//html_duplicate.filter('.link_group').prop('class', 'link_group new');
//var total_link = parseInt($("#total_link").val()) + 1;
var total_link = getMaxIndex();
$(this).closest('.link_group').after(html_duplicate);
var current_index = $(this).closest('.link_group').data('index');
$('.link_group.new').data('index',total_link);
updateNewLink(total_link, false, current_index);
});
//remove link - block link
$('.remove_link').live('click',function(e){
e.preventDefault();
if (confirm('Are you sure you want to delete?')) {
//console.log($(this).find('.tmp'));
$(this).closest('.link_group').find('.tmp').each(function(){
// console.log($(this).attr('name'));
var name_val = $(this).attr('name');
if($(this).closest(".translatable-field").length)
{
name_val = name_val.substring(0, name_val.lastIndexOf('_'));
updateField('remove',name_val,true);
}
else
{
updateField('remove',name_val,false);
}
});
$(this).closest('.link_group').fadeOut(function(){
$(this).remove();
$(".link_group:odd").css( "background-color", "#DAE4F0" );
$(".link_group:even").css( "background-color", "#FFFFFF" );
var total_link = parseInt($("#total_link").val())-1;
$("#total_link").val(total_link);
$('#list_id_link').val('');
$('.link_group').each(function(){
$('#list_id_link').val($('#list_id_link').val()+$(this).data('index')+',');
})
});
}
});
//copy to other language - block link
$('.copy_lang_value').live('click',function(e){
e.preventDefault();
// console.log('test');
// console.log($(this).parent().find('.translatable-field:visible'));
var value_copy = $(this).parent().find('.translatable-field:visible input').val();
// console.log($(this).parent().find('.translatable-field:hidden'));
$(this).parent().find('.translatable-field:hidden input').val(value_copy);
$(this).text(copy_lang_button_text_done);
var ele_obj = $(this);
// console.log(value_copy);
//copy_lang_button_text_done
setTimeout(function(){
ele_obj.text(copy_lang_button_text);
}, 2000);
});
//update value of input select - block link
// $('.link_group input').live('keyup',function(){
// console.log($(this).val());
// })
$('.link_group select').live('change',function(){
if($(this).val() != $(this).find('option[selected=selected]').val())
{
$(this).find('option[selected=selected]').removeAttr("selected");
$(this).find('option[value='+$(this).val()+']').attr('selected','selected');
}
});
//done for category_image widget
// Check type of Carousel type - BEGIN
$('.form-action').change(function(){
elementName = $(this).attr('name');
$('.'+elementName+'_sub').hide(300);
$('.'+elementName+'-'+$(this).val()).show(500);
});
$('.form-action').trigger("change");
// Check type of Carousel type - END
$("#configuration_form").validate({
rules : {
owl_items : {
min : 1,
},
owl_rows : {
min : 1,
}
}
});
});
function getMaxIndex()
{
if($('.link_group').length == 0)
{
return 1;
}
else
{
var list_index = [];
$('.link_group').each(function(){
list_index.push($(this).data('index'));
})
// console.log(list_index);
return Math.max.apply(Math,list_index) + 1;
// console.log(total_link);
}
}
//update when add a new link
function updateNewLink(total_link, scroll_to_new_e, current_index)
{
// console.log(id_language);
var array_id_lang = $.parseJSON(list_id_lang);
updateField('add','text_link_'+total_link,true);
updateField('add','url_type_'+total_link,true);
updateField('add','controller_type_parameter_'+total_link,true);
// console.log($('.link_group.new .form-group .tmp').closest(".translatable-field").length);
$('.link_group.new .form-group .tmp').each(function(){
var e_obj = $(this);
if($(this).closest(".translatable-field").length)
{
// console.log('aaaa');
$.each(array_id_lang, function( index, value ) {
// if (current_index == 0)
// {
// switch(e_obj.attr('id'))
// {
// case 'text_link_'+value:
// e_obj.attr('id','text_link_'+total_link+'_'+value);
// e_obj.attr('name','text_link_'+total_link+'_'+value);
// break;
// case 'url_type_'+value:
// e_obj.attr('id','url_type_'+total_link+'_'+value);
// e_obj.attr('name','url_type_'+total_link+'_'+value);
// break;
// case 'controller_type_parameter_'+value:
// e_obj.attr('id','controller_type_parameter_'+total_link+'_'+value);
// e_obj.attr('name','controller_type_parameter_'+total_link+'_'+value);
// break;
// }
// }
// else
// {
// console.log('test');
// console.log(e_obj.attr('id'));
switch(e_obj.attr('id'))
{
case 'text_link_'+current_index+'_'+value:
e_obj.attr('id','text_link_'+total_link+'_'+value);
e_obj.attr('name','text_link_'+total_link+'_'+value);
break;
case 'url_type_'+current_index+'_'+value:
e_obj.attr('id','url_type_'+total_link+'_'+value);
e_obj.attr('name','url_type_'+total_link+'_'+value);
break;
case 'controller_type_parameter_'+current_index+'_'+value:
e_obj.attr('id','controller_type_parameter_'+total_link+'_'+value);
e_obj.attr('name','controller_type_parameter_'+total_link+'_'+value);
break;
}
// }
});
}
else
{
// console.log(array_id_lang.length);
if(array_id_lang.length == 1)
{
switch(e_obj.attr('id'))
{
case 'text_link_'+current_index+'_'+id_lang:
e_obj.attr('id','text_link_'+total_link+'_'+id_lang);
e_obj.attr('name','text_link_'+total_link+'_'+id_lang);
break;
case 'url_type_'+current_index+'_'+id_lang:
e_obj.attr('id','url_type_'+total_link+'_'+id_lang);
e_obj.attr('name','url_type_'+total_link+'_'+id_lang);
break;
case 'controller_type_parameter_'+current_index+'_'+id_lang:
e_obj.attr('id','controller_type_parameter_'+total_link+'_'+id_lang);
e_obj.attr('name','controller_type_parameter_'+total_link+'_'+id_lang);
break;
default:
var old_id = e_obj.attr('id');
var old_name = e_obj.attr('name');
old_id = old_id.substring(0, old_id.lastIndexOf('_'));
old_name = old_name.substring(0, old_name.lastIndexOf('_'));
e_obj.attr('id',old_id+'_'+total_link);
e_obj.attr('name',old_name+'_'+total_link);
updateField('add',old_name+'_'+total_link, false);
if(old_id == 'product_type' || old_id == 'cms_type' || old_id == 'category_type' || old_id == 'manufacture_type' || old_id == 'supplier_type' || old_id == 'controller_type')
{
if (e_obj.is( "input" ))
{
e_obj.attr('class','link_type_group_'+total_link+' tmp');
}
if (e_obj.is( "select" ))
{
e_obj.attr('class','link_type_group_'+total_link+' tmp fixed-width-xl');
}
}
break;
}
}
else
{
// if(scroll_to_new_e == true)
// {
// var old_id = e_obj.attr('id');
// var old_name = e_obj.attr('name');
// }
// else
// {
var old_id = e_obj.attr('id');
var old_name = e_obj.attr('name');
old_id = old_id.substring(0, old_id.lastIndexOf('_'));
old_name = old_name.substring(0, old_name.lastIndexOf('_'));
// }
e_obj.attr('id',old_id+'_'+total_link);
e_obj.attr('name',old_name+'_'+total_link);
updateField('add',old_name+'_'+total_link, false);
if(old_id == 'product_type' || old_id == 'cms_type' || old_id == 'category_type' || old_id == 'manufacture_type' || old_id == 'supplier_type' || old_id == 'controller_type')
{
if (e_obj.is( "input" ))
{
e_obj.attr('class','link_type_group_'+total_link+' tmp');
}
if (e_obj.is( "select" ))
{
e_obj.attr('class','link_type_group_'+total_link+' tmp fixed-width-xl');
}
}
}
}
});
_updateLinkType(total_link);
$("#link_type_"+total_link).on('change',function(){
_updateLinkType(total_link);
});
if(scroll_to_new_e == true)
{
$(".link_group:odd").css("background-color", "#DAE4F0");
$(".link_group:even").css("background-color", "#FFFFFF");
}
if(scroll_to_new_e == true)
{
$('html, body').animate({
scrollTop: $('.link_group.new').offset().top
}, 500, function (){
$('.link_group.new').removeClass('new');
});
}
else
{
setTimeout(function(){
$('.link_group.new').removeClass('new');
$(".link_group:odd").css("background-color", "#DAE4F0");
$(".link_group:even").css("background-color", "#FFFFFF");
}, 500);
}
$("#total_link").val(total_link);
}
//update list field
function updateField(action, value, is_lang)
{
// console.log('test');
if (action == 'add')
{
if (is_lang == true)
{
$('#list_field_lang').val($('#list_field_lang').val()+value+',');
}
else
{
$('#list_field').val($('#list_field').val()+value+',');
}
}
else
{
// console.log('test');
if (is_lang == true)
{
var old_list_field_lang = $('#list_field_lang').val();
var new_list_field_lang = old_list_field_lang.replace(value,'');
$('#list_field_lang').val(new_list_field_lang);
}
else
{
var old_list_field = $('#list_field').val();
var new_list_field = old_list_field.replace(value,'');
$('#list_field').val(new_list_field);
}
}
$('#list_id_link').val('');
$('.link_group').each(function(){
$('#list_id_link').val($('#list_id_link').val()+$(this).data('index')+',');
})
}
//update link type
function _updateLinkType(total_link)
{
if (typeof total_link === "undefined" || total_link === null) {
var total_link_new = "";
total_link = "";
}
else
{
// var total_link_old = total_link;
var total_link_new = '_'+total_link;
}
$(".link_type_group"+total_link_new).parent().parent().hide();
if($("[id^=url_type_"+total_link+"]").closest('.form-group').find('.translatable-field').length)
$("[id^=url_type_"+total_link+"]").closest('.form-group').parent().parent().hide();
else
$("[id^=url_type_"+total_link+"]").closest('.form-group').hide();
if($("[id^=controller_type_parameter_"+total_link+"]").closest('.form-group').find('.translatable-field').length)
$("[id^=controller_type_parameter_"+total_link+"]").closest('.form-group').parent().parent().hide();
else
$("[id^=controller_type_parameter_"+total_link+"]").closest('.form-group').hide();
if($("[id^=content_text_"+total_link+"]").closest('.form-group').find('.translatable-field').length)
$("[id^=content_text_"+total_link+"]").closest('.form-group').parent().parent().hide();
else
$("[id^=content_text_"+total_link+"]").closest('.form-group').hide();
// console.log(total_link);
// console.log(total_link_new);
// console.log($("#link_type"+total_link_new).val());
if( $("#link_type"+total_link_new).val() =='url' ){
if($("[id^=url_type_"+total_link+"]").closest('.form-group').find('.translatable-field').length)
$("[id^=url_type_"+total_link+"]").closest('.form-group').parent().parent().show();
else
$("[id^=url_type_"+total_link+"]").closest('.form-group').show();
}
else {
$("#"+$("#link_type"+total_link_new).val()+"_type"+total_link_new).parent().parent().show();
if($("#link_type"+total_link_new).val() == 'controller')
{
// $("#"+$("#link_type").val()+"_type_parameter").parent().parent().show();
if($("[id^=controller_type_parameter_"+total_link+"]").closest('.form-group').find('.translatable-field').length)
$("[id^=controller_type_parameter_"+total_link+"]").closest('.form-group').parent().parent().show();
else
$("[id^=controller_type_parameter_"+total_link+"]").closest('.form-group').show();
}
}
}
/*
* Owl carousel
*/
// $(document).ready(function(){
// });
$.validator.addMethod("owl_items_custom", function(value, element) {
pattern_en = /^\[\[[0-9]+, [0-9]+\](, [\[[0-9]+, [0-9]+\])*\]$/; // [[320, 1], [360, 1]]
pattern_dis = /^0?$/
//console.clear();
//console.log (pattern.test(value));
return (pattern_en.test(value) || pattern_dis.test(value));
//return false;
}, "Please enter correctly config follow under example.");