Developers

You are a developer and you want to extend the functions of the Colorizer? Maybe a check against an external system? No problem!

At the moment the only feature you could extend are the condition functions like “is empty”, “is equal”, “is_lower”, … But this is the only point, which is interesting for you. In the directory modules/Colorizer/extends/functions/ you see a file called core.inc.php.

Here you could see the definitions of the original conditions and the structure you need to create your own functions. If you want to create your own conditions, the best way is to create your own file *.inc.php in this directory.

This file won't be deleted on module updates.

$formatCondition["<condition_key>"] = array("function" => "
                Javascript function, which does the condition.
                returns: true/false if the condition is true or false.",
        "title" => "<label in dropdown>",
        "description" => "<description>",
        "blockType" => array("<don't show this condition for this input types>"),
        "parameter" => array("<labelParameter1>", "<labelParameter2>"...)
);

The Parameter value could also be an integer. The Parameters won't shown any label in this case.

The JavaScript function get there parameter:

  • key For future use (At the moment it is “resultField”)
  • value the value of the field
  • record all values of the complete record (Only available in DetailView)
  • parameter : numeric array of parameters, you could define in administration
  • dynamic Is this check is done after “ajax-edit” (true) or after pageload (false)?

Availables values for blockType: boolean, string, picklist

Examples from core.inc.php:

$formatCondition["is_empty"] = array("function" => "
		if(key == 'resultField' && (value == '0' || !value || 0 === value.length || value == '0000-00-00'))
			return true; 
		else 
			return false;
		",
        "title" => "is empty",
		"description" => "Colorize if field is empty",
        "blockType" => array("boolean"),
		"parameter" => 0
);
$formatCondition["is_not_empty"] = array("function" => "
		if(key == 'resultField' && value != null && value != '' && value != '0' && 0 !== value.length)
			return true; 
		else 
			return false;
		",
        "title" => "is not empty",
		"description" => "Colorize if field is not empty",
        "blockType" => array("boolean"),
		"parameter" => 0
);
$formatCondition["is_bigger"] = array("function" => "
        if(jQuery.isNumeric(value))
            value = Number(value);
 
		if(key == 'resultField' && value > parameter[0])
			return true; 
		else 
			return false;
		",
        "title" => "is bigger",
        "blockType" => array("boolean"),
		"description" => "Colorize if field is bigger",
		"parameter" => array("bigger then")
);
$formatCondition["is_lower"] = array("function" => "
        if(jQuery.isNumeric(value))
            value = Number(value);
 
		if(key == 'resultField' && value < parameter[0])
			return true; 
		else 
			return false;
		",
        "title" => "is lower",
        "blockType" => array("boolean"),
        "description" => "Colorize if field is lower",
		"parameter" => array("lower then")
);
 
$formatCondition["is_equal"] = array("function" => "
		if(key == 'resultField' && value == parameter[0])
			return true; 
		else 
			return false;
		",
        "title" => "is equal",
        "blockType" => array("boolean"),
        "description" => "Colorize if field is equal to the first parameter",
		"parameter" => array("Equal to"));
 
$formatCondition["is_not_equal"] = array("function" => "
		if(key == 'resultField' && value != parameter[0]) 
			return true; 
		else 
			return false;
		",
        "title" => "is not equal",
        "blockType" => array("boolean"),
        "description" => "Colorize if field is not equal to the first parameter",
		"parameter" => array("Not equal to"));
 
