var Teasers = {
init: false,
init: function() {
if (this.initialized) return;
this.initialized = true;
this.Analoque_items();
},
Analoque_items: function() {
this.Analoque_sortable();
this.Analoque_del_item();
this.Analoque_add();
this.Analoque_search();
},
Analoque_update: function() {
this.Analoque_maxid();
this.Analoque_del_item();
this.Analoque_search();
AveAdmin.tooltip();
},
/**
* @return {number}
*/
Analoque_maxid: function(id)
{
var maxid = 1;
$('#analoque_lists_' + id).children('.analoque_list').each(function() {
maxid = Math.max(maxid, parseInt($(this).attr("data-id")) + 1);
});
return maxid;
},
Analoque_del_item: function()
{
$('.analoque_list .DelButton').on('click', function(event) {
event.preventDefault();
var id = $(this).attr('data-id');
jConfirm(
analoque_del_conf,
analoque_del_head,
function(b) {
if (b) {
$('#analoque_list_' + id).remove();
}
}
);
});
},
Analoque_add: function()
{
$('.AddButton').on('click', function() {
c_id = $(this).parent().parent('.analoque_lists').attr("data-id");
d_id = $(this).parent().parent('.analoque_lists').attr("data-docid");
i_id = Teasers.Analoque_maxid(d_id + '_' + c_id);
$('#analoque_lists_' + d_id + '_' + c_id + ':last').append(
'
'
);
Teasers.Analoque_update();
});
},
Analoque_sortable: function() {
$('.analoque_lists').sortable({
handle: ".handle",
placeholder: "ui-state-highlight grey_bg"
});
},
/**
* @return {boolean}
*/
Analoque_search: function() {
var res_search = false;
$('.search_analoque').on('input', function(event)
{
event.preventDefault();
var query = $(this);
var did = query.attr('data-docid');
var fid = query.attr('data-fieldid');
var kid = query.attr('data-id');
var field_id_input = $('.field_' + did + '_' + fid + '_' + kid);
if (res_search)
return false;
res_search = true;
query.autocomplete("index.php?do=fields&field=teasers&type=search&doc_id=" + did + "&field_id=" + fid, {
width: query.outerWidth(),
max: 5,
dataType: "json",
matchContains: "word",
scroll: true,
scrollHeight: 200,
parse: function(data) {
res_search = false;
if (typeof data === 'object')
{
return $.map(data, function(row) {
return {
data: row,
value: row.doc_title,
result: query.val()
}
});
}
return false;
},
formatItem: function(item) {
return '' + item.doc_article + ' ' + item.doc_name + '
';
}
}).result(function(e, item) {
query.val(item.doc_name);
field_id_input.val(item.doc_id);
});
return false;
});
return false;
}
}
$(document).ready(function() {
Teasers.init();
});