// -------------------------------------------------------------
// 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 = $.cookie('unm_pp');
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 = {};
params.per_page = $.cookie('unm_pp');
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');
$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;
params.per_page = $.cookie('unm_pp');
var $this_button = $ths.find('input[type=submit]');
if($this_button.is('.disabled, .pressed')){return false;}
$this_button.addClass('pressed');
settings.url += (settings.url.indexOf('?') >= 0 ? '&' : '?') + $.param(params);
}).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:beforeSend', function(event, xhr, settings){
var $elmt = $(this).parents('.rich_table_component');
$('.rich_table_component.updating').removeClass('updating');
$elmt.addClass('updating')
//
clearNormalSearch();
$elmt.st_tableGrid_loading({
message: t("searching"),
image: LOADING_IMAGE
});
//console.log("ADVANCED SEARCH");
//return false;
params = {};
$elmt.find('form#filter_form input').each(function(){
params[$(this).attr('name')] = $(this).attr('value')
});
params.page = 1;
params.per_page = $.cookie('unm_pp');
settings.url += (settings.url.indexOf('?') >= 0 ? '&' : '?') + $.param(params);
}).live('ajax:complete', function(event, xhr, status){
}).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.find(':input')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
});
// 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();
initMultipleSelection();
initCookies();
};
var initCookies = function(){
if($.cookie('unm_pp') == undefined){
$.cookie('unm_pp', $('.per_page_part').find('select').val());
}
$('.per_page_part').live('change', function(){
var $elmt = $(this).parents('.rich_table_component');
$.cookie('unm_pp', $(this).find('select').val());
$elmt.find('.go_to_page_part').find('input').val(1);
$elmt.find('.gotopage').trigger('click');
});
};
var clearAdvanceSearch = function(){
$('form.rtc_advanced_search').find('input[type=text]').val('');
$('form.rtc_advanced_search :input')
.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>' +
' ' +
' | |