HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/spire.komma-mediadesign.nl/wwwroot/kms/js/main.js
/*
data/*

	Javascript document // main.js
	
	Handles all javascript regarding MO-Beheer v3

*/

var activeKey = 0;
var activeTarget = [];
var activeCategory = 0;

var startHeight =
$(document).ready(function()
{
	//handle animation classes
	handleDisappear();
	handleSelectedListitem();

    // create hovers on buttons
    initButtons();

	//setup Tiny MCE
	initTinymce();
	
	//uploader
	initUploader();
	
	//datepicker
	$( ".datepicker" ).datepicker();
	
	//
	resizeMenu();
	$(window).resize(resizeMenu);

    // initProduct Thumb
    initProductThumbs();

    // hiddenTargets
    initHiddenTargets();

    // remove image -> add current thumb to link (product images)
    initProductThumbUpdate();

    awardCategories();

    initSortableProductImages();


    // WHERE TO BUY
    var lists = ['acc','cpu','mob','pc','sup','sys','tab'];

    for( var n=0;n<lists.length;n++)
    {
        $('#' + lists[n] + '_check').click(function(){

            var id = $(this).attr('id');
            var temp = id.split('_');
            var boxes = '#' + temp[0] + '_list  input[type="checkbox"]';

            if ($(this).attr("checked") )
            {
                $(boxes).attr("checked", "checked");
                $(boxes).checked = true;

            }
            else
            {
                $(boxes).attr("checked", "");
                $(boxes).removeAttr('checked');
                $(boxes).checked = false;
            }
        });
    }

    // filemanager
    $('#import_xml').click(function()
    {
        document.getElementById('xml_file').click();
    });
    $("#xml_file").live('change', function()
    {
        $('#import_form').submit();
        $('#import_loading').css({ display: 'block' });
    });

});

/**
 * Handles animation for all objects with a class js-disappear
 * For example the alerts
 *
 * @return null
 */
function handleDisappear()
{
	var time = 4000;
	var delay = 0;
	$('.js-disappear').each(function()
	{
		var _this = $(this);
		$(_this).animate({ opacity: 1 },200);
		setTimeout(function()
		{
			$(_this).animate({ opacity: 0 },400,function()
			{
				$(this).remove();
			});
		
		},time+delay);
		delay += 100;
	});
}

/**
 * Handles actions regarding selecting a list-item in a selectable list
 *
 * @return null
 */
function handleSelectedListitem()
{
	$('ul.selectable').each(function()
	{
		$(this).children('li').click(function(e)
		{
            var target = e.target;
            var type = $(target).get(0).tagName;

			if( ! $(this).hasClass('heading') && type != 'A' && type != 'INPUT')
			{
				if($(this).children('.cb').children('input').attr('checked'))
				{
					$(this).children('.cb').children('input').attr("checked", "");
					$(this).children('.cb').children('input').removeAttr('checked');
					$(this).children('.cb').children('input').checked = false;
					$(this).removeClass('sel');
				}
				else
				{
					$(this).children('.cb').children('input').attr("checked", "checked");
					$(this).children('.cb').children('input').checked = true;
					$(this).addClass('sel');
				}			
			}		
		});
	});
	
	$('ul.selectable input[type="checkbox"]').change(function()
	{
		if( ! $(this).parent().parent().hasClass('heading'))
		{
			if($(this).attr('checked'))
			{
				$(this).parent().parent().addClass('sel');
			}
			else
			{
				$(this).parent().parent().removeClass('sel');
			}
		}
	});
	

    $('#check_all').click(function(){
    if ($('#check_all').attr("checked") )
    {
        $('ul.selectable input[type="checkbox"]').attr("checked", "checked");
        $('ul.selectable input[type="checkbox"]').checked = true;
        $('ul.selectable li:not(.heading)').addClass('sel');
    }
    else
    {
        $('ul.selectable input[type="checkbox"]').attr("checked", "");
        $('ul.selectable input[type="checkbox"]').removeAttr('checked');
        $('ul.selectable input[type="checkbox"]').checked = false;
        $('ul.selectable li:not(.heading)').removeClass('sel');
    }



});

}

