// -------------------------------------------------------------
// Define Constant
var NOTIFICATION = 0;
var SUCCESS = 1;
var WAITING = 2;
var WARNING = 3;
var ERROR = 4;
var DATE_FORMAT = 'dd-mm-yy';
var LOCALE = "id";
var translations = {
"id": {
"loading": "Memuat...",
"sorting": "Mengurutkan...",
"searching": "Mencari...",
"refreshing": "Mensegarkan...",
"loading_add_form": "Memuat form penambahan...",
"loading_edit_form": "Memuat form perubahan...",
"loading_form": "Memuat form...",
"click_to_hide": "Klik untuk menyembunyikan...",
"processing": "Memproses...",
"saving": "Menyimpan...",
"updating": "Memperbarui..." ,
"deleting": "Menghapus...",
"redirecting": "Memindahkan alamat...",
"update_successful": "Berhasil mengubah",
"update_failure": "Gagal mengubah",
"loading_form_failed": "Gagal memuat form",
"sent": "Terkirim",
"sending": "Mengirim...",
"are_you_sure": "Apakah anda yakin?",
"delete": "Hapus",
},
};
var LOADING_IMAGE = '';
var ajaxifyTableGrid = function(){
$('.rtc_header .btn-group-view-toggle .btn').live('ajax:beforeSend', function(event, xhr, settings){
var $ths = $(this);
var $elmt = $(this).parents('.rich_table_component');
var $pagination = $elmt.find('.pagination');
$('.rich_table_component.updating').removeClass('updating');
$elmt.addClass('updating');
$elmt.st_tableGrid_loading({
message: t("loading"),
image: LOADING_IMAGE
});
var params = {};
if($elmt.find('input#search').val() != ''){
params = getSerializeArray($elmt.find('input#search').serializeArray());
}
$.extend(params, getSerializeArray($elmt.find('form#filter_form').serializeArray()));
params.list_view = $(this).data("list-view");
settings.url += (settings.url.indexOf('?') >= 0 ? '&' : '?') + $.param(params);
});
// PAGINATING
$('.pagination a').live('ajax:beforeSend', function(event, xhr, settings){
var $ths = $(this);
var $elmt = $(this).parents('.rich_table_component');
$('.rich_table_component.updating').removeClass('updating');
$elmt.addClass('updating');
$elmt.st_tableGrid_loading({
message: t("loading"),
image: LOADING_IMAGE
});
var $pagination = $elmt.find('.pagination');
var params = {};//$('#advance_search form').serializeArray();
var $href = this.href
// check if this is a "Go" button
if($(this).is('.gotopage')){
params.page = $pagination.find('input').val();
$href = $(this).parents('.pagination').find('a').eq(0).get(0).href;
}
//params.per_page = $pagination.find('select').val();
if($elmt.find('input#search').val() != '') {
params.search = $elmt.find('input#search').val();
}
else{
params = $.extend(params, getSerializeArray($elmt.find('form.rtc_advanced_search input').serializeArray()));
}
params.pgos = true;
settings.url += (settings.url.indexOf('?') >= 0 ? '&' : '?') + $.param(params);
});
// SORTING
$('.rtc_gh_item a').live('ajax:beforeSend', function(event, xhr, settings){
var $ths = $(this);
var $elmt = $(this).parents('.rich_table_component');
var $pagination = $elmt.find('.pagination');
$('.rich_table_component.updating').removeClass('updating');
$elmt.addClass('updating');
$elmt.st_tableGrid_loading({
message: t("loading"),
image: LOADING_IMAGE
});
var params = {};
if($elmt.find('input#search').val() != ''){
params = getSerializeArray($elmt.find('input#search').serializeArray());
}
else{
params = $.extend(params, getSerializeArray($elmt.find('form.rtc_advanced_search input').serializeArray()));
}
$list_view = $elmt.find('.rtc_header .btn-group-view-toggle .btn.active').data('list-view');
if($list_view == 'th') params.list_view = 'th';
settings.url += (settings.url.indexOf('?') >= 0 ? '&' : '?') + $.param(params);
}).live('ajax:success', function(){
var $ths = $(this);
var $elmt = $(this).parents('.rich_table_component');
$select = $elmt.find('.pagination_area').find('select[name=per_page]');
$select.find('option').filter(function(index) { return $(this).text() === $select.attr('data_value'); }).attr('selected', true);
$elmt.find('.rtc_gh_item a').removeClass('asc').removeClass('desc');
if($ths.attr('href').indexOf("=asc") != -1){
$ths.attr('href', $ths.attr('href').replace('=asc', '=desc')).addClass('asc');
}
else if($ths.attr('href').indexOf("=desc") != -1){
$ths.attr('href', $ths.attr('href').replace('=desc', '=asc')).addClass('desc');
}
});
// SEARCHING (single term)
$('.rtc_search #search').focus(function(event){
$(this).select();
});
$('.rtc_search').live('ajax:beforeSend', function(event, xhr, settings){
clearAdvanceSearch();
var $ths = $(this);
var $elmt = $(this).parents('.rich_table_component');
var $pagination = $elmt.find('.pagination');
$('.rich_table_component.updating').removeClass('updating');
$elmt.addClass('updating');
$elmt.st_tableGrid_loading({
message: t("loading"),
image: LOADING_IMAGE
});
var params = getSerializeArray($elmt.find('form#filter_form').serializeArray());
$.extend(params, getSerializeArray($(this).serializeArray()));
params['page'] = 1;
var $this_button = $ths.find('input[type=submit]');
if($this_button.is('.disabled, .pressed')){return false;}
$this_button.addClass('pressed');
}).live('ajax:success', function(){
var $this_button = $(this).find('input[type=submit]');
$this_button.removeClass('pressed');
});
$(
'.btn.btn_new'
)
.live("ajax:before", function(){
showGlobalNotification('Memuat...', {show_loading: true});
$(this).parents('.rich_table_component').addClass('showing_new_form');
}).live("ajax:success", function(){
removeGlobalNotification();
});
$(
'.button_create_presentation, ' +
'.edit'
)
.live("ajax:before", function(){
showGlobalNotification(translate('loading_form'), {show_loading: true});
$(this).parents('tr').addClass('lvr_entry_edited');
}).live("ajax:success", function(){
removeGlobalNotification();
}).live("ajax:error", function(xhr, status, error){
showGlobalNotification(translate(status.responseText), {type: ERROR});
});
$(
'.btn_approve, ' +
'.btn_reject'
).live("ajax:before", function(){
$(this).parents('tr').addClass('lvr_entry_edited');
});
$(
'.rich_table_component .rtc_grid .btn.delete'
)
.live("ajax:before", function(evt, data, status, xhr){
$(this).parents('tr').addClass('lvr_entry_deleted');
});
$(
'form.simple_form'
).live('ajax:before', function(){
$(this).find('.form-actions .btn_submit').button('loading');
});
// SEARCHING (advanced)
$(
'form.rtc_advanced_search'
).live('ajax:before', function(){
var $el = $(this);
var $elmt = $(this).parents('.rich_table_component');
$('.rich_table_component.updating').removeClass('updating');
$elmt.addClass('updating')
//
clearNormalSearch();
// append filter form
$el.find('.advanced_filter_form').remove();
$adv_ff = $('
');
$adv_ff.appendTo($el);
$elmt.find('form#filter_form input').each(function(){
$(this).clone().appendTo($adv_ff);
});
$adv_ff.find('input[name=page]').val('1');
$elmt.st_tableGrid_loading({
message: t("searching"),
image: LOADING_IMAGE
});
}).live('ajax:complete', function(event, xhr, status){
var $el = $(this);
$el.find('.advanced_filter_form').remove();
}).live("ajax:error", function(xhr, status, error){
showGlobalNotification(translate(status.responseText), {type: ERROR});
});
// RESETING ADVANCED SEARCH
$('form.rtc_advanced_search .clear_advanced_search').live('click', function(){
var $form = $(this).parents('form');
$form.find('input').val('');
$form.submit();
});
// HIDING ADVANCED SEARCH
$('form.rtc_advanced_search .hide_advanced_search').live('click', function(){
var $elmt = $(this).parents('.rich_table_component');
$elmt.find('.advanced_search_toggle_button').trigger('click');
});
// TOGGLING ADVANCED SEARCH
$('.advanced_search_toggle_button').live('click', function(){
var $elmt = $(this).parents('.rich_table_component');
if($(this).hasClass('active')){
$elmt.find('.rtc_header_expanded').slideDown('fast');
}
else{
$elmt.find('.rtc_header_expanded').slideUp('fast');
}
});
clearNormalSearch();
clearAdvanceSearch();
initExportButton();
initManualPopover();
initActiveTab();
initRecapitulation();
};
var clearAdvanceSearch = function(){
$('form.rtc_advanced_search').find('input[type=text]').val('');
$(':input', $('#advance_search form'))
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
};
// Enabling file upload using jquery-file-upload
var renderJqueryFileUpload = function(){
$('.document').fileUploadUI({
uploadTable: $('.upload_files'),
downloadTable: $('.download_files'),
buildUploadRow: function (files, index) {
var file = files[index];
return $('' + file.name + '<\/td>' +
' | <\/div><\/td>' +
' ' +
' | |