// this function gets called when the DOM is fully loaded and ready function domReadyInit(){ // make sure body height is at least the size of the display port so that bg image goes to the bottom $(window).resize(function(){ if($(window).height() > $("body").height()+10){ $("body").css({height: $(window).height() + 'px'}); } }).resize(); // anchor tooltip naming convention: title*='::' $("a[title*='::']").tooltip({showBody: "::", showURL: false}); // START: enable bulk-edit functionality $("a[href='#bulkedit']").click(function(){ var bulkEditIds = new Array(); var pathBulkEdit = document.location.href.split('/'); pathBulkEdit = pathBulkEdit[0] + '//' + pathBulkEdit[2] + '/' + pathBulkEdit[3] + '/bulkedit'; $('input[name^="BulkEdit[id_"]:checkbox:checked').each(function(){ bulkEditIds.push($(this).val()); }); $('#bulkEditForm').remove(); if(bulkEditIds.length > 0){ var formUrl = $(this).closest('form').attr('action').replace(/\.\.\//g, ''); $('body').append('
'); //$('body').append(''); //$('#bulkEditForm').submit(); tb_show('Bulk Edit', pathBulkEdit + '?hideWrapper=true&idList=' + escape(bulkEditIds.toString()) + '&prevUrl=' + escape(formUrl) + '&TB_iframe=true&width=900&height=500'); } }); // gray out bulk edit icon if no checkboxes are selected function setBulkEditIconOpacity(){ var numBulkEditChecked = $('input[name^="BulkEdit[id_"]:checkbox:checked').length; if(numBulkEditChecked == 0){ $("a[href='#bulkedit']").css({opacity: 0.3}); }else{ $("a[href='#bulkedit']").css({opacity: 1}); } } setBulkEditIconOpacity(); $('input[name^="BulkEdit[id_"]:checkbox').click(function(){ setBulkEditIconOpacity(); $('input[name="BulkEdit[toggleAll]"]:checkbox').removeAttr('checked'); }); // check all toggler function bulkEditAllToggle(){ numBulkEdit = $('input[name^="BulkEdit[id_"]:checkbox').length; numBulkEditUnChecked = $('input[name^="BulkEdit[id_"]:checkbox:not(:checked)').length; numBulkEditChecked = numBulkEdit - numBulkEditUnChecked; $('input[name="BulkEdit[toggleAll]"]:checkbox').removeAttr('checked'); if(numBulkEditChecked){ $('input[name^="BulkEdit[id_"]:checkbox:checked').click(); // un-tick tick all checkboxes }else{ $('input[name^="BulkEdit[id_"]:checkbox').click(); // un-tick checked boxes $('input[name="BulkEdit[toggleAll]"]:checkbox').attr({checked: 'checked'}); } } $('input[name="BulkEdit[toggleAll]"]:checkbox').click(bulkEditAllToggle); // END: enable bulk-edit functionality // submit from anchor $("form a[href='#save']").click(function(){ $(this).parents('form').submit(); }); // enable all disabled fields before submitting $("form").submit(function(){ try{ if($('#TB_overlay').length==0){ //tb_show('', 'http://www.google.com/?&modal=true'); $("#TB_overlay").show(); $("#TB_load").show(); } }catch(e){} $(this).find(":input").removeAttr("disabled"); }); // archive $("form a[href='#archive']").click(function(){ $(this).parents('form').attr({action: '../..//archive'}).submit(); }); // restore $("form a[href='#restore']").click(function(){ $(this).parents('form').attr({action: '../..//archive/restore'}).submit(); }); // close thickbox window $("form a[href='#tbCancel']").click(function(){ tb_remove(); }); // check all convention $("form input[type='checkbox'][name='checkall']").each(function(){ $(this).click(function(){ var checkAllElement = this; $(this).parents('form').find("input[type='checkbox'][name^='manage_']").each(function(){ if($(checkAllElement).is(':checked')){ $(this).attr({checked: "checked"}); }else{ $(this).removeAttr("checked"); } }).click(function(){ if($(this).is(":not('checked')")){ $(checkAllElement).removeAttr("checked"); } }); }); }); // language field toggling $("form [name*='_langToggle_']").parents('tr').hide(); $("form input[type='checkbox'][name^='languageIdToggle_']").each(function(){ toggleLangInputFields(this); }).click(function(){ toggleLangInputFields(this); }); // handle pagination $("button.pagination").click(function(){ var isOk = false; if($(this).children('a').length){ isOk = true; } if(isOk){ $(this).parents("form").attr({action: $(this).children('a').attr('href')}); } }); // START: datepicker enabling var d = new Date(); var n = d.getFullYear(); var yearStartRange = n - 5; var yearEndRange = n + 5; $("form input[class*='jsDatepicker']").each(function(){ var data = $(this).metadata(); var _yearRange = yearStartRange.toString() + ":" + yearEndRange.toString(); var _showButtonPanel = true; //if(data.yearRange){_yearRange = data.yearRange;} if(data.showButtonPanel != undefined){_showButtonPanel = data.showButtonPanel;} $(this).datepicker({ dateFormat: 'yy-mm-dd', showButtonPanel: _showButtonPanel, changeMonth: true, changeYear: true, showOn: 'both', buttonImageOnly: true, numberOfMonths: 1, closeText: 'OK', currentText: 'Today', onClose: function(date) { if($("#ui-datepicker-div .ui-datepicker-time .ui-datepicker-hour").val() != '00' || $("#ui-datepicker-div .ui-datepicker-time .ui-datepicker-minute").val() != '00' || $("#ui-datepicker-div .ui-datepicker-time .ui-datepicker-second").val() != '00'){ var time = $("#ui-datepicker-div .ui-datepicker-time .ui-datepicker-hour").val() + ':' + $("#ui-datepicker-div .ui-datepicker-time .ui-datepicker-minute").val() + ':' + $("#ui-datepicker-div .ui-datepicker-time .ui-datepicker-second").val(); if(time.indexOf('undefined') == -1){ $(this).val( $(this).val() + ' ' + time ); } } }, yearRange: _yearRange }); }); $("#ui-datepicker-div").hide(); // form validation $("form").each(function(){ $(this).validate({ meta: 'validator', invalidHandler: function(){ if($('#TB_window:visible').length==0){tb_remove();} }, ignoreTitle: true, highlight: function(element, errorClass){ $(element).parent('td').addClass('error'); $(element).addClass('error'); } }); // see functions outside of domReadyInit() styleFormValidation($(this)); }); // eol horizontal scroller $('div.eolScrollH').each(function(){ var marginIncrement = 250; var thisElement = this; $(this).find('div.eolScrollH-leftArrow').click(function(){ var currentMargin = Number($(thisElement).find('div.eolScrollH-content > div').css('marginLeft').replace('px', '')); if(currentMargin < 250){ currentMargin = -marginIncrement; } $(thisElement).find('div.eolScrollH-content > div').animate({ marginLeft: String(currentMargin + marginIncrement) + 'px' }, 200); }).click().hover( function(){ $(this).css({opacity:'0.5'}); }, function(){ $(this).css({opacity:'1'}); } ); $(this).find('div.eolScrollH-rightArrow').click(function(){ var currentMargin = Number($(thisElement).find('div.eolScrollH-content > div').css('marginLeft').replace('px', '')); if(currentMargin <= -250){ currentMargin = 0 ; } $(thisElement).find('div.eolScrollH-content > div').animate({ marginLeft: String(currentMargin - marginIncrement) + 'px' }, 200); }).hover( function(){ $(this).css({opacity:'0.5'}); }, function(){ $(this).css({opacity:'1'}); } ); }); // START: handle feature cycle // add numbers, depending on number of featured items $('h1 span.featureCycle').html('').each(function(){ var numFeatureTables = $(this).parents('h1').next('div.featureContainer').find('table.feature').length; if(numFeatureTables > 1){ for(var i=1; i <= numFeatureTables; i++){ $(this).append('' + i + ''); } $(this).find('span:first').addClass('cur'); } }); // add onClick functionality to numbering configuration above $('h1 span.featureCycle').show().find('span').css({cursor: 'pointer'}).click(function(){ var firstFeatureTable = $(this).parents('h1').next('div.featureContainer').find('table.feature:first'); var num = $(this).text(); num -= 1; if($(firstFeatureTable).is('.featureLarge')){ num *= -130; }else{ num *= -85; } $(firstFeatureTable).animate({marginTop: num + 'px'}, 1000); $(this).parents('span.featureCycle').find('span').removeClass('cur'); $(this).addClass('cur'); }); // END: handle feature cycle // START: handle client management switch $('select[name="switch_client_management"]').change(function(){ $(this).parents('form').submit(); }); // END: handle client management switch // START: handle quick navigation switch $('select[name="switch_admin_section"]').change(function(){ if($(this).val() != ''){ $(this).parents('form').submit(); } }); // END: handle quick navigation switch // START: call the realtime() function in the controller's specific javascript file try{realtime();} catch(err){} // backwards compatibility executeRealtime(); // END: call the realtime() function in the controller's specific javascript file } // form validation styling function styleFormValidation(formJqueryObject){ formJqueryObject.find('table td').each(function(){ try{ var data = $(this).next('td:first').find(':input:enabled').metadata(); if(data.validator.required != null){ if($.isFunction(data.validator.required)){ // for conditional required fields (e.g. functions) if(data.validator.required.call(this)){ $(this).removeClass('required').addClass('required'); }else{ $(this).removeClass('required'); } }else{ // for normal required fields if(data.validator.required){ if($(this).attr('class')=="key")$(this).removeClass('required').addClass('required'); }else{ $(this).removeClass('required'); } } } }catch(err){} }); }