args['return_array']= if this is set to true, then 'display()' function returns html and javascript
* in array format. This will allow granular control of html so that you can
* seperate the tables and customize the grid
*/
//convert values for gridcount in case they are in string form
if($this->args['gridcount'] == 'one'){
$this->args['gridcount'] = 0;
}elseif($this->args['gridcount'] == 'two'){
$this->args['gridcount'] = 1;
}elseif(
$this->args['gridcount'] == 'three'){$this->args['gridcount'] = 2;
}
if(!isset($this->args['classname']) || empty($this->args['classname'])){
$this->args['classname'] = 'DragDropGrid';
}
$json = getJSONobj();
//use Json to encode the arrays of data, for passing to javascript.
//we will always display at least one column, so set left column
$this->args['left_data'][] = array(' ', ' ');
$data0_enc = $json->encode($this->args['left_data']);
$left_div_name = $this->args['left_div_name'];
//if count is set to 1, then we are displaying two columns, set the 2 column variables
if($this->args['gridcount']==1){
$this->args['right_data'][] = array(' ', ' ');
$data1_enc = $json->encode($this->args['right_data']);
$right_div_name = $this->args['right_div_name'];
}
//if count is set to 2, then we are displaying three columns, set the 3 column variables
if($this->args['gridcount']==2){
$this->args['mid_data'][] = array(' ', ' ');
$data1_enc = $json->encode($this->args['mid_data']);
$mid_div_name = $this->args['mid_div_name'];
$this->args['right_data'][] = array(' ', ' ');
$data2_enc = $json->encode($this->args['right_data']);
$right_div_name = $this->args['right_div_name'];
}
$html_str_arr = array();
//create the table, with the divs that will get populated. Populate both the string and array version
$html_str = "
";
//set the middle column only if we are displaying 3 columns
if($this->args['gridcount']==2){
$html_str .= "
";
$html_str_arr['middle'] = "
";
}
//set the right column if we are not in 1 column only mode
if($this->args['gridcount']>0){
$html_str .= "
";
$html_str_arr['right'] = "
";
}
$html_str .= "
";
$html_str_arr['end'] = "";
//create the needed javascript to set the values and invoke listener
$j_str = " ";
//return display string
$str = $j_str . ' ' . $html_str;
$html_str_arr['script'] = $j_str;
if(isset($this->args['return_array']) && $this->args['return_array']){
return $html_str_arr;
}else{
return $str;
}
}
/*
* This script is the javascript class definition for the template drag drop object. This
* makes use of the args['classname'] parameter to name the class and to prefix variables with. This is done
* dynamically so that multiple template dragdrop objects can be defined on the same page if needed
* without having the variables mix up as you drag rows around.
*/
function displayDefinitionScript() {
//create some defaults in case arguments are missing
//convert values for gridcount in case they are in string form
if(!isset($this->args['gridcount']) || empty($this->args['gridcount']) || $this->args['gridcount'] == 'one'){
$this->args['gridcount'] = 0;
}elseif($this->args['gridcount'] == 'two'){
$this->args['gridcount'] = 1;
}elseif(
$this->args['gridcount'] == 'three'){$this->args['gridcount'] = 2;
}
//default class name
if(!isset($this->args['classname']) || empty($this->args['classname'])){
$this->args['classname'] = 'DragDropGrid';
}
//default columns to one if the value is set to anything other than the expected 0,1 or 2
if(($this->args['gridcount'] != 0) && ($this->args['gridcount'] != 1) && ($this->args['gridcount'] != 2)){
$this->args['gridcount'] = 0;
}
//default div names
if(!isset($this->args['left_div_name']) || empty($this->args['left_div_name'])){
$this->args['left_div_name'] = 'left';
}
if(!isset($this->args['mid_div_name']) || empty($this->args['mid_div_name'])){
$this->args['mid_div_name'] = 'mid';
}
if(!isset($this->args['right_div_name']) || empty($this->args['right_div_name'])){
$this->args['right_div_name'] = 'right';
}
//create javascript that defines the javascript class for this instance
//start by defining the variables that the grids will be referenced by
$j_str = "
";
//all done, return final script
return $j_str;
}
/*
* this function returns the src style sheet and script tags that need to be included
* for the template chooser to work
*/
function displayScriptTags() {
global $sugar_version, $sugar_config;
$j_str = "
";
return $j_str;
}
}
?>