/**
* Setup for textareas with the tiny mce class
*
* @return null
*/
function initTinymce(){
	$('textarea.tinymce').tinymce({
		// General options
		mode : 	"textareas",
		theme : "motheme",
		skin : 	"mikeontwerpt",
		height : "184",
		plugins : "inlinepopups,tabfocus,paste", 
		//init_instance_callback: myCustomInitInstance, 
		
		// Theme options
		theme_motheme_buttons1 : "bold,italic,underline,|,bullist,numlist,|,link,unlink",
		theme_motheme_buttons2 : "",
		theme_motheme_buttons3 : "",
		theme_motheme_buttons4 : "",
		theme_motheme_toolbar_location : "top",
		theme_motheme_toolbar_align : "left",
		theme_motheme_statusbar_location : "bottom",
		theme_motheme_resizing : false
	
		// Replace values for the template plugin
		/*
		template_replace_values : {
			username : "Mike Ontwerpt",
			staffid : "991234"
		}
		*/
	});	
}

/**
* Make sure we only have to click the upload button to upload files
*
* @return null
*/
function initUploader()
{
	// filemanager
 	$('#upload_file').click(function()
 	{
   		document.getElementById('my_file').click();
   	});
    $("#my_file").live('change', function()
    {
    	$('#mp_info').submit();
    	$('#loader').css({ display: 'block' });
	});
	
	// filemanager PDF
 	$('#upload_doc').click(function()
 	{
   		document.getElementById('my_doc').click();
   	});
    $("#my_doc").live('change', function()
    {
    	$('#mp_info').submit();
    	$('#docloader').css({ display: 'block' });
	});
}

/**
*
* Resizes the left menu
*
*/
function resizeMenu()
{
    var contentH = $('.content','#aside').height() + 80;
    var currentH = $('#header').height() + contentH + $('#footer').height();

    var windowH = $(window).height();
    var wrapperH = $('#wrapper').height();

    if(wrapperH < contentH)
    {
        if(currentH < windowH)
        {
            var asideH = windowH - $('#header').height() - $('#footer').height();
            $('#aside').css({ height: asideH+'px' });
        }
        else
        {
            $('#aside').css({ height: contentH+'px' });
        }
    }
    else
    {
        var wrapperH = $('#wrapper').height() + parseInt($('#wrapper').css('marginTop')) + 80;
        $('#aside').css({ height: wrapperH+'px' });
        setTimeout(function()
        {
            var wrapperH = $('#wrapper').height() + parseInt($('#wrapper').css('marginTop')) + 80;
            $('#aside').css({ height: wrapperH+'px' });
        },400);
    }
}

function initProductThumbs()
{
    $('#product_images').children('li').children('.holder').click(function()
    {
        var newKey = $(this).attr('data-key');

        if(activeKey != newKey)
        {
            $(this).addClass('isThumb');
            $('#product_image'+activeKey).removeClass('isThumb');
            activeKey = newKey;
            $('#thumbkey').attr('value',activeKey);

            // Update order in session
            $('#js_load').load('/kms/app/controllers/js_update_images_order.php?action=update-thumb&thumbKey='+activeKey,function()
            {
                window.location.reload();
            });
        }
    });
}

function setActiveKey(key)
{
    activeKey = key;
}

/**
 * Set Button hovers
 */
function initButtons(){
    $('.btn').hover(function(){
       $(this).children('.over').stop().animate({ opacity: 1 },60);
    },
    function(){
        $(this).children('.over').stop().animate({ opacity: 0 },100);
    });
}

