1
|
|
|
<?php |
2
|
|
|
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
3
|
|
|
|
4
|
|
|
/********************************************************************************* |
5
|
|
|
* SugarCRM Community Edition is a customer relationship management program developed by |
6
|
|
|
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
7
|
|
|
|
8
|
|
|
* SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
9
|
|
|
* Copyright (C) 2011 - 2014 Salesagility Ltd. |
10
|
|
|
* |
11
|
|
|
* This program is free software; you can redistribute it and/or modify it under |
12
|
|
|
* the terms of the GNU Affero General Public License version 3 as published by the |
13
|
|
|
* Free Software Foundation with the addition of the following permission added |
14
|
|
|
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
15
|
|
|
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
16
|
|
|
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
17
|
|
|
* |
18
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
19
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
20
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
21
|
|
|
* details. |
22
|
|
|
* |
23
|
|
|
* You should have received a copy of the GNU Affero General Public License along with |
24
|
|
|
* this program; if not, see http://www.gnu.org/licenses or write to the Free |
25
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
26
|
|
|
* 02110-1301 USA. |
27
|
|
|
* |
28
|
|
|
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
29
|
|
|
* SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
30
|
|
|
* |
31
|
|
|
* The interactive user interfaces in modified source and object code versions |
32
|
|
|
* of this program must display Appropriate Legal Notices, as required under |
33
|
|
|
* Section 5 of the GNU Affero General Public License version 3. |
34
|
|
|
* |
35
|
|
|
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
36
|
|
|
* these Appropriate Legal Notices must retain the display of the "Powered by |
37
|
|
|
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
38
|
|
|
* reasonably feasible for technical reasons, the Appropriate Legal Notices must |
39
|
|
|
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
40
|
|
|
********************************************************************************/ |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
require_once("include/templates/Template.php"); |
44
|
|
|
|
45
|
|
|
class TemplateDragDropChooser extends Template { |
46
|
|
|
var $args; |
47
|
|
|
function __construct() { |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead |
52
|
|
|
*/ |
53
|
|
|
function TemplateDragDropChooser(){ |
54
|
|
|
$deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code'; |
55
|
|
|
if(isset($GLOBALS['log'])) { |
56
|
|
|
$GLOBALS['log']->deprecated($deprecatedMessage); |
57
|
|
|
} |
58
|
|
|
else { |
59
|
|
|
trigger_error($deprecatedMessage, E_USER_DEPRECATED); |
60
|
|
|
} |
61
|
|
|
self::__construct(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/* |
66
|
|
|
* This function creates the html and uses the args parameter to call the class file |
67
|
|
|
* ideally, you would want to call the displayScriptTags() function, |
68
|
|
|
* followed by the displayDefinitionScript(); |
69
|
|
|
* and lastly call the display function |
70
|
|
|
*/ |
71
|
|
|
function display(){ |
72
|
|
|
|
73
|
|
|
/* valid entries for expected arguments array are as follow: |
74
|
|
|
* args['left_header'] = value of left table header |
75
|
|
|
* args['mid_header'] = value of middle table header |
76
|
|
|
* args['right_header'] = value of right table header |
77
|
|
|
* args['left_data'] = array to use in left data. |
78
|
|
|
* args['mid_data'] = array to use in middle data. |
79
|
|
|
* args['right_data'] =array to use in right data. |
80
|
|
|
* args['title'] = title (if any) to be used. |
81
|
|
|
* args['classname'] = name to be used as class. This helps when defining multiple templates on one screen. |
82
|
|
|
* args['left_div_name'] = Name to be used for left div (should be unique) |
83
|
|
|
* args['mid_div_name'] = Name to be used for middle div (should be unique) |
84
|
|
|
* args['right_div_name'] = Name to be used for right div (should be unique) |
85
|
|
|
* args['gridcount'] = Number of grids to show. Acceptable Values are 'one','two' and 'three' |
86
|
|
|
* The string is converted to numeric values, so you could also set these directly |
87
|
|
|
* The values are Zero Based, so to display one column, set to '0' |
88
|
|
|
* To display two columns set to '1', to display three columns set to '2'. |
89
|
|
|
* $this->args['return_array']= if this is set to true, then 'display()' function returns html and javascript |
90
|
|
|
* in array format. This will allow granular control of html so that you can |
91
|
|
|
* separate the tables and customize the grid |
92
|
|
|
*/ |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
//convert values for gridcount in case they are in string form |
96
|
|
|
if($this->args['gridcount'] == 'one'){ |
97
|
|
|
$this->args['gridcount'] = 0; |
98
|
|
|
}elseif($this->args['gridcount'] == 'two'){ |
99
|
|
|
$this->args['gridcount'] = 1; |
100
|
|
|
}elseif( |
101
|
|
|
$this->args['gridcount'] == 'three'){$this->args['gridcount'] = 2; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if(!isset($this->args['classname']) || empty($this->args['classname'])){ |
105
|
|
|
$this->args['classname'] = 'DragDropGrid'; |
106
|
|
|
} |
107
|
|
|
$json = getJSONobj(); |
108
|
|
|
//use Json to encode the arrays of data, for passing to javascript. |
109
|
|
|
//we will always display at least one column, so set left column |
110
|
|
|
$this->args['left_data'][] = array(' ', ' '); |
111
|
|
|
$data0_enc = $json->encode($this->args['left_data']); |
112
|
|
|
$left_div_name = $this->args['left_div_name']; |
113
|
|
|
|
114
|
|
|
//if count is set to 1, then we are displaying two columns, set the 2 column variables |
115
|
|
|
if($this->args['gridcount']==1){ |
116
|
|
|
$this->args['right_data'][] = array(' ', ' '); |
117
|
|
|
$data1_enc = $json->encode($this->args['right_data']); |
118
|
|
|
$right_div_name = $this->args['right_div_name']; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
//if count is set to 2, then we are displaying three columns, set the 3 column variables |
122
|
|
|
if($this->args['gridcount']==2){ |
123
|
|
|
$this->args['mid_data'][] = array(' ', ' '); |
124
|
|
|
$data1_enc = $json->encode($this->args['mid_data']); |
125
|
|
|
$mid_div_name = $this->args['mid_div_name']; |
126
|
|
|
$this->args['right_data'][] = array(' ', ' '); |
127
|
|
|
$data2_enc = $json->encode($this->args['right_data']); |
128
|
|
|
$right_div_name = $this->args['right_div_name']; |
129
|
|
|
} |
130
|
|
|
$html_str_arr = array(); |
131
|
|
|
//create the table, with the divs that will get populated. Populate both the string and array version |
132
|
|
|
$html_str = "<div id='" . $this->args['classname'] . "'><table align='left' width='180px' border='1' cellspacing='0' cellpadding='0'>"; |
133
|
|
|
$html_str_arr['begin'] = $html_str; |
134
|
|
|
$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>"; |
135
|
|
|
$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>"; |
136
|
|
|
//set the middle column only if we are displaying 3 columns |
137
|
|
|
if($this->args['gridcount']==2){ |
138
|
|
|
$html_str .= "<td width='180px' class='tabDetailViewDF'><div id='$mid_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>"; |
139
|
|
|
$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>"; |
140
|
|
|
} |
141
|
|
|
//set the right column if we are not in 1 column only mode |
142
|
|
|
if($this->args['gridcount']>0){ |
143
|
|
|
$html_str .= "<td width='180px' class='tabDetailViewDF'><div id='$right_div_name' class='ygrid-mso' style='width:180px;height:270px;overflow:hidden;'> </div></td>"; |
144
|
|
|
$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>"; |
145
|
|
|
} |
146
|
|
|
$html_str .= "</tr></table></div>"; |
147
|
|
|
$html_str_arr['end'] = "</tr></table></div>"; |
148
|
|
|
|
149
|
|
|
//create the needed javascript to set the values and invoke listener |
150
|
|
|
$j_str = "<script> "; |
151
|
|
|
$j_str .= $this->args['classname'] . ".rows0 = {$data0_enc};\n"; |
152
|
|
|
$j_str .= $this->args['classname'] . ".hdr0 = '{$this->args['left_header']}';\n"; |
153
|
|
|
if($this->args['gridcount']==1){ |
154
|
|
|
$j_str .= $this->args['classname'] . ".rows1 = {$data1_enc};\n"; |
155
|
|
|
$j_str .= $this->args['classname'] . ".hdr1 = '{$this->args['right_header']}';\n"; |
156
|
|
|
} |
157
|
|
|
if($this->args['gridcount']==2){ |
158
|
|
|
$j_str .= $this->args['classname'] . ".rows1 = {$data1_enc}; \n"; |
159
|
|
|
$j_str .= $this->args['classname'] . ".rows2 = {$data2_enc}; \n"; |
160
|
|
|
$j_str .= $this->args['classname'] . ".hdr1 = '{$this->args['mid_header']}'; \n"; |
161
|
|
|
$j_str .= $this->args['classname'] . ".hdr2 = '{$this->args['right_header']}'; \n"; |
162
|
|
|
} |
163
|
|
|
$divs_str = "'".$left_div_name ."'"; |
164
|
|
|
if($this->args['gridcount']==2){$divs_str .= ", '".$mid_div_name."'";} |
165
|
|
|
if($this->args['gridcount']>0) {$divs_str .= ", '".$right_div_name."'";} |
166
|
|
|
|
167
|
|
|
$j_str .= $this->args['classname'] . ".divs = [$divs_str]; "; |
168
|
|
|
|
169
|
|
|
$j_str .= "YAHOO.util.Event.on(window, 'load', " . $this->args['classname'] . ".init); "; |
170
|
|
|
$j_str .= "</script> "; |
171
|
|
|
//return display string |
172
|
|
|
$str = $j_str . ' ' . $html_str; |
173
|
|
|
$html_str_arr['script'] = $j_str; |
174
|
|
|
|
175
|
|
|
if(isset($this->args['return_array']) && $this->args['return_array']){ |
176
|
|
|
return $html_str_arr; |
177
|
|
|
}else{ |
178
|
|
|
return $str; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/* |
183
|
|
|
* This script is the javascript class definition for the template drag drop object. This |
184
|
|
|
* makes use of the args['classname'] parameter to name the class and to prefix variables with. This is done |
185
|
|
|
* dynamically so that multiple template dragdrop objects can be defined on the same page if needed |
186
|
|
|
* without having the variables mix up as you drag rows around. |
187
|
|
|
*/ |
188
|
|
|
function displayDefinitionScript() { |
189
|
|
|
//create some defaults in case arguments are missing |
190
|
|
|
|
191
|
|
|
//convert values for gridcount in case they are in string form |
192
|
|
|
if(!isset($this->args['gridcount']) || empty($this->args['gridcount']) || $this->args['gridcount'] == 'one'){ |
193
|
|
|
$this->args['gridcount'] = 0; |
194
|
|
|
}elseif($this->args['gridcount'] == 'two'){ |
195
|
|
|
$this->args['gridcount'] = 1; |
196
|
|
|
}elseif( |
197
|
|
|
$this->args['gridcount'] == 'three'){$this->args['gridcount'] = 2; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
|
202
|
|
|
//default class name |
203
|
|
|
if(!isset($this->args['classname']) || empty($this->args['classname'])){ |
204
|
|
|
$this->args['classname'] = 'DragDropGrid'; |
205
|
|
|
} |
206
|
|
|
//default columns to one if the value is set to anything other than the expected 0,1 or 2 |
207
|
|
|
if(($this->args['gridcount'] != 0) && ($this->args['gridcount'] != 1) && ($this->args['gridcount'] != 2)){ |
208
|
|
|
$this->args['gridcount'] = 0; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
//default div names |
212
|
|
|
if(!isset($this->args['left_div_name']) || empty($this->args['left_div_name'])){ |
213
|
|
|
$this->args['left_div_name'] = 'left'; |
214
|
|
|
} |
215
|
|
|
if(!isset($this->args['mid_div_name']) || empty($this->args['mid_div_name'])){ |
216
|
|
|
$this->args['mid_div_name'] = 'mid'; |
217
|
|
|
} |
218
|
|
|
if(!isset($this->args['right_div_name']) || empty($this->args['right_div_name'])){ |
219
|
|
|
$this->args['right_div_name'] = 'right'; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
|
223
|
|
|
|
224
|
|
|
//create javascript that defines the javascript class for this instance |
225
|
|
|
//start by defining the variables that the grids will be referenced by |
226
|
|
|
$j_str = " |
227
|
|
|
<script> |
228
|
|
|
var container = new YAHOO.util.Element('grid_Div').addClass('yui-skin-sam'); |
229
|
|
|
var " . $this->args['classname'] . "_grid2, " . $this->args['classname'] . "_grid1, " . $this->args['classname'] . "_grid0; |
230
|
|
|
var " . $this->args['classname'] . "_sugar_grid2, " . $this->args['classname'] . "_sugar_grid1, " . $this->args['classname'] . "_sugar_grid0; |
231
|
|
|
|
232
|
|
|
/* |
233
|
|
|
* This invokes the grid objects |
234
|
|
|
*/ |
235
|
|
|
|
236
|
|
|
" . $this->args['classname'] . " = {" ; |
237
|
|
|
$j_str .= " |
238
|
|
|
rows0 : [], |
239
|
|
|
rows1 : [], |
240
|
|
|
rows2 : [], |
241
|
|
|
hdr0 : [], |
242
|
|
|
hdr1 : [], |
243
|
|
|
hdr2 : [], |
244
|
|
|
divs : [], |
245
|
|
|
formatter : function(elCell, oRecord, oColumn, oData) { |
246
|
|
|
if (oRecord.getData()[0] == ' ' ) { |
247
|
|
|
return; |
248
|
|
|
} |
249
|
|
|
elCell.innerHTML = '<span id=\"' + oRecord.getData()[1] + '_row\">' + oRecord.getData()[0] + '</span>'; |
250
|
|
|
}, |
251
|
|
|
// bug50219 - added sorting for field labels |
252
|
|
|
customSort: function( a , b , desc , field ) { |
253
|
|
|
var comp = YAHOO.util.Sort.compare; |
254
|
|
|
var aString = a._oData[0].replace(/<[^>]*>/g, ''); |
255
|
|
|
var bString = b._oData[0].replace(/<[^>]*>/g, ''); |
256
|
|
|
return comp(aString, bString, desc); |
257
|
|
|
}, |
258
|
|
|
init : function(){ |
259
|
|
|
"; |
260
|
|
|
$count = 0; |
261
|
|
|
while($count<$this->args['gridcount']+1){ |
262
|
|
|
// bug50219 Set up default strings for sortable grids |
263
|
|
|
$sortParams = "sortable: false"; |
264
|
|
|
// set strings to sortable if it is SUGAR_GRID_grid0 |
265
|
|
|
if( $count == 0 ) { |
266
|
|
|
$sortParams = "sortable: true, sortOptions:{sortFunction: {$this->args['classname']}.customSort} "; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
$j_str .= " |
270
|
|
|
{$this->args['classname']}_grid{$count}source = new YAHOO.util.LocalDataSource({$this->args['classname']}.rows$count); |
271
|
|
|
{$this->args['classname']}_grid{$count}cols = [ |
272
|
|
|
{key:'label', {$sortParams} , label:{$this->args['classname']}.hdr$count, formatter: {$this->args['classname']}.formatter} |
273
|
|
|
]; |
274
|
|
|
{$this->args['classname']}_grid$count = new YAHOO.SUGAR.DragDropTable( |
275
|
|
|
{$this->args['classname']}.divs[$count], {$this->args['classname']}_grid{$count}cols, {$this->args['classname']}_grid{$count}source, |
276
|
|
|
{ |
277
|
|
|
trackMouseOver: false, |
278
|
|
|
height: '250px' |
279
|
|
|
} |
280
|
|
|
);"; |
281
|
|
|
|
282
|
|
|
$j_str .= " |
283
|
|
|
{$this->args['classname']}_sugar_grid$count = {$this->args['classname']}_grid$count;"; |
284
|
|
|
|
285
|
|
|
$count = $count+1; |
286
|
|
|
} |
287
|
|
|
$j_str.=" |
288
|
|
|
} |
289
|
|
|
}; |
290
|
|
|
|
291
|
|
|
</script> |
292
|
|
|
"; |
293
|
|
|
//all done, return final script |
294
|
|
|
return $j_str; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
|
298
|
|
|
/* |
299
|
|
|
* this function returns the src style sheet and script tags that need to be included |
300
|
|
|
* for the template chooser to work |
301
|
|
|
*/ |
302
|
|
|
|
303
|
|
|
function displayScriptTags() { |
304
|
|
|
global $sugar_version, $sugar_config; |
305
|
|
|
$j_str = " |
306
|
|
|
<link rel='stylesheet' type='text/css' href='include/javascript/yui/build/datatable/assets/skins/sam/datatable.css'/> |
307
|
|
|
<script type='text/javascript' src='cache/include/javascript/sugar_grp_yui_widgets.js'></script>"; |
308
|
|
|
|
309
|
|
|
return $j_str; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
?> |
315
|
|
|
|