1209 lines
34 KiB
JavaScript
1209 lines
34 KiB
JavaScript
$(window).on('start_loading', function() {
|
||
$('.loading').show();
|
||
});
|
||
|
||
$(window).on('end_loading', function() {
|
||
$('.loading').hide();
|
||
});
|
||
|
||
$(document).ready(function() {
|
||
$('*[data-toggle="tooltip"]').tooltip();
|
||
$('*[data-toggle="popover"]').popover();
|
||
|
||
$('*[required=required]').removeAttr('required');
|
||
|
||
$('input[type=checkbox]').each(function() {
|
||
if ($(this)[0]) {
|
||
var name = $(this).attr('name') ? $(this).attr('name') : '';
|
||
if (name.indexOf('delete_') !== -1 && !$(this).hasClass('delete_checkbox')) {
|
||
$(this).parent().remove();
|
||
}
|
||
}
|
||
});
|
||
|
||
if ($('.message').html()) {
|
||
$('.message').animate({
|
||
opacity: 1
|
||
}, 500);
|
||
$('.message').delay(3000).animate({
|
||
opacity: 0
|
||
});
|
||
}
|
||
});
|
||
|
||
$('.message').live(
|
||
'click',
|
||
function(event) {
|
||
console.log("toto");
|
||
$(event.target).hide();
|
||
}
|
||
);
|
||
|
||
var redirect = function(url) {
|
||
document.location.href = url;
|
||
}
|
||
|
||
$('.node_form form').live(
|
||
'submit',
|
||
function(event) {
|
||
event.preventDefault();
|
||
|
||
$('.modal-footer input[type=submit]').button('toggle')
|
||
|
||
var $form = $(this);
|
||
var $message = $form.find('.message').html('').fadeIn();
|
||
var nodeId = $(this).data('node');
|
||
|
||
$(window).trigger('start_loading');
|
||
|
||
$.post($form.attr('action'), $form.serialize())
|
||
.success(function(data) {
|
||
$('.node_form').html(data);
|
||
$('.node_form').find('.message').fadeIn().delay(3000).fadeOut();
|
||
$('#' + nodeId).slideUp().load(document.location.href + ' #' + nodeId + ' > div:first-child', function(data) {
|
||
$('#' + nodeId).slideDown()
|
||
});
|
||
})
|
||
.error(function() {
|
||
$(window).trigger('end_loading');
|
||
$message.append($('<div>').addClass('alert alert-error').html(trans('cms.js.request.error'))).fadeIn().delay(3000).fadeOut();
|
||
})
|
||
.complete(function() {
|
||
$('.modal-footer input[type=submit]').button('reset')
|
||
});
|
||
}
|
||
);
|
||
|
||
$('.accordion-toggle').live(
|
||
'click',
|
||
function() {
|
||
$('.accordion-toggle').parent().removeClass('opened');
|
||
$(this).parent().addClass('opened');
|
||
|
||
$input = $(this).find('input[type=radio]').attr('checked', 'checked');
|
||
|
||
if ($input.val() == 'url') {
|
||
$('.nodeUrl').hide();
|
||
} else {
|
||
$('.nodeUrl').show();
|
||
}
|
||
}
|
||
);
|
||
|
||
$('.accordion-toggle input[type=radio]').live(
|
||
'click',
|
||
function() {
|
||
$(this).attr('checked', 'checked');
|
||
}
|
||
);
|
||
|
||
$('.batch_th input').live(
|
||
'click',
|
||
function() {
|
||
$('.batch_td input').each(function() {
|
||
if ($(this).attr('checked')) {
|
||
$(this).removeAttr('checked');
|
||
} else {
|
||
$(this).attr('checked', 'checked');
|
||
}
|
||
});
|
||
}
|
||
);
|
||
|
||
var modale_it = function(data, title, locked) {
|
||
var preview = $('<div class="modal fade">').html(
|
||
'<div class="modal-header">' +
|
||
(!locked ? '<a class="close" href="#" data-dismiss="modal">×</a>' : '') +
|
||
'<h3>' + title + '</h3>' +
|
||
'</div>' + data
|
||
);
|
||
|
||
$(document.body).append(preview);
|
||
preview.modal({
|
||
show: true
|
||
});
|
||
}
|
||
|
||
var modal_it = function(data, title, locked) {
|
||
return modale_it(data, title, locked);
|
||
}
|
||
|
||
var windowNewNodeEvent = {
|
||
event: 'new_node'
|
||
}
|
||
|
||
var getUrlTitle = function(picker) {
|
||
var $picker = $(picker);
|
||
var url = $picker.val();
|
||
|
||
var $span = $picker.parent().find('.urlpicker_title');
|
||
|
||
if (!url) {
|
||
return;
|
||
}
|
||
|
||
(function(span) {
|
||
var $span = $(span);
|
||
|
||
$.ajax({
|
||
url: trans('TrinityContentManagerBundleNodeAdmin_tinymcenodes_title'),
|
||
data: {
|
||
query: url
|
||
},
|
||
dataType: 'json',
|
||
success: function(d) {
|
||
if (!$span.length) {
|
||
$span = $('<span class="urlpicker_title">');
|
||
$picker.parent().append($span);
|
||
}
|
||
|
||
$span.html(d.title);
|
||
}
|
||
});
|
||
})($span);
|
||
}
|
||
|
||
var reloadUrlpicker = function() {
|
||
$('.urlpicker').each(function() {
|
||
if (0 === $(this).parent().children('.urlpicker_open').length) {
|
||
$(this)
|
||
.parent()
|
||
.append($('<img>').attr('src', '/bundles/trinityadmin/img/urlpicker.png').addClass('urlpicker_open'));
|
||
|
||
getUrlTitle($(this));
|
||
}
|
||
});
|
||
}
|
||
|
||
$(window).on(
|
||
windowNewNodeEvent.event,
|
||
function() {
|
||
reloadUrlpicker();
|
||
}
|
||
);
|
||
|
||
$(document).ready(function() {
|
||
$(window).trigger(windowNewNodeEvent.event);
|
||
|
||
$('.urlpicker_open').live(
|
||
'click',
|
||
function(e) {
|
||
e.preventDefault();
|
||
|
||
var $target = $(e.target);
|
||
var $input = $target.prev();
|
||
|
||
(function(input) {
|
||
var $input = $(input);
|
||
|
||
var $modal_html = $('<div class="modal fade">').html(
|
||
'<div class="modal-header">' +
|
||
'<a class="close" href="#" data-dismiss="modal">×</a>' +
|
||
'<h3>' + trans('crud.form.urlpicker.title') + '</h3>' +
|
||
'</div>' +
|
||
'<div class="modal-body">' +
|
||
'<form id="urlpicker_select">' +
|
||
'<select class="urlpicker_select_options"><option>' + trans('Loading...') + '</option></select>' +
|
||
'</form>' +
|
||
'</div>' +
|
||
'<div class="modal-footer">' +
|
||
'<button class="insert_url btn btn-primary">OK</button>' +
|
||
'</div>'
|
||
);
|
||
|
||
$modal_html.modal({
|
||
show: true,
|
||
backdrop: false
|
||
});
|
||
|
||
$.getJSON(
|
||
trans('TrinityContentManagerBundleNodeAdmin_tinymcenodes_link'),
|
||
function(links) {
|
||
var $select = $('.urlpicker_select_options');
|
||
|
||
$select.children().html('');
|
||
|
||
$.each(links, function(key, val) {
|
||
var $options = $('<option>').val(val.value).html(val.title);
|
||
$select.append($options);
|
||
});
|
||
|
||
}
|
||
);
|
||
|
||
$('.insert_url').live(
|
||
'click',
|
||
function() {
|
||
var val = $modal_html.find('select.urlpicker_select_options option:selected').val();
|
||
$input.val(val);
|
||
$modal_html.remove();
|
||
getUrlTitle($input);
|
||
}
|
||
);
|
||
})($input);
|
||
}
|
||
);
|
||
});
|
||
|
||
var scroll_to = function(y) {
|
||
$('html').animate({
|
||
scrollTop: y
|
||
}, 600);
|
||
}
|
||
|
||
|
||
$('#login_form').live(
|
||
'submit',
|
||
function(event) {
|
||
event.preventDefault();
|
||
|
||
$form = $(this);
|
||
|
||
var $message = $(this).find('.message').html('');
|
||
var $form = $(this);
|
||
|
||
$.post($form.attr('action'), $form.serialize())
|
||
.success(function() {
|
||
run_check_authentication_timer();
|
||
$('.modal').modal('hide');
|
||
})
|
||
.error(function() {
|
||
$('#login_form').load(url_prefix + '/admin/login');
|
||
});
|
||
}
|
||
);
|
||
|
||
$('.user_profile_edit').live('click', function(e) {
|
||
var form_url = $(this).data('url');
|
||
|
||
$(window).trigger('start_loading');
|
||
|
||
$('<div>').load(
|
||
form_url,
|
||
function(data) {
|
||
$(window).trigger('end_loading');
|
||
|
||
modale_it(
|
||
data,
|
||
trans('dashboard.profile.edit')
|
||
);
|
||
}
|
||
);
|
||
});
|
||
|
||
$('.fos_user_profile_edit').live('submit', function(e) {
|
||
e.preventDefault();
|
||
$form = $(this);
|
||
|
||
$.post($form.attr('action'), $form.serialize())
|
||
.success(function(data) {
|
||
$('.fos_user_profile_edit').html($(data).find('.fos_user_profile_edit').html());
|
||
$('.fos_user_profile_edit').find('.message').fadeIn().delay(3000).fadeOut();
|
||
});
|
||
});
|
||
|
||
$('.node_action_edit').live('click', function() {
|
||
var form_url = $(this).data('url');
|
||
var $node = $('#' + $(this).data('node'));
|
||
|
||
$(window).trigger('start_loading');
|
||
|
||
$('<div>').load(
|
||
form_url,
|
||
function(data) {
|
||
$(window).trigger('end_loading');
|
||
|
||
modale_it(
|
||
data,
|
||
trans('cms.node.form.edit.title')
|
||
);
|
||
}
|
||
);
|
||
});
|
||
|
||
$('.node_action_drag').live(
|
||
'click',
|
||
function() {
|
||
$(window).trigger('start_loading');
|
||
|
||
var title = $(this).data('node');
|
||
|
||
$('<div>').load(
|
||
$(this).data('url'),
|
||
function(data) {
|
||
$(window).trigger('end_loading');
|
||
|
||
modale_it(
|
||
data,
|
||
trans('cms.node.form.move.title') + title
|
||
);
|
||
}
|
||
);
|
||
|
||
}
|
||
);
|
||
|
||
$('.node_action_add').live(
|
||
'click',
|
||
function() {
|
||
$(window).trigger('start_loading');
|
||
|
||
$('<div>').load(
|
||
$(this).data('url'),
|
||
function(data) {
|
||
$(window).trigger('end_loading');
|
||
|
||
modale_it(
|
||
data,
|
||
trans('cms.node.form.add.title')
|
||
);
|
||
}
|
||
);
|
||
}
|
||
);
|
||
|
||
$('.node_action_remove').live(
|
||
'click',
|
||
function() {
|
||
$(window).trigger('start_loading');
|
||
|
||
$('<div>').load(
|
||
$(this).data('url'),
|
||
function(data) {
|
||
$(window).trigger('end_loading');
|
||
|
||
modale_it(
|
||
data,
|
||
trans('cms.node.form.remove.title')
|
||
);
|
||
}
|
||
);
|
||
}
|
||
);
|
||
|
||
$('.confirm').live(
|
||
'click',
|
||
function(event) {
|
||
event.preventDefault();
|
||
|
||
if (confirm(trans('admin.confirm'))) {
|
||
if ($(this).attr('href')) {
|
||
redirect($(this).attr('href'));
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
);
|
||
|
||
$('.content-type-tabs a').live('click', function() {
|
||
var id = $(this).data('pid');
|
||
var value = $(this).data('value');
|
||
|
||
$('#' + id + ' option').removeAttr('selected');
|
||
$('#' + id + ' option[value=' + value + ']').attr('selected', 'selected');
|
||
});
|
||
|
||
$('.node-position i').live('click', function() {
|
||
$(this)
|
||
.parent()
|
||
.find('input')
|
||
.val($(this).data('position'));
|
||
|
||
$(this)
|
||
.parent()
|
||
.find('i')
|
||
.removeClass('active');
|
||
|
||
$(this).addClass('active');
|
||
});
|
||
|
||
$('.toggle.minus, .toggle.plus').live(
|
||
'click',
|
||
function() {
|
||
if ($(this).hasClass('minus')) {
|
||
$('#' + $(this).data('parent') + ' > div > .node_children').hide();
|
||
$(this).removeClass('minus').addClass('plus');
|
||
localStorage.treeHide = localStorage.treeHide + ';' + $(this).data('parent');
|
||
} else if ($(this).hasClass('plus')) {
|
||
$('#' + $(this).data('parent') + ' > div > .node_children').show();
|
||
$(this).removeClass('plus').addClass('minus');
|
||
localStorage.treeHide = (localStorage.treeHide).replace(';' + $(this).data('parent'), '');
|
||
}
|
||
}
|
||
);
|
||
|
||
$(document).ready(function() {
|
||
if (localStorage.treeHide) {
|
||
var parents = (localStorage.treeHide).split(';');
|
||
|
||
$(parents).each(function(i, v) {
|
||
var selector = '#' + v;
|
||
if ($(selector)[0]) {
|
||
$(selector + ' > div > .toggle').removeClass('minus').addClass('plus');
|
||
$(selector + ' > div > .node_children').hide();
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
var check_authentication_timer = null;
|
||
|
||
var check_authentication = function() {
|
||
var rand = '?' + (Math.random()).toString();
|
||
|
||
$.ajax({
|
||
type: 'GET',
|
||
url: url_prefix + '/admin/xhr_check' + rand,
|
||
dataType: 'json',
|
||
success: function(data) {
|
||
if (data.success != true) {
|
||
clearInterval(check_authentication_timer);
|
||
|
||
$(window).trigger('start_loading');
|
||
|
||
$('<div>').load(
|
||
url_prefix + '/admin/login' + rand,
|
||
function(data) {
|
||
$(window).trigger('end_loading');
|
||
modale_it(
|
||
data,
|
||
trans('admin.login.form.title'),
|
||
true
|
||
);
|
||
}
|
||
)
|
||
}
|
||
}
|
||
});
|
||
};
|
||
|
||
$('#edit_page_preview_link').live(
|
||
'click',
|
||
function() {
|
||
$div = $('#edit_page_preview').html('');
|
||
$iframe = $('<iframe>').attr('src', $(this).data('url')).attr('height', $(document).height() - $('#edit_page_preview').offset().top - 100);
|
||
|
||
$div.append($iframe);
|
||
}
|
||
);
|
||
|
||
var run_check_authentication_timer = function() {
|
||
check_authentication_timer = setInterval(check_authentication, 60000);
|
||
}
|
||
|
||
var form_helpers = function() {
|
||
var TimePickerConf = {
|
||
closeText: trans('crud.picker.closeText'),
|
||
prevText: trans('crud.picker.prevText'),
|
||
nextText: trans('crud.picker.nextText'),
|
||
currentText: trans('crud.picker.currentText'),
|
||
monthNames: trans('crud.picker.monthNames'),
|
||
monthNamesShort: trans('crud.picker.monthNamesShort'),
|
||
dayNames: trans('crud.picker.dayNames'),
|
||
dayNamesShort: trans('crud.picker.dayNamesShort'),
|
||
dayNamesMin: trans('crud.picker.dayNamesMin'),
|
||
weekHeader: trans('crud.picker.weekHeader'),
|
||
firstDay: 2,
|
||
dateFormat: 'HH:mm:ss',
|
||
yearSuffix: ''
|
||
}
|
||
|
||
$('.timepicker').timepicker(TimePickerConf);
|
||
|
||
$(".timepicker").each(function() {
|
||
$(this).timepicker(TimePickerConf);
|
||
});
|
||
|
||
$(".datetimepicker").each(function() {
|
||
$(this).datetimepicker({
|
||
closeText: trans('crud.picker.closeText'),
|
||
prevText: trans('crud.picker.prevText'),
|
||
nextText: trans('crud.picker.nextText'),
|
||
currentText: trans('crud.picker.currentText'),
|
||
monthNames: trans('crud.picker.monthNames'),
|
||
monthNamesShort: trans('crud.picker.monthNamesShort'),
|
||
dayNames: trans('crud.picker.dayNames'),
|
||
dayNamesShort: trans('crud.picker.dayNamesShort'),
|
||
dayNamesMin: trans('crud.picker.dayNamesMin'),
|
||
weekHeader: trans('crud.picker.weekHeader'),
|
||
dateFormat: $(this).data('format') ? $(this).data('format') : 'yy-mm-dd',
|
||
timeFormat: 'HH:mm:ss',
|
||
showSecond: true
|
||
});
|
||
});
|
||
|
||
$(".datepicker").each(function() {
|
||
$(this).datepicker({
|
||
closeText: trans('crud.picker.closeText'),
|
||
prevText: trans('crud.picker.prevText'),
|
||
nextText: trans('crud.picker.nextText'),
|
||
currentText: trans('crud.picker.currentText'),
|
||
monthNames: trans('crud.picker.monthNames'),
|
||
monthNamesShort: trans('crud.picker.monthNamesShort'),
|
||
dayNames: trans('crud.picker.dayNames'),
|
||
dayNamesShort: trans('crud.picker.dayNamesShort'),
|
||
dayNamesMin: trans('crud.picker.dayNamesMin'),
|
||
weekHeader: trans('crud.picker.weekHeader'),
|
||
dateFormat: $(this).data('format') ? $(this).data('format') : 'yy-mm-dd'
|
||
});
|
||
});
|
||
|
||
$('.fileupload').fileupload();
|
||
}
|
||
|
||
$('.goto a').live(
|
||
'click',
|
||
function() {
|
||
var max = $(this).data('max');
|
||
var url = $(this).data('url');
|
||
var page = parseInt(prompt(trans('crud.pager.askPage').replace('%max%', max), 1));
|
||
|
||
if (page <= max) {
|
||
document.location.href = url.replace('0', page);
|
||
}
|
||
}
|
||
);
|
||
|
||
$('.nav-select select').live(
|
||
'change',
|
||
function() {
|
||
var value = $(this).val();
|
||
if (value) {
|
||
redirect(value);
|
||
}
|
||
}
|
||
);
|
||
|
||
$('.message').live(
|
||
'click',
|
||
function() {
|
||
$(this).fadeOut();
|
||
}
|
||
);
|
||
|
||
$(document).ready(function() {
|
||
run_check_authentication_timer();
|
||
form_helpers();
|
||
});
|
||
|
||
var crud_sortable = function(page) {
|
||
$('#crud-datas tbody').sortable({
|
||
axis: 'y',
|
||
update: function(event, ui) {
|
||
var datas = []
|
||
$('#crud-datas tbody tr').each(function() {
|
||
var id = $(this).data('id');
|
||
|
||
if (id) {
|
||
datas.push(id);
|
||
}
|
||
});
|
||
|
||
$('#rank_objects').val(datas.join(' '));
|
||
$('#rank_page').val(page);
|
||
|
||
var $form = $('#rank-form');
|
||
$.post($form.attr('action'), $form.serialize());
|
||
}
|
||
});
|
||
}
|
||
|
||
if (typeof(Storage) !== 'undefined') {
|
||
$('#panel .nav-tabs a[data-toggle="tab"], #panel .accordion a[data-toggle="collapse"]').live(
|
||
'click',
|
||
function() {
|
||
if ($(this).data('save') && $(this).data('true')) {
|
||
var data = $(this).attr('href');
|
||
var key = $(this).data('toggle') == 'collapse' ? 'panelCollapse' : 'panelTab';
|
||
|
||
localStorage[key] = data;
|
||
}
|
||
}
|
||
);
|
||
|
||
$('#edit_page_container a[data-toggle="tab"]').live(
|
||
'click',
|
||
function() {
|
||
var data = $(this).attr('href');
|
||
|
||
localStorage['editPageContainerTab'] = data;
|
||
}
|
||
);
|
||
|
||
$(document).ready(function() {
|
||
var panelCollapse = localStorage['panelCollapse'];
|
||
var panelTab = localStorage['panelTab'];
|
||
var editPageContainerTab = localStorage['editPageContainerTab'];
|
||
|
||
if (panelCollapse) {
|
||
var selector = '#panel .accordion a[href=' + panelCollapse + ']';
|
||
|
||
if ($(selector)[0]) {
|
||
if ($(selector).data('save') && $(selector).data('true')) {
|
||
$(panelCollapse).parent().parent().parent().parent().find('.accordion-body').removeClass('in');
|
||
$(panelCollapse).addClass('in');
|
||
}
|
||
}
|
||
}
|
||
|
||
if (panelTab) {
|
||
var selector = '#panel .nav-tabs a[href=' + panelTab + ']';
|
||
|
||
if ($(selector)[0]) {
|
||
$(selector).tab('show');
|
||
}
|
||
}
|
||
|
||
if (editPageContainerTab) {
|
||
var selector = '#edit_page_container .nav-tabs a[href=' + editPageContainerTab + ']';
|
||
|
||
if ($(selector)[0]) {
|
||
$(selector).tab('show');
|
||
$(selector).trigger('click');
|
||
}
|
||
}
|
||
|
||
window.setInterval(function() {
|
||
var $panel = $('#panel');
|
||
|
||
if (!$panel.length) {
|
||
return;
|
||
}
|
||
|
||
var body_height = $('body').height();
|
||
|
||
if ($panel.height() < body_height) {
|
||
$panel.css('min-height', body_height);
|
||
}
|
||
}, 3000);
|
||
});
|
||
}
|
||
|
||
$(document).ready(function() {
|
||
$('.editorial_block_table tbody').sortable({
|
||
axis: 'y',
|
||
update: function(event, ui) {
|
||
var $table = $(this).parent().parent();
|
||
var $input = $table.children('input');
|
||
var $tbody = $table.find('tbody');
|
||
|
||
$input.val('');
|
||
|
||
$tbody.find('tr').each(function() {
|
||
var id = $(this).data('id');
|
||
|
||
if (id) {
|
||
var value = ' ' + id + ' ';
|
||
$input.val($input.val() + value);
|
||
$input.trigger('change');
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
$('.editorial_block_table').each(function() {
|
||
var $table = $(this);
|
||
var $addBtn = $table.find('.editorial_block_add');
|
||
var $addSelect = $table.find('.editorial_block_select');
|
||
var $tbody = $table.find('tbody');
|
||
var $tfoot = $table.find('tfoot');
|
||
var $removeBtn = $table.find('.editorial_block_remove');
|
||
var $input = $table.children('input');
|
||
|
||
if (!$addBtn[0] || !$addSelect[0]) {
|
||
return false;
|
||
}
|
||
|
||
var input_change_load = function() {
|
||
var value = ($input.val()).replace(/[ ]*/g, '');
|
||
|
||
if (value != "") {
|
||
$tbody.children('.editorial_block_no_blocks').hide();
|
||
} else {
|
||
$tbody.children('.editorial_block_no_blocks').show();
|
||
}
|
||
}
|
||
|
||
input_change_load();
|
||
|
||
$input.change(input_change_load);
|
||
|
||
$addBtn.click(function() {
|
||
if (!$addSelect.val()) {
|
||
return false;
|
||
}
|
||
|
||
$option = $addSelect.children('option:selected');
|
||
var value = ' ' + $option.val() + ' ';
|
||
|
||
if ((' ' + $input.val() + ' ').indexOf(value) === -1) {
|
||
$tbody.append($addSelect.children('option:selected').data('prototype'));
|
||
$input.val($input.val() + value);
|
||
$input.trigger('change');
|
||
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
});
|
||
|
||
$removeBtn.live(
|
||
'click',
|
||
function() {
|
||
var inputVal = ($input.val()).split(' ');
|
||
var value = $(this).data('id');
|
||
|
||
$(inputVal).each(function(i, v) {
|
||
if (v == value) {
|
||
inputVal[i] = null;
|
||
}
|
||
});
|
||
|
||
$input.val(inputVal.join(' '));
|
||
|
||
$(this).parent().parent().remove();
|
||
|
||
$input.trigger('change');
|
||
|
||
return false;
|
||
}
|
||
);
|
||
|
||
return true;
|
||
});
|
||
|
||
$('.embeded-form').parent('.controls').each(function() {
|
||
$(this).css('margin-left', 3);
|
||
$(this).prev().hide();
|
||
});
|
||
});
|
||
|
||
$(document).ready(function() {
|
||
$('.slideshow_item_table tbody').sortable({
|
||
axis: 'y',
|
||
update: function(event, ui) {
|
||
var $table = $(this).parent().parent();
|
||
var $tbody = $table.find('tbody');
|
||
|
||
$tbody.find('tr').each(function(rank) {
|
||
var $tr = $(this);
|
||
$input = $tr.find('input.rank');
|
||
|
||
if ($input[0]) {
|
||
$input.val(rank);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
$('.slideshow_item_table').each(function() {
|
||
var $table_sld = $(this);
|
||
var $tbody_sld = $table_sld.find('tbody');
|
||
var $addForm_sld = $table_sld.find('.slideshow_item_add_form');
|
||
var $addBtn_sld = $table_sld.find('.slideshow_item_add');
|
||
var $removeBtn_sld = $table_sld.find('.slideshow_item_remove');
|
||
var $editBtn_sld = $table_sld.find('.slideshow_item_edit');
|
||
var $previewBtn_sld = $table_sld.find('.slideshow_item_preview');
|
||
|
||
$addBtn_sld.click(function() {
|
||
var id = $tbody_sld.children().length - 1;
|
||
var add_form = $addForm_sld.data('prototype').replace(/__name__/g, id);
|
||
$tbody_sld.append('<tr style="background-color: #d3d3d3;">' +
|
||
'<td colspan="2" class="edit_form">' + add_form + '</td>' +
|
||
'<td width="15">' +
|
||
'<i title="' + trans("slider.add.preview") + '" data-id="' + id + '" class="slideshow_item_preview icon-eye-open"></i>' +
|
||
'<i title="' + trans("slider.add.remove") + '" data-id="' + id + '" class="slideshow_item_remove icon-remove"></i>' +
|
||
'</td>' +
|
||
'</tr>');
|
||
$tbody_sld.find('.slideshow_block_no_items').hide();
|
||
$(window).trigger(windowNewNodeEvent.event);
|
||
});
|
||
|
||
$removeBtn_sld.live(
|
||
'click',
|
||
function() {
|
||
$(this).parent().parent().remove();
|
||
if ($tbody_sld.children().length - 1 == 0) {
|
||
$tbody_sld.find('.slideshow_block_no_items').show();
|
||
}
|
||
return false;
|
||
}
|
||
);
|
||
|
||
$editBtn_sld.live(
|
||
'click',
|
||
function() {
|
||
$(this).parent().parent().find('.edit_form').toggle();
|
||
$(this).parent().parent().find('.preview').toggle();
|
||
return false;
|
||
}
|
||
);
|
||
|
||
$previewBtn_sld.live(
|
||
'click',
|
||
function() {
|
||
var form = $(this).parent().parent().find('.edit_form');
|
||
if ($(this).parent().parent().find('.preview').length) {
|
||
$(this).parent().parent().find('.preview').toggle();
|
||
} else {
|
||
$(this).parent().parent().prepend(
|
||
'<td width="100" class="preview"><i class="icon-file"></i></td>' +
|
||
'<td width="485" class="preview">' + form.find('.title').val() + '</td>'
|
||
);
|
||
}
|
||
form.toggle();
|
||
return false;
|
||
}
|
||
);
|
||
|
||
if ($tbody_sld.children().length - 1 == 0) {
|
||
$tbody_sld.find('.slideshow_block_no_items').show();
|
||
}
|
||
});
|
||
});
|
||
|
||
var do_crud_i18n = function(i18nDiv, cultures) {
|
||
var $i18nDiv = i18nDiv;
|
||
var cultures_copy = arrayCopy(cultures);
|
||
var rand = Math.floor(Math.random() * 100000);
|
||
|
||
var $children = $i18nDiv.children();
|
||
|
||
var prototype = $i18nDiv.data('prototype').replace(/^<div>/, '').replace(/<\/div>$/, '');
|
||
|
||
if ($children.length > 0) {
|
||
$children.each(function(i, v) {
|
||
var culture = $(this).find('input[data-locale]').val();
|
||
|
||
if (!$(this).hasClass('crud_culture')) {
|
||
var html = $(this).html().replace(/^<div>/, '').replace(/<\/div>$/, '');
|
||
|
||
$(this).addClass('crud_culture tab-pane well').attr('id', 'local-' + rand + '-' + culture).data('culture', culture).html(html);
|
||
}
|
||
|
||
$(cultures).each(function(i, v) {
|
||
if (v == culture) {
|
||
cultures[i] = null;
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
$i18nDiv.html('<div class="tab-content">' + $i18nDiv.html() + '</div>');
|
||
|
||
$(cultures).each(function(i, v) {
|
||
if (v === null) {
|
||
return true;
|
||
}
|
||
|
||
var html = prototype.replace(/__name__/g, i);
|
||
|
||
$divI18n = $('<div class="crud_culture tab-pane well" id="local-' + rand + '-' + v + '" data-culture="' + v + '">').html(html);
|
||
$divI18n.find('input[data-locale]').val(v);
|
||
$i18nDiv.children().append($divI18n);
|
||
});
|
||
|
||
$divI18nMenu = $('<ul class="nav nav-tabs crud_culture_menu">');
|
||
|
||
$(cultures_copy).each(function(i, v) {
|
||
var aClass = 'nav-tab-' + v;
|
||
|
||
$divI18nMenu.append('<li class="' + aClass + '"><a href="#local-' + rand + '-' + v + '" data-toggle="tab">' + v + '</a></li>');
|
||
});
|
||
|
||
$i18nDiv.prepend($divI18nMenu);
|
||
|
||
//$i18nDiv.parent().parent().removeClass('well').addClass('control-group-culture');
|
||
|
||
$($i18nDiv.find('a')[0]).tab('show');
|
||
|
||
$i18nDiv.prev().hide();
|
||
|
||
$('.crud_culture').each(function() {
|
||
var culture = $(this).attr('id').split('-')[2];
|
||
var test = $.inArray(culture, cultures_copy);
|
||
|
||
if (test === -1) {
|
||
$(this).remove();
|
||
}
|
||
});
|
||
|
||
return $i18nDiv;
|
||
}
|
||
|
||
|
||
var crud_i18n = function(cultures) {
|
||
var $i18nDiv = null;
|
||
|
||
$('div[data-prototype]').each(function() {
|
||
if ($(this).attr('id').indexOf('I18ns') !== -1) {
|
||
$i18nDiv = $(this);
|
||
}
|
||
});
|
||
|
||
if ($i18nDiv === null) {
|
||
return false;
|
||
}
|
||
|
||
do_crud_i18n($i18nDiv, cultures);
|
||
|
||
$i18nDiv.find('.error_list').each(function() {
|
||
var $br = $('<br>');
|
||
$br.insertAfter($(this));
|
||
$br.next().css('margin-left', 160);
|
||
});
|
||
|
||
window.load_tinymce();
|
||
}
|
||
|
||
var do_crud_collection = function(div, label, cultures) {
|
||
var $div = div;
|
||
var $button = $('<input type="button" class="add_collection_element_btn btn btn-small btn-primary">').val(label);
|
||
|
||
$button.insertAfter($div);
|
||
|
||
$button.click(function() {
|
||
var $child = $($div.data('prototype')).addClass('embeded-form');
|
||
|
||
$div.append($child);
|
||
|
||
var $children = $child.children();
|
||
var $label = $($children[0]).hide();
|
||
var $form = $($children[1]);
|
||
|
||
if (cultures) {
|
||
var $divI18n = $form.find('div[data-prototype]');
|
||
|
||
do_crud_i18n($divI18n, cultures);
|
||
}
|
||
});
|
||
}
|
||
|
||
var crud_collections = function(fields, cultures) {
|
||
$.each(fields, function(id, label) {
|
||
var $div = $('#' + id);
|
||
|
||
console.log(fields);
|
||
console.log($div[0]);
|
||
|
||
if ($div.length && $div.data('prototype')) {
|
||
var prototype = $div.data('prototype');
|
||
|
||
$div.prev().show();
|
||
|
||
$div.addClass('i18n_form_collection');
|
||
|
||
var $children = $div.children();
|
||
|
||
var cultures_copy = arrayCopy(cultures);
|
||
|
||
if ($children.length) {
|
||
var ref = null;
|
||
|
||
$.each(
|
||
$children,
|
||
function(i, v) {
|
||
if (0 === i % cultures_copy.length || i === $children.length - 1) {
|
||
if (i === $children.length - 1) {
|
||
ref.append($(this).clone());
|
||
|
||
$(this).remove();
|
||
}
|
||
|
||
if (i > 0) {
|
||
if (ref !== null) {
|
||
do_crud_i18n(ref, arrayCopy(cultures));
|
||
}
|
||
}
|
||
|
||
ref = get_collection_culture_container(prototype);
|
||
$div.append(ref);
|
||
}
|
||
|
||
ref.append($(this).clone());
|
||
|
||
$(this).remove();
|
||
}
|
||
);
|
||
}
|
||
do_crud_collection($div, label, arrayCopy(cultures));
|
||
}
|
||
});
|
||
}
|
||
|
||
var get_collection_culture_container = function(prototype) {
|
||
var $container = $('<div />');
|
||
$container.attr('data-prototype', prototype);
|
||
|
||
return $container;
|
||
}
|
||
|
||
var arrayCopy = function(source) {
|
||
var array = [];
|
||
|
||
for (i in source) {
|
||
if (typeof source[i] == 'source') {
|
||
array[i] = new arrayCopy(source[i]);
|
||
} else {
|
||
array[i] = source[i];
|
||
}
|
||
}
|
||
|
||
return array;
|
||
}
|
||
|
||
$('.file-preview-lightbox-img').live(
|
||
'click',
|
||
function(e) {
|
||
e.preventDefault();
|
||
|
||
var href = $(this).attr('href');
|
||
var parts = href.split('/');
|
||
var filename = parts[parts.length - 1];
|
||
var fullurl = location.protocol + '//' + (location.host + '/' + href).replace(/[\/]+/g, '/');
|
||
|
||
modale_it(
|
||
'<div class="modal-body">' +
|
||
'<input class="auto-select" style="width: 97%" type="text" value="' + fullurl + '" />' +
|
||
'<img class="file-preview-modale-img" src="' + href + '" alt="' + filename + '" title="' + filename + '" />' +
|
||
'</div>',
|
||
filename,
|
||
true
|
||
);
|
||
}
|
||
);
|
||
|
||
$('input.auto-select').live(
|
||
'click',
|
||
function() {
|
||
$(this)[0].select();
|
||
}
|
||
);
|
||
|
||
$('*[data-countable]').live(
|
||
'keyup',
|
||
function() {
|
||
$next = $(this).next();
|
||
$ref = $(this);
|
||
|
||
if ($next.hasClass('form-icon-helper')) {
|
||
$ref = $next;
|
||
$next = $next.next();
|
||
}
|
||
|
||
if (!$next.hasClass('data-countable-counter')) {
|
||
$next = $('<span class="data-countable-counter">');
|
||
$next.insertAfter($ref);
|
||
}
|
||
|
||
var size = $(this).val().length;
|
||
|
||
if ($(this).data('max-chars')) {
|
||
var max = parseInt($(this).data('max-chars'));
|
||
|
||
if (size >= max / 10 * 9) {
|
||
$next.removeClass('orange').addClass('red');
|
||
$(this).val($(this).val().substr(0, max));
|
||
} else if (size >= max / 3 * 2) {
|
||
$next.removeClass('red').addClass('orange');
|
||
} else {
|
||
$next.removeClass('red').removeClass('orange');
|
||
}
|
||
}
|
||
|
||
size = $(this).val().length;
|
||
|
||
$next.html(size + ' ' + (size > 1 ? trans('form.chars') : trans('form.char')));
|
||
}
|
||
);
|
||
|
||
$(document).ready(function() {
|
||
$('*[data-help]').each(function() {
|
||
if ($(this).data('help-show') === false) {
|
||
return;
|
||
}
|
||
|
||
$helper = $(this).next();
|
||
|
||
var help = $(this).data('help');
|
||
|
||
$helper = $("<i class='form-icon-helper icon-info-sign' data-placement='right' data-toggle='tooltip'>");
|
||
$helper.attr('data-original-title', help);
|
||
|
||
$ref = $(this).prev();
|
||
|
||
if ($(this).parent().hasClass('controls')) {
|
||
$ref = $(this).parent().prev();
|
||
}
|
||
|
||
$ref.append($helper);
|
||
});
|
||
|
||
$('.form-icon-helper').css('margin-left', '3px').tooltip();
|
||
|
||
$('#crud form > ul.error_list').addClass('alert').addClass('alert-danger');
|
||
|
||
if ($('#page_dataModel').length && $('#page_dataModelId').length) {
|
||
var $pageDataModel = $('#page_dataModel');
|
||
var $pageDataModelId = $('#page_dataModelId');
|
||
|
||
var checkDatModelSelect = function() {
|
||
if (!$pageDataModel.val()) {
|
||
$pageDataModelId.find('option:selected').removeAttr('selected');
|
||
$pageDataModelId.attr('disabled', 'disabled');
|
||
|
||
return;
|
||
}
|
||
|
||
$pageDataModelId.removeAttr('disabled');
|
||
|
||
var dataModelName = $.trim($pageDataModel.children('option:selected').html());
|
||
var $selected = [];
|
||
|
||
$pageDataModelId.children('optgroup').each(function() {
|
||
if ($.trim($(this).attr('label')) !== dataModelName) {
|
||
$(this).find('option:selected').removeAttr('selected');
|
||
$(this).hide();
|
||
} else {
|
||
$selected = $(this).find('option[selected]');
|
||
$(this).show();
|
||
}
|
||
});
|
||
|
||
if ($selected.length) {
|
||
$selected.removeAttr('selected').attr('selected', 'selected');
|
||
}
|
||
|
||
$pageDataModelId.trigger("chosen:updated");
|
||
}
|
||
|
||
$pageDataModel.change(checkDatModelSelect);
|
||
checkDatModelSelect();
|
||
}
|
||
});
|
||
|
||
$('#media-categories-tree a').live(
|
||
'click',
|
||
function(e) {
|
||
e.preventDefault();
|
||
|
||
$('#media_categoryId').val($(this).data('id'));
|
||
$('.media-filter').submit();
|
||
}
|
||
);
|
||
|
||
$('#crud tfoot').each(function() {
|
||
$(this).find('th:first-child').attr('colspan', $(this).prev().find('th').length);
|
||
});
|
||
|
||
$('#form-tab li > a').each(function() {
|
||
var $a = $(this);
|
||
var selector = $a.attr('href');
|
||
|
||
if ($(selector + ' .error_list').length) {
|
||
$a.prepend('<i class="icon-remove-sign"></i> ');
|
||
}
|
||
});
|