$formatCondition["within_x_days"] = array("function" => "
		if(value == null) return false;
		if(/[0-9]{4}-[0-9]{2}-[0-9]{2}/.test(value)) {
			var start = new Date(value);
		} else {
			if(value.indexOf(' ') != -1) { value = value.split(' ')[0]; }
 
			if((dynamic != undefined && dynamic == true) || (listView != undefined && listView == true)) {
				var valParts = splitDateVal(value);
				var start = new Date(valParts[2],valParts[1] - 1,valParts[0]);
			} else {
				var start = new Date(value);
			}
		}
 
        var end = new Date();
        var diff = new Date(start - end);
        var days = diff / 1000 / 60 / 60 / 24;
 
        if(days < parameter[0] && days > -1) {
            return true;
        } else {
            return false;
        }
        		",
        "title" => "is within X days",
        "blockType" => array("boolean"),
        "description" => "Colorize if the date is within ... days",
		"parameter" => array("within the next X days"));
$formatCondition["within_last_x_days"] = array("function" => "
		if(value == null) return false;
		if(/[0-9]{4}-[0-9]{2}-[0-9]{2}/.test(value)) {
			var start = new Date(value);
		} else {
			if(value.indexOf(' ') != -1) { value = value.split(' ')[0]; }
 
			if((dynamic != undefined && dynamic == true) || (listView != undefined && listView == true)) {
				var valParts = splitDateVal(value);
				var start = new Date(valParts[2],valParts[1] - 1,valParts[0]);
			} else {
				var start = new Date(value);
			}
		}
 
        var end = new Date();
        var diff = new Date(start - end);
        var days = diff / 1000 / 60 / 60 / 24;
 
        if(days > -1 * parameter[0] && days < -1) {
            return true;
        } else {
            return false;
        }
        		",
        "blockType" => array("boolean"),
        "title" => "is within last X days",
		"description" => "Colorize if the date is within last ... days",
		"parameter" => array("within the last X days"));
 
$formatCondition["is_futuredate"] = array("function" => "
		if(value == null) return false;
		if(/[0-9]{4}-[0-9]{2}-[0-9]{2}/.test(value)) {
			var start = new Date(value);
		} else {
			if(value.indexOf(' ') != -1) { value = value.split(' ')[0]; }
 
			if((dynamic != undefined && dynamic == true) || (listView != undefined && listView == true)) {
				var valParts = splitDateVal(value);
				var start = new Date(valParts[2],valParts[1] - 1,valParts[0]);
			} else {
				var start = new Date(value);
			}
		}
 
        var end = new Date();
        if(start > end) {
            return true;
        } else {
            return false;
        }
        		",
        "title" => "is date in future",
        "blockType" => array("boolean"),
        "description" => "Colorize if the date in in the future",
		"parameter" => 0);
$formatCondition["is_checked"] = array("function" => "
        if(value == 1)
            return true;
 
        return false;
        		",
        "title" => "is checked",
        "blockType" => array("picklist", "string"),
		"description" => "Check if Checkbox is checked",
		"parameter" => 0);
$formatCondition["contains"] = array("function" => "
    if(value.indexOf(parameter[0]) > -1)
        return true;
    else
        return false;
        		",
        "title" => "contains",
        "blockType" => array("boolean"),
		"description" => "colorize if String contains value",
		"parameter" => 1);
 
 
/* Example for own own functions */
/* 
// Parameters will be numbered from 1 till n
$colorCondition["is_equal"] = array("function" => "
		console.log(parameter[0]); console.log(value);
		if(key == 'resultField' && value == parameter[0]) 
			return true; 
		else 
			return false;
		", 
		"description" => "Colorize if field is equal to the first parameter",
		"parameter" => 1);
 
// Parameters will be named by description ("Equal to:")		
$colorCondition["is_equal2"] = array("function" => "
		if(key == 'resultField' && value == parameter[0]) 
			return true; 
		else 
			return false;
		", 
		"description" => "Colorize if field is equal to the first parameter",
		"parameter" => array("Equal to"));
*/
Enter your comment. Wiki syntax is allowed:
 ______  ____   __  __  ____    __  ___
/_  __/ / __ \ / / / / / __ \  /  |/  /
 / /   / /_/ // /_/ / / /_/ / / /|_/ / 
/_/    \___\_\\____/  \____/ /_/  /_/