var Items = function(){ var i = this; this.initialize = function(){ i.bindHandlers(); i.itemQuantity(); i.bindEditAddPageHandlers(); $(".sortable").delegate(".brand, .delete", clickEvent, function(e){ if($(this).hasClass('delete')) { $target = $(this); $('#dialog').modal('show'); } else { if($(this).closest('li').children('ol').length > 0){ $(this).closest('li').toggleClass('collapsed'); } } e.preventDefault(); }); } this.bindHandlers = function(){ $('.sortable').nestedSortable({ handle: '.brand', items: 'li', maxLevels: 3, opacity: .6, disableNesting: 'no-nest', toleranceElement: '> div', placeholder: 'placeholder', startCollapsed: true, update: function(event, ui) { var parent = (ui.item.parent().closest('li').length ? ui.item.parent().closest('li') : ui.item.parent().closest('ol')), children = (parent.hasClass("root") ? parent.find(">li") : parent.find(">ol li")), children_ids = []; children.each(function(){ children_ids.push($(this).attr("id")); }) $.ajax({ url : "<%= Rails.application.routes.url_helpers.pages_update_item_position_path %>", data : {"parent_id" : parent.attr("id"), "id" : ui.item.attr("id"),"children_ids" : children_ids}, dataType : "json", type : "post" }) } }); } this.itemQuantity = function(){ var $sortable = $('.sortable'), $host = $sortable.children('.navbar').eq(0), $navbar = $('.sortable li').children('.navbar'), $quantity = $sortable.find('li').length; $host.find('.badge').text($quantity); $navbar.each(function(i) { if($navbar.eq(i).next('ol').length>0) { var $amount = $navbar.eq(i).next('ol').find('li').length; $navbar.eq(i).find('.badge').text($amount); }else{ $navbar.eq(i).find('.badge').text('0'); } $navbar.eq(i).find('.badge').text()>0 ? $navbar.eq(i).find('.badge').addClass('badge-info'):$navbar.eq(i).find('.badge').removeClass('badge-info'); }) } this.reBindHandlers = function(){ console.log("binded") $.pageslide.close(); window.openSlide(); i.itemQuantity(); i.bindHandlers(); i.bindEditAddPageHandlers(); } this.bindEditAddPageHandlers = function(){ var sidePanel = $(".view-page .content"); sidePanel.on("click","#categories_list input[type=checkbox]",function(){ if($(this).is(":checked") && $(this).hasClass("checkbox-all")){ $(".view-page .content #categories_list input[type=checkbox]").not($(this)).removeAttr("checked"); }else{ $(".view-page .content #categories_list input[type=checkbox].checkbox-all").removeAttr("checked"); } }) sidePanel.on("click","#tags_list input[type=checkbox]",function(){ if($(this).is(":checked") && $(this).hasClass("checkbox-all")){ $(".view-page .content #tags_list input[type=checkbox]").not($(this)).removeAttr("checked"); }else{ $(".view-page .content #tags_list input[type=checkbox].checkbox-all").removeAttr("checked"); } }) sidePanel.on("click","#role_list input[type=checkbox]",function(){ if($(this).is(":checked") && $(this).hasClass("checkbox-all")){ $(".view-page .content #role_list input[type=checkbox]").not($(this)).removeAttr("checked"); }else{ $(".view-page .content #role_list input[type=checkbox].checkbox-all").removeAttr("checked"); $("#status-list-"+$(this).val()+" input[type=checkbox]").removeAttr("checked"); } }) sidePanel.on("click",".status-checkbox",function(){ if($(this).is(":checked")){ $(this).parent().parent().parent().parent().find(".role-checkbox").removeAttr("checked"); } }) sidePanel.on("click","#enable-menu .main-enable-parent",function(e){ if(!$(this).is(":checked")){ var parent = $(this).parent().parent(); parent.find(".main-enable-child,.main-enable-child-child").removeAttr("checked"); } }) sidePanel.on("click","#enable-menu .main-enable-child",function(e){ if(!$("input[for=checkbox_for_"+ $(this).val() +"]").is(":checked")){ $(this).removeAttr("checked"); } if(!$(this).is(":checked")){ $(this).parent().parent().parent().find(".main-enable-child-child").removeAttr("checked"); } }) sidePanel.on("click","#enable-menu .main-enable-child-child",function(e){ if(!$("input[for=checkbox_for_child_"+ $(this).val() +"]").is(":checked")){ $(this).removeAttr("checked"); } }) sidePanel.on("change","select.module_select", function(){ var this_value = $(this).val(), categories_list = $("#categories_list") tags_list = $("#tags_list"), role_list = $("#role_list"), layouts_list = $("#layouts_list"), data_count_area = $("#data_count_area"); categories_list.html(""); tags_list.html(""); role_list.html(""); if(this_value){ $.ajax({ url : "<%= Rails.application.routes.url_helpers.pages_get_categories_path %>", data : {"module" : this_value}, type : "get", dataType : "json" }).done(function(data){ var controlDiv = $("
"); if(data.categories.length){ categories_list.parent().find("label.control-label").text("<%= I18n.t(:category) %> :"); var checkbox = $(""); controlDiv.append(checkbox); $.each(data.categories,function(i,category){ var checkbox = $(""); controlDiv.append(checkbox); }) categories_list.html(controlDiv); }else{ categories_list.parent().find("label.control-label").text(""); } var controlDiv = $(""); if(data.tags.length){ tags_list.parent().find("label.control-label").text("<%= I18n.t(:tags) %> :"); var checkbox = $(""); controlDiv.append(checkbox); $.each(data.tags,function(i,tag){ var checkbox = $(""); controlDiv.append(checkbox); }) tags_list.html(controlDiv); }else{ tags_list.parent().find("label.control-label").text(""); } var controlDiv = $(""); if(data.roles.length){ role_list.parent().find("label.control-label").text("<%= I18n.t(:role) %> :"); var checkbox = $(""); controlDiv.append(checkbox); $.each(data.roles,function(i,role){ var status_list = '