2014-04-15 04:49:38 +00:00
|
|
|
var Items = function(){
|
|
|
|
var i = this;
|
|
|
|
this.initialize = function(){
|
|
|
|
i.bindHandlers();
|
2014-04-21 07:19:29 +00:00
|
|
|
i.itemQuantity();
|
|
|
|
i.bindEditAddPageHandlers();
|
2014-04-15 04:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.bindHandlers = function(){
|
|
|
|
var $openSlide = $('.open-slide'),
|
2014-04-21 07:19:29 +00:00
|
|
|
$pageslideW = $(window).width() > 1440 ? 1024 : 954;
|
|
|
|
$(window).resize(function() {
|
2014-04-15 04:49:38 +00:00
|
|
|
$(this).width() > 1440 ? $pageslideW = 1024 : $pageslideW = 954;
|
|
|
|
});
|
|
|
|
$iFrame = $openSlide.filter('.view-page.open-slide');
|
|
|
|
$iFrame.pageslide({
|
|
|
|
W: $pageslideW,
|
|
|
|
iframe: true
|
2014-04-21 07:19:29 +00:00
|
|
|
});
|
|
|
|
$('.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"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
2014-04-15 04:49:38 +00:00
|
|
|
}
|
2014-04-21 07:19:29 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-15 04:49:38 +00:00
|
|
|
this.reBindHandlers = function(){
|
|
|
|
$.pageslide.close();
|
2014-04-30 10:57:09 +00:00
|
|
|
i.itemQuantity();
|
2014-04-15 04:49:38 +00:00
|
|
|
i.bindHandlers();
|
2014-04-30 10:57:09 +00:00
|
|
|
window.openSlide();
|
2014-04-15 04:49:38 +00:00
|
|
|
}
|
2014-04-21 07:19:29 +00:00
|
|
|
|
|
|
|
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","#enable-menu .main-enable-parent",function(e){
|
|
|
|
if(!$(this).is(":checked")){
|
2014-04-30 10:57:09 +00:00
|
|
|
var parent = $(this).parent().parent();
|
|
|
|
parent.find(".main-enable-child,.main-enable-child-child").removeAttr("checked");
|
|
|
|
|
2014-04-21 07:19:29 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
sidePanel.on("click","#enable-menu .main-enable-child",function(e){
|
|
|
|
if(!$("input[for=checkbox_for_"+ $(this).val() +"]").is(":checked")){
|
|
|
|
$(this).removeAttr("checked");
|
|
|
|
}
|
2014-04-30 10:57:09 +00:00
|
|
|
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");
|
|
|
|
}
|
2014-04-21 07:19:29 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
sidePanel.on("change","select.module_select", function(){
|
|
|
|
var this_value = $(this).val(),
|
|
|
|
categories_list = $("#categories_list");
|
|
|
|
|
|
|
|
categories_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(categories){
|
|
|
|
var controlDiv = $("<div class='controls'></div>");
|
|
|
|
if(categories.categories.length){
|
|
|
|
categories_list.parent().find("label.control-label").prepend("Category List :");
|
|
|
|
var checkbox = $("<label class='checkbox'><input type='checkbox' value='all' name='page[categories][]' class='checkbox-all' /> All </label>");
|
|
|
|
controlDiv.append(checkbox);
|
|
|
|
}
|
|
|
|
$.each(categories.categories,function(i,category){
|
|
|
|
var checkbox = $("<label class='checkbox'><input type='checkbox' value='"+ category.id +"' name='page[categories][]' /> " + category.title + " </label>");
|
|
|
|
controlDiv.append(checkbox);
|
|
|
|
})
|
|
|
|
categories_list.append(controlDiv);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-04-15 04:49:38 +00:00
|
|
|
i.initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
itemsLibrary = new Items();
|
2014-05-30 07:57:12 +00:00
|
|
|
|
|
|
|
$(function(){
|
|
|
|
$(".open-slide").click(function(){
|
|
|
|
$("#pageslide .content").css("padding","0");
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".mobile-view-btn").click(function(){
|
|
|
|
$(".nano").nanoScroller();
|
|
|
|
$("#pageslide .content").css( "background-image", "url('/assets/grey_wash_wall.png')");
|
|
|
|
$("#pageslide_iframe").css("width","400px");
|
|
|
|
$("#pageslide_iframe").css("left","28%");
|
|
|
|
$("#pageslide_iframe").css("box-shadow","0px 0px 40px #333");
|
|
|
|
});
|
|
|
|
});
|