1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
40 * Namespace for Sugar Objects
42 if (typeof(SUGAR) == "undefined") {
46 * Creates a namespace if it doesn't exist and then returns it.
48 * Note: this implementation only creates a top-level namespace. Extend this function if
49 * multi-level namespaces are needed.
52 namespace: function(ns) {
53 SUGAR[ns] = SUGAR[ns] || {};
55 return ((typeof SUGAR[ns] === "object") && (SUGAR[ns] !== null)) ? SUGAR[ns] : false;
59 * Add properties of an object to target object.
63 append: function(target, obj) {
64 for (var prop in obj) {
65 if (obj[prop] !== void 0) target[prop] = obj[prop];
74 SUGAR.namespace("themes");
75 SUGAR.namespace("tour");
78 * Namespace for Homepage
80 SUGAR.namespace("sugarHome");
83 * Namespace for Subpanel Utils
85 SUGAR.namespace("subpanelUtils");
90 SUGAR.namespace("ajaxStatusClass");
95 SUGAR.namespace("tabChooser");
98 * General namespace for Sugar utils
100 SUGAR.namespace("utils");
101 SUGAR.namespace("savedViews");
106 SUGAR.namespace("dashlets");
107 SUGAR.namespace("unifiedSearchAdvanced");
109 SUGAR.namespace("searchForm");
110 SUGAR.namespace("language");
111 SUGAR.namespace("Studio");
112 SUGAR.namespace("contextMenu");
113 SUGAR.namespace("config");
117 var requiredIndex = 2;
122 var altMsgIndex = 15;
123 var compareToIndex = 7;
125 var operatorIndex = 13;
126 var callbackIndex = 16;
128 var validate = new Array();
130 var requiredTxt = 'Missing Required Field:';
131 var invalidTxt = 'Invalid Value:';
132 var secondsSinceLoad = 0;
134 var inputsWithErrors = new Array();
135 var tabsWithErrors = new Array();
136 var lastSubmitTime = 0;
137 var alertList = new Array();
138 var oldStartsWith = '';
143 * As of Sugar version 6.2.3 (MSIE Version 9) this function is deprecated. The preferred method is to use the
144 * user agent check supplied by YUI to check for IE:
146 * for checking if a browser is IE in general : if(YAHOO.env.ua.ie) {...}
148 * or for checking specific versions: if (YAHOO.env.ua.ie >= 5.5 && YAHOO.env.ua.ie < 9) {...}
151 function isSupportedIE() {
152 var userAgent = navigator.userAgent.toLowerCase() ;
154 // IE Check supports ActiveX controls
155 if (userAgent.indexOf("msie") != -1 && userAgent.indexOf("mac") == -1 && userAgent.indexOf("opera") == -1) {
156 var version = navigator.appVersion.match(/MSIE (\d+\.\d+)/)[1] ;
157 if(version >= 5.5 && version < 10) {
165 function checkMinSupported(c, s) {
166 var current = c.split(".");
167 var supported = s.split(".");
168 for (var i in supported) {
169 if (current[i] && parseInt(current[i]) > parseInt(supported[i])) return true;
170 else if (current[i] && parseInt(current[i]) < parseInt(supported[i])) return false;
175 function checkMaxSupported(c, s) {
176 var current = c.split(".");
177 var supported = s.split(".");
178 for (var i in supported) {
179 if (current[i] && parseInt(current[i]) > parseInt(supported[i])) return false;
180 else if (current[i] && parseInt(current[i]) < parseInt(supported[i])) return true;
185 SUGAR.isSupportedBrowser = function(){
186 var supportedBrowsers = {
187 msie : {min:8, max:10}, // IE 8, 9, 10
188 safari : {min:534}, // Safari 5.1
189 mozilla : {min:22.0}, // Firefox 23.0
190 chrome : {min:28} // Chrome 28
192 var current = String($.browser.version);
194 if ($.browser.msie){ // Internet Explorer
195 supported = supportedBrowsers['msie'];
197 else if ($.browser.mozilla) { // Firefox
198 supported = supportedBrowsers['mozilla'];
201 $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
202 if($.browser.chrome){ // Chrome
203 current = navigator.userAgent.match(/Chrome\/(.*?) /)[1];
204 supported = supportedBrowsers['chrome'];
206 else if($.browser.safari){ // Safari
207 supported = supportedBrowsers['safari'];
210 if (current && supported)
211 return checkMinSupported(current, String(supported.min)) && (!supported.max || checkMaxSupported(current, String(supported.max)));
216 SUGAR.isIECompatibilityMode = function(){
217 var agentStr = navigator.userAgent;
219 if (agentStr.indexOf("MSIE 7.0") > -1 &&
220 (agentStr.indexOf("Trident/5.0") > -1 || // IE9 Compatibility View
221 agentStr.indexOf("Trident/4.0") > -1 // IE8 Compatibility View
230 SUGAR.isIE = isSupportedIE();
231 var isSafari = (navigator.userAgent.toLowerCase().indexOf('safari')!=-1);
233 // escapes regular expression characters
234 RegExp.escape = function(text) { // http://simon.incutio.com/archive/2006/01/20/escape
235 if (!arguments.callee.sRE) {
236 var specials = ['/', '.', '*', '+', '?', '|','(', ')', '[', ']', '{', '}', '\\'];
237 arguments.callee.sRE = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
239 return text.replace(arguments.callee.sRE, '\\$1');
242 function addAlert(type, name,subtitle, description,time, redirect) {
243 var addIndex = alertList.length;
244 alertList[addIndex]= new Array();
245 alertList[addIndex]['name'] = name;
246 alertList[addIndex]['type'] = type;
247 alertList[addIndex]['subtitle'] = subtitle;
248 alertList[addIndex]['description'] = replaceHTMLChars(description.replace(/<br>/gi, "\n"));
249 alertList[addIndex]['time'] = time;
250 alertList[addIndex]['done'] = 0;
251 alertList[addIndex]['redirect'] = redirect;
253 function checkAlerts() {
254 secondsSinceLoad += 1;
257 for(mj = 0 ; mj < alertList.length; mj++) {
258 if(alertList[mj]['done'] == 0) {
259 if(alertList[mj]['time'] < secondsSinceLoad && alertList[mj]['time'] > -1 ) {
260 alertmsg = alertList[mj]['type'] + ":" + alertList[mj]['name'] + "\n" +alertList[mj]['subtitle']+ "\n"+ alertList[mj]['description'] + "\n\n";
261 alertList[mj]['done'] = 1;
262 if(alertList[mj]['redirect'] == '') {
265 else if(confirm(alertmsg)) {
266 window.location = alertList[mj]['redirect'];
272 alertsTimeoutId = setTimeout("checkAlerts()", 1000);
275 function toggleDisplay(id) {
276 if(this.document.getElementById(id).style.display == 'none') {
277 this.document.getElementById(id).style.display = '';
278 if(this.document.getElementById(id+"link") != undefined) {
279 this.document.getElementById(id+"link").style.display = 'none';
281 if(this.document.getElementById(id+"_anchor") != undefined)
282 this.document.getElementById(id+"_anchor").innerHTML='[ - ]';
285 this.document.getElementById(id).style.display = 'none';
286 if(this.document.getElementById(id+"link") != undefined) {
287 this.document.getElementById(id+"link").style.display = '';
289 if(this.document.getElementById(id+"_anchor") != undefined)
290 this.document.getElementById(id+"_anchor").innerHTML='[+]';
294 function checkAll(form, field, value) {
295 for (i = 0; i < form.elements.length; i++) {
296 if(form.elements[i].name == field)
297 form.elements[i].checked = value;
301 function replaceAll(text, src, rep) {
302 offset = text.toLowerCase().indexOf(src.toLowerCase());
303 while(offset != -1) {
304 text = text.substring(0, offset) + rep + text.substring(offset + src.length ,text.length);
305 offset = text.indexOf( src, offset + rep.length + 1);
310 function addForm(formname) {
311 validate[formname] = new Array();
314 function addToValidate(formname, name, type, required, msg) {
315 if(typeof validate[formname] == 'undefined') {
318 validate[formname][validate[formname].length] = new Array(name, type,required, msg);
321 // Bug #47961 Callback validator definition
322 function addToValidateCallback(formname, name, type, required, msg, callback)
324 addToValidate(formname, name, type, required, msg);
325 var iIndex = validate[formname].length -1;
326 validate[formname][iIndex][jstypeIndex] = 'callback';
327 validate[formname][iIndex][callbackIndex] = callback;
330 function addToValidateRange(formname, name, type,required, msg,min,max) {
331 addToValidate(formname, name, type,required, msg);
332 validate[formname][validate[formname].length - 1][jstypeIndex] = 'range';
333 validate[formname][validate[formname].length - 1][minIndex] = min;
334 validate[formname][validate[formname].length - 1][maxIndex] = max;
337 function addToValidateIsValidDate(formname, name, type, required, msg) {
338 addToValidate(formname, name, type, required, msg);
339 validate[formname][validate[formname].length - 1][jstypeIndex] = 'date';
342 function addToValidateIsValidTime(formname, name, type, required, msg) {
343 addToValidate(formname, name, type, required, msg);
344 validate[formname][validate[formname].length - 1][jstypeIndex] = 'time';
347 function addToValidateDateBefore(formname, name, type, required, msg, compareTo) {
348 addToValidate(formname, name, type,required, msg);
349 validate[formname][validate[formname].length - 1][jstypeIndex] = 'isbefore';
350 validate[formname][validate[formname].length - 1][compareToIndex] = compareTo;
353 function addToValidateDateBeforeAllowBlank(formname, name, type, required, msg, compareTo, allowBlank) {
354 addToValidate(formname, name, type,required, msg);
355 validate[formname][validate[formname].length - 1][jstypeIndex] = 'isbefore';
356 validate[formname][validate[formname].length - 1][compareToIndex] = compareTo;
357 validate[formname][validate[formname].length - 1][allowblank] = allowBlank;
360 function addToValidateBinaryDependency(formname, name, type, required, msg, compareTo) {
361 addToValidate(formname, name, type, required, msg);
362 validate[formname][validate[formname].length - 1][jstypeIndex] = 'binarydep';
363 validate[formname][validate[formname].length - 1][compareToIndex] = compareTo;
366 function addToValidateComparison(formname, name, type, required, msg, compareTo) {
367 addToValidate(formname, name, type, required, msg);
368 validate[formname][validate[formname].length - 1][jstypeIndex] = 'comparison';
369 validate[formname][validate[formname].length - 1][compareToIndex] = compareTo;
372 function addToValidateIsInArray(formname, name, type, required, msg, arr, operator) {
373 addToValidate(formname, name, type, required, msg);
374 validate[formname][validate[formname].length - 1][jstypeIndex] = 'in_array';
375 validate[formname][validate[formname].length - 1][arrIndex] = arr;
376 validate[formname][validate[formname].length - 1][operatorIndex] = operator;
379 function addToValidateVerified(formname, name, type, required, msg, arr, operator) {
380 addToValidate(formname, name, type, required, msg);
381 validate[formname][validate[formname].length - 1][jstypeIndex] = 'verified';
384 function addToValidateLessThan(formname, name, type, required, msg, max, max_field_msg) {
385 addToValidate(formname, name, type, required, msg);
386 validate[formname][validate[formname].length - 1][jstypeIndex] = 'less';
387 validate[formname][validate[formname].length - 1][maxIndex] = max;
388 validate[formname][validate[formname].length - 1][altMsgIndex] = max_field_msg;
391 function addToValidateMoreThan(formname, name, type, required, msg, min) {
392 addToValidate(formname, name, type, required, msg);
393 validate[formname][validate[formname].length - 1][jstypeIndex] = 'more';
394 validate[formname][validate[formname].length - 1][minIndex] = min;
398 function removeFromValidate(formname, name) {
399 for(i = 0; i < validate[formname].length; i++)
401 if(validate[formname][i][nameIndex] == name)
403 validate[formname].splice(i--,1); // We subtract 1 from i since the slice removed an element, and we'll skip over the next item we scan
407 function checkValidate(formname, name) {
408 if(validate[formname]){
409 for(i = 0; i < validate[formname].length; i++){
410 if(validate[formname][i][nameIndex] == name){
417 var formsWithFieldLogic=null;
418 var formWithPrecision =null;
419 function addToValidateFieldLogic(formId,minFieldId, maxFieldId, defaultFieldId, lenFieldId,type,msg){
420 this.formId = document.getElementById(formId);
421 this.min=document.getElementById(minFieldId);
422 this.max= document.getElementById(maxFieldId);
423 this._default= document.getElementById(defaultFieldId);
424 this.len = document.getElementById(lenFieldId);
428 //@params: formid- Dom id of the form containing the precision and float fields
429 // valudId- Dom id of the field containing a float whose precision is to be checked.
430 // precisionId- Dom id of the field containing precision value.
431 function addToValidatePrecision(formId, valueId, precisionId){
432 this.form = document.getElementById(formId);
433 this.float = document.getElementById(valueId);
434 this.precision = document.getElementById(precisionId);
437 //function checkLength(value, referenceValue){
441 function isValidPrecision(value, precision){
442 value = trim(value.toString());
448 if( (precision == "0") ){
449 if (value.indexOf(dec_sep)== -1){
456 if(value.charAt(value.length-precision-1) == num_grp_sep){
457 if(value.substr(value.indexOf(dec_sep), 1)==dec_sep){
462 var actualPrecision = value.substr(value.indexOf(dec_sep)+1, value.length).length;
463 return actualPrecision == precision;
465 function toDecimal(original, precision) {
466 precision = (precision == null) ? 2 : precision;
467 num = Math.pow(10, precision);
468 temp = Math.round(original*num)/num;
469 if((temp * 100) % 100 == 0)
471 if((temp * 10) % 10 == 0)
476 function isInteger(s) {
477 if(typeof num_grp_sep != 'undefined' && typeof dec_sep != 'undefined')
479 s = unformatNumberNoParse(s, num_grp_sep, dec_sep).toString();
481 return /^[+-]?[0-9]*$/.test(s) ;
484 function isDecimal(s) {
485 if (typeof s == "string" && s == "") // bug# 46530, this is required in order to
486 return true; // not check empty decimal fields
488 if(typeof num_grp_sep != 'undefined' && typeof dec_sep != 'undefined')
490 s = unformatNumberNoParse(s, num_grp_sep, dec_sep).toString();
492 return /^[+-]?[0-9]*\.?[0-9]*$/.test(s) ;
495 function isNumeric(s) {
499 if (typeof date_reg_positions != "object") var date_reg_positions = {'Y': 1,'m': 2,'d': 3};
500 if (typeof date_reg_format != "string") var date_reg_format = '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})';
502 function isDate(dtStr) {
504 if(dtStr.length== 0) {
508 // Check that we have numbers
509 myregexp = new RegExp(date_reg_format)
510 if(!myregexp.test(dtStr))
517 var dateParts = dtStr.match(date_reg_format);
518 for(key in date_reg_positions) {
519 index = date_reg_positions[key];
521 m = dateParts[index];
522 } else if(key == 'd') {
523 d = dateParts[index];
525 y = dateParts[index];
529 // Check that date is real
530 var dd = new Date(y,m,0);
531 // reject negative years
534 // reject month less than 1 and greater than 12
537 // reject days less than 1 or days not in month (e.g. February 30th)
538 if (d < 1 || d > dd.getDate())
543 function getDateObject(dtStr) {
544 if(dtStr.length== 0) {
548 myregexp = new RegExp(date_reg_format)
550 if(myregexp.exec(dtStr)) var dt = myregexp.exec(dtStr)
553 var yr = dt[date_reg_positions['Y']];
554 var mh = dt[date_reg_positions['m']];
555 var dy = dt[date_reg_positions['d']];
556 var dtar = dtStr.split(' ');
557 if(typeof(dtar[1])!='undefined' && isTime(dtar[1])) {//if it is a timedate, we should make date1 to have time value
558 var t1 = dtar[1].replace(/am/i,' AM');
559 var t1 = t1.replace(/pm/i,' PM');
560 //bug #37977: where time format 23.00 causes java script error
561 t1=t1.replace(/\./, ':');
562 date1 = new Date(Date.parse(mh+'/'+dy+ '/'+yr+' '+t1));
566 var date1 = new Date();
567 date1.setFullYear(yr); // xxxx 4 char year
568 date1.setMonth(mh-1); // 0-11 Bug 4048: javascript Date obj months are 0-index
569 date1.setDate(dy); // 1-31
574 function isBefore(value1, value2) {
575 var d1 = getDateObject(value1);
576 var d2 = getDateObject(value2);
577 if(typeof(d2)=='boolean') {// if d2 is not set, we should let it pass, the d2 may not need to be set. the empty check should not be done here.
583 function isValidEmail(emailStr) {
585 if(emailStr.length== 0) {
588 // cn: bug 7128, a period at the end of the string mangles checks. (switched to accept spaces and delimiters)
589 var lastChar = emailStr.charAt(emailStr.length - 1);
590 if(!lastChar.match(/[^\.]/i)) {
593 //bug 40068, According to rules in page 6 of http://www.apps.ietf.org/rfc/rfc3696.html#sec-3,
594 //first character of local part of an email address
595 //should not be a period i.e. '.'
597 var firstLocalChar=emailStr.charAt(0);
598 if(firstLocalChar.match(/\./)){
602 //bug 40068, According to rules in page 6 of http://www.apps.ietf.org/rfc/rfc3696.html#sec-3,
603 //last character of local part of an email address
604 //should not be a period i.e. '.'
606 var pos=emailStr.lastIndexOf("@");
607 var localPart = emailStr.substr(0, pos);
608 var lastLocalChar=localPart.charAt(localPart.length - 1);
609 if(lastLocalChar.match(/\./)){
616 while ((results = reg.exec(emailStr)) != null) {
617 var original = results[0];
618 parsedResult = results[0].replace(';', '::;::');
619 emailStr = emailStr.replace (original, parsedResult);
623 while ((results = reg.exec(emailStr)) != null) {
624 var original = results[0];
625 //Check if we were using ; as a delimiter. If so, skip the commas
626 if(original.indexOf("::;::") == -1) {
627 var parsedResult = results[0].replace(',', '::;::');
628 emailStr = emailStr.replace (original, parsedResult);
632 // mfh: bug 15010 - more practical implementation of RFC 2822 from http://www.regular-expressions.info/email.html, modifed to accept CAPITAL LETTERS
633 //if(!/[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/.test(emailStr))
636 //bug 40068, According to rules in page 6 of http://www.apps.ietf.org/rfc/rfc3696.html#sec-3,
637 //allowed special characters ! # $ % & ' * + - / = ? ^ _ ` . { | } ~ in local part
638 var emailArr = emailStr.split(/::;::/);
639 for (var i = 0; i < emailArr.length; i++) {
640 var emailAddress = emailArr[i];
641 if (trim(emailAddress) != '') {
642 if(!/^\s*[\w.%+\-&'#!\$\*=\?\^_`\{\}~\/]+@([A-Z0-9-]+\.)*[A-Z0-9-]+\.[\w-]{2,}\s*$/i.test(emailAddress) &&
643 !/^.*<[A-Z0-9._%+\-&'#!\$\*=\?\^_`\{\}~]+?@([A-Z0-9-]+\.)*[A-Z0-9-]+\.[\w-]{2,}>\s*$/i.test(emailAddress)) {
652 function isValidPhone(phoneStr) {
653 if(phoneStr.length== 0) {
656 if(!/^[0-9\-\(\)\s]+$/.test(phoneStr))
660 function isFloat(floatStr) {
661 if(floatStr.length== 0) {
664 if(!(typeof(num_grp_sep)=='undefined' || typeof(dec_sep)=='undefined')) {
665 floatStr = unformatNumberNoParse(floatStr, num_grp_sep, dec_sep).toString();
668 return /^(-)?[0-9\.]+$/.test(floatStr);
670 function isDBName(str) {
675 // must start with a letter
676 if(!/^[a-zA-Z][a-zA-Z\_0-9]*$/.test(str))
680 var time_reg_format = "[0-9]{1,2}\:[0-9]{2}";
681 function isTime(timeStr) {
682 var timeRegex = time_reg_format;
683 // eliminate the am/pm from the external time_reg_format
684 timeRegex = timeRegex.replace(/[ ]*\([^)]*m\)/i, '');
685 if(timeStr.length== 0){
688 //we now support multiple time formats
689 myregexp = new RegExp(timeRegex);
690 if(!myregexp.test(timeStr)) {
697 function inRange(value, min, max) {
698 if (typeof num_grp_sep != 'undefined' && typeof dec_sep != 'undefined')
699 value = unformatNumberNoParse(value, num_grp_sep, dec_sep).toString();
701 if (typeof min == 'number' && value < min)
705 if (typeof max == 'number' && value > max)
712 function bothExist(item1, item2) {
713 if(typeof item1 == 'undefined') { return false; }
714 if(typeof item2 == 'undefined') { return false; }
715 if((item1 == '' && item2 != '') || (item1 != '' && item2 == '') ) { return false; }
719 trim = YAHOO.lang.trim;
722 function check_form(formname) {
723 if (typeof(siw) != 'undefined' && siw
724 && typeof(siw.selectingSomething) != 'undefined' && siw.selectingSomething)
726 return validate_form(formname, '');
729 function add_error_style(formname, input, txt, flash) {
730 var raiseFlag = false;
731 if (typeof flash == "undefined")
734 inputHandle = typeof input == "object" ? input : document.forms[formname][input];
735 style = get_current_bgcolor(inputHandle);
737 // strip off the colon at the end of the warning strings
738 if ( txt.substring(txt.length-1) == ':' )
739 txt = txt.substring(0,txt.length-1)
741 // Bug 28249 - To help avoid duplicate messages for an element, strip off extra messages and
742 // match on the field name itself
743 requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
744 invalidTxt = SUGAR.language.get('app_strings', 'ERR_INVALID_VALUE');
745 nomatchTxt = SUGAR.language.get('app_strings', 'ERR_SQS_NO_MATCH_FIELD');
746 matchTxt = txt.replace(requiredTxt,'').replace(invalidTxt,'').replace(nomatchTxt,'');
748 YUI().use('node', function (Y) {
749 Y.one(inputHandle).get('parentNode').get('children').each(function(node, index, nodeList){
750 if(node.hasClass('validation-message') && node.get('text').search(matchTxt)){
757 errorTextNode = document.createElement('div');
758 errorTextNode.className = 'required validation-message';
759 errorTextNode.innerHTML = txt;
760 if ( inputHandle.parentNode.className.indexOf('x-form-field-wrap') != -1 ) {
761 inputHandle.parentNode.parentNode.appendChild(errorTextNode);
764 inputHandle.parentNode.appendChild(errorTextNode);
767 inputHandle.style.backgroundColor = "#FF0000";
768 inputsWithErrors.push(inputHandle);
772 // We only need to setup the flashy-flashy on the first entry, it loops through all fields automatically
773 if ( inputsWithErrors.length == 1 ) {
774 for(var wp = 1; wp <= 10; wp++) {
775 window.setTimeout('fade_error_style(style, '+wp*10+')',1000+(wp*50));
778 if(typeof (window[formname + "_tabs"]) != "undefined") {
779 var tabView = window[formname + "_tabs"];
780 var parentDiv = YAHOO.util.Dom.getAncestorByTagName(inputHandle, "div");
782 var tabs = tabView.get("tabs");
783 for (var i in tabs) {
784 if (tabs[i].get("contentEl") == parentDiv
785 || YAHOO.util.Dom.isAncestor(tabs[i].get("contentEl"), inputHandle))
787 tabs[i].get("labelEl").style.color = "red";
788 if ( inputsWithErrors.length == 1 )
789 tabView.selectTab(i);
794 window.setTimeout("inputsWithErrors[" + (inputsWithErrors.length - 1) + "].style.backgroundColor = '';", 2000);
798 // Catch errors here so we don't allow an incomplete record through the javascript validation
804 * removes all error messages for the current form
806 function clear_all_errors() {
807 for(var wp = 0; wp < inputsWithErrors.length; wp++) {
808 if(typeof(inputsWithErrors[wp]) !='undefined' && typeof inputsWithErrors[wp].parentNode != 'undefined' && inputsWithErrors[wp].parentNode != null) {
809 if ( inputsWithErrors[wp].parentNode.className.indexOf('x-form-field-wrap') != -1 )
811 inputsWithErrors[wp].parentNode.parentNode.removeChild(inputsWithErrors[wp].parentNode.parentNode.lastChild);
815 inputsWithErrors[wp].parentNode.removeChild(inputsWithErrors[wp].parentNode.lastChild);
819 if (inputsWithErrors.length == 0) return;
821 if ( YAHOO.util.Dom.getAncestorByTagName(inputsWithErrors[0], "form") ) {
822 var formname = YAHOO.util.Dom.getAncestorByTagName(inputsWithErrors[0], "form").getAttribute("name");
823 if(typeof (window[formname + "_tabs"]) != "undefined") {
824 var tabView = window[formname + "_tabs"];
826 var tabs = tabView.get("tabs");
827 for (var i in tabs) {
828 if (typeof tabs[i] == "object")
829 tabs[i].get("labelEl").style.color = "";
833 inputsWithErrors = new Array();
837 function get_current_bgcolor(input) {
838 if(input.currentStyle) {// ie
839 style = input.currentStyle.backgroundColor;
840 return style.substring(1,7);
844 styleRGB = document.defaultView.getComputedStyle(input, '').getPropertyValue("background-color");
845 comma = styleRGB.indexOf(',');
846 style += dec2hex(styleRGB.substring(4, comma));
847 commaPrevious = comma;
848 comma = styleRGB.indexOf(',', commaPrevious+1);
849 style += dec2hex(styleRGB.substring(commaPrevious+2, comma));
850 style += dec2hex(styleRGB.substring(comma+2, styleRGB.lastIndexOf(')')));
855 function hex2dec(hex){return(parseInt(hex,16));}
856 var hexDigit=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
857 function dec2hex(dec){return(hexDigit[dec>>4]+hexDigit[dec&15]);}
859 function fade_error_style(normalStyle, percent) {
860 errorStyle = 'c60c30';
861 var r1 = hex2dec(errorStyle.slice(0,2));
862 var g1 = hex2dec(errorStyle.slice(2,4));
863 var b1 = hex2dec(errorStyle.slice(4,6));
865 var r2 = hex2dec(normalStyle.slice(0,2));
866 var g2 = hex2dec(normalStyle.slice(2,4));
867 var b2 = hex2dec(normalStyle.slice(4,6));
870 var pc = percent / 100;
872 r= Math.floor(r1+(pc*(r2-r1)) + .5);
873 g= Math.floor(g1+(pc*(g2-g1)) + .5);
874 b= Math.floor(b1+(pc*(b2-b1)) + .5);
876 for(var wp = 0; wp < inputsWithErrors.length; wp++) {
877 inputsWithErrors[wp].style.backgroundColor = "#" + dec2hex(r) + dec2hex(g) + dec2hex(b);
881 function isFieldTypeExceptFromEmptyCheck(fieldType)
884 var exemptList = ['bool','file'];
885 for(var i=0;i<exemptList.length;i++)
887 if(fieldType == exemptList[i])
892 function validate_form(formname, startsWith){
893 requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
894 invalidTxt = SUGAR.language.get('app_strings', 'ERR_INVALID_VALUE');
896 if ( typeof (formname) == 'undefined')
900 if ( typeof (validate[formname]) == 'undefined')
902 disableOnUnloadEditView(document.forms[formname]);
906 var form = document.forms[formname];
909 var _date = new Date();
910 if(_date.getTime() < (lastSubmitTime + 2000) && startsWith == oldStartsWith) { // ignore submits for the next 2 seconds
913 lastSubmitTime = _date.getTime();
914 oldStartsWith = startsWith;
916 clear_all_errors(); // remove previous error messages
918 inputsWithErrors = new Array();
919 for(var i = 0; i < validate[formname].length; i++){
920 if(validate[formname][i][nameIndex].indexOf(startsWith) == 0){
921 if(typeof form[validate[formname][i][nameIndex]] != 'undefined' && typeof form[validate[formname][i][nameIndex]].value != 'undefined'){
925 //If a field is not required and it is blank or is binarydependant, skip validation.
926 //Example of binary dependant fields would be the hour/min/meridian dropdowns in a date time combo widget, which require further processing than a blank check
927 if(!validate[formname][i][requiredIndex] && trim(form[validate[formname][i][nameIndex]].value) == '' && (typeof(validate[formname][i][jstypeIndex]) != 'undefined' && validate[formname][i][jstypeIndex] != 'binarydep'))
932 if(validate[formname][i][requiredIndex]
933 && !isFieldTypeExceptFromEmptyCheck(validate[formname][i][typeIndex])
935 if(typeof form[validate[formname][i][nameIndex]] == 'undefined' || trim(form[validate[formname][i][nameIndex]].value) == ""){
936 add_error_style(formname, validate[formname][i][nameIndex], requiredTxt +' ' + validate[formname][i][msgIndex]);
941 switch(validate[formname][i][typeIndex]){
943 if(!isValidEmail(trim(form[validate[formname][i][nameIndex]].value))){
945 add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
949 if( !isTime(trim(form[validate[formname][i][nameIndex]].value))){
951 add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
953 case 'date': if(!isDate(trim(form[validate[formname][i][nameIndex]].value))){
955 add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
960 if(!isDBName(trim(form[validate[formname][i][nameIndex]].value))){
962 add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
965 // Bug #49614 : Check value without trimming before
967 if(!isDBName(form[validate[formname][i][nameIndex]].value)){
969 add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
975 var file_input = form[validate[formname][i][nameIndex] + '_file'];
976 if( file_input && validate[formname][i][requiredIndex] && trim(file_input.value) == "" && !file_input.disabled ) {
978 add_error_style(formname, validate[formname][i][nameIndex], requiredTxt + " " + validate[formname][i][msgIndex]);
982 if(!isInteger(trim(form[validate[formname][i][nameIndex]].value))){
984 add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
988 if(!isDecimal(trim(form[validate[formname][i][nameIndex]].value))){
990 add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
995 if(!isFloat(trim(form[validate[formname][i][nameIndex]].value))){
997 add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
1000 case 'teamset_mass':
1001 var div_element_id = formname + '_' + form[validate[formname][i][nameIndex]].name + '_operation_div';
1002 var input_elements = YAHOO.util.Selector.query('input', document.getElementById(div_element_id));
1003 var primary_field_id = '';
1004 var validation_passed = false;
1005 var replace_selected = false;
1007 //Loop through the option elements (replace or add currently)
1008 for(t in input_elements) {
1009 if(input_elements[t].type && input_elements[t].type == 'radio' && input_elements[t].checked == true && input_elements[t].value == 'replace') {
1011 //Now find where the primary radio button is and if a value has been set
1012 var radio_elements = YAHOO.util.Selector.query('input[type=radio]', document.getElementById(formname + '_team_name_table'));
1014 for(var x = 0; x < radio_elements.length; x++) {
1015 if(radio_elements[x].name != 'team_name_type') {
1016 primary_field_id = 'team_name_collection_' + radio_elements[x].value;
1017 if(radio_elements[x].checked) {
1018 replace_selected = true;
1019 if(trim(document.forms[formname].elements[primary_field_id].value) != '') {
1020 validation_passed = true;
1023 } else if(trim(document.forms[formname].elements[primary_field_id].value) != '') {
1024 replace_selected = true;
1031 if(replace_selected && !validation_passed) {
1032 add_error_style(formname, primary_field_id, SUGAR.language.get('app_strings', 'ERR_NO_PRIMARY_TEAM_SPECIFIED'));
1037 var table_element_id = formname + '_' + form[validate[formname][i][nameIndex]].name + '_table';
1038 if(document.getElementById(table_element_id)) {
1039 var input_elements = YAHOO.util.Selector.query('input[type=radio]', document.getElementById(table_element_id));
1040 var has_primary = false;
1041 var primary_field_id = form[validate[formname][i][nameIndex]].name + '_collection_0';
1043 for(t in input_elements) {
1044 primary_field_id = form[validate[formname][i][nameIndex]].name + '_collection_' + input_elements[t].value;
1045 if(input_elements[t].type && input_elements[t].type == 'radio' && input_elements[t].checked == true) {
1046 if(document.forms[formname].elements[primary_field_id].value != '') {
1055 var field_id = form[validate[formname][i][nameIndex]].name + '_collection_' + input_elements[0].value;
1056 add_error_style(formname, field_id, SUGAR.language.get('app_strings', 'ERR_NO_PRIMARY_TEAM_SPECIFIED'));
1062 add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex]);
1066 if(typeof validate[formname][i][jstypeIndex] != 'undefined'/* && !isError*/){
1068 switch(validate[formname][i][jstypeIndex]){
1069 // Bug #47961 May be validation through callback is best way.
1071 if (typeof validate[formname][i][callbackIndex] == 'function')
1073 var result = validate[formname][i][callbackIndex](formname, validate[formname][i][nameIndex]);
1074 if (result == false)
1077 add_error_style(formname, validate[formname][i][nameIndex], requiredTxt + " " + validate[formname][i][msgIndex]);
1082 if(!inRange(trim(form[validate[formname][i][nameIndex]].value), validate[formname][i][minIndex], validate[formname][i][maxIndex])){
1084 var lbl_validate_range = SUGAR.language.get('app_strings', 'LBL_VALIDATE_RANGE');
1085 if (typeof validate[formname][i][minIndex] == 'number' && typeof validate[formname][i][maxIndex] == 'number')
1087 add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + " value " + form[validate[formname][i][nameIndex]].value + " " + lbl_validate_range + " (" +validate[formname][i][minIndex] + " - " + validate[formname][i][maxIndex] + ")");
1089 else if (typeof validate[formname][i][minIndex] == 'number')
1091 add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + " " + SUGAR.language.get('app_strings', 'MSG_SHOULD_BE') + ' ' + validate[formname][i][minIndex] + ' ' + SUGAR.language.get('app_strings', 'MSG_OR_GREATER'));
1093 else if (typeof validate[formname][i][maxIndex] == 'number')
1095 add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + " " + SUGAR.language.get('app_strings', 'MSG_IS_MORE_THAN') + ' ' + validate[formname][i][maxIndex]);
1100 compareTo = form[validate[formname][i][compareToIndex]];
1101 if( typeof compareTo != 'undefined'){
1102 if(trim(compareTo.value) != '' || (validate[formname][i][allowblank] != 'true') ) {
1103 date2 = trim(compareTo.value);
1104 date1 = trim(form[validate[formname][i][nameIndex]].value);
1106 if(trim(date1).length != 0 && !isBefore(date1,date2)){
1109 //jc:#12287 - adding translation for the is not before message
1110 add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + "(" + date1 + ") " + SUGAR.language.get('app_strings', 'MSG_IS_NOT_BEFORE') + ' ' +date2);
1116 value=unformatNumber(trim(form[validate[formname][i][nameIndex]].value), num_grp_sep, dec_sep);
1117 maximum = parseFloat(validate[formname][i][maxIndex]);
1118 if( typeof maximum != 'undefined'){
1121 add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] +" " +SUGAR.language.get('app_strings', 'MSG_IS_MORE_THAN')+ ' ' + validate[formname][i][altMsgIndex]);
1126 value=unformatNumber(trim(form[validate[formname][i][nameIndex]].value), num_grp_sep, dec_sep);
1127 minimum = parseFloat(validate[formname][i][minIndex]);
1128 if( typeof minimum != 'undefined'){
1131 add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] +" " +SUGAR.language.get('app_strings', 'MSG_SHOULD_BE')+ ' ' + minimum + ' ' + SUGAR.language.get('app_strings', 'MSG_OR_GREATER'));
1136 compareTo = form[validate[formname][i][compareToIndex]];
1137 if( typeof compareTo != 'undefined') {
1138 item1 = trim(form[validate[formname][i][nameIndex]].value);
1139 item2 = trim(compareTo.value);
1140 if(!bothExist(item1, item2)) {
1142 add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex]);
1147 compareTo = form[validate[formname][i][compareToIndex]];
1148 if( typeof compareTo != 'undefined') {
1149 item1 = trim(form[validate[formname][i][nameIndex]].value);
1150 item2 = trim(compareTo.value);
1151 if(!bothExist(item1, item2) || item1 != item2) {
1153 add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex]);
1158 arr = eval(validate[formname][i][arrIndex]);
1159 operator = validate[formname][i][operatorIndex];
1160 item1 = trim(form[validate[formname][i][nameIndex]].value);
1161 if (operator.charAt(0) == 'u') {
1162 item1 = item1.toUpperCase();
1163 operator = operator.substring(1);
1164 } else if (operator.charAt(0) == 'l') {
1165 item1 = item1.toLowerCase();
1166 operator = operator.substring(1);
1168 for(j = 0; j < arr.length; j++){
1170 if((operator == "==" && val == item1) || (operator == "!=" && val != item1)){
1172 add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
1177 if(trim(form[validate[formname][i][nameIndex]].value) == 'false'){
1178 //Fake an error so form does not submit
1188 /* nsingh: BUG#15102
1189 Check min max default field logic.
1190 Can work with float values as well, but as of 10/8/07 decimal values in MB and studio don't have min and max value constraints.*/
1191 if(formsWithFieldLogic){
1192 var invalidLogic=false;
1193 if(formsWithFieldLogic.min && formsWithFieldLogic.max && formsWithFieldLogic._default) {
1194 var showErrorsOn={min:{value:'min', show:false, obj:formsWithFieldLogic.min.value},
1195 max:{value:'max',show:false, obj:formsWithFieldLogic.max.value},
1196 _default:{value:'default',show:false, obj:formsWithFieldLogic._default.value},
1197 len:{value:'len', show:false, obj:parseInt(formsWithFieldLogic.len.value,10)}};
1199 var min = (formsWithFieldLogic.min.value !='') ? parseFloat(formsWithFieldLogic.min.value) : 'undef';
1200 var max = (formsWithFieldLogic.max.value !='') ? parseFloat(formsWithFieldLogic.max.value) : 'undef';
1201 var _default = (formsWithFieldLogic._default.value!='')? parseFloat(formsWithFieldLogic._default.value) : 'undef';
1203 /*Check all lengths are <= max size.*/
1204 for(var i in showErrorsOn){
1205 if(showErrorsOn[i].value!='len' && showErrorsOn[i].obj.length > showErrorsOn.len.obj){
1207 showErrorsOn[i].show=true;
1208 showErrorsOn.len.show=true;
1212 if(min!='undef' && max!='undef' && _default!='undef'){
1213 if(!inRange(_default,min,max)){
1215 showErrorsOn.min.show=true;
1216 showErrorsOn.max.show=true;
1217 showErrorsOn._default.show=true;
1220 if(min!='undef' && max!= 'undef' && min > max){
1221 invalidLogic = true;
1222 showErrorsOn.min.show=true;
1223 showErrorsOn.max.show=true;
1225 if(min!='undef' && _default!='undef' && _default < min){
1227 invalidLogic = true;
1228 showErrorsOn.min.show=true;
1229 showErrorsOn._default.show=true;
1231 if(max!='undef' && _default !='undef' && _default>max){
1233 invalidLogic = true;
1234 showErrorsOn.max.show=true;
1235 showErrorsOn._default.show=true;
1240 for(var error in showErrorsOn)
1241 if(showErrorsOn[error].show)
1242 add_error_style(formname,showErrorsOn[error].value, formsWithFieldLogic.msg);
1247 formsWithFieldLogic = null;
1250 if(formWithPrecision){
1251 if (!isValidPrecision(formWithPrecision.float.value, formWithPrecision.precision.value)){
1253 add_error_style(formname, 'default', SUGAR.language.get('app_strings', 'ERR_COMPATIBLE_PRECISION_VALUE'));
1261 if (isError == true) {
1263 if (self.pageYOffset) // all except Explorer
1265 nwX = self.pageXOffset;
1266 seX = self.innerWidth;
1267 nwY = self.pageYOffset;
1268 seY = self.innerHeight;
1270 else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
1272 nwX = document.documentElement.scrollLeft;
1273 seX = document.documentElement.clientWidth;
1274 nwY = document.documentElement.scrollTop;
1275 seY = document.documentElement.clientHeight;
1277 else if (document.body) // all other Explorers
1279 nwX = document.body.scrollLeft;
1280 seX = document.body.clientWidth;
1281 nwY = document.body.scrollTop;
1282 seY = document.body.clientHeight;
1285 var inView = true; // is there an error within viewport of browser
1286 for(var wp = 0; wp < inputsWithErrors.length; wp++) {
1287 var elementCoor = findElementPos(inputsWithErrors[wp]);
1288 if(!(elementCoor.x >= nwX && elementCoor.y >= nwY &&
1289 elementCoor.x <= seX+nwX && elementCoor.y <= seY+nwY)) { // if input is not within viewport, modify for SI bug 52497
1291 scrollToTop = elementCoor.y - 75;
1292 scrollToLeft = elementCoor.x - 75;
1294 else { // on first input within viewport, don't scroll
1300 if(!inView) window.scrollTo(scrollToLeft,scrollToTop);
1305 disableOnUnloadEditView(form);
1312 * This array is used to remember mark status of rows in browse mode
1314 var marked_row = new Array;
1318 * Sets/unsets the pointer and marker in browse mode
1320 * @param object the table row
1321 * @param interger the row number
1322 * @param string the action calling this script (over, out or click)
1323 * @param string the default background color
1324 * @param string the color to use for mouseover
1325 * @param string the color to use for marking a row
1327 * @return boolean whether pointer is set or not
1329 function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) {
1330 var theCells = null;
1332 // 1. Pointer and mark feature are disabled or the browser can't get the
1334 if ((thePointerColor == '' && theMarkColor == '')
1335 || typeof(theRow.style) == 'undefined') {
1339 // 2. Gets the current row and exits if the browser can't get it
1340 if (typeof(document.getElementsByTagName) != 'undefined') {
1341 theCells = theRow.getElementsByTagName('td');
1343 else if (typeof(theRow.cells) != 'undefined') {
1344 theCells = theRow.cells;
1350 // 3. Gets the current color...
1351 var rowCellsCnt = theCells.length;
1352 var domDetect = null;
1353 var currentColor = null;
1354 var newColor = null;
1355 // 3.1 ... with DOM compatible browsers except Opera that does not return
1356 // valid values with "getAttribute"
1357 if (typeof(window.opera) == 'undefined'
1358 && typeof(theCells[0].getAttribute) != 'undefined') {
1359 currentColor = theCells[0].getAttribute('bgcolor');
1362 // 3.2 ... with other browsers
1364 currentColor = theCells[0].style.backgroundColor;
1368 // 4. Defines the new color
1369 // 4.1 Current color is the default one
1370 if (currentColor == ''
1371 || (currentColor!= null && (currentColor.toLowerCase() == theDefaultColor.toLowerCase()))) {
1372 if (theAction == 'over' && thePointerColor != '') {
1373 newColor = thePointerColor;
1375 else if (theAction == 'click' && theMarkColor != '') {
1376 newColor = theMarkColor;
1377 marked_row[theRowNum] = true;
1380 // 4.1.2 Current color is the pointer one
1381 else if (currentColor!= null && (currentColor.toLowerCase() == thePointerColor.toLowerCase())
1382 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
1383 if (theAction == 'out') {
1384 newColor = theDefaultColor;
1386 else if (theAction == 'click' && theMarkColor != '') {
1387 newColor = theMarkColor;
1388 marked_row[theRowNum] = true;
1391 // 4.1.3 Current color is the marker one
1392 else if (currentColor!= null && (currentColor.toLowerCase() == theMarkColor.toLowerCase())) {
1393 if (theAction == 'click') {
1394 newColor = (thePointerColor != '')
1397 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
1403 // 5. Sets the new color...
1406 // 5.1 ... with DOM compatible browsers except Opera
1408 for (c = 0; c < rowCellsCnt; c++) {
1409 theCells[c].setAttribute('bgcolor', newColor, 0);
1412 // 5.2 ... with other browsers
1414 for (c = 0; c < rowCellsCnt; c++) {
1415 theCells[c].style.backgroundColor = newColor;
1421 } // end of the 'setPointer()' function
1425 * listbox redirection
1427 function goToUrl(selObj, goToLocation) {
1428 eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
1433 var json_objects = new Object();
1435 function getXMLHTTPinstance() {
1436 var xmlhttp = false;
1437 var userAgent = navigator.userAgent.toLowerCase() ;
1439 // IE Check supports ActiveX controls
1440 if (userAgent.indexOf("msie") != -1 && userAgent.indexOf("mac") == -1 && userAgent.indexOf("opera") == -1) {
1441 var version = navigator.appVersion.match(/MSIE (\d+\.\d+)/)[1] ;
1442 if(version >= 5.5 ) {
1444 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
1448 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
1457 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
1458 xmlhttp = new XMLHttpRequest();
1463 // NOW LOAD THE OBJECT..
1464 var global_xmlhttp = getXMLHTTPinstance();
1466 function http_fetch_sync(url,post_data) {
1467 global_xmlhttp = getXMLHTTPinstance();
1470 if(typeof(post_data) != 'undefined') method = 'POST';
1472 global_xmlhttp.open(method, url,false);
1475 alert('message:'+e.message+":url:"+url);
1477 if(method == 'POST') {
1478 global_xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1481 global_xmlhttp.send(post_data);
1483 if (SUGAR.util.isLoginPage(global_xmlhttp.responseText))
1486 var args = {"responseText" : global_xmlhttp.responseText,
1487 "responseXML" : global_xmlhttp.responseXML,
1488 "request_id" : typeof(request_id) != "undefined" ? request_id : 0};
1492 // this is a GET unless post_data is defined
1494 function http_fetch_async(url,callback,request_id,post_data) {
1496 if(typeof(post_data) != 'undefined') {
1501 global_xmlhttp.open(method, url,true);
1504 alert('message:'+e.message+":url:"+url);
1506 if(method == 'POST') {
1507 global_xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1509 global_xmlhttp.onreadystatechange = function() {
1510 if(global_xmlhttp.readyState==4) {
1511 if(global_xmlhttp.status == 200) {
1512 if (SUGAR.util.isLoginPage(global_xmlhttp.responseText))
1514 var args = {"responseText" : global_xmlhttp.responseText,
1515 "responseXML" : global_xmlhttp.responseXML,
1516 "request_id" : request_id };
1517 callback.call(document,args);
1520 alert("There was a problem retrieving the XML data:\n" + global_xmlhttp.statusText);
1524 global_xmlhttp.send(post_data);
1527 function insert_at_cursor(field, value) {
1529 if (document.selection) {
1531 sel = document.selection.createRange();
1535 else if(field.selectionStart || field.selectionStart == '0') {
1536 var start_pos = field.selectionStart;
1537 var end_pos = field.selectionEnd;
1538 field.value = field.value.substring(0, start_pos) + value + field.value.substring(end_pos, field.value.length);
1541 field.value += value;
1545 function checkParentType(type,button) {
1546 if(button == null) {
1549 if(typeof disabledModules != 'undefined' && typeof(disabledModules[type]) != 'undefined') {
1550 button.disabled='disabled';
1553 button.disabled = false;
1557 function parseDate(input, format) {
1559 format = format.replace(/%/g, '');
1560 sep = format.charAt(1);
1561 yAt = format.indexOf('Y')
1562 // 1-1-06 or 1-12-06 or 1-1-2006 or 1-12-2006
1563 if(date.match(/^\d{1,2}[\/-]\d{1,2}[\/-]\d{2,4}$/) && yAt == 4) {
1564 if(date.match(/^\d{1}[\/-].*$/)) date = '0' + date;
1565 if(date.match(/^\d{2}[\/-]\d{1}[\/-].*$/)) date = date.substring(0,3) + '0' + date.substring(3,date.length);
1566 if(date.match(/^\d{2}[\/-]\d{2}[\/-]\d{2}$/)) date = date.substring(0,6) + '20' + date.substring(6,date.length);
1568 // 06-11-1 or 06-1-1
1569 else if(date.match(/^\d{2,4}[\/-]\d{1,2}[\/-]\d{1,2}$/)) {
1570 if(date.match(/^\d{2}[\/-].*$/)) date = '20' + date;
1571 if(date.match(/^\d{4}[\/-]\d{1}[\/-].*$/)) date = date.substring(0,5) + '0' + date.substring(5,date.length);
1572 if(date.match(/^\d{4}[\/-]\d{2}[\/-]\d{1}$/)) date = date.substring(0,8) + '0' + date.substring(8,date.length);
1574 else if(date.match(/^\d{4,8}$/)) { // digits only
1576 if(date.match(/^\d{8}$/)) digits = 8;// match for 8 digits
1577 else if(date.match(/\d{6}/)) digits = 6;// match for 5 digits
1578 else if(date.match(/\d{4}/)) digits = 4;// match for 5 digits
1579 else if(date.match(/\d{5}/)) digits = 5;// match for 5 digits
1584 case 4: date = '20' + date.substring(0,2) + sep + '0' + date.substring(2, 3) + sep + '0' + date.substring(3,4); break;
1585 case 5: date = '20' + date.substring(0,2) + sep + date.substring(2, 4) + sep + '0' + date.substring(4,5); break;
1586 case 6: date = '20' + date.substring(0,2) + sep + date.substring(2, 4) + sep + date.substring(4,6); break;
1587 case 8: date = date.substring(0,4) + sep + date.substring(4, 6) + sep + date.substring(6,8); break;
1592 case 4: date = '0' + date.substring(0,1) + sep + '20' + date.substring(1, 3) + sep + '0' + date.substring(3,4); break;
1593 case 5: date = date.substring(0,2) + sep + '20' + date.substring(2, 4) + sep + '0' + date.substring(4,5); break;
1594 case 6: date = date.substring(0,2) + sep + '20' + date.substring(2, 4) + sep + date.substring(4,6); break;
1595 case 8: date = date.substring(0,2) + sep + date.substring(2, 6) + sep + date.substring(6,8); break;
1599 case 4: date = '0' + date.substring(0,1) + sep + '0' + date.substring(1, 2) + sep + '20' + date.substring(2,4); break;
1600 case 5: date = '0' + date.substring(0,1) + sep + date.substring(1, 3) + sep + '20' + date.substring(3,5); break;
1601 case 6: date = date.substring(0,2) + sep + date.substring(2, 4) + sep + '20' + date.substring(4,6); break;
1602 case 8: date = date.substring(0,2) + sep + date.substring(2, 4) + sep + date.substring(4,8); break;
1607 date = date.replace(/[\/-]/g, sep);
1611 // find obj's position
1612 function findElementPos(obj) {
1615 if (obj.offsetParent) {
1616 while (obj.offsetParent) {
1617 x += obj.offsetLeft;
1619 obj = obj.offsetParent;
1621 }//if offsetParent exists
1622 else if (obj.x && obj.y) {
1626 return new coordinate(x, y);
1630 // get dimensions of the browser window
1631 function getClientDim() {
1632 var nwX, nwY, seX, seY;
1633 if (self.pageYOffset) // all except Explorer
1635 nwX = self.pageXOffset;
1636 seX = self.innerWidth + nwX;
1637 nwY = self.pageYOffset;
1638 seY = self.innerHeight + nwY;
1640 else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
1642 nwX = document.documentElement.scrollLeft;
1643 seX = document.documentElement.clientWidth + nwX;
1644 nwY = document.documentElement.scrollTop;
1645 seY = document.documentElement.clientHeight + nwY;
1647 else if (document.body) // all other Explorers
1649 nwX = document.body.scrollLeft;
1650 seX = document.body.clientWidth + nwX;
1651 nwY = document.body.scrollTop;
1652 seY = document.body.clientHeight + nwY;
1654 return {'nw' : new coordinate(nwX, nwY), 'se' : new coordinate(seX, seY)};
1658 * stop propagation on events
1660 function freezeEvent(e) {
1662 if (e.preventDefault) e.preventDefault();
1663 e.returnValue = false;
1664 e.cancelBubble = true;
1665 if (e.stopPropagation) e.stopPropagation();
1674 function coordinate(_x, _y) {
1683 return new position(this.x + rh.x, this.y + rh.y);
1687 return new position(this.x + rh.x, this.y + rh.y);
1691 // sends theForm via AJAX and fills in the theDiv
1692 function sendAndRetrieve(theForm, theDiv, loadingStr) {
1693 function success(data) {
1694 document.getElementById(theDiv).innerHTML = data.responseText;
1695 ajaxStatus.hideStatus();
1697 if(typeof loadingStr == 'undefined') SUGAR.language.get('app_strings', 'LBL_LOADING');
1698 ajaxStatus.showStatus(loadingStr);
1699 oForm = new YAHOO.util.Element(theForm);
1700 if ( oForm.get('enctype') && oForm.get('enctype') == 'multipart/form-data' ) {
1701 // the second argument is true to indicate file upload.
1702 YAHOO.util.Connect.setForm(theForm, true);
1703 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', {upload: success, failure: success});
1705 YAHOO.util.Connect.setForm(theForm);
1706 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success});
1711 //save the form and redirect
1712 function sendAndRedirect(theForm, loadingStr, redirect_location) {
1713 function success(data) {
1714 if(redirect_location){
1715 location.href=redirect_location;
1717 ajaxStatus.hideStatus();
1719 if(typeof loadingStr == 'undefined') SUGAR.language.get('app_strings', 'LBL_LOADING');
1720 ajaxStatus.showStatus(loadingStr);
1721 oForm = new YAHOO.util.Element(theForm);
1722 if ( oForm.get('enctype') && oForm.get('enctype') == 'multipart/form-data' ) {
1723 // the second argument is true to indicate file upload.
1724 YAHOO.util.Connect.setForm(theForm, true);
1725 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', {upload: success, failure: success});
1727 YAHOO.util.Connect.setForm(theForm);
1728 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success});
1733 function saveForm(theForm, theDiv, loadingStr) {
1734 if(check_form(theForm)){
1735 for(i = 0; i < ajaxFormArray.length; i++){
1736 if(ajaxFormArray[i] == theForm){
1737 ajaxFormArray.splice(i, 1);
1740 return sendAndRetrieve(theForm, loadingStr, theDiv);
1746 // Builds a "snapshot" of the form, so we can use it to see if someone has changed it.
1747 function snapshotForm(theForm) {
1748 var snapshotTxt = '';
1749 var elemList = theForm.elements;
1753 for( var i = 0; i < elemList.length ; i++ ) {
1755 if ( typeof(elem.type) == 'undefined' ) {
1759 elemType = elem.type.toLowerCase();
1761 snapshotTxt = snapshotTxt + elem.name;
1763 if ( elemType == 'text' || elemType == 'textarea' || elemType == 'password' ) {
1764 snapshotTxt = snapshotTxt + elem.value;
1766 else if ( elemType == 'select' || elemType == 'select-one' || elemType == 'select-multiple' ) {
1767 var optionList = elem.options;
1768 for ( var ii = 0 ; ii < optionList.length ; ii++ ) {
1769 if ( optionList[ii].selected ) {
1770 snapshotTxt = snapshotTxt + optionList[ii].value;
1774 else if ( elemType == 'radio' || elemType == 'checkbox' ) {
1775 if ( elem.selected ) {
1776 snapshotTxt = snapshotTxt + 'checked';
1779 else if ( elemType == 'hidden' ) {
1780 snapshotTxt = snapshotTxt + elem.value;
1787 function initEditView(theForm) {
1788 if (SUGAR.util.ajaxCallInProgress()) {
1789 window.setTimeout(function(){initEditView(theForm);}, 100);
1793 if ( theForm == null || theForm.id == null ) {
1794 // Not much we can do here.
1798 // we don't need to check if the data is changed in the search popup
1799 if (theForm.id == 'popup_query_form' || theForm.id == 'MassUpdate') {
1802 if ( typeof editViewSnapshots == 'undefined' || editViewSnapshots == null ) {
1803 editViewSnapshots = new Object();
1805 if ( typeof SUGAR.loadedForms == 'undefined' || SUGAR.loadedForms == null) {
1806 SUGAR.loadedForms = new Object();
1809 editViewSnapshots[theForm.id] = snapshotForm(theForm);
1810 SUGAR.loadedForms[theForm.id] = true;
1813 function onUnloadEditView(theForm) {
1815 var dataHasChanged = false;
1816 if ( typeof editViewSnapshots == 'undefined' ) {
1817 // No snapshots, move along
1821 if ( typeof theForm == 'undefined' ) {
1822 // Need to check all editViewSnapshots
1823 for ( var idx in editViewSnapshots ) {
1825 theForm = document.getElementById(idx);
1826 // console.log('DEBUG: Checking all forms '+theForm.id);
1827 if ( theForm == null
1828 || typeof editViewSnapshots[theForm.id] == 'undefined'
1829 || editViewSnapshots[theForm.id] == null
1830 || !SUGAR.loadedForms[theForm.id]) {
1834 var snap = snapshotForm(theForm);
1835 if ( editViewSnapshots[theForm.id] != snap ) {
1836 dataHasChanged = true;
1840 // Just need to check a single form for changes
1841 if ( editViewSnapshots == null || typeof theForm.id == 'undefined' || typeof editViewSnapshots[theForm.id] == 'undefined' || editViewSnapshots[theForm.id] == null ) {
1845 // console.log('DEBUG: Checking one form '+theForm.id);
1846 if ( editViewSnapshots[theForm.id] != snapshotForm(theForm) ) {
1847 // Data has changed.
1848 dataHasChanged = true;
1852 if ( dataHasChanged == true ) {
1853 return SUGAR.language.get('app_strings','WARN_UNSAVED_CHANGES');
1860 function disableOnUnloadEditView(theForm) {
1861 // If you don't pass anything in, it disables all checking
1862 if ( typeof theForm == 'undefined' || typeof editViewSnapshots == 'undefined' || theForm == null || editViewSnapshots == null) {
1863 window.onbeforeunload = null;
1864 editViewSnapshots = null;
1866 // console.log('DEBUG: Disabling all edit view checks');
1869 // Otherwise, it just disables it for this form
1870 if ( typeof(theForm.id) != 'undefined' && typeof(editViewSnapshots[theForm.id]) != 'undefined' ) {
1871 editViewSnapshots[theForm.id] = null;
1874 // console.log('DEBUG : Disabling just checks for '+theForm.id);
1880 * save some forms using an ajax call
1881 * theForms - the ids of all of theh forms to save
1882 * savingStr - the string to display when saving the form
1883 * completeStr - the string to display when the form has been saved
1885 function saveForms( savingStr, completeStr) {
1887 theForms = ajaxFormArray;
1888 function success(data) {
1889 var theForm = document.getElementById(ajaxFormArray[0]);
1890 document.getElementById('multiedit_'+theForm.id).innerHTML = data.responseText;
1891 var saveAllButton = document.getElementById('ajaxsaveall');
1892 ajaxFormArray.splice(index, 1);
1893 if(saveAllButton && ajaxFormArray.length <= 1){
1894 saveAllButton.style.visibility = 'hidden';
1897 if(index == theForms.length){
1898 ajaxStatus.showStatus(completeStr);
1899 window.setTimeout('ajaxStatus.hideStatus();', 2000);
1901 saveAllButton.style.visibility = 'hidden';
1906 if(typeof savingStr == 'undefined') SUGAR.language.get('app_strings', 'LBL_LOADING');
1907 ajaxStatus.showStatus(savingStr);
1909 //loop through the forms saving each one
1910 for(i = 0; i < theForms.length; i++){
1911 var theForm = document.getElementById(theForms[i]);
1912 if(check_form(theForm.id)){
1913 theForm.action.value='AjaxFormSave';
1914 YAHOO.util.Connect.setForm(theForm);
1915 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success});
1917 ajaxStatus.hideStatus();
1919 lastSubmitTime = lastSubmitTime-2000;
1924 // -- start sugarListView class
1925 // js functions used for ListView
1926 function sugarListView() {
1930 sugarListView.prototype.confirm_action = function(del) {
1932 return confirm( SUGAR.language.get('app_strings', 'NTC_DELETE_CONFIRMATION_NUM') + sugarListView.get_num_selected() + SUGAR.language.get('app_strings', 'NTC_DELETE_SELECTED_RECORDS'));
1935 return confirm( SUGAR.language.get('app_strings', 'NTC_UPDATE_CONFIRMATION_NUM') + sugarListView.get_num_selected() + SUGAR.language.get('app_strings', 'NTC_DELETE_SELECTED_RECORDS'));
1939 sugarListView.get_num_selected = function () {
1940 var selectCount = $("input[name='selectCount[]']:first");
1941 if(selectCount.length > 0)
1942 return parseInt(selectCount.val().replace("+", ""));
1946 sugarListView.update_count = function(count, add) {
1947 if(typeof document.MassUpdate != 'undefined') {
1948 the_form = document.MassUpdate;
1949 for(var wp = 0; wp < the_form.elements.length; wp++) {
1950 if(typeof the_form.elements[wp].name != 'undefined' && the_form.elements[wp].name == 'selectCount[]') {
1952 the_form.elements[wp].value = parseInt(the_form.elements[wp].value,10) + count;
1953 if (the_form.select_entire_list.value == 1 && the_form.show_plus.value) {
1954 the_form.elements[wp].value += '+';
1957 if (the_form.select_entire_list.value == 1 && the_form.show_plus.value) {
1958 the_form.elements[wp].value = count + '+';
1960 the_form.elements[wp].value = count;
1967 sugarListView.prototype.use_external_mail_client = function(no_record_txt, module) {
1968 selected_records = sugarListView.get_checks_count();
1969 if(selected_records <1) {
1970 alert(no_record_txt);
1974 if (document.MassUpdate.select_entire_list.value == 1) {
1975 if (totalCount > 10) {
1976 alert(totalCountError);
1981 else if (document.MassUpdate.massall.checked == true)
1985 sugarListView.get_checks();
1987 if(select) { // use selected items
1988 ids = document.MassUpdate.uid.value;
1990 else { // use current page
1991 inputs = document.MassUpdate.elements;
1993 for(i = 0; i < inputs.length; i++) {
1994 if(inputs[i].name == 'mass[]' && inputs[i].checked && typeof(inputs[i].value) != 'function') {
1995 ar.push(inputs[i].value);
2000 YAHOO.util.Connect.asyncRequest("POST", "index.php?", {
2001 success: this.use_external_mail_client_callback
2002 }, SUGAR.util.paramsToUrl({
2005 listViewExternalClient: 1,
2006 action_module: module,
2014 sugarListView.prototype.use_external_mail_client_callback = function(o)
2017 location.href = 'mailto:' + o.responseText;
2020 sugarListView.prototype.send_form_for_emails = function(select, currentModule, action, no_record_txt,action_module,totalCount, totalCountError) {
2021 if ( typeof(SUGAR.config.email_sugarclient_listviewmaxselect) != 'undefined' ) {
2025 maxCount = SUGAR.config.email_sugarclient_listviewmaxselect;
2028 if (document.MassUpdate.select_entire_list.value == 1) {
2029 if (totalCount > maxCount) {
2030 alert(totalCountError);
2035 else if (document.MassUpdate.massall.checked == true)
2040 sugarListView.get_checks();
2041 // create new form to post (can't access action property of MassUpdate form due to action input)
2042 var newForm = document.createElement('form');
2043 newForm.method = 'post';
2044 newForm.action = action;
2045 newForm.name = 'newForm';
2046 newForm.id = 'newForm';
2047 var uidTa = document.createElement('textarea');
2049 uidTa.style.display = 'none';
2051 if(select) { // use selected items
2052 uidTa.value = document.MassUpdate.uid.value;
2054 else { // use current page
2055 inputs = document.MassUpdate.elements;
2057 for(i = 0; i < inputs.length; i++) {
2058 if(inputs[i].name == 'mass[]' && inputs[i].checked && typeof(inputs[i].value) != 'function') {
2059 ar.push(inputs[i].value);
2062 uidTa.value = ar.join(',');
2065 if(uidTa.value == '') {
2066 alert(no_record_txt);
2070 var selectedArray = uidTa.value.split(",");
2071 if(selectedArray.length > maxCount) {
2072 alert(totalCountError);
2075 newForm.appendChild(uidTa);
2077 var moduleInput = document.createElement('input');
2078 moduleInput.name = 'module';
2079 moduleInput.type = 'hidden';
2080 moduleInput.value = currentModule;
2081 newForm.appendChild(moduleInput);
2083 var actionInput = document.createElement('input');
2084 actionInput.name = 'action';
2085 actionInput.type = 'hidden';
2086 actionInput.value = 'Compose';
2087 newForm.appendChild(actionInput);
2089 if (typeof action_module != 'undefined' && action_module!= '') {
2090 var actionModule = document.createElement('input');
2091 actionModule.name = 'action_module';
2092 actionModule.type = 'hidden';
2093 actionModule.value = action_module;
2094 newForm.appendChild(actionModule);
2096 //return_info must follow this pattern."&return_module=Accounts&return_action=index"
2097 if (typeof return_info!= 'undefined' && return_info != '') {
2098 var params= return_info.split('&');
2099 if (params.length > 0) {
2100 for (var i=0;i< params.length;i++) {
2101 if (params[i].length > 0) {
2102 var param_nv=params[i].split('=');
2103 if (param_nv.length==2){
2104 returnModule = document.createElement('input');
2105 returnModule.name = param_nv[0];
2106 returnModule.type = 'hidden';
2107 returnModule.value = param_nv[1];
2108 newForm.appendChild(returnModule);
2115 var isAjaxCall = document.createElement('input');
2116 isAjaxCall.name = 'ajaxCall';
2117 isAjaxCall.type = 'hidden';
2118 isAjaxCall.value = true;
2119 newForm.appendChild(isAjaxCall);
2121 var isListView = document.createElement('input');
2122 isListView.name = 'ListView';
2123 isListView.type = 'hidden';
2124 isListView.value = true;
2125 newForm.appendChild(isListView);
2127 var toPdf = document.createElement('input');
2128 toPdf.name = 'to_pdf';
2129 toPdf.type = 'hidden';
2131 newForm.appendChild(toPdf);
2133 //Grab the Quick Compose package for the listview
2134 YAHOO.util.Connect.setForm(newForm);
2137 success: function(o) {
2138 var resp = YAHOO.lang.JSON.parse(o.responseText);
2139 var quickComposePackage = new Object();
2140 quickComposePackage.composePackage = resp;
2141 quickComposePackage.fullComposeUrl = 'index.php?module=Emails&action=Compose&ListView=true' +
2142 '&uid=' + uidTa.value + '&action_module=' + action_module;
2144 SUGAR.quickCompose.init(quickComposePackage);
2148 YAHOO.util.Connect.asyncRequest('POST','index.php', callback,null);
2150 // awu Bug 18624: Fixing issue where a canceled Export and unselect of row will persist the uid field, clear the field
2151 document.MassUpdate.uid.value = '';
2156 sugarListView.prototype.send_form = function(select, currentModule, action, no_record_txt,action_module,return_info) {
2157 if (document.MassUpdate.select_entire_list.value == 1) {
2159 if(sugarListView.get_checks_count() < 1) {
2160 alert(no_record_txt);
2165 if ( action.indexOf('?') != -1 )
2166 href += '&module=' + currentModule;
2168 href += '?module=' + currentModule;
2171 href += return_info;
2172 var newForm = document.createElement('form');
2173 newForm.method = 'post';
2174 newForm.action = href;
2175 newForm.name = 'newForm';
2176 newForm.id = 'newForm';
2177 var postTa = document.createElement('textarea');
2178 postTa.name = 'current_post';
2179 postTa.value = document.MassUpdate.current_query_by_page.value;
2180 postTa.style.display = 'none';
2181 newForm.appendChild(postTa);
2182 document.MassUpdate.parentNode.appendChild(newForm);
2186 else if (document.MassUpdate.massall.checked == true)
2191 sugarListView.get_checks();
2192 // create new form to post (can't access action property of MassUpdate form due to action input)
2193 var newForm = document.createElement('form');
2194 newForm.method = 'post';
2195 newForm.action = action;
2196 newForm.name = 'newForm';
2197 newForm.id = 'newForm';
2198 var uidTa = document.createElement('textarea');
2200 uidTa.style.display = 'none';
2201 uidTa.value = document.MassUpdate.uid.value;
2203 if(uidTa.value == '') {
2204 alert(no_record_txt);
2208 newForm.appendChild(uidTa);
2210 var moduleInput = document.createElement('input');
2211 moduleInput.name = 'module';
2212 moduleInput.type = 'hidden';
2213 moduleInput.value = currentModule;
2214 newForm.appendChild(moduleInput);
2216 var actionInput = document.createElement('input');
2217 actionInput.name = 'action';
2218 actionInput.type = 'hidden';
2219 actionInput.value = 'index';
2220 newForm.appendChild(actionInput);
2222 if (typeof action_module != 'undefined' && action_module!= '') {
2223 var actionModule = document.createElement('input');
2224 actionModule.name = 'action_module';
2225 actionModule.type = 'hidden';
2226 actionModule.value = action_module;
2227 newForm.appendChild(actionModule);
2229 //return_info must follow this pattern."&return_module=Accounts&return_action=index"
2230 if (typeof return_info!= 'undefined' && return_info != '') {
2231 var params= return_info.split('&');
2232 if (params.length > 0) {
2233 for (var i=0;i< params.length;i++) {
2234 if (params[i].length > 0) {
2235 var param_nv=params[i].split('=');
2236 if (param_nv.length==2){
2237 returnModule = document.createElement('input');
2238 returnModule.name = param_nv[0];
2239 returnModule.type = 'hidden';
2240 returnModule.value = param_nv[1];
2241 newForm.appendChild(returnModule);
2248 document.MassUpdate.parentNode.appendChild(newForm);
2251 // awu Bug 18624: Fixing issue where a canceled Export and unselect of row will persist the uid field, clear the field
2252 document.MassUpdate.uid.value = '';
2256 //return a count of checked row.
2257 sugarListView.get_checks_count = function() {
2260 if(document.MassUpdate.uid.value != '') {
2261 oldUids = document.MassUpdate.uid.value.split(',');
2262 for(uid in oldUids) {
2263 if(typeof(oldUids[uid]) != 'function') {
2264 ar[oldUids[uid]] = 1;
2268 // build associated array of uids, associated array ensures uniqueness
2269 inputs = document.MassUpdate.elements;
2270 for(i = 0; i < inputs.length; i++) {
2271 if(inputs[i].name == 'mass[]') {
2272 ar[inputs[i].value] = (inputs[i].checked) ? 1 : 0; // 0 of it is unchecked
2276 // build regular array of uids
2279 if((typeof(ar[i]) != 'function') && ar[i] == 1) {
2287 // saves the checks on the current page into the uid textarea
2288 sugarListView.get_checks = function() {
2290 if(typeof document.MassUpdate != 'undefined' ){
2291 if(document.MassUpdate.uid.value != '') {
2292 oldUids = document.MassUpdate.uid.value.split(',');
2293 for(uid in oldUids) {
2294 if(typeof(oldUids[uid]) != 'function') {
2295 ar[oldUids[uid]] = 1;
2300 // build associated array of uids, associated array ensures uniqueness
2301 inputs = document.MassUpdate.elements;
2302 for(i = 0; i < inputs.length; i++) {
2303 if(inputs[i].name == 'mass[]') {
2304 ar[inputs[i].value] = (inputs[i].checked) ? 1 : 0; // 0 of it is unchecked
2308 // build regular array of uids
2311 if(typeof(ar[i]) != 'function' && ar[i] == 1) {
2316 document.MassUpdate.uid.value = uids.join(',');
2318 if(uids.length == 0) return false; // return false if no checks to get
2319 return true; // there are saved checks
2324 sugarListView.prototype.order_checks = function(order,orderBy,moduleString){
2325 checks = sugarListView.get_checks();
2326 eval('document.MassUpdate.' + moduleString + '.value = orderBy');
2327 document.MassUpdate.lvso.value = order;
2328 if(typeof document.MassUpdate.massupdate != 'undefined') {
2329 document.MassUpdate.massupdate.value = 'false';
2332 //we must first clear the action of massupdate, change it to index
2333 document.MassUpdate.action.value = document.MassUpdate.return_action.value;
2334 document.MassUpdate.return_module.value='';
2335 document.MassUpdate.return_action.value='';
2336 document.MassUpdate.submit();
2340 sugarListView.prototype.save_checks = function(offset, moduleString) {
2341 checks = sugarListView.get_checks();
2342 if(typeof document.MassUpdate != 'undefined'){
2343 eval('document.MassUpdate.' + moduleString + '.value = offset');
2345 if(typeof document.MassUpdate.massupdate != 'undefined') {
2346 document.MassUpdate.massupdate.value = 'false';
2349 //we must first clear the action of massupdate, change it to index
2350 document.MassUpdate.action.value = document.MassUpdate.return_action.value;
2351 document.MassUpdate.return_module.value='';
2352 document.MassUpdate.return_action.value='';
2353 document.MassUpdate.submit();
2361 sugarListView.prototype.check_item = function(cb, form) {
2363 sugarListView.update_count(1, true);
2366 sugarListView.update_count(-1, true);
2367 if(typeof form != 'undefined' && form != null) {
2368 sugarListView.prototype.updateUid(cb, form);
2371 sugarListView.prototype.toggleSelected();
2374 sugarListView.prototype.toggleSelected = function() {
2376 var numSelected = sugarListView.get_num_selected();
2377 var selectedRecords = document.getElementById("selectedRecordsTop");
2378 var selectActions = document.getElementById("selectActions");
2379 var selectActionsDisabled = document.getElementById("selectActionsDisabled");
2380 if(numSelected > 0) {
2381 $(selectedRecords).removeAttr("style").addClass("show");
2382 $(".selectActionsDisabled").hide();
2383 jQuery('ul[name=selectActions]').each(function () {
2384 jQuery(this).removeAttr("style").addClass("show");
2388 $(selectedRecords).hide();
2389 $(".selectActionsDisabled").removeAttr("style").addClass("show");
2390 jQuery('ul[name=selectActions]').each(function () {
2391 jQuery(this).hide();
2397 /**#28000, remove the unselect record id from MassUpdate.uid **/
2398 sugarListView.prototype.updateUid = function(cb , form){
2399 if(form.name == 'MassUpdate' && form.uid && form.uid.value && cb.value && form.uid.value.indexOf(cb.value) != -1){
2400 if(form.uid.value.indexOf(','+cb.value)!= -1){
2401 form.uid.value = form.uid.value.replace(','+cb.value , '');
2402 }else if(form.uid.value.indexOf(cb.value + ',')!= -1){
2403 form.uid.value = form.uid.value.replace(cb.value + ',' , '');
2404 }else if(form.uid.value.indexOf(cb.value)!= -1){
2405 form.uid.value = form.uid.value.replace(cb.value , '');
2410 sugarListView.prototype.check_entire_list = function(form, field, value, list_count) {
2411 // count number of items
2413 $(document.MassUpdate.massall).each(function(){
2414 $(this).attr('checked', true).attr('disabled', true);
2416 for (i = 0; i < form.elements.length; i++) {
2417 if(form.elements[i].name == field && form.elements[i].disabled == false) {
2418 if(form.elements[i].checked != value) count++;
2419 form.elements[i].checked = value;
2420 form.elements[i].disabled = true;
2423 document.MassUpdate.select_entire_list.value = 1;
2424 sugarListView.update_count(list_count, false);
2425 sugarListView.prototype.toggleSelected();
2428 sugarListView.prototype.check_all = function(form, field, value, pageTotal) {
2429 // count number of items
2431 $(document.MassUpdate.massall).each(function(){$(this).attr('checked', value);});
2432 if (document.MassUpdate.select_entire_list &&
2433 document.MassUpdate.select_entire_list.value == 1)
2435 sugarListView.prototype.toggleSelected();
2436 $(document.MassUpdate.massall).each(function(){$(this).attr('disabled', true);});
2440 $(document.MassUpdate.massall).each(function(){$(this).attr('disabled', false);});
2442 for (i = 0; i < form.elements.length; i++) {
2443 if(form.elements[i].name == field && !(form.elements[i].disabled == true && form.elements[i].checked == false)) {
2444 form.elements[i].disabled = false;
2446 if(form.elements[i].checked != value)
2448 form.elements[i].checked = value;
2450 sugarListView.prototype.updateUid(form.elements[i], form);
2455 sugarListView.update_count(pageTotal);
2457 sugarListView.update_count(count, true);
2459 sugarListView.update_count(-1 * count, true);
2461 sugarListView.prototype.toggleSelected();
2463 sugarListView.check_all = sugarListView.prototype.check_all;
2464 sugarListView.confirm_action = sugarListView.prototype.confirm_action;
2466 sugarListView.prototype.check_boxes = function() {
2467 var inputsCount = 0;
2468 var checkedCount = 0;
2469 var existing_onload = window.onload;
2470 var theForm = document.MassUpdate;
2471 inputs_array = theForm.elements;
2473 if(typeof theForm.uid.value != 'undefined' && theForm.uid.value != "") {
2474 checked_items = theForm.uid.value.split(",");
2475 if (theForm.select_entire_list.value == 1) {
2476 document.MassUpdate.massall.disabled = true;
2477 sugarListView.prototype.toggleSelected();
2478 $("a[name=selectall]:first").click();
2481 for(var wp = 0 ; wp < inputs_array.length; wp++) {
2482 if(inputs_array[wp].name == "mass[]") {
2484 if (theForm.select_entire_list.value == 1) {
2485 inputs_array[wp].checked = true;
2486 inputs_array[wp].disabled = true;
2490 for(i in checked_items) {
2491 if(inputs_array[wp].value == checked_items[i]) {
2493 inputs_array[wp].checked = true;
2494 //Bug#52748: Total # of checked items are calculated in back-end side
2495 //sugarListView.prototype.check_item(inputs_array[wp], document.MassUpdate);
2503 for(var wp = 0 ; wp < inputs_array.length; wp++) {
2504 if(inputs_array[wp].name == "mass[]") {
2505 inputs_array[wp].checked = false;
2506 inputs_array[wp].disabled = false;
2509 if (document.MassUpdate.massall) {
2510 document.MassUpdate.massall.checked = false;
2511 document.MassUpdate.massall.disabled = false;
2513 sugarListView.update_count(0)
2515 if(checkedCount > 0 && checkedCount == inputsCount)
2516 document.MassUpdate.massall.checked = true;
2521 * This function is used in Email Template Module's listview.
2522 * It will check whether the templates are used in Campaing->EmailMarketing.
2523 * If true, it will notify user.
2525 function check_used_email_templates() {
2526 var ids = document.MassUpdate.uid.value;
2528 success:function(r) {
2529 if(r.responseText != '') {
2530 if(!confirm(SUGAR.language.get('app_strings','NTC_TEMPLATES_IS_USED') + r.responseText)) {
2534 document.MassUpdate.submit();
2538 url = "index.php?module=EmailTemplates&action=CheckDeletable&from=ListView&to_pdf=1&records="+ids;
2539 YAHOO.util.Connect.asyncRequest('POST',url, call_back,null);
2543 sugarListView.prototype.send_mass_update = function(mode, no_record_txt, del) {
2544 formValid = check_form('MassUpdate');
2545 if(!formValid && !del) return false;
2548 if (document.MassUpdate.select_entire_list &&
2549 document.MassUpdate.select_entire_list.value == 1)
2554 var ar = new Array();
2558 for(var wp = 0; wp < document.MassUpdate.elements.length; wp++) {
2559 var reg_for_existing_uid = new RegExp('^'+RegExp.escape(document.MassUpdate.elements[wp].value)+'[\s]*,|,[\s]*'+RegExp.escape(document.MassUpdate.elements[wp].value)+'[\s]*,|,[\s]*'+RegExp.escape(document.MassUpdate.elements[wp].value)+'$|^'+RegExp.escape(document.MassUpdate.elements[wp].value)+'$');
2560 //when the uid is already in document.MassUpdate.uid.value, we should not add it to ar.
2561 if(typeof document.MassUpdate.elements[wp].name != 'undefined'
2562 && document.MassUpdate.elements[wp].name == 'mass[]'
2563 && document.MassUpdate.elements[wp].checked
2564 && !reg_for_existing_uid.test(document.MassUpdate.uid.value)) {
2565 ar.push(document.MassUpdate.elements[wp].value);
2568 if(document.MassUpdate.uid.value != '') document.MassUpdate.uid.value += ',';
2569 document.MassUpdate.uid.value += ar.join(',');
2570 if(document.MassUpdate.uid.value == '') {
2571 alert(no_record_txt);
2574 if(typeof(current_admin_id)!='undefined' && document.MassUpdate.module!= 'undefined' && document.MassUpdate.module.value == 'Users' && (document.MassUpdate.is_admin.value!='' || document.MassUpdate.status.value!='')) {
2575 var reg_for_current_admin_id = new RegExp('^'+current_admin_id+'[\s]*,|,[\s]*'+current_admin_id+'[\s]*,|,[\s]*'+current_admin_id+'$|^'+current_admin_id+'$');
2576 if(reg_for_current_admin_id.test(document.MassUpdate.uid.value)) {
2577 //if current user is admin, we should not allow massupdate the user_type and status of himself
2578 alert(SUGAR.language.get('Users','LBL_LAST_ADMIN_NOTICE'));
2584 var entireInput = document.createElement('input');
2585 entireInput.name = 'entire';
2586 entireInput.type = 'hidden';
2587 entireInput.value = 'index';
2588 document.MassUpdate.appendChild(entireInput);
2589 //confirm(no_record_txt);
2590 if(document.MassUpdate.module!= 'undefined' && document.MassUpdate.module.value == 'Users' && (document.MassUpdate.is_admin.value!='' || document.MassUpdate.status.value!='')) {
2591 alert(SUGAR.language.get('Users','LBL_LAST_ADMIN_NOTICE'));
2597 if(!sugarListView.confirm_action(del))
2601 var deleteInput = document.createElement('input');
2602 deleteInput.name = 'Delete';
2603 deleteInput.type = 'hidden';
2604 deleteInput.value = true;
2605 document.MassUpdate.appendChild(deleteInput);
2606 if(document.MassUpdate.module!= 'undefined' && document.MassUpdate.module.value == 'EmailTemplates') {
2607 check_used_email_templates();
2613 document.MassUpdate.submit();
2618 sugarListView.prototype.clear_all = function() {
2619 document.MassUpdate.uid.value = '';
2620 document.MassUpdate.select_entire_list.value = 0;
2621 sugarListView.check_all(document.MassUpdate, 'mass[]', false);
2622 $(document.MassUpdate.massall).each(function(){
2623 $(this).attr('checked', false).attr('disabled', false);
2625 sugarListView.update_count(0);
2626 sugarListView.prototype.toggleSelected();
2629 sListView = new sugarListView();
2630 // -- end sugarListView class
2632 // format and unformat numbers
2633 function unformatNumber(n, num_grp_sep, dec_sep) {
2634 var x=unformatNumberNoParse(n, num_grp_sep, dec_sep);
2637 return parseFloat(x);
2642 function unformatNumberNoParse(n, num_grp_sep, dec_sep) {
2643 if(typeof num_grp_sep == 'undefined' || typeof dec_sep == 'undefined') return n;
2644 n = n ? n.toString() : '';
2647 if(num_grp_sep != '')
2649 num_grp_sep_re = new RegExp('\\'+num_grp_sep, 'g');
2650 n = n.replace(num_grp_sep_re, '');
2653 n = n.replace(dec_sep, '.');
2655 if(typeof CurrencySymbols != 'undefined') {
2656 // Need to strip out the currency symbols from the start.
2657 for ( var idx in CurrencySymbols ) {
2658 n = n.replace(CurrencySymbols[idx], '');
2666 // round parameter can be negative for decimal, precision has to be postive
2667 function formatNumber(n, num_grp_sep, dec_sep, round, precision) {
2668 if(typeof num_grp_sep == 'undefined' || typeof dec_sep == 'undefined') return n;
2669 n = n ? n.toString() : '';
2670 if(n.split) n = n.split('.');
2673 if(n.length > 2) return n.join('.'); // that's not a num!
2675 if(typeof round != 'undefined') {
2676 if(round > 0 && n.length > 1) { // round to decimal
2677 n[1] = parseFloat('0.' + n[1]);
2678 n[1] = Math.round(n[1] * Math.pow(10, round)) / Math.pow(10, round);
2679 n[1] = n[1].toString().split('.')[1];
2681 if(round <= 0) { // round to whole number
2682 n[0] = Math.round(parseInt(n[0],10) * Math.pow(10, round)) / Math.pow(10, round);
2687 if(typeof precision != 'undefined' && precision >= 0) {
2688 if(n.length > 1 && typeof n[1] != 'undefined') n[1] = n[1].substring(0, precision); // cut off precision
2690 if(n[1].length < precision) {
2691 for(var wp = n[1].length; wp < precision; wp++) n[1] += '0';
2695 regex = /(\d+)(\d{3})/;
2696 while(num_grp_sep != '' && regex.test(n[0])) n[0] = n[0].toString().replace(regex, '$1' + num_grp_sep + '$2');
2697 return n[0] + (n.length > 1 && n[1] != '' ? dec_sep + n[1] : '');
2700 // --- begin ajax status class
2701 SUGAR.ajaxStatusClass = function() {};
2702 SUGAR.ajaxStatusClass.prototype.statusDiv = null;
2703 SUGAR.ajaxStatusClass.prototype.oldOnScroll = null;
2704 SUGAR.ajaxStatusClass.prototype.shown = false; // state of the status window
2706 // reposition the status div, top and centered
2707 SUGAR.ajaxStatusClass.prototype.positionStatus = function() {
2708 //this.statusDiv.style.top = document.body.scrollTop + 8 + 'px';
2709 statusDivRegion = YAHOO.util.Dom.getRegion(this.statusDiv);
2710 statusDivWidth = statusDivRegion.right - statusDivRegion.left;
2711 this.statusDiv.style.left = YAHOO.util.Dom.getViewportWidth() / 2 - statusDivWidth / 2 + 'px';
2714 // private func, create the status div
2715 SUGAR.ajaxStatusClass.prototype.createStatus = function(text) {
2716 statusDiv = document.createElement('div');
2717 statusDiv.className = 'dataLabel';
2718 statusDiv.id = 'ajaxStatusDiv';
2719 document.body.appendChild(statusDiv);
2720 this.statusDiv = document.getElementById('ajaxStatusDiv');
2723 // public - show the status div with text
2724 SUGAR.ajaxStatusClass.prototype.showStatus = function(text) {
2725 if(!this.statusDiv) {
2726 this.createStatus(text);
2729 this.statusDiv.style.display = '';
2731 this.statusDiv.innerHTML = ' <b>' + text + '</b> ';
2732 this.positionStatus();
2735 this.statusDiv.style.display = '';
2736 if(window.onscroll) this.oldOnScroll = window.onscroll; // save onScroll
2737 window.onscroll = this.positionStatus;
2742 SUGAR.ajaxStatusClass.prototype.hideStatus = function(text) {
2743 if(!this.shown) return;
2745 if(this.oldOnScroll) window.onscroll = this.oldOnScroll;
2746 else window.onscroll = '';
2747 this.statusDiv.style.display = 'none';
2750 SUGAR.ajaxStatusClass.prototype.flashStatus = function(text, time){
2751 this.showStatus(text);
2752 window.setTimeout('ajaxStatus.hideStatus();', time);
2756 var ajaxStatus = new SUGAR.ajaxStatusClass();
2757 // --- end ajax status class
2760 * Unified Search Advanced - for global search
2762 SUGAR.unifiedSearchAdvanced = function() {
2772 SUGAR.unifiedSearchAdvanced.usa_div = document.getElementById('unified_search_advanced_div');
2773 SUGAR.unifiedSearchAdvanced.usa_img = document.getElementById('unified_search_advanced_img');
2775 if(!SUGAR.unifiedSearchAdvanced.usa_div || !SUGAR.unifiedSearchAdvanced.usa_img) return;
2776 var attributes = { height: { to: 300 } };
2777 SUGAR.unifiedSearchAdvanced.anim_open = new YAHOO.util.Anim('unified_search_advanced_div', attributes );
2778 SUGAR.unifiedSearchAdvanced.anim_open.duration = 0.75;
2779 SUGAR.unifiedSearchAdvanced.anim_close = new YAHOO.util.Anim('unified_search_advanced_div', { height: {to: 0} } );
2780 SUGAR.unifiedSearchAdvanced.anim_close.duration = 0.75;
2781 //SUGAR.unifiedSearchAdvanced.anim_close.onComplete.subscribe(function() {SUGAR.unifiedSearchAdvanced.usa_div.style.display = 'none'});
2783 SUGAR.unifiedSearchAdvanced.usa_img._x = YAHOO.util.Dom.getX(SUGAR.unifiedSearchAdvanced.usa_img);
2784 SUGAR.unifiedSearchAdvanced.usa_img._y = YAHOO.util.Dom.getY(SUGAR.unifiedSearchAdvanced.usa_img);
2787 SUGAR.unifiedSearchAdvanced.usa_open = false;
2788 SUGAR.unifiedSearchAdvanced.usa_content = null;
2790 YAHOO.util.Event.addListener('unified_search_advanced_img', 'click', SUGAR.unifiedSearchAdvanced.get_content);
2793 get_content: function(e)
2795 query_string = trim(document.getElementById('query_string').value);
2796 if(query_string != '')
2798 window.location.href = 'index.php?module=Home&action=UnifiedSearch&query_string=' + query_string;
2800 window.location.href = 'index.php?module=Home&action=UnifiedSearch&form_only=true';
2804 animate: function(data) {
2805 ajaxStatus.hideStatus();
2808 SUGAR.unifiedSearchAdvanced.usa_content = data.responseText;
2809 SUGAR.unifiedSearchAdvanced.usa_div.innerHTML = SUGAR.unifiedSearchAdvanced.usa_content;
2811 if(SUGAR.unifiedSearchAdvanced.usa_open) {
2812 document.UnifiedSearch.advanced.value = 'false';
2813 SUGAR.unifiedSearchAdvanced.anim_close.animate();
2816 document.UnifiedSearch.advanced.value = 'true';
2817 SUGAR.unifiedSearchAdvanced.usa_div.style.display = '';
2818 YAHOO.util.Dom.setX(SUGAR.unifiedSearchAdvanced.usa_div, SUGAR.unifiedSearchAdvanced.usa_img._x - 90);
2819 YAHOO.util.Dom.setY(SUGAR.unifiedSearchAdvanced.usa_div, SUGAR.unifiedSearchAdvanced.usa_img._y + 15);
2820 SUGAR.unifiedSearchAdvanced.anim_open.animate();
2822 SUGAR.unifiedSearchAdvanced.usa_open = !SUGAR.unifiedSearchAdvanced.usa_open;
2827 checkUsaAdvanced: function() {
2828 if(document.UnifiedSearch.advanced.value == 'true') {
2829 document.UnifiedSearchAdvanced.query_string.value = document.UnifiedSearch.query_string.value;
2830 document.UnifiedSearchAdvanced.submit();
2837 if(typeof YAHOO != 'undefined') YAHOO.util.Event.addListener(window, 'load', SUGAR.unifiedSearchAdvanced.init);
2842 * Toggles the header
2844 toggleHeader : function() {
2845 var h = document.getElementById('header');
2849 if(h.style.display == 'none') {
2850 h.style.display = '';
2852 h.style.display = 'none';
2856 alert(SUGAR.language.get("app_strings", "ERR_NO_HEADER_ID"));
2863 * General Sugar Utils
2865 SUGAR.util = function () {
2866 var additionalDetailsCache;
2867 var additionalDetailsCalls;
2868 var additionalDetailsRpcCall;
2871 getAndRemove : function (el) {
2872 if (YAHOO && YAHOO.util && YAHOO.util.Dom)
2873 el = YAHOO.util.Dom.get(el);
2874 else if (typeof (el) == "string")
2875 el = document.getElementById(el);
2876 if (el && el.parentNode)
2877 el.parentNode.removeChild(el);
2881 paramsToUrl : function (params) {
2883 for (var i in params)
2885 if (params.hasOwnProperty(i))
2887 parts.push(encodeURIComponent(i) + '=' + encodeURIComponent(params[i]));
2890 return parts.join("&")+"&";
2892 // Evaluates a script in a global context
2893 // Workarounds based on findings by Jim Driscoll
2894 // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
2895 globalEval: function( data ) {
2896 var rnotwhite = /\S/;
2897 if ( data && rnotwhite.test( data ) ) {
2898 // We use execScript on Internet Explorer
2899 // We use an anonymous function so that context is window
2900 // rather than jQuery in Firefox
2901 ( window.execScript || function( data ) {
2902 window[ "eval" ].call( window, data );
2906 evalScript:function(text){
2908 var waitUntilLoaded = function(){
2909 SUGAR.evalScript_waitCount--;
2910 if (SUGAR.evalScript_waitCount == 0) {
2911 var headElem = document.getElementsByTagName('head')[0];
2912 for ( var i = 0; i < SUGAR.evalScript_evalElem.length; i++) {
2913 var tmpElem = document.createElement('script');
2914 tmpElem.type = 'text/javascript';
2915 tmpElem.text = SUGAR.evalScript_evalElem[i];
2916 headElem.appendChild(tmpElem);
2921 var tmpElem = document.createElement('div');
2922 tmpElem.innerHTML = text;
2923 var results = tmpElem.getElementsByTagName('script');
2924 if (results == null) {
2925 // No scripts found, bail out
2929 var headElem = document.getElementsByTagName('head')[0];
2931 SUGAR.evalScript_waitCount = 0;
2932 SUGAR.evalScript_evalElem = new Array();
2933 for (var i = 0; i < results.length; i++) {
2934 if (typeof(results[i]) != 'object') {
2937 tmpElem = document.createElement('script');
2938 tmpElem.type = 'text/javascript';
2939 if (results[i].src != null && results[i].src != '') {
2940 tmpElem.src = results[i].src;
2942 // Need to defer execution of these scripts until the
2943 // required javascript files are fully loaded
2944 SUGAR.evalScript_evalElem[SUGAR.evalScript_evalElem.length] = results[i].text;
2947 tmpElem.addEventListener('load', waitUntilLoaded);
2948 SUGAR.evalScript_waitCount++;
2949 headElem.appendChild(tmpElem);
2951 // Add some code to handle pages without any external scripts
2952 SUGAR.evalScript_waitCount++;
2955 // Don't try and process things the IE way
2959 var objRegex = /<\s*script([^>]*)>((.|\s|\v|\0)*?)<\s*\/script\s*>/igm;
2961 var result = objRegex.exec(text);
2962 while(result && result.index > lastIndex){
2963 lastIndex = result.index
2965 // Bug #49205 : Subpanels fail to load when selecting subpanel tab
2966 // Change approach to handle javascripts included to body of ajax response.
2967 // To load & run javascripts and inline javascript in correct order load them as synchronous requests
2968 // JQuery library uses this approach to eval scripts
2969 if(result[1].indexOf("src=") > -1){
2970 var srcRegex = /.*src=['"]([a-zA-Z0-9_\-\&\/\.\?=:-]*)['"].*/igm;
2971 var srcResult = result[1].replace(srcRegex, '$1');
2973 // Check is ulr cross domain or not
2974 var r1 = /:\/\//igm;
2975 if ( r1.test(srcResult) && srcResult.indexOf(window.location.hostname) == -1 )
2977 // if script is cross domain it cannot be loaded via ajax request
2978 // try load script asynchronous by creating script element in the body
2979 // YUI 3.3 doesn't allow load scrips synchronously
2981 YUI().use('get', function (Y)
2983 var url = srcResult;
2984 Y.Get.script(srcResult,
2987 onSuccess : function(o) { },
2988 onFailure: function(o) { },
2989 onTimeout: function(o) { }
2992 // TODO: for YUI 3.5 - load scripts as script object synchronous
2994 YUI().use('get', function (Y) {
2995 var url = srcResult;
2996 Y.Get.js([{url: url, async: false}], function (err) {});
3002 // Bug #49205 : Subpanels fail to load when selecting subpanel tab
3003 // Create a YUI instance using the io-base module.
3004 (function (srcResult) {
3005 YUI().use("io-base",function(Y)
3012 success:function(transactionid,response,arguments)
3014 SUGAR.util.globalEval(response.responseText);
3018 // Call synchronous request to load javascript content
3019 // restonse will be processed in success function
3020 response=Y.io(srcResult,cfg);
3025 // Bug #49205 : Subpanels fail to load when selecting subpanel tab
3026 // execute script in global context
3027 // Bug #57288 : don't eval with html comment-out script; that causes syntax error in IE
3028 var srcRegex = /<!--([\s\S]*?)-->/;
3029 var srcResult = srcRegex.exec(result[2]);
3030 if (srcResult && srcResult.index > -1)
3032 SUGAR.util.globalEval(srcResult[1]);
3036 SUGAR.util.globalEval(result[2]);
3041 if(typeof(console) != "undefined" && typeof(console.log) == "function")
3043 console.log("error adding script");
3045 console.log(result);
3048 result = objRegex.exec(text);
3052 * Gets the sidebar object
3053 * @return object pointer to the sidebar element
3055 getLeftColObj: function() {
3056 leftColObj = document.getElementById('leftCol');
3057 while(leftColObj.nodeName != 'TABLE') {
3058 leftColObj = leftColObj.firstChild;
3060 leftColTable = leftColObj;
3061 leftColTd = leftColTable.getElementsByTagName('td')[0];
3062 leftColTdRegion = YAHOO.util.Dom.getRegion(leftColTd);
3063 leftColTd.style.width = (leftColTdRegion.right - leftColTdRegion.left) + 'px';
3068 * Fills the shortcut menu placeholders w/ actual content
3069 * Call this on load event
3071 * @param shortcutContent Array array of content to fill in
3073 fillShortcuts: function(e, shortcutContent) {
3076 // don't do this if leftCol isn't available
3077 if (document.getElementById('leftCol') == undefined) { return; }
3079 spans = document.getElementById('leftCol').getElementsByTagName('span');
3080 hideCol = document.getElementById('HideMenu').getElementsByTagName('span');
3081 w = spans.length + 1;
3083 spans[w] = hideCol[i];
3086 for(je in shortcutContent) {
3088 if(typeof spans[wp].innerHTML != 'undefined' && spans[wp].innerHTML == ('wp_shortcut_fill_' + je)) {
3089 if(typeof spans[wp].parentNode.parentNode == 'object') {
3090 if(typeof spans[wp].parentNode.parentNode.onclick != 'undefined') {
3091 spans[wp].parentNode.parentNode.onclick = null;
3093 // If the wp_shortcut span is contained by an A tag, replace the A with a DIV.
3094 if(spans[wp].parentNode.tagName == 'A' && !isIE) {
3095 var newDiv = document.createElement('DIV');
3096 var parentAnchor = spans[wp].parentNode;
3098 spans[wp].parentNode.parentNode.style.display = 'none';
3100 // Copy styles over to the new container div
3101 if(window.getComputedStyle) {
3102 var parentStyle = window.getComputedStyle(parentAnchor, '');
3103 for(var styleName in parentStyle) {
3104 if(typeof parentStyle[styleName] != 'function'
3105 && styleName != 'display'
3106 && styleName != 'borderWidth'
3107 && styleName != 'visibility') {
3109 newDiv.style[styleName] = parentStyle[styleName];
3111 // Catches .length and .parentRule, and others
3117 // Replace the A with the DIV
3118 newDiv.appendChild(spans[wp]);
3119 parentAnchor.parentNode.replaceChild(newDiv, parentAnchor);
3121 spans[wp].parentNode.parentNode.style.display = '';
3124 spans[wp].innerHTML = shortcutContent[je]; // fill w/ content
3125 if(spans[wp].style) spans[wp].style.display = '';
3131 * Make an AJAX request.
3133 * @param url string resource to load
3134 * @param theDiv string id of element to insert loaded data into
3135 * @param postForm string if set, a POST request will be made to resource specified by url using the form named by postForm
3136 * @param callback string name of function to invoke after HTTP response is recieved
3137 * @param callbackParam any parameter to pass to callback when invoked
3138 * @param appendMode bool if true, HTTP response will be appended to the contents of theDiv, or else contents will be overriten.
3140 retrieveAndFill: function(url, theDiv, postForm, callback, callbackParam, appendMode) {
3141 if(typeof theDiv == 'string') {
3143 theDiv = document.getElementById(theDiv);
3150 var success = function(data) {
3151 if (typeof theDiv != 'undefined' && theDiv != null)
3154 if (typeof appendMode != 'undefined' && appendMode)
3156 theDiv.insertAdjacentHTML('beforeend', data.responseText);
3160 theDiv.innerHTML = data.responseText;
3167 if (typeof callback != 'undefined' && callback != null) callback(callbackParam);
3170 if(typeof postForm == 'undefined' || postForm == null) {
3171 var cObj = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
3174 YAHOO.util.Connect.setForm(postForm);
3175 var cObj = YAHOO.util.Connect.asyncRequest('POST', url, {success: success, failure: success});
3178 checkMaxLength: function() { // modified from http://www.quirksmode.org/dom/maxlength.html
3179 var maxLength = this.getAttribute('maxlength');
3180 var currentLength = this.value.length;
3181 if (currentLength > maxLength) {
3182 this.value = this.value.substring(0, maxLength);
3187 * Adds maxlength attribute to textareas
3189 setMaxLength: function() { // modified from http://www.quirksmode.org/dom/maxlength.html
3190 var x = document.getElementsByTagName('textarea');
3191 for (var i=0;i<x.length;i++) {
3192 if (x[i].getAttribute('maxlength')) {
3193 x[i].onkeyup = x[i].onchange = SUGAR.util.checkMaxLength;
3200 * Renders Query UI Help Dialog
3202 showHelpTips: function(el,helpText,myPos,atPos,id) {
3203 if(myPos == undefined || myPos == "") {
3206 if(atPos == undefined || atPos == "") {
3207 atPos = "right top";
3210 var pos = $(el).offset(),
3211 ofWidth = $(el).width(),
3212 elmId = id || 'helpTip' + pos.left + '_' + ofWidth,
3213 $dialog = elmId ? ( $("#"+elmId).length > 0 ? $("#"+elmId) : $('<div></div>').attr("id", elmId) ) : $('<div></div>');
3214 $dialog.html(helpText)
3217 title: SUGAR.language.get('app_strings', 'LBL_HELP'),
3226 var width = $dialog.dialog( "option", "width" );
3228 if((pos.left + ofWidth) - 40 < width) {
3229 $dialog.dialog("option","position",{my: 'left top',at: 'right top',of: $(el)}) ;
3231 $dialog.dialog('open');
3232 $(".ui-dialog").appendTo("#content");
3236 getStaticAdditionalDetails: function(el, body, caption, show_buttons) {
3237 if(typeof show_buttons == "undefined") {
3238 show_buttons = false;
3241 $(".ui-dialog").find(".open").dialog("close");
3243 var $dialog = $('<div class="open"></div>')
3257 $(".ui-dialog").find('.ui-dialog-titlebar-close').css("display","none");
3258 $(".ui-dialog").find('.ui-dialog-title').css("width","100%");
3262 var width = $dialog.dialog( "option", "width" );
3263 var pos = $(el).offset();
3264 var ofWidth = $(el).width();
3266 if((pos.left + ofWidth) - 40 < width) {
3267 $dialog.dialog("option","position",{my: 'left top',at: 'right top',of: $(el)}) ;
3270 $dialog.dialog('open');
3271 $(".ui-dialog").appendTo("#content");
3275 closeStaticAdditionalDetails: function() {
3276 $(".ui-dialog").find(".open").dialog("close");
3279 * Retrieves additional details dynamically
3281 getAdditionalDetails: function(bean, id, spanId, show_buttons) {
3282 if(typeof show_buttons == "undefined")
3283 show_buttons = false;
3284 var el = '#'+spanId;
3286 oReturn = function(body, caption, width, theme) {
3288 $(".ui-dialog").find(".open").dialog("close");
3290 var $dialog = $('<div class="open"></div>')
3303 $(".ui-dialog").find('.ui-dialog-titlebar-close').css("display","none");
3304 $(".ui-dialog").find('.ui-dialog-title').css("width","100%");
3307 var width = $dialog.dialog( "option", "width" );
3308 var pos = $(el).offset();
3309 var ofWidth = $(el).width();
3311 if((pos.left + ofWidth) - 40 < width) {
3312 $dialog.dialog("option","position",{my: 'left top',at: 'right top',of: $(el)}) ;
3315 $dialog.dialog('open');
3316 $(".ui-dialog").appendTo("#content");
3319 success = function(data) {
3320 eval(data.responseText);
3322 SUGAR.util.additionalDetailsCache[id] = new Array();
3323 SUGAR.util.additionalDetailsCache[id]['body'] = result['body'];
3324 SUGAR.util.additionalDetailsCache[id]['caption'] = result['caption'];
3325 SUGAR.util.additionalDetailsCache[id]['width'] = result['width'];
3326 SUGAR.util.additionalDetailsCache[id]['theme'] = result['theme'];
3327 ajaxStatus.hideStatus();
3328 return oReturn(SUGAR.util.additionalDetailsCache[id]['body'], SUGAR.util.additionalDetailsCache[id]['caption'], SUGAR.util.additionalDetailsCache[id]['width'], SUGAR.util.additionalDetailsCache[id]['theme']);
3331 if(typeof SUGAR.util.additionalDetailsCache[id] != 'undefined')
3332 return oReturn(SUGAR.util.additionalDetailsCache[id]['body'], SUGAR.util.additionalDetailsCache[id]['caption'], SUGAR.util.additionalDetailsCache[id]['width'], SUGAR.util.additionalDetailsCache[id]['theme']);
3334 if(typeof SUGAR.util.additionalDetailsCalls[id] != 'undefined') // call already in progress
3336 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
3337 url = 'index.php?to_pdf=1&module=Home&action=AdditionalDetailsRetrieve&bean=' + bean + '&id=' + id;
3339 url += '&show_buttons=true';
3340 SUGAR.util.additionalDetailsCalls[id] = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
3344 SUGAR.util.additionalDetailsRpcCall = window.setTimeout('go()', 250);
3346 clearAdditionalDetailsCall: function() {
3347 if(typeof SUGAR.util.additionalDetailsRpcCall == 'number') window.clearTimeout(SUGAR.util.additionalDetailsRpcCall);
3350 * A function that extends functionality from parent to child.
3352 extend : function(subc, superc, overrides) {
3353 subc.prototype = new superc; // set the superclass
3356 for (var i in overrides) subc.prototype[i] = overrides[i];
3359 hrefURL : function(url) {
3361 // IE needs special treatment since otherwise it would not pass Referer
3362 var trampoline = document.createElement('a');
3363 trampoline.href = url;
3364 document.body.appendChild(trampoline);
3366 document.body.removeChild(trampoline);
3368 document.location.href = url;
3372 openWindow : function(URL, windowName, windowFeatures) {
3374 // IE needs special treatment since otherwise it would not pass Referer
3375 win = window.open('', windowName, windowFeatures);
3376 var trampoline = document.createElement('a');
3377 trampoline.href = URL;
3378 trampoline.target = windowName;
3379 document.body.appendChild(trampoline);
3381 document.body.removeChild(trampoline);
3383 win = window.open(URL, windowName, windowFeatures);
3387 //Reset the scroll on the window
3392 //Based on YUI onAvailible, but will use any boolean function instead of an ID
3393 doWhen : function(condition, fn, params, scope)
3395 this._doWhenStack.push({
3399 overrideContext: scope
3402 this._doWhenretryCount = 50;
3403 this._startDoWhenInterval();
3406 _startDoWhenInterval : function(){
3407 if (!this._doWhenInterval) {
3408 this._doWhenInterval = YAHOO.lang.later(50, this, this._doWhenCheck, null, true);
3412 _doWhenInterval : false,
3413 _doWhenCheck : function() {
3414 if (this._doWhenStack.length === 0) {
3415 this._doWhenretryCount = 0;
3416 if (this._doWhenInterval) {
3417 // clearInterval(this._interval);
3418 this._doWhenInterval.cancel();
3419 this._doWhenInterval = null;
3424 if (this._doWhenLocked) {
3429 // Hold off if DOMReady has not fired and check current
3430 // readyState to protect against the IE operation aborted
3432 if (!YAHOO.util.Event.DOMReady) {
3433 this._startDoWhenInterval();
3438 this._doWhenLocked = true;
3441 // keep trying until after the page is loaded. We need to
3442 // check the page load state prior to trying to bind the
3443 // elements so that we can be certain all elements have been
3444 // tested appropriately
3445 var tryAgain = YAHOO.util.Event.DOMReady;
3447 tryAgain = (this._doWhenretryCount > 0 && this._doWhenStack.length > 0);
3453 var executeItem = function (context, item) {
3454 if (item.overrideContext) {
3455 if (item.overrideContext === true) {
3458 context = item.overrideContext;
3462 item.fn.call(context, item.obj);
3466 var i, len, item, test;
3468 // onAvailable onContentReady
3469 for (i=0, len=this._doWhenStack.length; i<len; i=i+1) {
3470 item = this._doWhenStack[i];
3473 if ((typeof(test) == "string" && eval(test)) || (typeof(test) == "function" && test())) {
3474 executeItem(this, item);
3475 this._doWhenStack[i] = null;
3478 notAvail.push(item);
3483 this._doWhenretryCount--;
3486 for (i=this._doWhenStack.length-1; i>-1; i--) {
3487 item = this._doWhenStack[i];
3488 if (!item || !item.check) {
3489 this._doWhenStack.splice(i, 1);
3492 this._startDoWhenInterval();
3494 if (this._doWhenInterval) {
3495 // clearInterval(this._interval);
3496 this._doWhenInterval.cancel();
3497 this._doWhenInterval = null;
3500 this._doWhenLocked = false;
3502 buildAccessKeyLabels : function() {
3503 if (typeof(Y.env.ua) !== 'undefined'){
3505 browserOS = Y.env.ua['os'];
3506 isIE = Y.env.ua['ie'];
3507 isCR = Y.env.ua['chrome'];
3508 isFF = Y.env.ua['gecko'];
3509 isWK = Y.env.ua['webkit'];
3510 isOP = Y.env.ua['opera'];
3513 //first determine the OS
3514 if(browserOS=='macintosh'){
3515 //we got a mac, lets use the mac specific commands while we check the browser
3517 //IE on a Mac? Not possible, but let's assign alt anyways for completions sake
3518 controlKey = 'Alt+';
3519 }else if(isWK || isFF){
3520 //Chrome or safari on a mac
3521 //firefox moved to webkit standard starting with FF14
3522 controlKey = 'Ctrl+Opt+';
3525 controlKey = 'Shift+Esc: ';
3527 //default for everything else on a mac
3528 controlKey = 'Ctrl+';
3531 //this is not a mac so let's use the windows/unix commands while we check the browser
3533 //FF on windows/unix
3534 controlKey = 'Alt+Shift+';
3536 //Opera on windows/unix
3537 controlKey = 'Shift+Esc: ';
3539 //this is the default for safari, IE and Chrome
3540 //if this is webkit and is NOT google, then we are most likely looking at Safari
3541 controlKey = 'Alt+';
3546 //now lets retrieve all elements of type input
3547 allButtons = document.getElementsByTagName('input');
3548 //iterate through list and modify title if the accesskey is not empty
3549 for(i=0;i<allButtons.length;i++){
3550 if(allButtons[i].getAttribute('accesskey') && allButtons[i].getAttribute('type') && allButtons[i].getAttribute('type')=='button'){
3551 allButtons[i].setAttribute('title',allButtons[i].getAttribute('title')+' ['+controlKey+allButtons[i].getAttribute('accesskey')+']');
3554 //now change the text in the help div
3555 $("#shortcuts_dialog").html(function(i, text) {
3556 return text.replace(/Alt\+/g,controlKey);
3558 }// end if (typeof(Y.env.ua) !== 'undefined')
3559 }//end buildAccessKeyLabels()
3562 SUGAR.util.additionalDetailsCache = new Array();
3563 SUGAR.util.additionalDetailsCalls = new Array();
3564 if(typeof YAHOO != 'undefined') YAHOO.util.Event.addListener(window, 'load', SUGAR.util.setMaxLength); // allow textareas to obey maxlength attrib
3566 SUGAR.savedViews = function() {
3567 var selectedOrderBy;
3568 var selectedSortOrder;
3571 var columnsMeta; // meta data for the display columns
3574 setChooser: function() {
3576 var displayColumnsDef = new Array();
3577 var hideTabsDef = new Array();
3579 var left_td = document.getElementById('display_tabs_td');
3580 if(typeof left_td == 'undefined' || left_td == null) return; // abort!
3581 var right_td = document.getElementById('hide_tabs_td');
3583 var displayTabs = left_td.getElementsByTagName('select')[0];
3584 var hideTabs = right_td.getElementsByTagName('select')[0];
3586 for(i = 0; i < displayTabs.options.length; i++) {
3587 displayColumnsDef.push(displayTabs.options[i].value);
3590 if(typeof hideTabs != 'undefined') {
3591 for(i = 0; i < hideTabs.options.length; i++) {
3592 hideTabsDef.push(hideTabs.options[i].value);
3595 if (!SUGAR.savedViews.clearColumns)
3596 document.getElementById('displayColumnsDef').value = displayColumnsDef.join('|');
3597 document.getElementById('hideTabsDef').value = hideTabsDef.join('|');
3600 select: function(saved_search_select) {
3601 for(var wp = 0; wp < document.search_form.saved_search_select.options.length; wp++) {
3602 if(typeof document.search_form.saved_search_select.options[wp].value != 'undefined' &&
3603 document.search_form.saved_search_select.options[wp].value == saved_search_select) {
3604 document.search_form.saved_search_select.selectedIndex = wp;
3605 document.search_form.ss_delete.style.display = '';
3606 document.search_form.ss_update.style.display = '';
3610 saved_search_action: function(action, delete_lang) {
3611 if(action == 'delete') {
3612 if(!confirm(delete_lang)) return;
3614 if(action == 'save') {
3615 if(document.search_form.saved_search_name.value.replace(/^\s*|\s*$/g, '') == '') {
3616 alert(SUGAR.language.get('app_strings', 'LBL_SAVED_SEARCH_ERROR'));
3621 // This check is needed for the Activities module (Calls/Meetings/Tasks).
3622 if (document.search_form.saved_search_action)
3624 document.search_form.saved_search_action.value = action;
3625 document.search_form.search_module.value = document.search_form.module.value;
3626 document.search_form.module.value = 'SavedSearch';
3627 // Bug 31922 - Make sure to specify that we want to hit the index view here of
3628 // the SavedSearch module, since the ListView doesn't have the logic to save the
3629 // search and redirect back
3630 document.search_form.action.value = 'index';
3632 SUGAR.ajaxUI.submitForm(document.search_form);
3634 shortcut_select: function(selectBox, module) {
3636 selecturl = 'index.php?module=SavedSearch&search_module=' + module + '&action=index&saved_search_select=' + selectBox.options[selectBox.selectedIndex].value
3637 //add searchFormTab to url if it is available. This determines what tab to render
3638 if(typeof(document.getElementById('searchFormTab'))!='undefined'){
3639 selecturl = selecturl + '&searchFormTab=' + document.search_form.searchFormTab.value;
3641 //add showSSDIV to url if it is available. This determines whether saved search sub form should
3642 //be rendered open or not
3643 if(document.getElementById('showSSDIV') && typeof(document.getElementById('showSSDIV') !='undefined')){
3644 selecturl = selecturl + '&showSSDIV='+document.getElementById('showSSDIV').value;
3646 //use created url to navigate
3647 document.location.href = selecturl;
3649 handleForm: function() {
3650 SUGAR.tabChooser.movementCallback = function(left_side, right_side) {
3651 while(document.getElementById('orderBySelect').childNodes.length != 0) { // clear out order by options
3652 document.getElementById('orderBySelect').removeChild(document.getElementById('orderBySelect').lastChild);
3655 var selectedIndex = 0;
3656 var nodeCount = -1; // need this because the counter i also includes "undefined" nodes
3657 // which was breaking Calls and Meetings
3659 for(i in left_side.childNodes) { // fill in order by options
3660 if(typeof left_side.childNodes[i].nodeName != 'undefined' &&
3661 left_side.childNodes[i].nodeName.toLowerCase() == 'option' &&
3662 typeof SUGAR.savedViews.columnsMeta[left_side.childNodes[i].value] != 'undefined' && // check if column is sortable
3663 typeof SUGAR.savedViews.columnsMeta[left_side.childNodes[i].value]['sortable'] == 'undefined' &&
3664 SUGAR.savedViews.columnsMeta[left_side.childNodes[i].value]['sortable'] != false) {
3666 optionNode = document.createElement('option');
3667 optionNode.value = left_side.childNodes[i].value;
3668 optionNode.innerHTML = left_side.childNodes[i].innerHTML;
3669 document.getElementById('orderBySelect').appendChild(optionNode);
3670 if(optionNode.value == SUGAR.savedViews.selectedOrderBy)
3671 selectedIndex = nodeCount;
3674 // Firefox needs this to be set after all the option nodes are created.
3675 document.getElementById('orderBySelect').selectedIndex = selectedIndex;
3677 SUGAR.tabChooser.movementCallback(document.getElementById('display_tabs_td').getElementsByTagName('select')[0]);
3679 // This check is needed for the Activities module (Calls/Meetings/Tasks).
3680 if (document.search_form.orderBy)
3682 if (document.search_form.orderBy.length > 1 && document.search_form.orderBy[1].type == 'select-one')
3684 document.search_form.orderBy[1].options.value = SUGAR.savedViews.selectedOrderBy;
3688 document.search_form.orderBy.options.value = SUGAR.savedViews.selectedOrderBy;
3693 if(SUGAR.savedViews.selectedSortOrder == 'DESC') document.getElementById('sort_order_desc_radio').checked = true;
3694 else document.getElementById('sort_order_asc_radio').checked = true;
3699 SUGAR.searchForm = function() {
3702 // searchForm tab selector util
3703 searchFormSelect: function(view, previousView) {
3704 var module = view.split('|')[0];
3705 var theView = view.split('|')[1];
3707 var handleDisplay = function() { // hide other divs
3708 document.search_form.searchFormTab.value = theView;
3709 patt = module+"(.*)SearchForm$";
3710 divId=document.search_form.getElementsByTagName('div');
3711 // Hide all the search forms and retrive the name of the previous search tab (useful for the first load because previousView is empty)
3712 for (i=0;i<divId.length;i++){
3713 if(divId[i].id.match(module)==module){
3714 if(divId[i].id.match('SearchForm')=='SearchForm'){
3715 if(document.getElementById(divId[i].id).style.display == ''){
3716 previousTab=divId[i].id.match(patt)[1];
3718 document.getElementById(divId[i].id).style.display = 'none';
3723 //clear thesearch form accesekeys and reset them to the appropriate link
3724 adv = document.getElementById('advanced_search_link');
3725 bas = document.getElementById('basic_search_link');
3726 adv.setAttribute('accesskey','');
3727 bas.setAttribute('accesskey','');
3728 a_key = SUGAR.language.get("app_strings", "LBL_ADV_SEARCH_LNK_KEY");
3730 //reset the ccesskey based on theview
3731 if(theView === 'advanced_search'){
3733 bas.setAttribute('accesskey',a_key);
3735 adv.setAttribute('accesskey',a_key);
3738 // show the good search form.
3739 document.getElementById(module + theView + 'SearchForm').style.display = '';
3740 //if its not the first tab show there is a previous tab.
3742 thepreviousView=previousView.split('|')[1];
3745 thepreviousView=previousTab;
3747 thepreviousView=thepreviousView.replace(/_search/, "");
3748 // Process to retrieve the completed field from one tab to an other.
3749 for(num in document.search_form.elements) {
3750 if(document.search_form.elements[num]) {
3751 el = document.search_form.elements[num];
3752 pattern="^(.*)_"+thepreviousView+"$";
3753 if(typeof el.type != 'undefined' && typeof el.name != 'undefined' && el.name.match(pattern)) {
3754 advanced_input_name = el.name.match(pattern)[1]; // strip
3755 advanced_input_name = advanced_input_name+"_"+theView.replace(/_search/, "");
3756 if(typeof document.search_form[advanced_input_name] != 'undefined') // if advanced input of same name exists
3757 SUGAR.searchForm.copyElement(advanced_input_name, el);
3761 // Remove the previously selected div, so that only data from current div to be sent as form data to the server-side
3762 if (document.getElementById(module + thepreviousView + '_search' + 'SearchForm'))
3764 document.getElementById(module + thepreviousView + '_search' + 'SearchForm').innerHTML = '';
3768 // if tab is not cached
3769 if(document.getElementById(module + theView + 'SearchForm').innerHTML == '') {
3770 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
3771 var success = function(data) {
3772 document.getElementById(module + theView + 'SearchForm').innerHTML = data.responseText;
3774 SUGAR.util.evalScript(data.responseText);
3775 // pass script variables to global scope
3776 if(theView == 'saved_views') {
3777 if(typeof columnsMeta != 'undefined') SUGAR.savedViews.columnsMeta = columnsMeta;
3778 if(typeof selectedOrderBy != 'undefined') SUGAR.savedViews.selectedOrderBy = selectedOrderBy;
3779 if(typeof selectedSortOrder != 'undefined') SUGAR.savedViews.selectedSortOrder = selectedSortOrder;
3784 ajaxStatus.hideStatus();
3786 url = 'index.php?module=' + module + '&action=index&search_form_only=true&to_pdf=true&search_form_view=' + theView;
3788 //check to see if tpl has been specified. If so then pass location through url string
3790 if(document.getElementById('search_tpl') !=null && typeof(document.getElementById('search_tpl')) != 'undefined'){
3791 tpl = document.getElementById('search_tpl').value;
3792 if(tpl != ''){url += '&search_tpl='+tpl;}
3795 if(theView == 'saved_views') // handle the tab chooser
3796 url += '&displayColumns=' + SUGAR.savedViews.displayColumns + '&hideTabs=' + SUGAR.savedViews.hideTabs + '&orderBy=' + SUGAR.savedViews.selectedOrderBy + '&sortOrder=' + SUGAR.savedViews.selectedSortOrder;
3798 var cObj = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
3800 else { // that form already retrieved
3805 // copies one input to another
3806 copyElement: function(inputName, copyFromElement) {
3807 switch(copyFromElement.type) {
3810 document.search_form[inputName].value = copyFromElement.value;
3814 // This function is here to clear the form, instead of "resubmitting it
3815 clear_form: function(form, skipElementNames) {
3816 var elemList = form.elements;
3820 for( var i = 0; i < elemList.length ; i++ ) {
3822 if ( typeof(elem.type) == 'undefined' ) {
3826 if ( typeof(elem.type) != 'undefined' && typeof(skipElementNames) != 'undefined'
3827 && SUGAR.util.arrayIndexOf(skipElementNames, elem.name) != -1 )
3832 elemType = elem.type.toLowerCase();
3834 if ( elemType == 'text' || elemType == 'textarea' || elemType == 'password' ) {
3836 } else if (elemType == 'select-one') {
3837 // We have, what I hope, is a select box, time to unselect all options
3838 var optionList = elem.options,
3840 for (var ii = 0; ii < optionList.length; ii++) {
3841 if (optionList[ii].value == '') {
3846 if (optionList.length > 0) {
3847 optionList[selectedIndex].selected = "selected";
3849 } else if (elemType == 'select-multiple') {
3850 var optionList = elem.options;
3851 for ( var ii = 0 ; ii < optionList.length ; ii++ ) {
3852 optionList[ii].selected = false;
3855 else if ( elemType == 'radio' || elemType == 'checkbox' ) {
3856 elem.checked = false;
3857 elem.selected = false;
3859 else if ( elemType == 'hidden' ) {
3861 // For bean selection
3862 elem.name.indexOf("_id") != -1
3863 // For custom fields
3864 || elem.name.indexOf("_c") != -1
3865 // For advanced fields, like team collection, or datetime fields
3866 || elem.name.indexOf("_advanced") != -1
3874 // If there are any collections
3875 if (typeof(collection) !== 'undefined')
3877 // Loop through all the collections on the page and run clean_up()
3878 for (key in collection)
3880 // Clean up only removes blank fields, if any
3881 collection[key].clean_up();
3885 SUGAR.searchForm.clearBasicSearchOrderToDefault(form);
3886 SUGAR.savedViews.clearColumns = true;
3888 // This function sets sorting to default Sugar values after BasicSearch Clear button is pressed
3889 clearBasicSearchOrderToDefault: function(form)
3891 if(form.elements['searchFormTab']){
3892 var formType = form.elements['searchFormTab'].value;
3893 if (formType == 'basic_search')
3895 form.elements['orderBy'].value = 'DATE_ENTERED';
3896 form.elements['sortOrder'].value = 'DESC';
3902 // Code for the column/tab chooser used on homepage and in admin section
3903 SUGAR.tabChooser = function () {
3904 var object_refs = new Array();
3906 /* Describe certain transfers as invalid */
3909 movementCallback: function(left_side, right_side) {},
3910 orderCallback: function(left_side, right_side) {},
3912 freezeOptions: function(left_name, right_name, target) {
3913 if(!SUGAR.tabChooser.frozenOptions) { SUGAR.tabChooser.frozenOptions = []; }
3914 if(!SUGAR.tabChooser.frozenOptions[left_name]) { SUGAR.tabChooser.frozenOptions[left_name] = []; }
3915 if(!SUGAR.tabChooser.frozenOptions[left_name][right_name]) { SUGAR.tabChooser.frozenOptions[left_name][right_name] = []; }
3916 if(typeof target == 'array') {
3917 for(var i in target) {
3918 SUGAR.tabChooser.frozenOptions[left_name][right_name][target[i]] = true;
3921 SUGAR.tabChooser.frozenOptions[left_name][right_name][target] = true;
3925 buildSelectHTML: function(info) {
3926 var text = "<select";
3928 if(typeof (info['select']['size']) != 'undefined') {
3929 text +=" size=\""+ info['select']['size'] +"\"";
3932 if(typeof (info['select']['name']) != 'undefined') {
3933 text +=" name=\""+ info['select']['name'] +"\"";
3936 if(typeof (info['select']['style']) != 'undefined') {
3937 text +=" style=\""+ info['select']['style'] +"\"";
3940 if(typeof (info['select']['onchange']) != 'undefined') {
3941 text +=" onChange=\""+ info['select']['onchange'] +"\"";
3944 if(typeof (info['select']['multiple']) != 'undefined') {
3949 for(i=0; i<info['options'].length;i++) {
3950 option = info['options'][i];
3951 text += "<option value=\""+option['value']+"\" ";
3952 if ( typeof (option['selected']) != 'undefined' && option['selected']== true) {
3955 text += ">"+option['text']+"</option>";
3957 text += "</select>";
3961 left_to_right: function(left_name, right_name, left_size, right_size) {
3962 SUGAR.savedViews.clearColumns = false;
3963 var left_td = document.getElementById(left_name+'_td');
3964 var right_td = document.getElementById(right_name+'_td');
3966 var display_columns_ref = left_td.getElementsByTagName('select')[0];
3967 var hidden_columns_ref = right_td.getElementsByTagName('select')[0];
3969 var selected_left = new Array();
3970 var notselected_left = new Array();
3971 var notselected_right = new Array();
3973 var left_array = new Array();
3975 var frozen_options = SUGAR.tabChooser.frozenOptions;
3976 frozen_options = frozen_options && frozen_options[left_name] && frozen_options[left_name][right_name]?frozen_options[left_name][right_name]:[];
3978 // determine which options are selected in left
3979 for (i=0; i < display_columns_ref.options.length; i++)
3981 if ( display_columns_ref.options[i].selected == true && !frozen_options[display_columns_ref.options[i].value])
3983 selected_left[selected_left.length] = {text: display_columns_ref.options[i].text, value: display_columns_ref.options[i].value};
3987 notselected_left[notselected_left.length] = {text: display_columns_ref.options[i].text, value: display_columns_ref.options[i].value};
3992 for (i=0; i < hidden_columns_ref.options.length; i++)
3994 notselected_right[notselected_right.length] = {text:hidden_columns_ref.options[i].text, value:hidden_columns_ref.options[i].value};
3998 var left_select_html_info = new Object();
3999 var left_options = new Array();
4000 var left_select = new Object();
4002 left_select['name'] = left_name+'[]';
4003 left_select['id'] = left_name;
4004 left_select['size'] = left_size;
4005 left_select['multiple'] = 'true';
4007 var right_select_html_info = new Object();
4008 var right_options = new Array();
4009 var right_select = new Object();
4011 right_select['name'] = right_name+'[]';
4012 right_select['id'] = right_name;
4013 right_select['size'] = right_size;
4014 right_select['multiple'] = 'true';
4016 for (i = 0; i < notselected_right.length; i++) {
4017 right_options[right_options.length] = notselected_right[i];
4020 for (i = 0; i < selected_left.length; i++) {
4021 right_options[right_options.length] = selected_left[i];
4023 for (i = 0; i < notselected_left.length; i++) {
4024 left_options[left_options.length] = notselected_left[i];
4026 left_select_html_info['options'] = left_options;
4027 left_select_html_info['select'] = left_select;
4028 right_select_html_info['options'] = right_options;
4029 right_select_html_info['select'] = right_select;
4030 right_select_html_info['style'] = 'background: lightgrey';
4032 var left_html = this.buildSelectHTML(left_select_html_info);
4033 var right_html = this.buildSelectHTML(right_select_html_info);
4035 left_td.innerHTML = left_html;
4036 right_td.innerHTML = right_html;
4038 object_refs[left_name] = left_td.getElementsByTagName('select')[0];
4039 object_refs[right_name] = right_td.getElementsByTagName('select')[0];
4041 this.movementCallback(object_refs[left_name], object_refs[right_name]);
4047 right_to_left: function(left_name, right_name, left_size, right_size, max_left) {
4048 SUGAR.savedViews.clearColumns = false;
4049 var left_td = document.getElementById(left_name+'_td');
4050 var right_td = document.getElementById(right_name+'_td');
4052 var display_columns_ref = left_td.getElementsByTagName('select')[0];
4053 var hidden_columns_ref = right_td.getElementsByTagName('select')[0];
4055 var selected_right = new Array();
4056 var notselected_right = new Array();
4057 var notselected_left = new Array();
4059 var frozen_options = SUGAR.tabChooser.frozenOptions;
4060 frozen_options = SUGAR.tabChooser.frozenOptions && SUGAR.tabChooser.frozenOptions[right_name] && SUGAR.tabChooser.frozenOptions[right_name][left_name]?SUGAR.tabChooser.frozenOptions[right_name][left_name]:[];
4062 for (i=0; i < hidden_columns_ref.options.length; i++)
4064 if (hidden_columns_ref.options[i].selected == true && !frozen_options[hidden_columns_ref.options[i].value])
4066 selected_right[selected_right.length] = {text:hidden_columns_ref.options[i].text, value:hidden_columns_ref.options[i].value};
4070 notselected_right[notselected_right.length] = {text:hidden_columns_ref.options[i].text, value:hidden_columns_ref.options[i].value};
4075 if(max_left != '' && (display_columns_ref.length + selected_right.length) > max_left) {
4076 alert('Maximum of ' + max_left + ' columns can be displayed.');
4080 for (i=0; i < display_columns_ref.options.length; i++)
4082 notselected_left[notselected_left.length] = {text:display_columns_ref.options[i].text, value:display_columns_ref.options[i].value};
4086 var left_select_html_info = new Object();
4087 var left_options = new Array();
4088 var left_select = new Object();
4090 left_select['name'] = left_name+'[]';
4091 left_select['id'] = left_name;
4092 left_select['multiple'] = 'true';
4093 left_select['size'] = left_size;
4095 var right_select_html_info = new Object();
4096 var right_options = new Array();
4097 var right_select = new Object();
4099 right_select['name'] = right_name+ '[]';
4100 right_select['id'] = right_name;
4101 right_select['multiple'] = 'true';
4102 right_select['size'] = right_size;
4104 for (i = 0; i < notselected_left.length; i++) {
4105 left_options[left_options.length] = notselected_left[i];
4108 for (i = 0; i < selected_right.length; i++) {
4109 left_options[left_options.length] = selected_right[i];
4111 for (i = 0; i < notselected_right.length; i++) {
4112 right_options[right_options.length] = notselected_right[i];
4114 left_select_html_info['options'] = left_options;
4115 left_select_html_info['select'] = left_select;
4116 right_select_html_info['options'] = right_options;
4117 right_select_html_info['select'] = right_select;
4118 right_select_html_info['style'] = 'background: lightgrey';
4120 var left_html = this.buildSelectHTML(left_select_html_info);
4121 var right_html = this.buildSelectHTML(right_select_html_info);
4123 left_td.innerHTML = left_html;
4124 right_td.innerHTML = right_html;
4126 object_refs[left_name] = left_td.getElementsByTagName('select')[0];
4127 object_refs[right_name] = right_td.getElementsByTagName('select')[0];
4129 this.movementCallback(object_refs[left_name], object_refs[right_name]);
4134 up: function(name, left_name, right_name) {
4135 SUGAR.savedViews.clearColumns = false;
4136 var left_td = document.getElementById(left_name+'_td');
4137 var right_td = document.getElementById(right_name+'_td');
4138 var td = document.getElementById(name+'_td');
4139 var obj = td.getElementsByTagName('select')[0];
4140 obj = (typeof obj == "string") ? document.getElementById(obj) : obj;
4141 if (obj.tagName.toLowerCase() != "select" && obj.length < 2)
4143 var sel = new Array();
4145 for (i=0; i<obj.length; i++) {
4146 if (obj[i].selected == true) {
4147 sel[sel.length] = i;
4150 for (i=0; i < sel.length; i++) {
4151 if (sel[i] != 0 && !obj[sel[i]-1].selected) {
4152 var tmp = new Array(obj[sel[i]-1].text, obj[sel[i]-1].value);
4153 obj[sel[i]-1].text = obj[sel[i]].text;
4154 obj[sel[i]-1].value = obj[sel[i]].value;
4155 obj[sel[i]].text = tmp[0];
4156 obj[sel[i]].value = tmp[1];
4157 obj[sel[i]-1].selected = true;
4158 obj[sel[i]].selected = false;
4162 object_refs[left_name] = left_td.getElementsByTagName('select')[0];
4163 object_refs[right_name] = right_td.getElementsByTagName('select')[0];
4165 this.orderCallback(object_refs[left_name], object_refs[right_name]);
4170 down: function(name, left_name, right_name) {
4171 SUGAR.savedViews.clearColumns = false;
4172 var left_td = document.getElementById(left_name+'_td');
4173 var right_td = document.getElementById(right_name+'_td');
4174 var td = document.getElementById(name+'_td');
4175 var obj = td.getElementsByTagName('select')[0];
4176 if (obj.tagName.toLowerCase() != "select" && obj.length < 2)
4178 var sel = new Array();
4179 for (i=obj.length-1; i>-1; i--) {
4180 if (obj[i].selected == true) {
4181 sel[sel.length] = i;
4184 for (i=0; i < sel.length; i++) {
4185 if (sel[i] != obj.length-1 && !obj[sel[i]+1].selected) {
4186 var tmp = new Array(obj[sel[i]+1].text, obj[sel[i]+1].value);
4187 obj[sel[i]+1].text = obj[sel[i]].text;
4188 obj[sel[i]+1].value = obj[sel[i]].value;
4189 obj[sel[i]].text = tmp[0];
4190 obj[sel[i]].value = tmp[1];
4191 obj[sel[i]+1].selected = true;
4192 obj[sel[i]].selected = false;
4196 object_refs[left_name] = left_td.getElementsByTagName('select')[0];
4197 object_refs[right_name] = right_td.getElementsByTagName('select')[0];
4199 this.orderCallback(object_refs[left_name], object_refs[right_name]);
4204 }(); // end tabChooser
4206 SUGAR.language = function() {
4208 languages : new Array(),
4210 setLanguage: function(module, data) {
4211 if (!SUGAR.language.languages) {
4214 SUGAR.language.languages[module] = data;
4217 get: function(module, str) {
4218 if(typeof SUGAR.language.languages[module] == 'undefined' || typeof SUGAR.language.languages[module][str] == 'undefined')
4222 return SUGAR.language.languages[module][str];
4225 translate: function(module, str)
4227 text = this.get(module, str);
4228 return text != 'undefined' ? text : this.get('app_strings', str);
4233 SUGAR.contextMenu = function() {
4235 objects: new Object(),
4236 objectTypes: new Object(),
4238 * Registers a new object for the context menu.
4239 * objectType - name of the type
4241 * metaData - metaData to pass to the action function
4243 registerObject: function(objectType, id, metaData) {
4244 SUGAR.contextMenu.objects[id] = new Object();
4245 SUGAR.contextMenu.objects[id] = {'objectType' : objectType, 'metaData' : metaData};
4248 * Registers a new object type
4249 * name - name of the type
4250 * menuItems - array of menu items
4252 registerObjectType: function(name, menuItems) {
4253 SUGAR.contextMenu.objectTypes[name] = new Object();
4254 SUGAR.contextMenu.objectTypes[name] = {'menuItems' : menuItems, 'objects' : new Array()};
4257 * Determines which menu item was clicked
4259 getListItemFromEventTarget: function(p_oNode) {
4261 if(p_oNode.tagName == "LI") {
4266 if(p_oNode.tagName == "LI") {
4271 } while((p_oNode = p_oNode.parentNode));
4276 * handles movement within context menu
4278 onContextMenuMove: function() {
4279 var oNode = this.contextEventTarget;
4280 var bDisabled = (oNode.tagName == "UL");
4281 var i = this.getItemGroups()[0].length - 1;
4283 this.getItem(i).cfg.setProperty("disabled", bDisabled);
4288 * handles clicks on a context menu ITEM
4290 onContextMenuItemClick: function(p_sType, p_aArguments, p_oItem) {
4291 var oLI = SUGAR.contextMenu.getListItemFromEventTarget(this.parent.contextEventTarget);
4292 id = this.parent.contextEventTarget.parentNode.id; // id of the target
4293 funct = eval(SUGAR.contextMenu.objectTypes[SUGAR.contextMenu.objects[id]['objectType']]['menuItems'][this.index]['action']);
4294 funct(this.parent.contextEventTarget, SUGAR.contextMenu.objects[id]['metaData']);
4297 * Initializes all context menus registered
4300 for(var i in SUGAR.contextMenu.objects) { // make a variable called objects in objectTypes containg references to all triggers
4301 if(typeof SUGAR.contextMenu.objectTypes[SUGAR.contextMenu.objects[i]['objectType']]['objects'] == 'undefined')
4302 SUGAR.contextMenu.objectTypes[SUGAR.contextMenu.objects[i]['objectType']]['objects'] = new Array();
4303 SUGAR.contextMenu.objectTypes[SUGAR.contextMenu.objects[i]['objectType']]['objects'].push(document.getElementById(i));
4305 // register the menus
4306 for(var i in SUGAR.contextMenu.objectTypes) {
4307 var oContextMenu = new YAHOO.widget.ContextMenu(i, {'trigger': SUGAR.contextMenu.objectTypes[i]['objects']});
4308 var aMainMenuItems = SUGAR.contextMenu.objectTypes[i]['menuItems'];
4309 var nMainMenuItems = aMainMenuItems.length;
4311 for(var j = 0; j < nMainMenuItems; j++) {
4312 oMenuItem = new YAHOO.widget.ContextMenuItem(aMainMenuItems[j].text, { helptext: aMainMenuItems[j].helptext });
4313 oMenuItem.clickEvent.subscribe(SUGAR.contextMenu.onContextMenuItemClick, oMenuItem, true);
4314 oContextMenu.addItem(oMenuItem);
4316 // Add a "move" event handler to the context menu
4317 oContextMenu.moveEvent.subscribe(SUGAR.contextMenu.onContextMenuMove, oContextMenu, true);
4318 // Add a "keydown" event handler to the context menu
4319 oContextMenu.keyDownEvent.subscribe(SUGAR.contextMenu.onContextMenuItemClick, oContextMenu, true);
4320 // Render the context menu
4321 oContextMenu.render(document.body);
4327 SUGAR.contextMenu.actions = function() {
4330 * redirects to a new note with the clicked on object as the target
4332 createNote: function(itemClicked, metaData) {
4333 loc = 'index.php?module=Notes&action=EditView';
4334 for(i in metaData) {
4335 if(i == 'notes_parent_type') loc += '&parent_type=' + metaData[i];
4336 else if(i != 'module' && i != 'parent_type') loc += '&' + i + '=' + metaData[i];
4338 document.location = loc;
4341 * redirects to a new note with the clicked on object as the target
4343 scheduleMeeting: function(itemClicked, metaData) {
4344 loc = 'index.php?module=Meetings&action=EditView';
4345 for(i in metaData) {
4346 if(i != 'module') loc += '&' + i + '=' + metaData[i];
4348 document.location = loc;
4351 * redirects to a new note with the clicked on object as the target
4353 scheduleCall: function(itemClicked, metaData) {
4354 loc = 'index.php?module=Calls&action=EditView';
4355 for(i in metaData) {
4356 if(i != 'module') loc += '&' + i + '=' + metaData[i];
4358 document.location = loc;
4361 * redirects to a new contact with the clicked on object as the target
4363 createContact: function(itemClicked, metaData) {
4364 loc = 'index.php?module=Contacts&action=EditView';
4365 for(i in metaData) {
4366 if(i != 'module') loc += '&' + i + '=' + metaData[i];
4368 document.location = loc;
4371 * redirects to a new task with the clicked on object as the target
4373 createTask: function(itemClicked, metaData) {
4374 loc = 'index.php?module=Tasks&action=EditView';
4375 for(i in metaData) {
4376 if(i != 'module') loc += '&' + i + '=' + metaData[i];
4378 document.location = loc;
4381 * redirects to a new opportunity with the clicked on object as the target
4383 createOpportunity: function(itemClicked, metaData) {
4384 loc = 'index.php?module=Opportunities&action=EditView';
4385 for(i in metaData) {
4386 if(i != 'module') loc += '&' + i + '=' + metaData[i];
4388 document.location = loc;
4391 * redirects to a new opportunity with the clicked on object as the target
4393 createCase: function(itemClicked, metaData) {
4394 loc = 'index.php?module=Cases&action=EditView';
4395 for(i in metaData) {
4396 if(i != 'module') loc += '&' + i + '=' + metaData[i];
4398 document.location = loc;
4401 * handles add to favorites menu selection
4403 addToFavorites: function(itemClicked, metaData) {
4404 success = function(data) {
4406 var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?to_pdf=true&module=Home&action=AddToFavorites&target_id=' + metaData['id'] + '&target_module=' + metaData['module'], {success: success, failure: success});
4411 //if(typeof YAHOO != 'undefined') YAHOO.util.Event.addListener(window, 'load', SUGAR.contextMenu.init);
4413 // initially from popup_parent_helper.js
4414 var popup_request_data;
4417 function get_popup_request_data()
4419 return YAHOO.lang.JSON.stringify(window.document.popup_request_data);
4422 function get_close_popup()
4424 return window.document.close_popup;
4427 function open_popup(module_name, width, height, initial_filter, close_popup, hide_clear_button, popup_request_data, popup_mode, create, metadata)
4429 if (typeof(popupCount) == "undefined" || popupCount == 0)
4432 // set the variables that the popup will pull from
4433 window.document.popup_request_data = popup_request_data;
4434 window.document.close_popup = close_popup;
4436 //globally changing width and height of standard pop up window from 600 x 400 to 800 x 800
4437 width = (width == 600) ? 800 : width;
4438 height = (height == 400) ? 800 : height;
4442 + 'module=' + module_name
4445 if (initial_filter != '') {
4446 URL += '&query=true' + initial_filter;
4447 // Bug 41891 - Popup Window Name
4448 popupName = initial_filter.replace(/[^a-z_0-9]+/ig, '_');
4449 windowName = module_name + '_popup_window' + popupName;
4451 windowName = module_name + '_popup_window' + popupCount;
4455 if (hide_clear_button) {
4456 URL += '&hide_clear_button=true';
4459 windowFeatures = 'width=' + width
4460 + ',height=' + height
4461 + ',resizable=1,scrollbars=1';
4463 if (popup_mode == '' || popup_mode == undefined) {
4464 popup_mode='single';
4466 URL+='&mode='+popup_mode;
4467 if (create == '' || create == undefined) {
4470 URL+='&create='+create;
4472 if (metadata != '' && metadata != undefined) {
4473 URL+='&metadata='+metadata;
4476 // Bug #46842 : The relate field field_to_name_array fails to copy over custom fields
4477 // post fields that should be populated from popup form
4478 if(popup_request_data.jsonObject) {
4479 var request_data = popup_request_data.jsonObject;
4481 var request_data = popup_request_data;
4483 var field_to_name_array_url = '';
4485 if (request_data && request_data.field_to_name_array != undefined) {
4486 for(var key in request_data.field_to_name_array) {
4487 if ( key.toLowerCase() != 'id' ) {
4488 field_to_name_array_url += '&field_to_name[]='+encodeURIComponent(key.toLowerCase());
4492 if ( field_to_name_array_url ) {
4493 URL+=field_to_name_array_url;
4496 win = SUGAR.util.openWindow(URL, windowName, windowFeatures);
4500 // put the focus on the popup if the browser supports the focus() method
4504 win.popupCount = popupCount;
4510 * The reply data must be a JSON array structured with the following information:
4511 * 1) form name to populate
4512 * 2) associative array of input names to values for populating the form
4514 var from_popup_return = false;
4516 //Function replaces special HTML chars for usage in text boxes
4517 function replaceHTMLChars(value) {
4518 return value.replace(/&/gi,'&').replace(/</gi,'<').replace(/>/gi,'>').replace(/'/gi,'\'').replace(/"/gi,'"');
4521 function set_return_basic(popup_reply_data,filter)
4523 var form_name = popup_reply_data.form_name;
4524 var name_to_value_array = popup_reply_data.name_to_value_array;
4525 for (var the_key in name_to_value_array)
4527 if(the_key == 'toJSON')
4531 else if(the_key.match(filter))
4533 var displayValue=replaceHTMLChars(name_to_value_array[the_key]);
4534 // begin andopes change: support for enum fields (SELECT)
4535 if(window.document.forms[form_name] && window.document.forms[form_name].elements[the_key]) {
4536 if(window.document.forms[form_name].elements[the_key].tagName == 'SELECT') {
4537 var selectField = window.document.forms[form_name].elements[the_key];
4538 for(var i = 0; i < selectField.options.length; i++) {
4539 if(selectField.options[i].text == displayValue) {
4540 selectField.options[i].selected = true;
4541 SUGAR.util.callOnChangeListers(selectField);
4546 window.document.forms[form_name].elements[the_key].value = displayValue;
4547 SUGAR.util.callOnChangeListers(window.document.forms[form_name].elements[the_key]);
4550 // end andopes change: support for enum fields (SELECT)
4555 function set_return(popup_reply_data)
4557 from_popup_return = true;
4558 var form_name = popup_reply_data.form_name;
4559 var name_to_value_array = popup_reply_data.name_to_value_array;
4560 if(typeof name_to_value_array != 'undefined' && name_to_value_array['account_id'])
4563 var label_data_str = '';
4564 var current_label_data_str = '';
4565 var popupConfirm = popup_reply_data.popupConfirm;
4566 for (var the_key in name_to_value_array)
4568 if(the_key == 'toJSON')
4574 var displayValue=replaceHTMLChars(name_to_value_array[the_key]);
4575 if(window.document.forms[form_name] && document.getElementById(the_key+'_label') && !the_key.match(/account/)) {
4576 var data_label = document.getElementById(the_key+'_label').innerHTML.replace(/\n/gi,'').replace(/<\/?[^>]+(>|$)/g, "");
4577 label_str += data_label + ' \n';
4578 label_data_str += data_label + ' ' + displayValue + '\n';
4579 if(window.document.forms[form_name].elements[the_key]) {
4580 current_label_data_str += data_label + ' ' + window.document.forms[form_name].elements[the_key].value +'\n';
4586 if(label_data_str != label_str && current_label_data_str != label_str){
4588 if (typeof popupConfirm != 'undefined')
4590 if (popupConfirm > -1) {
4591 set_return_basic(popup_reply_data,/\S/);
4593 set_return_basic(popup_reply_data,/account/);
4597 else if(confirm(SUGAR.language.get('app_strings', 'NTC_OVERWRITE_ADDRESS_PHONE_CONFIRM') + '\n\n' + label_data_str))
4599 set_return_basic(popup_reply_data,/\S/);
4603 set_return_basic(popup_reply_data,/account/);
4605 }else if(label_data_str != label_str && current_label_data_str == label_str){
4606 set_return_basic(popup_reply_data,/\S/);
4607 }else if(label_data_str == label_str){
4608 set_return_basic(popup_reply_data,/account/);
4611 set_return_basic(popup_reply_data,/\S/);
4615 function set_return_lead_conv(popup_reply_data) {
4616 set_return(popup_reply_data);
4617 if (document.getElementById('lead_conv_ac_op_sel') && typeof onBlurKeyUpHandler=='function') {
4618 onBlurKeyUpHandler();
4622 function set_return_and_save(popup_reply_data)
4624 var form_name = popup_reply_data.form_name;
4625 var name_to_value_array = popup_reply_data.name_to_value_array;
4627 for (var the_key in name_to_value_array)
4629 if(the_key == 'toJSON')
4635 window.document.forms[form_name].elements[the_key].value = name_to_value_array[the_key];
4639 window.document.forms[form_name].return_module.value = window.document.forms[form_name].module.value;
4640 window.document.forms[form_name].return_action.value = 'DetailView';
4641 window.document.forms[form_name].return_id.value = window.document.forms[form_name].record.value;
4642 window.document.forms[form_name].action.value = 'Save';
4643 window.document.forms[form_name].submit();
4647 * This is a helper function to construct the initial filter that can be
4648 * passed into the open_popup() function. It assumes that there is an
4649 * account_id and account_name field in the given form_name to use to
4650 * construct the intial filter string.
4652 function get_initial_filter_by_account(form_name)
4654 var account_id = window.document.forms[form_name].account_id.value;
4655 var account_name = escape(window.document.forms[form_name].account_name.value);
4656 var initial_filter = "&account_id=" + account_id + "&account_name=" + account_name;
4658 return initial_filter;
4660 // end code from popup_parent_helper.js
4662 // begin code for address copy
4664 * This is a function used by the Address widget that will fill
4665 * in the given array fields using the fromKey and toKey as a
4666 * prefix into the form objects HTML elements.
4668 * @param form The HTML form object to parse
4669 * @param fromKey The prefix of elements to copy from
4670 * @param toKey The prefix of elements to copy into
4671 * @return boolean true if successful, false otherwise
4673 function copyAddress(form, fromKey, toKey) {
4675 var elems = new Array("address_street", "address_city", "address_state", "address_postalcode", "address_country");
4676 var checkbox = document.getElementById(toKey + "_checkbox");
4678 if(typeof checkbox != "undefined") {
4679 if(!checkbox.checked) {
4681 t = toKey + "_" + elems[x];
4682 document.getElementById(t).removeAttribute('readonly');
4686 f = fromKey + "_" + elems[x];
4687 t = toKey + "_" + elems[x];
4689 document.getElementById(t).value = document.getElementById(f).value;
4690 document.getElementById(t).setAttribute('readonly', true);
4696 // end code for address copy
4699 * This function is used in Email Template Module.
4700 * It will check whether the template is used in Campaing->EmailMarketing.
4701 * If true, it will notify user.
4704 function check_deletable_EmailTemplate() {
4705 id = document.getElementsByName('record')[0].value;
4706 currentForm = document.getElementById('form');
4708 success:function(r) {
4709 if(r.responseText == 'true') {
4710 if(!confirm(SUGAR.language.get('app_strings','NTC_TEMPLATE_IS_USED'))) {
4714 if(!confirm(SUGAR.language.get('app_strings','NTC_DELETE_CONFIRMATION'))) {
4718 currentForm.return_module.value='EmailTemplates';
4719 currentForm.return_action.value='ListView';
4720 currentForm.action.value='Delete';
4721 currentForm.submit();
4724 url = "index.php?module=EmailTemplates&action=CheckDeletable&from=DetailView&to_pdf=1&record="+id;
4725 YAHOO.util.Connect.asyncRequest('POST',url, call_back,null);
4729 remove_upload_imagefile : function(field_name) {
4730 var field=document.getElementById('remove_imagefile_' + field_name);
4733 //enable the file upload button.
4734 var field=document.getElementById( field_name);
4735 field.style.display="";
4737 //hide the image and remove button.
4738 var field=document.getElementById('img_' + field_name);
4739 field.style.display="none";
4740 var field=document.getElementById('bt_remove_' + field_name);
4741 field.style.display="none";
4743 if(document.getElementById(field_name + '_duplicate')) {
4744 var field = document.getElementById(field_name + '_duplicate');
4749 confirm_imagefile : function(field_name) {
4750 var field=document.getElementById(field_name);
4751 var filename=field.value;
4752 var fileExtension = filename.substring(filename.lastIndexOf(".")+1);
4753 fileExtension = fileExtension.toLowerCase();
4754 if (fileExtension == "jpg" || fileExtension == "jpeg"
4755 || fileExtension == "gif" || fileExtension == "png" || fileExtension == "bmp"){
4760 alert(SUGAR.language.get('app_strings', 'LBL_UPLOAD_IMAGE_FILE_INVALID'));
4764 lightbox : function(image)
4766 if (typeof(SUGAR.image.lighboxWindow) == "undefined")
4767 SUGAR.image.lighboxWindow = new YAHOO.widget.SimpleDialog('sugarImageViewer', {
4770 id:'sugarMsgWindow',
4773 msg: "<img src='" + image + "'> </img>",
4776 SUGAR.image.lighboxWindow.setBody("<img src='" + image + "'> </img>");
4777 SUGAR.image.lighboxWindow.render(document.body);
4778 SUGAR.image.lighboxWindow.show();
4779 SUGAR.image.lighboxWindow.center()
4783 SUGAR.append(SUGAR.util, {
4784 isTouchScreen: function() {
4785 // first check if we have forced use of the touch enhanced interface
4786 if (Get_Cookie("touchscreen") == '1') {
4790 // next check if we should use the touch interface with our device
4791 if ((navigator.userAgent.match(/iPad/i) != null)) {
4798 isLoginPage: function(content) {
4799 //skip if this is packageManager screen
4800 if(SUGAR.util.isPackageManager()) {return false;}
4801 var loginPageStart = "<!DOCTYPE";
4802 if (content.substr(0, loginPageStart.length) == loginPageStart && content.indexOf("<html>") != -1 && content.indexOf("login_module") != -1) {
4803 window.location.href = window.location.protocol + window.location.pathname;
4808 isPackageManager: function(){
4809 if(typeof(document.the_form) !='undefined' && typeof(document.the_form.language_pack_escaped) !='undefined'){
4811 }else{return false;}
4814 ajaxCallInProgress: function(){
4816 //First check if we are in a popup.
4817 if (typeof (send_back) != "function"){
4818 //If the page content is blank, it means we are probably still waiting on something
4819 var c = document.getElementById("content");
4820 if (!c) return true;
4821 t = YAHOO.lang.trim(SUGAR.util.innerText(c));
4823 return SUGAR_callsInProgress != 0 || t == "";
4825 //Firefox doesn't support innerText (textContent includes script content)
4826 innerText : function(el) {
4827 if (el.tagName == "SCRIPT")
4829 if(typeof(el.innerText) == "string")
4830 return el.innerText;
4832 for (var i in el.childNodes){
4833 var c = el.childNodes[i];
4834 if (typeof(c) != "object")
4836 if (typeof(c.nodeName) == "string" && c.nodeName == "#text")
4839 t += SUGAR.util.innerText(c);
4844 callOnChangeListers: function(field){
4845 var listeners = YAHOO.util.Event.getListeners(field, 'change');
4846 if (listeners != null) {
4847 for (var i = 0; i < listeners.length; i++) {
4848 var l = listeners[i];
4849 l.fn.call(l.scope ? l.scope : this, l.obj);
4854 closeActivityPanel: {
4855 show:function(module,id,new_status,viewType,parentContainerId){
4856 if (SUGAR.util.closeActivityPanel.panel)
4857 SUGAR.util.closeActivityPanel.panel.destroy();
4858 var singleModule = SUGAR.language.get("app_list_strings", "moduleListSingular")[module];
4859 singleModule = typeof(singleModule != 'undefined') ? singleModule.toLowerCase() : '';
4860 var closeText = SUGAR.language.get("app_strings", "LBL_CLOSE_ACTIVITY_CONFIRM").replace("#module#",singleModule);
4861 SUGAR.util.closeActivityPanel.panel =
4862 new YAHOO.widget.SimpleDialog("closeActivityDialog",
4869 constraintoviewport: true,
4870 buttons: [ { text:SUGAR.language.get("app_strings", "LBL_EMAIL_OK"), handler:function(){
4871 if (SUGAR.util.closeActivityPanel.panel)
4872 SUGAR.util.closeActivityPanel.panel.hide();
4874 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
4875 var args = "action=save&id=" + id + "&record=" + id + "&status=" + new_status + "&module=" + module;
4876 // 20110307 Frank Steegmans: Fix for bug 42361, Any field with a default configured in any activity will be set to this default when closed using the close dialog
4877 // TODO: Take id out and regression test. Left id in for now to not create any other unexpected problems
4878 //var args = "action=save&id=" + id + "&status=" + new_status + "&module=" + module;
4882 // Bug 51984: We need to submit the form just incase we have a form already submitted
4883 // so we dont get a popup stating that the form needs to be resubmitted like it doesn,
4884 // when you do a reload/refresh
4885 window.setTimeout(function(){if(document.getElementById('search_form')) document.getElementById('search_form').submit(); else window.location.reload(true);}, 0);
4887 argument:{'parentContainerId':parentContainerId}
4890 YAHOO.util.Connect.asyncRequest('POST', 'index.php', callback, args);
4892 }, isDefault:true },
4893 { text:SUGAR.language.get("app_strings", "LBL_EMAIL_CANCEL"), handler:function(){SUGAR.util.closeActivityPanel.panel.hide(); }} ]
4896 SUGAR.util.closeActivityPanel.panel.setHeader(SUGAR.language.get("app_strings", "LBL_CLOSE_ACTIVITY_HEADER"));
4897 SUGAR.util.closeActivityPanel.panel.render(document.body);
4898 SUGAR.util.closeActivityPanel.panel.show();
4902 setEmailPasswordDisplay: function(id, exists, formName) {
4903 link = document.getElementById(id+'_link');
4904 pwd = document.getElementById(id);
4905 if(!pwd || !link) return;
4907 pwd.disabled = true;
4908 pwd.style.display = 'none';
4909 link.style.display = '';
4910 if(typeof(formName) != 'undefined')
4911 removeFromValidate(formName, id);
4913 pwd.disabled = false;
4914 pwd.style.display = '';
4915 link.style.display = 'none';
4919 setEmailPasswordEdit: function(id) {
4920 link = document.getElementById(id+'_link');
4921 pwd = document.getElementById(id);
4922 if(!pwd || !link) return;
4923 pwd.disabled = false;
4924 pwd.style.display = '';
4925 link.style.display = 'none';
4929 * Compares a filename with a supplied array of allowed file extensions.
4930 * @param fileName string
4931 * @param allowedTypes array of allowed file extensions
4934 validateFileExt: function(fileName, allowedTypes) {
4935 var ext = fileName.split('.').pop().toLowerCase();
4937 for (var i = allowedTypes.length; i >= 0; i--) {
4938 if (ext === allowedTypes[i]) {
4946 arrayIndexOf: function(arr, val, start) {
4947 if (typeof arr.indexOf == "function")
4948 return arr.indexOf(val, start);
4949 for (var i = (start || 0), j = arr.length; i < j; i++) {
4950 if (arr[i] === val) {
4958 SUGAR.clearRelateField = function(form, name, id)
4960 if (typeof form[name] == "object"){
4961 form[name].value = '';
4962 SUGAR.util.callOnChangeListers(form[name]);
4965 if (typeof form[id] == "object"){
4966 form[id].value = '';
4967 SUGAR.util.callOnChangeListers(form[id]);
4970 if(typeof(SUGAR.AutoComplete) == 'undefined') SUGAR.AutoComplete = {};
4972 SUGAR.AutoComplete.getOptionsArray = function(options_index){
4973 var return_arr = [];
4975 var opts = SUGAR.language.get('app_list_strings', options_index);
4976 if(typeof(opts) != 'undefined'){
4978 // Since we are using auto complete, we excluse blank dropdown entries since they can just leave it blank
4979 if(key != '' && opts[key] != ''){
4982 item['text'] = opts[key];
4983 return_arr.push(item);
4990 if(typeof(SUGAR.MultiEnumAutoComplete) == 'undefined') SUGAR.MultiEnumAutoComplete = {};
4992 SUGAR.MultiEnumAutoComplete.getMultiSelectKeysFromValues = function(options_index, val_string){
4993 var opts = SUGAR.language.get('app_list_strings', options_index);
4994 var selected_values = val_string.split(", ");
4995 // YUI AutoComplete adds a blank. We remove it automatically here
4996 if(selected_values.length > 0 && selected_values.indexOf('') == selected_values.length - 1){
4997 selected_values.pop();
4999 var final_arr = new Array();
5000 for(idx in selected_values){
5002 if(selected_values[idx] == opts[o_idx]){
5003 final_arr.push(o_idx);
5010 SUGAR.MultiEnumAutoComplete.getMultiSelectValuesFromKeys = function(options_index, val_string){
5011 var opts = SUGAR.language.get('app_list_strings', options_index);
5012 val_string=val_string.replace(/^\^/,'').replace(/\^$/,'') //fixes bug where string starts or ends with ^
5013 var selected_values = val_string.split("^,^");
5015 // YUI AutoComplete adds a blank. We remove it automatically here
5016 if(selected_values.length > 0 && selected_values.indexOf('') == selected_values.length - 1){
5017 selected_values.pop();
5020 var final_arr = new Array();
5021 for(idx in selected_values){
5023 if(selected_values[idx] == o_idx){
5024 final_arr.push(opts[o_idx]);
5031 function convertReportDateTimeToDB(dateValue, timeValue)
5033 var date_match = dateValue.match(date_reg_format);
5034 var time_match = timeValue.match(/([0-9]{1,2})\:([0-9]{1,2})([ap]m)/);
5035 if ( date_match != null && time_match != null) {
5036 time_match[1] = parseInt(time_match[1]);
5037 if (time_match[3] == 'pm') {
5038 time_match[1] = time_match[1] + 12;
5039 if (time_match[1] >= 24) {
5040 time_match[1] = time_match[1] - 24;
5042 } else if (time_match[3] == 'am' && time_match[1] == 12) {
5045 if (time_match[1] < 10) {
5046 time_match[1] = '0' + time_match[1];
5048 return date_match[date_reg_positions['Y']] + "-"+date_match[date_reg_positions['m']] + "-"+date_match[date_reg_positions['d']] + ' '+ time_match[1] + ':' + time_match[2] + ':00';