function initHiddenTargets()
{
    $('.targetSelect').change(function()
    {
        // get group Id (id of select element)
        var group = $(this).attr('id');

        // check each option for id
        var id = $(this).children('option:selected').attr('id');
        if(id != null)
        {
            // if option has id, its named "activator_ + group + _ + nr"
            var groupNr = id.substring(10);
            var temp = groupNr.split('_');
            var nr = temp[1];

            // close active target in group
            if(activeTarget[group] != null)
            {
                $('#target_'+group+'_'+activeTarget[group]).stop().animate({ height: 0 },300);

                // extension:
                if(activeTarget[group] == '4a' || nr == '4a')
                {
                    // also close 4b
                    $('#target_'+group+'_4b').stop().animate({ height: 0 },300);
                }
            }

            // we need to open "target+nr"
            var openObj = $('#target_'+group+'_'+nr);
            var h = $(openObj).children('.hiddenHolder').height()+20;
            $(openObj).stop().animate({ height: h+'px'},300);

            // extension:
            if(nr == '4a')
            {
                // also open 4b
                var openObj4b = $('#target_'+group+'_4b');
                var h4b = $(openObj4b).children('.hiddenHolder').height()+20;
                $(openObj4b).stop().animate({ height: h4b+'px'},300);
            }

            activeTarget[group] = nr;
        }
        else{
            // close active target in group
            if(activeTarget[group] != null)
            {
                $('#target_'+group+'_'+activeTarget[group]).stop().animate({ height: 0 },300);

                // extension:
                if(activeTarget[group] == '4a' || nr == '4a')
                {
                    // also close 4b
                    $('#target_'+group+'_4b').stop().animate({ height: 0 },300);
                }
            }
        }
    });

    $('.activator').change(function()
    {
        var activatorId = $(this).attr('data-activator');
        var checked = $(this).attr('checked');
        if(typeof activatorId !== 'undefined' || activatorId !== false)
        {
            if(typeof checked == 'undefined' || checked == false)
            {
                // was checked, so is unchecked now

                var closeObj = '#target_' + activatorId;
                $(closeObj).stop().animate({ height: 0 },300);
                $(closeObj+' select').attr('disabled','');
                $(closeObj+' input').attr('disabled','');
            }
            else
            {
                // was unchecked, so is checked now
                var openObj ='#target_' + activatorId;
                var h = $(openObj).children('.hiddenHolder').height();
                $(openObj).stop().animate({ height: h+'px'},300);
                $(openObj+' select').removeAttr('disabled');
                $(openObj+' input').removeAttr('disabled');
            }
        }
    });
}

function initProductThumbUpdate()
{
    $('.jsRemoveImage').click(function(e){
        e.preventDefault();

        // href is something like "/kms/en/accessories/remove-image/2/"
        var href = $(this).attr('href');

        // get current thumb which is updated by javascript
        var thumbKey = $('#thumbkey').val();

        window.location.href= href+thumbKey+'/';
    });
}


function awardCategories()
{
    $('#categoryId').change(function(){
        if(activeCategory != 0){
            $('#sub'+activeCategory).css({display : 'none'});
            $('#label'+activeCategory).css({display : 'none'});
        }

        var id = $(this).val();
        $('#sub'+id).css({display : 'block'})
        $('#label'+id).css({display : 'block'})
        activeCategory = id;
    })
}

function initSortableProductImages()
{
    $('body').append('<div id="js_load"></div>');

    /* grab important elements */
    var sortInput = $('#sort_order');
    var thumbKey = $('#thumbkey').val();
    var sessionName = $('#session_name').val();
    var list = $('#product_images');

    /* worker function */
    var fnSubmit = function() {
        var sortOrder = [];
        list.children('li').each(function(){
            sortOrder.push($(this).attr('data-order'));
        });

        //sortOrder.reverse();
        sortInput.val(sortOrder.join(','));

        // Update order in session
        $('#js_load').load('/kms/app/controllers/js_update_images_order.php?action=update-order&order='+sortInput.val()+'&sessionName='+sessionName+'&thumbKey='+thumbKey,function()
        {
            // Update thumb key
            var newThumb = $('#new_thumb').html();

            // Set hidden input field
            $('#thumbkey').val(newThumb);

            window.location.reload();
        });

    };

    /* store values */
    list.children('li').each(function() {
        var li = $(this);
        li.data('id',li.attr('title')).attr('title','');
    });

    /* sortable */
    list.sortable({
        helper : 'clone',
        opacity: 0.7,
        update: function() {
            fnSubmit();
        }
    });
    list.disableSelection();
}