Orbit/app/assets/javascripts/lib/items/page_part.js.erb

142 lines
6.2 KiB
Plaintext
Raw Permalink Normal View History

function getPageData() {
$.getJSON("<%= Rails.application.routes.url_helpers.get_page_module_json_admin_page_parts_path %>").done(function(data) {
_pageData = data;
});
}
function getView(module_id, id) {
var _data = {};
_data.val = $('#module_widget #page_part_widget_path option:selected').val();
_data.id = id;
_data.module_id = module_id
$.ajax({
url: "<%= Rails.application.routes.url_helpers.get_display_style_admin_page_parts_path %>",
dataType: "script",
data: _data,
contentType: "application/html; charset=utf-8",
cache: false,
});
}
$(function() {
$pageModule = $('#module_widget #page_part_module_app'),
$pageF2E = $('#module_widget #page_part_widget_path'),
$pageCategory = $('#module_widget #page-category'),
$pageCategoryGroup = $('#module_widget #page-category-groups'),
$pageTags = $('#module_widget #page-tags'),
$pageTagsGroup = $('#module_widget #page-tags-groups'),
$pageCount = $('#module_widget #page_count'),
_boolean = null,
_ID = null,
_type = null,
_status = null,
_pageData = null,
_selectData = null;
$('#module_widget').on('change', '.change', function(event) {
var _data, _select, $subSelete;
if(event.target.id !== 'page_part_widget_path') {
_data = _pageData.module;
_select = _boolean ? _selectData.module : null;
$subSelete = $('#module_widget #page_part_widget_path');
$(this).children("option:selected").each(function () {
var _val = $(this).val();
$subSelete.empty();
$pageCount.empty();
if(_val) {
$.each(_data, function(index, val) {
if(_val == val.main[1]) {
$.each(val.sub, function(index, val) {
var _selected = _select && $(this)[1] == _select.sub ? 'selected="selected"' : '';
$subSelete.append('<option value="' + $(this)[1] + '" ' + _selected.sub + '>' + $(this)[0] + '</option>');
});
$.each(val.count, function(index, val) {
$pageCount.append('<option value="' + val + '" ' + (_select && _select.main == _val && val == _selectData.module.count ? 'selected="selected"' : '') + '>' + val+ '</option>');
2013-10-29 03:09:20 +00:00
});
getView(val.main[1]);
if(event.target.id == 'page_part_module_app') {
$pageCategory.empty();
if(val.category.length > 0) {
$.each(val.category, function(index, val) {
if(val !== 0) {
var _arr = _select ? $.inArray($(this)[1], _select.category[1]) : '';
$pageCategory.append('<label class="checkbox"><input type="checkbox" name="page[category][]" value="'+ $(this)[1] + '">'+ $(this)[0] +'</label>');
if(_select && !_select.category[0] && _arr !== -1) {
$pageCategory.find('input[type="checkbox"]').eq(index).prop('checked', true);
}
_select && _val == _select.main && _select.category[0] ? $pageCategory.siblings('.checkbox').children('.select_all').prop('checked', true) : '';
}
});
$pageCategoryGroup.show();
} else {
$pageCategoryGroup.hide();
}
if(val.tags.length > 0) {
$pageTags.empty();
$.each(val.tags, function(index, val) {
if(val !== 0) {
var _arr = _select ? $.inArray($(this)[1], _select.tags[1]) : '';
$pageTags.append('<label class="checkbox"><input type="checkbox" name="page[tag][]" value="'+ $(this)[1] + '">'+ $(this)[0] +'</label>');
if(_select && !_select.tags[0] && _arr !== -1) {
$pageTags.find('input[type="checkbox"]').eq(index).prop('checked', true);
}
_select && _val == _select.main && _select.tags[0] ? $pageTags.siblings('.checkbox').children('.select_all').prop('checked', true) : '';
}
});
$pageTagsGroup.show();
} else {
$pageTagsGroup.hide();
}
}
return false;
};
});
} else {
$pageCategory.empty();
$pageCategoryGroup.hide();
$pageTags.empty();
$pageTagsGroup.hide();
$pageF2E.empty();
$pageCount.empty();
}
});
}
else {
getView($pageModule.val());
}
event.preventDefault();
});
$('#module_widget').on('change', '.checkbox-groups input', function(event) {
var $checked = $(this);
if($checked.attr('type') == 'checkbox') {
if($checked.hasClass('select_all') && $checked.prop('checked')) {
$checked.closest('.checkbox').siblings('.groups').find('input[type="checkbox"]').prop('checked', false);
} else if($checked.prop('checked') && !$checked.hasClass('lang-enable')) {
$checked.closest('.groups').siblings('.checkbox').find('.select_all').prop('checked', false);
} else {
if($checked.prop('checked')) {
$checked.closest('.active-link').addClass('active').siblings('active-link').removeClass('active').end().find('.active-mune').slideDown(300);
if(_status) {
var _index = $checked.closest('.link-options').find('.active').index() - 1,
_index = _type == 'page' ? _selectData.module.link[_index][1] : _linkData.link[_index][1] ;
$checked.closest('.active-link').find('.active-mune input').eq(_index).prop('checked', true);
}
} else {
$('.active-link').removeClass('active');
$checked.closest('.active-link').find('.active-mune').slideUp(300, function() {
$(this).find('input:eq(0)').prop('checked', true);
})
}
}
return false;
} else if($checked.attr('type') == 'radio' && !$(this).closest('div').hasClass('active-mune')) {
$('#module_widget #page_is_published_true').prop('checked') || $('#module_widget #link_is_published_true').prop('checked') ? $('.link-options').slideDown(300) : $('.link-options').slideUp(300);
return false;
}
event.preventDefault();
});
getPageData();
});