
<script type="application/javascript">

    full_loaded = true; // Disable product categories ajax loading.

</script>
{$form}

<script type="application/javascript">

    (function($){
        var $document = $(document);
        var error_messages = {
            'no_params' : '{l s="Category parameters is not valid" mod='myswissstyle'}',
            'no_valid' : '{l s="Category parameters is not valid" mod='myswissstyle'}',
            'no_titles' : '{l s="Enter the name of the category" mod='myswissstyle'}',
            'no_created' : '{l s="Server error" mod='myswissstyle'}'
        };

        $document.off('click','#SaveClipartCategoryButton');
        $document.on('click','#SaveClipartCategoryButton', function(){

            var data = { };

            var items = $('.param-item');
            $.each(items, function(key, item) {
                var $item = $(item);
                data[$item.attr('name')] = $item.val();
            });

            data['status'] = '' + $('input[name="active"]:checked').val();
            data['parent_id'] = '' + $('input[name="id_parent"]:checked').val();


            var ajax_action = '';

            var $edit_category_input = $('input[type="hidden"][name="edit_category_id"]');
            if ($edit_category_input.val() && $edit_category_input.val() != '') {
                ajax_action = 'update_clipart_category';
                data['category_id'] = '' + $edit_category_input.val();
            } else {
                ajax_action = 'add_clipart_category';

            }
            $.ajax({
                type: 'POST',
                headers: { "cache-control": "no-cache" },
                async: false,
                url: '{$ajax_route}?subject=Admin&action=' + ajax_action + '&token={$token}',
                data: data,
                success: function(data) {

                    data = $.parseJSON(data);


                    if (data.status == 'success') {
                        if (data.message !== undefined && data.message != '') {

                            var text_message = $.parseJSON(data.message);

                            if (text_message.status == 'success') {
                                document.location = '{$location}'
                            } else {
                                $.fancybox.open([
                                            {
                                                type: 'inline',
                                                autoScale: true,
                                                minHeight: 30,
                                                content: '<p class="fancybox-error">' + error_messages[text_message.message] + '</p>'
                                            }],
                                        {
                                            padding: 0
                                        });
                            }
                        }
                    } else {
                        $.fancybox.open([
                                    {
                                        type: 'inline',
                                        autoScale: true,
                                        minHeight: 30,
                                        minWidth: 300,
                                        content: '<p class="fancybox-error">{l s="Server error" mod="myswissstyle"}</p>'
                                    }],
                                {
                                    padding: 0
                                });
                    }
                }
            });
            return false;
        });

    })(jQuery);

</script>
