Subversion-Projekte lars-tiefland.laravel_shop

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

        /*
         * Remote Chained - jQuery AJAX(J) chained selects plugin
         *
         * Copyright (c) 2010-2013 Mika Tuupola
         *
         * Licensed under the MIT license:
         *   http://www.opensource.org/licenses/mit-license.php
         *
         * Project home:
         *   http://www.appelsiini.net/projects/lazyload
         *
         * Version:  0.9.3
         *
         */
        //$Id: jquery.chained.remote.js 2896 2022-03-29 14:30:51Z tiefland $
        $(".buttonx").button().click(function() 
        {
            Kategorie_fill();   
        });
        function Kategorie_fill()
        {
            var divEbayCat = document.getElementById("EbayCat") 
            var divEbayCatName = document.getElementById("EbayCatName");
            var typ=$('#typ').val();
            if(typ=="d")
            {
                $('#cat_name').html(divEbayCatName.innerHTML);
                $('#cat_id').val(divEbayCat.innerHTML);
                $('#cat_id_out').html(divEbayCat.innerHTML);
                $('#newCategoryForm').formwizard("next");
            }
            else
            {
                /* Kategorie in Hauptformular schreiben */
                c_id=$('#cat_selected').val();
                document.forms["vportale_artikel_form"].elements["kategorie_"+c_id].value = divEbayCat.innerHTML;
                $('#delcat_'+c_id).show();
                document.getElementById("kategorie"+c_id).innerHTML = divEbayCatName.innerHTML;
                $( "#link_cat_dlg" ).dialog("close");                       
            }
        }
        /*
         * Erste Ebene laden
         *
        */      
        function ErsteEbene()  
        {
            var self   = "#ebene1";
            var data = {};  
            vPId=$('#vportale_sel').val();
            if(vPId==undefined)
            {
                vPId=$('#vportal_id').val();
            }
            data["category"] = "NULL";
            data["vPId"] = vPId;
            $.getJSON("/vportale/json.php", data, function(json) {
            /* If select already had something selected, preserve it. */
            var selected_key = $(':selected', self).val();

            /* Clear the select. */
            $("option", self).remove();

            var option_list = [];
            if ($.isArray(json)) {
                /* JSON is already an array (which preserves the ordering of options) */
                /* [["","--"],["series-1","1 series"],["series-3","3 series"]] */
                option_list = json;
            }
            else 
            {
                /* JSON is an JavaScript object. Rebuild it as an array. */
                /* {"":"--","series-1":"1 series","series-3":"3 series"} */
                for (var key in json) {
                    if (json.hasOwnProperty(key)) {
                        option_list.push([key, json[key]]);
                    }
                }
            }
            

            /* Add new options from json. */
            for (var i=0; i!==option_list.length; i++) 
            {
                var key = option_list[i][0];
                var value = option_list[i][1];

                /* Set the selected option from JSON. */
                if ("selected" === key) 
                {
                    selected_key = value;
                    continue;
                }
                var option = $("<option />").val(key).append(value);
                $(self).append(option);
            }
                                    
            /* Loop option again to set selected. IE needed this... */
            $(self).children().each(function() 
            {
                if ($(this).val() === selected_key) {
                    $(this).attr("selected", "selected");
                }
            });
            
            /* Force updating the children. */
            //$(self).trigger("change");
            
            
            });
        }
        ErsteEbene();       

(function($) {
    //"use strict";
    $.fn.remoteChained = function(parent_selector, url, options) {
        //parent_selector="#category";
       
        return this.each(function() {
            
            /* Save this to self because this changes when scope changes. */
            var self   = this;
            var backup = $(self).clone();
                        
            /* Handles maximum two parents now. */
            $(parent_selector).each(function() {
                $(this).bind("change", function() {
                   
                    /* Build data array from parents values. */
                    var data = {};
                    $(parent_selector).each(function() {
                        var ebene = this.id.substr(5,1);
                        var value = $(":selected", this).val();
                        var name = $(":selected", this).text();
                        vPId=$('#vportale_sel').val();
                        data["vPId"] = vPId;
                        if(name)
                        {
                            if(ebene >= 2)
                            {
                                $.get("/vportale/only_end_cats.php?vPId="+vPId,function(only_end_cats){
                                    //console.log(only_end_cats);
                                    if(only_end_cats==0)
                                    {
                                        $(".buttonx").show();
                                    }
                                    else
                                    {
                                        $('.buttonx').hide();
                                    }
                                })
                            }
                            data["category"] = value;
                            $("#EbayCatName").html(name);
                            $('#EbayCat').html(value);    
                        }
                    });
                    
                    $.getJSON(url, data, function(json) {
                        /* If select already had something selected, preserve it. */
                        var selected_key = $(':selected', self).val();

                        /* Clear the select. */
                        $("option", self).remove();

                        var option_list = [];
                        if ($.isArray(json)) {
                            /* JSON is already an array (which preserves the ordering of options) */
                            /* [["","--"],["series-1","1 series"],["series-3","3 series"]] */
                            option_list = json;
                        } else {
                            /* JSON is an JavaScript object. Rebuild it as an array. */
                            /* {"":"--","series-1":"1 series","series-3":"3 series"} */
                            for (var key in json) {
                                if (json.hasOwnProperty(key)) {
                                    option_list.push([key, json[key]]);
                                }
                            }
                        }
                        

                        /* Add new options from json. */
                        for (var i=0; i!==option_list.length; i++) {
                            var key = option_list[i][0];
                            var value = option_list[i][1];

                            /* Set the selected option from JSON. */
                            if ("selected" === key) {
                                selected_key = value;
                                continue;
                            }
                            var option = $("<option />").val(key).append(value);
                            $(self).append(option);
                        }
                                                
                        /* Loop option again to set selected. IE needed this... */
                        $(self).children().each(function() {
                            if ($(this).val() === selected_key) {
                                $(this).attr("selected", "selected");
                            }
                        });
                        
                        if(option_list.length == 1)
                        {
                            if(option_list[0][0]=== "eb") 
                            {
                               var divEbayCat = document.getElementById("EbayCat"); 
                               divEbayCat.innerHTML = option_list[0][1];
                               /*var divEbayCatName = document.getElementById("EbayCatName");
                               divEbayCatName.innerHTML = option_list[0][0];*/
                               $(".buttonx").show();
                              
                            } else {
                            } 
                           
                           $(self).hide("slide", "", 200);
                           return true;
                        } else {
                             $(self).show("slide", "", 200);
                            //$(self).removeAttr("hidden");
                            
                        }
                        
                        /* Force updating the children. */
                        $(self).trigger("change");
                        
                        
                    });

                });

                /* Force updating the children. */
                $(this).trigger("change");

            });
        });
    };
    
    /* Alias for those who like to use more English like syntax. */
    $.fn.remoteChainedTo = $.fn.remoteChained;
    
})(jQuery);