Methods

  • BrainJS: u.method()
  • BrainXML: <u>method()</u>
function User( ) {
this.getCertData = function(app) {
  
     var url = 'http://acobot.com/api/';
     switch (app){
       case 'vocabulary':
         url += 'vb';
         break;
         
       case 'listening':
         url += 'listening';
         break;
             
       case 'speaking':
         url += 'speaking';
         break;
   
       default:
         return '';
     }
     
     url += '/cert/' + this.uid_key;
     return sraix(url);
  
};
this.getChineseSign = function( year) {
     if(year) {
      return chineseSign(year);
     }
     if (!this.birth.year) {
       return false;
     }    
     if (this.birth.year === '') {
       return false;
     }    
     return chineseSign(parseInt(this.birth.year,10));
  
};
this.getChineseTime = function( ) {
   return chineseTime();
};
this.getCountry = function( ) {
  
     var country = this.location.country;
     if (country == "") {
       country = this.device.country;
     }
     return country;
  
};
this.getFullName = function( ) {
  
     if (this.name &&  this.name) {
       return this.name + ' ' + this.name;
     }
     else {
       return '';
     }
  
};
this.getHolidayToday = function( ) {
     var d = new Date();
     return holidayUS(d);  
  
};
this.getIdle = function(unit) {
  
     switch (unit){
       case "days":
         return Math.floor(this.idle / 86400);
       case "hours":
         return Math.floor(this.idle / 3600);      
       default:
         return this.idle;      
     }
  
};
this.getIndex = function(name, relation) {
    
     if (!name && !relation) {
       return '';
     }
     var i;
     var lowerName = '';
     if (name) {
       lowerName = name.toLowerCase();
       // name first, matching relation if any
       for ( i in this.people) {
         if (this.people[i].name){
           if (this.people[i].name.toLowerCase() === lowerName) {
             if (relation) {
               if (this.people[i].relation === relation) {          
                 return i;
               }
             }
             else {
               return i;
             }
           }
         }
       }
       // if not found, look among ones without name
       if (relation) {
         for ( i in this.people) {
           if (!this.people[i].name){
             if (this.people[i].relation === relation) {          
               return i;
             }
           } 
         }
       }
     }
     else {
       for (var j in this.people) {
         if (this.people[j].relation === relation) {
           return j;
         }
       }
     }    
     return '';
  
};
this.getJSON = function( ) {
  
     return JSON.stringify(this);    
  
};
this.getLang = function(src) {
  var result = "en";
  	var scCount = 0;
  	var wordsCount = 1;
  	var hasSc = false;
  	var normSentence = "";
  	if(src == null) {
  	  return result;
  	} 
  	  
  	for(var i=0; i 255) {
  			normSentence = normSentence + " " + src.charAt(i) + " ";
  			scCount ++;
  			hasSc = true;
  		} else {
  			normSentence = normSentence + src.charAt(i);
  		}
  	}
  	
  	while(normSentence.indexOf("  ") > -1) {
  		normSentence = normSentence.replace("  ", " ");
  	}
  	if(hasSc) {
  		wordsCount = normSentence.trim().split(" ").length;
  	}
  	if(wordsCount <= scCount * 2) {
  		result = "sc";
  	}
  	return result;
  	
};

Pages