/** * Code to run when the DOM is finished loading * Uses .ready from jQuery instead of document.onload * jQuery must be loaded before this file. */ $(document).ready(init); //global variables to track loaded objects/files etc GLOBAL_GRID_EXTENSIONS_LOADED = false; function init() { //works in IE only - look at removing window.defaultStatus = "Software Developed by Database Communications"; $("a").bind("mouseover",function() { window.status = "Software Developed by Database Communications"; }); if ($.browser.msie == true) { try { document.execCommand('BackgroundImageCache', false, true); } catch (e) { //do nothing } } try{ //initaliase all calendars linked to fields with class="field-datepicker" initCalendars(); // Init the singleton. Any tag-based quick tips will start working. Ext.QuickTips.init(); // Apply a set of config properties to the singleton Ext.apply(Ext.QuickTips.getQuickTip(), { maxWidth: 300, minWidth: 50, showDelay: 0, trackMouse: true, dismissDelay: 0, hideDelay: 100 }); } catch(e) { //do nothing } } function initFlash() { //fix for latest IE versions to automatically activate Flash objects theObjects = document.getElementsByTagName("object"); for (var i = 0; i < theObjects.length; i++) { theObjects[i].outerHTML = theObjects[i].outerHTML; } } /** * Set focus on the first form element * in the specified form */ function setFormFocus($formId) { var bFound = false; // for each element in each form for(i=0; i < document.forms[$formId].length; i++) { // if it's not a hidden element if (document.forms[$formId][i].type != "hidden") { // and it's not disabled if (document.forms[$formId][i].disabled != true) { //and its empty if (document.forms[$formId][i].value == "") { // set the focus to it document.forms[$formId][i].focus(); bFound = true; } } } // if found in this element, stop looking if (bFound == true) break; } } /** * generates a random string * often used to force cache refresh in a URL */ function randomTime() { var now = new Date(); var serial = now.valueOf(); return serial; } /** * These functions are responsible for internal windows * * @param {Object} objWindow */ function openWindow(objWindow) { eval("openWin_"+objWindow+"()"); } function closeWindow(objWindow) { eval("win_"+objWindow+".hide()"); } /** * Check Browser * Values = msie, gecko, opera, safari?? */ function checkBrowser($browser) { // convert all characters to lowercase to simplify testing var agt=navigator.userAgent.toLowerCase(); if(agt.indexOf($browser) != -1) return true; else return false; } /** * Get inner window size * works across all browsers */ function getWindowSize($dimension) { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } if($dimension == "width") return myWidth; else return myHeight; } function reloadMain($url) { if($url != undefined) { top.document.getElementById('iframeMain').src = $url; } else { top.document.getElementById('iframeMain').src = top.document.getElementById('iframeMain').src; } } function reloadWindow($id, $url) { if($url != undefined) { top.getWindow($id).location = $url; } else { top.getWindow($id).location = top.getWindow($id).location; } } function reloadNav($url) { if($url != undefined) { top.iframeNav.document.getElementById('iframeTree').src = $url; } else { top.document.getElementById('iframeNav').src = top.document.getElementById('iframeNav').src; } } function reloadNavTree($url, $title) { if($url != undefined) { top.iframeNav.document.getElementById('iframeTree').src = $url; } else { top.iframeNav.document.getElementById('iframeTree').src = top.iframeNav.document.getElementById('iframeTree').src; } if($title != undefined) { top.iframeNav.document.getElementById('iframeTreeTitle').className = 'nav-header'; top.iframeNav.document.getElementById('iframeTreeTitle').innerHTML = $title; } } function showMessage($id, $message) { $('#'+$id).html('' + $message + ""); $('#'+$id).fadeOut(2500, function(){ $('#'+$id).html(" ").show() }); } /** * Trims whitespace from string */ function Trim (pStr) { var s = pStr.replace(/^\s*/, ''); s = s.replace(/\s*$/, ''); return s; } /** * Will create a new window with the content rendered * Great for debugging messages */ function debugWindow(content) { top.consoleRef=window.open('','myconsole','width=350,height=250,menubar=0,toolbar=1,status=0,scrollbars=1,resizable=1') top.consoleRef.document.writeln(content) top.consoleRef.document.close() } /** * Will get the form values from the specified form and return as * serialised object. This is a wrapper for the xajax.getFormValues() * so can only be used on Xajax pages. */ function getFormValues($formName, $form2, $form3, $form4, $form5, $form6) { $formdata1 = xajax.getFormValues($formName); if($form2 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata2 = xajax.getFormValues($form2); $formdata2 = $formdata2.replace("",""); $formdata1 = $formdata1 + $formdata2; } if($form3 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata3 = xajax.getFormValues($form3); $formdata3 = $formdata3.replace("",""); $formdata1 = $formdata1 + $formdata3; } if($form4 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata4 = xajax.getFormValues($form4); $formdata4 = $formdata4.replace("",""); $formdata1 = $formdata1 + $formdata4; } if($form5 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata5 = xajax.getFormValues($form5); $formdata5 = $formdata5.replace("",""); $formdata1 = $formdata1 + $formdata5; } if($form6 != undefined) { $formdata1 = $formdata1.replace("","&"); $formdata6 = xajax.getFormValues($form6); $formdata6 = $formdata6.replace("",""); $formdata1 = $formdata1 + $formdata6; } return $formdata1; } /** * A string replace function */ function str_replace($needle, $replacement, $haystack) { var $string = new String($haystack); $newstr = $string.replace($needle,$replacement); return $newstr; } function str_contains($needle, $haystack) { var pos=$haystack.indexOf($needle); if (pos>=0) { return pos } else { return false; } } // Returns true if the passed value is found in the // array. Returns false if it is not. function in_array($needle, $haystack) { var i; for (i=0; i < $haystack.length; i++) { // Matches identical (===), not just similar (==). if ($haystack[i] === $needle) { return true; } } return false; } function is_array(obj) { if (obj.constructor.toString().indexOf("Array") == -1) { return false; } else { return true; } } function is_object(obj) { if(obj instanceof Array) { return false; } else { return (obj !== null) && (typeof( obj ) == 'object'); } } function showMessageBox($message, $buttons, $function, $title, $modal, $width) { if (typeof Ext === 'undefined') { alert($message); return; } if($buttons == undefined) $buttons = Ext.Msg.OK; if($title == undefined) $title = 'Notice'; if($function == undefined) $function = false; if($modal == undefined) $modal = true; if($buttons == 'OK') { $buttons = Ext.Msg.OK; } else if($buttons == 'OKCANCEL') { $buttons = Ext.Msg.OKCANCEL; } else if($buttons == 'YESNO') { $buttons = Ext.Msg.YESNO; } //strip bad spaces $message = $message.replace(/\%20/g, " "); if($width == undefined) { Ext.Msg.show({ title: $title, msg: $message, buttons: $buttons, fn: $function, modal: $modal }); } else { Ext.Msg.show({ title: $title, msg: $message, buttons: $buttons, fn: $function, modal: $modal, width: $width }); } } function showProgressBox(message) { var message = message || 'Please wait...'; showMessageBox(message+'
'); } /** * Prepare Xajax for any custom requests */ var xajaxRequestUri="/xajax/"; var xajaxDebug=false; var xajaxStatusMessages=false; var xajaxWaitCursor=true; var xajaxDefinedGet=0; var xajaxDefinedPost=1; var xajaxLoaded=false; // is dirty form functions var isDirty = 0; var custom_windowName = ''; function initDirtyCheck(formName,windowName,bind) { var bind = (bind == undefined) ? true : bind; if (bind) { if(Ext.isGecko) { $('input').bind('keyup', setDirty); $('textarea').bind('keyup', setDirty); } else { $('input').bind('change', setDirty); $('textarea').bind('change', setDirty); } $('select').bind('change', setDirty); } if(top.windows[windowName]) { document.custom_windowName = windowName; } else { var window_type = windowName; document.custom_windowName = window_type.replace(/[0-9]/g,""); } } function checkIsDirty($window_name, display_message, callback) { var display_message = display_message || 'You have not saved your changes. Are you sure you want to close this window?'; var on_confirm = callback || customProcessDlg; if( isDirty == 1 ) { top.windows[document.custom_windowName].show(); if(Ext.isIE6) { var $ICON_TYPE = 'gif'; } else { var $ICON_TYPE = 'png'; } showMessageBox("
" + display_message + "
","YESNO",on_confirm,'Warning!',true,280); return false; } else { return true; } } function customProcessDlg(option) { if( option=="yes" ) { isDirty = 0; top.destroyWindow(document.custom_windowName); } } function setDirty(dirty) { isDirty = 1; } function clearDirty() { isDirty = 0; } function format_currency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + num + '.' + cents); } function format_number(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } function generateDropdown(options) { var options = options || { force_selection: true, store: false, scope: false, disable_hidden: true, hidden_id: undefined, mode: 'local', transform: false, callback: {}, parameters: {} }; if (typeof options.callback !== 'function') { options.callback = function() { return true; }; } var dropdown = new Ext.form.ComboBox({ //typeAhead is actually really annoying //typeAhead: true, //typeAheadDelay: 1000, hiddenId: options.hidden_id, parameters: options.parameters, triggerAction: 'all', transform: options.transform, width: options.width, enableKeyEvents: true, disableHiddenField: options.disable_hidden, store: options.store, mode: options.mode || 'local', valueField: options.value_field || 'value', displayField: options.display_field || 'text', forceSelection: options.force_selection, plugins: new Ext.ux.plugins.CustomFilterCombo({ filterFn: function(rec, id, field, value) { var groupRex = new RegExp('^__group'); if(!value.replace(/[^A-Za-z0-9]*/g,'') > '') { return true; } else if(groupRex.test(id)) { return false; } else { var rex = new RegExp('.*' + value + '.*', 'i'); return rex.test(rec.get(field)); } } }), listWidth: options.list_width, minListWidth: options.width, id: 'ext-'+options.transform }); //dropdown.on('change', options.callback, options.scope); dropdown.on('select', function(combo,rec,i) { options.callback.call(this); }, options.scope); dropdown.on('keydown', function(c,e) { if (e.getCharCode() == e.TAB) { var selected_records = c.view.getSelectedRecords(); // we need to check the current value as we // don't want to set it if it hasn't changed if (selected_records.length == 1 && c.getValue() != selected_records[0].get('value')) { c.setValue(selected_records[0].get('value')); options.callback.call(this); } } }, options.scope); return dropdown; } function transformDropdown(combo, width, list_width, callback, forceSelection) { var options = { force_selection: (typeof forceSelection === 'undefined') ? true : forceSelection, callback: (typeof callback === 'function') ? callback : {}, hidden_id: combo || undefined, transform: combo || false, list_width: list_width || false, width: width || false, disable_hidden: true, scope: false, store: false }; return generateDropdown(options); } function setStrLength(string, maxlength) { if (string.length <= maxlength) { return string; } string = (string.substr(0, maxlength))+" ..." return string; } function reloadLoader($url) { if($url != undefined) { top.document.getElementById('iframeLoader').src = $url; } else { top.document.getElementById('iframeLoader').src = top.document.getElementById('iframeLoader').src; } } function printObject(obj) { var str = ""; for(prop in obj) { str+=prop + " value = "+ obj[prop]+"\n"; } alert(str); } function urlencode($string) { return encodeURIComponent($string); } function getFrame($name) { var $length = window.frames.length; for (var i=0; i < $length; i++) { if($.browser.msie) { $iframe = window.frames(i); } else { $iframe = frames[i]; } if($iframe.name == $name) { return $iframe; } } return false; } function reloadFrame($frame, $url) { $("iframe[name='"+$frame+"']").attr('src', $url); } var $searchfield_timeout; function createSearchField($field_id, $fn, $icon, $default_text) { var $field = $('#'+$field_id); $field.bind('keypress', function(event) { if(event.which == 13) { eval($fn); } }); $field.bind('keyup', function(event) { try { clearTimeout( $searchfield_timeout ); } catch(e) {} $searchfield_timeout = setTimeout('searchFieldLookup("'+$field_id+'",'+$fn+','+event.which+');',500); }); if($icon != undefined) { if(Ext.isIE) { var $icon_padding_top = 3; var $field_padding_left = 19; } else { var $icon_padding_top = 2; var $field_padding_left = 18; } var $div = '
'; $field.before($div); $field.addClass('field-input'); $field.css('padding-left', $field_padding_left); $field.css('padding-top', '2px'); $('#'+$field_id+'_icon').bind('click', function() { $('#'+$field_id).val(''); eval($fn); $('#'+$field_id).focus(); }); } if($default_text != undefined) { $field.css('color', '#CCC'); $field.val($default_text); $field.bind('focus', function() { $(this).css('color', '#000'); if($(this).val() == $default_text) { $(this).val(''); } }); } } function searchFieldLookup($field_id, $fn, $key) { var $str = ''; try { clearTimeout( $searchfield_timeout ); } catch(e) {} str = $('#'+$field_id).val(); try { if( $string.length > 2 || $key == 8 ) { eval($fn); } } catch(e) {} } function validateUrl($url) { if ((($url.indexOf("http://")==0) || ($url.indexOf("https://")==0) || ($url.indexOf("ftp://")==0) || ($url.indexOf("mailto:")==0)) && ($url.length>8)) { return true; } else { return false; } } function ajaxSaveGridPreference(grid_name, type, columnNumber, changedValue) { xajax.call('ajaxSaveGridPreferences', [ 'Ajax_Preferences', grid_name, type, columnNumber, changedValue ], 1); } function ucfirst($words, $strip_extra) { if($strip_extra != false) { $words = str_replace('-', ' ', $words); $words = str_replace('_', ' ', $words); } // Split the string into words if string contains multiple words. var x = $words.split(/\s+/g); for (var i = 0; i < x.length; i++) { var parts = x[i].match(/(\w)(\w*)/); x[i] = parts[1].toUpperCase() + parts[2].toLowerCase(); } // Rejoin the string and return. return x.join(' '); } function get_html_translation_table (table, quote_style) { var entities = {}, hash_map = {}, decimal = 0, symbol = ''; var constMappingTable = {}, constMappingQuoteStyle = {}; var useTable = {}, useQuoteStyle = {}; // Translate arguments constMappingTable[0] = 'HTML_SPECIALCHARS'; constMappingTable[1] = 'HTML_ENTITIES'; constMappingQuoteStyle[0] = 'ENT_NOQUOTES'; constMappingQuoteStyle[2] = 'ENT_COMPAT'; constMappingQuoteStyle[3] = 'ENT_QUOTES'; useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS'; useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT'; if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') { throw new Error("Table: " + useTable + ' not supported'); // return false; } } entities['38'] = '&'; entities['60'] = '<'; entities['62'] = '>'; if (useTable === 'HTML_ENTITIES') { entities['160'] = ' '; entities['161'] = '¡'; entities['162'] = '¢'; entities['163'] = '£'; entities['164'] = '¤'; entities['165'] = '¥'; entities['166'] = '¦'; entities['167'] = '§'; entities['168'] = '¨'; entities['169'] = '©'; entities['170'] = 'ª'; entities['171'] = '«'; entities['172'] = '¬'; entities['173'] = '­'; entities['174'] = '®'; entities['175'] = '¯'; entities['176'] = '°'; entities['177'] = '±'; entities['178'] = '²'; entities['179'] = '³'; entities['180'] = '´'; entities['181'] = 'µ'; entities['182'] = '¶'; entities['183'] = '·'; entities['184'] = '¸'; entities['185'] = '¹'; entities['186'] = 'º'; entities['187'] = '»'; entities['188'] = '¼'; entities['189'] = '½'; entities['190'] = '¾'; entities['191'] = '¿'; entities['192'] = 'À'; entities['193'] = 'Á'; entities['194'] = 'Â'; entities['195'] = 'Ã'; entities['196'] = 'Ä'; entities['197'] = 'Å'; entities['198'] = 'Æ'; entities['199'] = 'Ç'; entities['200'] = 'È'; entities['201'] = 'É'; entities['202'] = 'Ê'; entities['203'] = 'Ë'; entities['204'] = 'Ì'; entities['205'] = 'Í'; entities['206'] = 'Î'; entities['207'] = 'Ï'; entities['208'] = 'Ð'; entities['209'] = 'Ñ'; entities['210'] = 'Ò'; entities['211'] = 'Ó'; entities['212'] = 'Ô'; entities['213'] = 'Õ'; entities['214'] = 'Ö'; entities['215'] = '×'; entities['216'] = 'Ø'; entities['217'] = 'Ù'; entities['218'] = 'Ú'; entities['219'] = 'Û'; entities['220'] = 'Ü'; entities['221'] = 'Ý'; entities['222'] = 'Þ'; entities['223'] = 'ß'; entities['224'] = 'à'; entities['225'] = 'á'; entities['226'] = 'â'; entities['227'] = 'ã'; entities['228'] = 'ä'; entities['229'] = 'å'; entities['230'] = 'æ'; entities['231'] = 'ç'; entities['232'] = 'è'; entities['233'] = 'é'; entities['234'] = 'ê'; entities['235'] = 'ë'; entities['236'] = 'ì'; entities['237'] = 'í'; entities['238'] = 'î'; entities['239'] = 'ï'; entities['240'] = 'ð'; entities['241'] = 'ñ'; entities['242'] = 'ò'; entities['243'] = 'ó'; entities['244'] = 'ô'; entities['245'] = 'õ'; entities['246'] = 'ö'; entities['247'] = '÷'; entities['248'] = 'ø'; entities['249'] = 'ù'; entities['250'] = 'ú'; entities['251'] = 'û'; entities['252'] = 'ü'; entities['253'] = 'ý'; entities['254'] = 'þ'; entities['255'] = 'ÿ'; } if (useQuoteStyle !== 'ENT_NOQUOTES') { entities['34'] = '"'; } if (useQuoteStyle === 'ENT_QUOTES') { entities['39'] = '''; } // ascii decimals to real symbols for (decimal in entities) { symbol = String.fromCharCode(decimal); hash_map[symbol] = entities[decimal]; } return hash_map; } function html_entity_decode (string, quote_style) { var hash_map = {}, symbol = '', tmp_str = '', entity = ''; tmp_str = string.toString(); if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) { return false; } delete(hash_map['&']); hash_map['&'] = '&'; for (symbol in hash_map) { entity = hash_map[symbol]; tmp_str = tmp_str.split(entity).join(symbol); } tmp_str = tmp_str.split(''').join("'"); return tmp_str; } function strip_tags(input, allowed) { allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, commentsAndPhpTags = /|<\?(?:php)?[\s\S]*?\?>/gi; return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) { return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''; }); } function buildToolbar($container) { var $tbar = []; Ext.get($container).select('>li').each( function() { var html = this.dom.innerHTML; //check for separator if(html == "") { var currentItem = '-'; $tbar.push(currentItem); } else { //normal menu link var link = this.child('a', true); var link_html = link.innerHTML //check for icon try{ var image = this.child('img:first', true); var icon = image.src; if(link_html == "") { var classname = 'x-btn-icon'; } else { var classname = 'x-btn-text-icon'; } } catch(e) { var icon = ""; var classname = 'x-btn-text' } if(link.className == 'disabled') { $disabled = true; } else { $disabled = false; } if(link.className == 'hidden') { $hidden = true; } else { $hidden = false; } var currentItem = { text: link.innerHTML, cls: classname, icon: icon, id: link.id, tooltip: link.title, handler: evalHandler(link.href), menu: eval(link.target), disabled: $disabled, hidden: $hidden }; $tbar.push(currentItem); } }); return $tbar; } function addslashes($string) { $string = $string.replace(/\\/g,'\\\\'); $string = $string.replace(/\'/g,'\\\''); $string = $string.replace(/\0/g,'\\0'); //$string = $string.replace(/\"/g,'\\\"'); return $string; } function cf_formatDollar(field) { var num = $(field).val(); num = num.toString().replace(/[^0-9.]/g,''); if(num!="" && !isNaN(num)) { sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); $(field).val((((sign)?'':'-') + num + '.' + cents)); } else { $(field).val(""); } } /** * The following should be in ext-patches.js, here it causes * a JS error on the log in page. I'm reluctant to move it as * it could cause issues to other parts of m-savvy. */ if (typeof Ext !== 'undefined') { Ext.ns('Ext.ux.plugins'); /** * allow custom value in combobox * if the entered value is not found in the store the value is used as the combos value * * @author Gustav Rek * @date 21.01.2010 * @version 1 * */ Ext.ux.plugins.CustomFilterCombo = function(config) { Ext.apply(this, config); Ext.ux.plugins.CustomFilterCombo.superclass.constructor.call(this); }; Ext.extend(Ext.ux.plugins.CustomFilterCombo, Object, { /** * @cfg {Boolean} anyMatch true to match any part not just the beginning (default=false) */ anyMatch : false, /** * @cfg {Boolean} caseSensitive true for case sensitive comparison (default=false) */ caseSensitive : false, /** * @cfg {Function} filterFn Filter by a function. This function will be called for each * Record in this Store. If the function returns true the Record is included, * otherwise it is filtered out (default=undefined). * When using this parameter anyMathch and caseSensitive are ignored! * @param {Ext.data.Record} record The {@link Ext.data.Record record} * to test for filtering. Access field values using {@link Ext.data.Record#get}. * @param {Object} id The ID of the Record passed. * @param {String} field The field filtered in (normally the displayField of the combo). * Use this with {@link Ext.data.Record#get} to fetch the String to match against. * @param {String} value The value typed in by the user. */ filterFn : undefined, init : function(combo) { this.combo = combo; if(Ext.isFunction(this.filterFn)) { combo.store.filter = this.filterBy.createDelegate(this); } else { // save this funtcion for later use, before we overwrite it combo.store.originalFilter = combo.store.filter; combo.store.filter = this.filter.createDelegate(this); } }, // scope: this filterBy : function(field, value) { this.combo.store.filterBy(this.filterFn.createDelegate(this.combo, [field, value], true)); }, // scope: this filter : function(field, value) { this.combo.store.originalFilter(field, value, this.anyMatch, this.caseSensitive); } }); Ext.preg('customfiltercombo', Ext.ux.plugins.CustomFilterCombo); }