2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
4 /*********************************************************************************
5 * SugarCRM is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
40 require_once("include/templates/Template.php");
42 class TemplateDragDropChooser extends Template {
44 function TemplateDragDropChooser() {
48 * This function creates the html and uses the args parameter to call the class file
49 * ideally, you would want to call the displayScriptTags() function,
50 * followed by the displayDefinitionScript();
51 * and lastly call the display function
55 /* valid entries for expected arguments array are as follow:
56 * args['left_header'] = value of left table header
57 * args['mid_header'] = value of middle table header
58 * args['right_header'] = value of right table header
59 * args['left_data'] = array to use in left data.
60 * args['mid_data'] = array to use in middle data.
61 * args['right_data'] =array to use in right data.
62 * args['title'] = title (if any) to be used.
63 * args['classname'] = name to be used as class. This helps when defining multiple templates on one screen.
64 * args['left_div_name'] = Name to be used for left div (should be unique)
65 * args['mid_div_name'] = Name to be used for middle div (should be unique)
66 * args['right_div_name'] = Name to be used for right div (should be unique)
67 * args['gridcount'] = Number of grids to show. Acceptable Values are 'one','two' and 'three'
68 * The string is converted to numeric values, so you could also set these directly
69 * The values are Zero Based, so to display one column, set to '0'
70 * To display two columns set to '1', to display three columns set to '2'.
71 * $this->args['return_array']= if this is set to true, then 'display()' function returns html and javascript
72 * in array format. This will allow granular control of html so that you can
73 * seperate the tables and customize the grid
77 //convert values for gridcount in case they are in string form
78 if($this->args['gridcount'] == 'one'){
79 $this->args['gridcount'] = 0;
80 }elseif($this->args['gridcount'] == 'two'){
81 $this->args['gridcount'] = 1;
83 $this->args['gridcount'] == 'three'){$this->args['gridcount'] = 2;
86 if(!isset($this->args['classname']) || empty($this->args['classname'])){
87 $this->args['classname'] = 'DragDropGrid';
90 //use Json to encode the arrays of data, for passing to javascript.
91 //we will always display at least one column, so set left column
92 $this->args['left_data'][] = array(' ', ' ');
93 $data0_enc = $json->encode($this->args['left_data']);
94 $left_div_name = $this->args['left_div_name'];
96 //if count is set to 1, then we are displaying two columns, set the 2 column variables
97 if($this->args['gridcount']==1){
98 $this->args['right_data'][] = array(' ', ' ');
99 $data1_enc = $json->encode($this->args['right_data']);
100 $right_div_name = $this->args['right_div_name'];
103 //if count is set to 2, then we are displaying three columns, set the 3 column variables
104 if($this->args['gridcount']==2){
105 $this->args['mid_data'][] = array(' ', ' ');
106 $data1_enc = $json->encode($this->args['mid_data']);
107 $mid_div_name = $this->args['mid_div_name'];
108 $this->args['right_data'][] = array(' ', ' ');
109 $data2_enc = $json->encode($this->args['right_data']);
110 $right_div_name = $this->args['right_div_name'];
112 $html_str_arr = array();
113 //create the table, with the divs that will get populated. Populate both the string and array version
114 $html_str = "<div id='" . $this->args['classname'] . "'><table align='left' width='180px' border='1' cellspacing='0' cellpadding='0'>";
115 $html_str_arr['begin'] = $html_str;
116 $html_str .= "<tr><td width='180px' class='tabDetailViewDF'><div id='$left_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>";
117 $html_str_arr['left'] = "<tr><td width='180px' class='tabDetailViewDF'><div id='$left_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>";
118 //set the middle column only if we are displaying 3 columns
119 if($this->args['gridcount']==2){
120 $html_str .= "<td width='180px' class='tabDetailViewDF'><div id='$mid_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>";
121 $html_str_arr['middle'] = "<td width='180px' class='tabDetailViewDF'><div id='$mid_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>";
123 //set the right column if we are not in 1 column only mode
124 if($this->args['gridcount']>0){
125 $html_str .= "<td width='180px' class='tabDetailViewDF'><div id='$right_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>";
126 $html_str_arr['right'] = "<td width='180px' class='tabDetailViewDF'><div id='$right_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>";
128 $html_str .= "</tr></table></div>";
129 $html_str_arr['end'] = "</tr></table></div>";
131 //create the needed javascript to set the values and invoke listener
132 $j_str = "<script> ";
133 $j_str .= $this->args['classname'] . ".rows0 = {$data0_enc};\n";
134 $j_str .= $this->args['classname'] . ".hdr0 = '{$this->args['left_header']}';\n";
135 if($this->args['gridcount']==1){
136 $j_str .= $this->args['classname'] . ".rows1 = {$data1_enc};\n";
137 $j_str .= $this->args['classname'] . ".hdr1 = '{$this->args['right_header']}';\n";
139 if($this->args['gridcount']==2){
140 $j_str .= $this->args['classname'] . ".rows1 = {$data1_enc}; \n";
141 $j_str .= $this->args['classname'] . ".rows2 = {$data2_enc}; \n";
142 $j_str .= $this->args['classname'] . ".hdr1 = '{$this->args['mid_header']}'; \n";
143 $j_str .= $this->args['classname'] . ".hdr2 = '{$this->args['right_header']}'; \n";
145 $divs_str = "'".$left_div_name ."'";
146 if($this->args['gridcount']==2){$divs_str .= ", '".$mid_div_name."'";}
147 if($this->args['gridcount']>0) {$divs_str .= ", '".$right_div_name."'";}
149 $j_str .= $this->args['classname'] . ".divs = [$divs_str]; ";
151 $j_str .= "YAHOO.util.Event.on(window, 'load', " . $this->args['classname'] . ".init); ";
152 $j_str .= "</script> ";
153 //return display string
154 $str = $j_str . ' ' . $html_str;
155 $html_str_arr['script'] = $j_str;
157 if(isset($this->args['return_array']) && $this->args['return_array']){
158 return $html_str_arr;
165 * This script is the javascript class definition for the template drag drop object. This
166 * makes use of the args['classname'] parameter to name the class and to prefix variables with. This is done
167 * dynamically so that multiple template dragdrop objects can be defined on the same page if needed
168 * without having the variables mix up as you drag rows around.
170 function displayDefinitionScript() {
171 //create some defaults in case arguments are missing
173 //convert values for gridcount in case they are in string form
174 if(!isset($this->args['gridcount']) || empty($this->args['gridcount']) || $this->args['gridcount'] == 'one'){
175 $this->args['gridcount'] = 0;
176 }elseif($this->args['gridcount'] == 'two'){
177 $this->args['gridcount'] = 1;
179 $this->args['gridcount'] == 'three'){$this->args['gridcount'] = 2;
185 if(!isset($this->args['classname']) || empty($this->args['classname'])){
186 $this->args['classname'] = 'DragDropGrid';
188 //default columns to one if the value is set to anything other than the expected 0,1 or 2
189 if(($this->args['gridcount'] != 0) && ($this->args['gridcount'] != 1) && ($this->args['gridcount'] != 2)){
190 $this->args['gridcount'] = 0;
194 if(!isset($this->args['left_div_name']) || empty($this->args['left_div_name'])){
195 $this->args['left_div_name'] = 'left';
197 if(!isset($this->args['mid_div_name']) || empty($this->args['mid_div_name'])){
198 $this->args['mid_div_name'] = 'mid';
200 if(!isset($this->args['right_div_name']) || empty($this->args['right_div_name'])){
201 $this->args['right_div_name'] = 'right';
206 //create javascript that defines the javascript class for this instance
207 //start by defining the variables that the grids will be referenced by
210 var container = new YAHOO.util.Element('grid_Div').addClass('yui-skin-sam');
211 var " . $this->args['classname'] . "_grid2, " . $this->args['classname'] . "_grid1, " . $this->args['classname'] . "_grid0;
212 var " . $this->args['classname'] . "_sugar_grid2, " . $this->args['classname'] . "_sugar_grid1, " . $this->args['classname'] . "_sugar_grid0;
215 * This invokes the grid objects
218 " . $this->args['classname'] . " = {" ;
227 formatter : function(elCell, oRecord, oColumn, oData) {
228 if (oRecord.getData()[0] == ' ' ) {
231 elCell.innerHTML = '<span id=\"' + oRecord.getData()[1] + '_row\">' + oRecord.getData()[0] + '</span>';
236 while($count<$this->args['gridcount']+1){
238 {$this->args['classname']}_grid{$count}source = new YAHOO.util.LocalDataSource({$this->args['classname']}.rows$count);
239 {$this->args['classname']}_grid{$count}cols = [
240 {key:'label', label:{$this->args['classname']}.hdr$count, formatter: {$this->args['classname']}.formatter}
242 {$this->args['classname']}_grid$count = new YAHOO.SUGAR.DragDropTable(
243 {$this->args['classname']}.divs[$count], {$this->args['classname']}_grid{$count}cols, {$this->args['classname']}_grid{$count}source,
245 trackMouseOver: false,
251 {$this->args['classname']}_sugar_grid$count = {$this->args['classname']}_grid$count;";
261 //all done, return final script
267 * this function returns the src style sheet and script tags that need to be included
268 * for the template chooser to work
271 function displayScriptTags() {
272 global $sugar_version, $sugar_config;
274 <link rel='stylesheet' type='text/css' href='include/javascript/yui/build/datatable/assets/skins/sam/datatable.css'/>
275 <script type='text/javascript' src='".getJSPath("include/javascript/sugar_grp_yui_widgets.js")."'></script>";