// ------------------------------------------------------------- // 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>' + '' + '' + '

' + ' Meng-ekspor' + '

' + '
' + ' ' + '' ); var $elmt = $(this).parents('.rich_table_component'); var $the_form = $(this).parent().find('.hide .export_form').clone(); $the_form.append('
') $elmt.find('form#filter_form input').each(function(){ $(this).clone().appendTo($the_form.find('.hide')); }); // change form action to pdf if it's pdf if($(this).hasClass('btn_pdf')){ $the_form.attr('action', $the_form.attr('action').replace('.xls', '.pdf')); } // append filter form var $el = $elmt.find('.rtc_advanced_search'); if($el.length > 0 && $elmt.find('.rtc_search #search').val() == ''){ $el.find('input').each(function(){ $(this).clone().appendTo($the_form.find('.hide')); }); } else{ $elmt.find('.rtc_search #search').clone().appendTo($the_form.find('.hide')); } $('#export_modal').find('.part.form_part').html($the_form).end().modal('show'); }); }; var initManualPopover = function(){ // Live tooltip // $('body').tooltip({ // selector: '[rel=tooltip], [rel=tooltip nofollow]' // }); // // Live popover // $('body').popover({ // selector: '[rel=popover], [rel=popover nofollow]' // }); $("[rel=popover]").popover({ trigger: 'manual' }).hover(function(e){ $("[rel=popover]").not(this).popover('hide'); $(this).popover('show'); e.preventDefault(); }, function(){ // }); // $(".tooltip").tooltip(); // $("a[rel=tooltip]").tooltip(); $(document).click(function(evt){ if(!$(evt.target).hasClass('close') && ($(evt.target).hasClass('popover') || $(evt.target).parents('.popover').length > 0)){ } else{ $("[rel=popover]").popover('hide'); } }); }; // initialize hash active tab for bootstrap tab var initActiveTab = function(){ // activate first hash for active tab var activeTab = $('[href=' + location.hash + ']'); activeTab && activeTab.tab('show'); $('#myTab a').click(function (e) { e.preventDefault(); window.location.hash = $(this).attr('href').substr(1); $(this).tab('show'); }); var locationHashChanged = function(){ var activeTab = $('[href=' + location.hash + ']'); if(activeTab.length > 0){ activeTab.tab('show'); } else{ $('#myTab a:first').tab('show'); } } window.onhashchange = locationHashChanged; }; // Initialize racpitulation matrix var initRecapitulation = function(){ // $('.recapitulation_form').live('ajax:beforeSend', function(event, xhr, settings){ if(settings.url.indexOf('&export_pdf=') > 0){ settings.url += (settings.url.indexOf('?') >= 0 ? '&' : '?'); location.href = settings.url + '&format=pdf'; } else if(settings.url.indexOf('&export_xls=') > 0){ settings.url += (settings.url.indexOf('?') >= 0 ? '&' : '?'); location.href = settings.url + '&format=xls'; } }).live('ajax:success', function(){ if (recapitulation_error != null){ alert(recapitulation_error.message); } else{ $(this).parent('.well').find('.recapitulation_result').remove(); var $recapitulation_result = $('
').addClass('recapitulation_result'); $(this).parent('.well').append($recapitulation_result); $recapitulation_result.st_recapitulationMatrix({recapitulation_matrix: recapitulation_matrix}); } }); };