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

' + ' 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')); }); $el.find('select').each(function(i){ var select = this; $(this).clone().appendTo($the_form.find('.hide')); $the_form.find('.hide').find('select').eq(i).val($(select).val()); }); } 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){ $(this).parent('.well').find('.recapitulation_result').remove(); var $recapitulation_result = $('
Mengkalkulasi rekapitulasi...
').addClass('recapitulation_result'); $(this).parent('.well').append($recapitulation_result); 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}); } }); }; // Initialize Multiple Selection var initMultipleSelection = function(){ // $('.rtc_select_all').attr({checked: false}); $('.rtc_row_select').attr({checked: false}); $('.rtc_select_all').live('change', function(){ if($(this).attr('checked')){ $(this).parents('.rtc_content').find('> .rtc_grid table').find('tr .rtc_row_select').attr({checked: true}); } else{ $(this).parents('.rtc_content').find('> .rtc_grid table').find('tr .rtc_row_select').attr({checked: false}); } }); $('.rtc_row_select').live('change', function(){ if($(this).attr('checked')){ } else{ console.log('unchecked'); $(this).parents('.rtc_content').find('> .rtc_grid_header').find('.rtc_select_all').attr({checked: false}); } }); $( 'form.multiple_selection_form' ).live("ajax:before", function(){ var $this_form = $(this); var $temp_multiple_selection_container = $('
').addClass('temp_multiple_selection_container hide'); $this_form.find('.temp_multiple_selection_container').remove(); $this_form.parents('.rich_table_component').find('.rtc_grid table tr .rtc_row_select').each(function(){ if($(this).attr('checked')){ var $cloned = $(this).clone(); $cloned.attr({checked: true}); $temp_multiple_selection_container.append($cloned); } }); $this_form.append($temp_multiple_selection_container); }); };